Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3426 linux chrome credentials collector #3665

Merged
merged 13 commits into from
Sep 12, 2023

Conversation

ilija-lazoroski
Copy link
Contributor

What does this PR do?

Fixes #put issue number here.

Add any further explanations here.

PR Checklist

  • Have you added an explanation of what your changes do and why you'd like to include them?
  • Is the TravisCI build passing?
  • Was the CHANGELOG.md updated to reflect the changes?
  • Was the documentation framework updated to reflect the changes?
  • Have you checked that you haven't introduced any duplicate code?

Testing Checklist

  • Added relevant unit tests?
  • Do all unit tests pass?
  • Do all end-to-end tests pass?
  • Any other testing performed?

    Tested by {Running the Monkey locally with relevant config/running Island/...}

  • If applicable, add screenshots or log transcripts of the feature working

@ilija-lazoroski ilija-lazoroski changed the title 3426 linux chrom credentials collector 3426 linux chrome credentials collector Sep 7, 2023
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we copied this from somewhere, make sure we include the original author, source repository link, and license information at the top.

Copy link
Collaborator

@mssalvatore mssalvatore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this PR is too big. Rebase and then split into smaller PRs. Suggestion: 1 for collector and one for processor.

@cakekoa cakekoa force-pushed the 3426-linux-chrom-credentials-collector branch 2 times, most recently from b195cdc to f978052 Compare September 7, 2023 17:07
@cakekoa cakekoa marked this pull request as ready for review September 7, 2023 18:11
@ilija-lazoroski ilija-lazoroski force-pushed the 3426-linux-chrom-credentials-collector branch 2 times, most recently from 1f6c3e3 to 238959f Compare September 11, 2023 12:55
@ilija-lazoroski ilija-lazoroski changed the base branch from develop to 3426-windows-credentials-database-selector September 11, 2023 13:55
@cakekoa cakekoa force-pushed the 3426-windows-credentials-database-selector branch 2 times, most recently from a817ceb to d6555c1 Compare September 11, 2023 19:55
@cakekoa cakekoa force-pushed the 3426-linux-chrom-credentials-collector branch from 17da9d8 to eb80534 Compare September 11, 2023 19:58
Copy link
Contributor

@shreyamalviya shreyamalviya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you test manually

Comment on lines 20 to 26
("Brave", ".config/BraveSoftware/Brave-Browser"),
("SlimJet", ".config/slimjet"),
("Dissenter Browser", ".config/GabAI/Dissenter-Browser"),
("Vivaldi", ".config/vivaldi"),
("Microsoft Edge (Dev)", ".config/microsoft-edge-dev"),
("Microsoft Edge (Beta)", ".config/microsoft-edge-beta"),
("Microsoft Edge", ".config/microsoft-edge"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all of these. We're only supporting Chrome and Chromium on Linux.

for browser_name, browser_path in CHROMIUM_BASED_DB_PATHS:
browser_db_path = home_dir_path / browser_path
try:
if self._directory_is_accessible(browser_db_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the processor's responsibility

Comment on lines 43 to 60
try:
sub_profile_dirs = profile_dir_path.iterdir()
for subdir in sub_profile_dirs:
if subdir == (profile_dir_path / LOGIN_DATABASE_FILENAME):
if self._file_is_accessible(subdir):
login_data_paths.add(
BrowserCredentialsDatabasePath(
database_file_path=subdir, master_key=DEFAULT_MASTER_KEY
)
)

login_database_path = profile_dir_path / subdir / LOGIN_DATABASE_FILENAME
if self._file_is_accessible(login_database_path):
login_data_paths.add(
BrowserCredentialsDatabasePath(
database_file_path=login_database_path, master_key=DEFAULT_MASTER_KEY
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flake8 doesn't complain about complexity here?

)

login_database_path = profile_dir_path / subdir / LOGIN_DATABASE_FILENAME
if self._file_is_accessible(login_database_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the processor's responsibility

Comment on lines 44 to 60
sub_profile_dirs = profile_dir_path.iterdir()
for subdir in sub_profile_dirs:
if subdir == (profile_dir_path / LOGIN_DATABASE_FILENAME):
if self._file_is_accessible(subdir):
login_data_paths.add(
BrowserCredentialsDatabasePath(
database_file_path=subdir, master_key=DEFAULT_MASTER_KEY
)
)

login_database_path = profile_dir_path / subdir / LOGIN_DATABASE_FILENAME
if self._file_is_accessible(login_database_path):
login_data_paths.add(
BrowserCredentialsDatabasePath(
database_file_path=login_database_path, master_key=DEFAULT_MASTER_KEY
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems way more complex than it needs to be.
Just do:

sub_profile_dirs = profile_dir_path.iterdir()

if (profile_dir_path / LOGIN_DATABASE_FILENAME).exists():
    login_data_paths.add(...)

for subdir in sub_profile_dirs:
    login_database_path = profile_dir_path / subdir / LOGIN_DATABASE_FILENAME
    login_data_paths.add(...)

def __call__(self) -> Collection[BrowserCredentialsDatabasePath]:
return []
database_paths: Set[BrowserCredentialsDatabasePath] = set()
for profile_dir in self._get_browser_database_paths():
Copy link
Contributor

@shreyamalviya shreyamalviya Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paths being returned from self._get_browser_database_paths() are not profile directory paths. They're browser directory paths for each user on the system. The name profile_dir makes it seem like you're talking about the profiles in the browser.

)
)

login_database_path = profile_dir_path / subdir / LOGIN_DATABASE_FILENAME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all the files inside profile_dir_path only for the browser's user profiles? If no, this could add files to login_data_paths that aren't related to user profiles in any way.

Can't you just check the name of the directories and then add them to the set like we do for Windows? In Windows, we check for directories that start with "Profile".

@shreyamalviya shreyamalviya force-pushed the 3426-windows-credentials-database-selector branch from d6555c1 to 87662ba Compare September 12, 2023 08:55
@ilija-lazoroski ilija-lazoroski force-pushed the 3426-linux-chrom-credentials-collector branch from e25e9c8 to 12d09c3 Compare September 12, 2023 09:48
@shreyamalviya shreyamalviya force-pushed the 3426-windows-credentials-database-selector branch from 87662ba to 9f745a6 Compare September 12, 2023 11:24
@ilija-lazoroski ilija-lazoroski force-pushed the 3426-linux-chrom-credentials-collector branch from 92694a6 to b3e8df5 Compare September 12, 2023 11:34
Comment on lines 62 to 63
if home_path not in home_dirs.values():
home_dirs[os.getlogin()] = home_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check necessary?

Comment on lines 60 to 63
if "HOME" in os.environ:
home_path = Path(os.environ["HOME"])
if home_path not in home_dirs.values():
home_dirs[os.getlogin()] = home_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is any of this necessary?

Comment on lines 75 to 91
if (browser_database_path / LOGIN_DATABASE_FILENAME).exists():
login_data_paths.add(
BrowserCredentialsDatabasePath(
database_file_path=(browser_database_path / LOGIN_DATABASE_FILENAME),
master_key=DEFAULT_MASTER_KEY,
)
)

sub_browser_database_paths = browser_database_path.iterdir()
for subdir in sub_browser_database_paths:
login_database_path = browser_database_path / subdir / LOGIN_DATABASE_FILENAME
if login_database_path.exists():
login_data_paths.add(
BrowserCredentialsDatabasePath(
database_file_path=login_database_path, master_key=DEFAULT_MASTER_KEY
)
)
Copy link
Collaborator

@mssalvatore mssalvatore Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these conditions and all of the searching can just be replaced with a glob.

for database_file in browser_database_path.glob(f'**/{LOGIN_DATABASE_FILENAME}'):
    login_data_paths.add(...)

^ Not tested.

Base automatically changed from 3426-windows-credentials-database-selector to develop September 12, 2023 17:04
Comment on lines 59 to 63
home_dirs = {
p.pw_name: Path(p.pw_dir) for p in pwd.getpwall() # type: ignore[attr-defined]
}

return home_dirs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
home_dirs = {
p.pw_name: Path(p.pw_dir) for p in pwd.getpwall() # type: ignore[attr-defined]
}
return home_dirs
return {
p.pw_name: Path(p.pw_dir) for p in pwd.getpwall() # type: ignore[attr-defined]
}

try:
if browser_db_path.exists():
database_paths.append(browser_db_path)
except Exception as err:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exception can be raised here?

@ilija-lazoroski ilija-lazoroski force-pushed the 3426-linux-chrom-credentials-collector branch from 06512dd to d48dd12 Compare September 12, 2023 18:38
try:
login_data_paths = self._get_login_data_paths(browser_database_path)
database_paths.update(login_data_paths)
except Exception:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exception can be raised here? Would it be better handled within _get_login_data_paths() so that function doesn't short circuit?

if browser_db_path.exists():
database_paths.append(browser_db_path)
except Exception as err:
logger.exception(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logs at the error level. Does the average user really need an error message?

@ilija-lazoroski ilija-lazoroski force-pushed the 3426-linux-chrom-credentials-collector branch 3 times, most recently from 8f64dd5 to 7661839 Compare September 12, 2023 19:05
@ilija-lazoroski ilija-lazoroski force-pushed the 3426-linux-chrom-credentials-collector branch from 7661839 to 3d5f087 Compare September 12, 2023 19:12
@mssalvatore mssalvatore merged commit ef5b2fa into develop Sep 12, 2023
@mssalvatore mssalvatore deleted the 3426-linux-chrom-credentials-collector branch September 12, 2023 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants