Skip to content

Conversation

VakarisZ
Copy link
Contributor

@VakarisZ VakarisZ commented Jun 5, 2020

What is this?

Fixes #471 #583
Replaces mimikatz binary with pypykatz python module.
Hides credential map until we fix it.

Checklist

  • Tested changes locally
  • Tested changes on cloud: WMI pth tests, windows 2012/2016/2019 tests
  • Is the TravisCI build passing?

@codecov
Copy link

codecov bot commented Jun 5, 2020

Codecov Report

Merging #678 into develop will decrease coverage by 0.13%.
The diff coverage is 82.60%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #678      +/-   ##
===========================================
- Coverage    56.62%   56.49%   -0.14%     
===========================================
  Files          120      135      +15     
  Lines         4044     4381     +337     
===========================================
+ Hits          2290     2475     +185     
- Misses        1754     1906     +152     
Impacted Files Coverage Δ
monkey/infection_monkey/system_info/__init__.py 41.26% <0.00%> (ø)
...em_info/windows_cred_collector/pypykatz_handler.py 78.00% <78.00%> (ø)
...fo/windows_cred_collector/test_pypykatz_handler.py 100.00% <100.00%> (ø)
...info/windows_cred_collector/windows_credentials.py 100.00% <100.00%> (ø)
...y/infection_monkey/telemetry/attack/usage_telem.py 44.44% <0.00%> (ø)
monkey/common/network/test_segmentation_utils.py 100.00% <0.00%> (ø)
...y/infection_monkey/telemetry/attack/t1005_telem.py 40.00% <0.00%> (ø)
...ection_monkey/system_info/system_info_collector.py 70.58% <0.00%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33ef1f6...966599a. Read the comment docs.

Copy link
Contributor

@ShayNehmad ShayNehmad left a comment

Choose a reason for hiding this comment

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

This PR fills me with joy. konmari style 🧼🧽🧹

See my comment + If you're getting rid of PTH map in this PR as well, I think we should get rid of all related code

Comment on lines 423 to 426
<div style={{position: 'relative' /*, height: '80vh'*/}}>
{/*Disable PTH map until we fix it
this.generateReportPthMap()*/}
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to comment out code. Delete, git remembers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still not sure what's the best routine for this type of code. Just deleting and forcing future developer to search for this isn't the best solution. When future developer will try to implement pth map, he might not even be aware that this code existed.

Comment on lines 63 to 75
def get_mimikatz_info(self):
mimikatz_collector = MimikatzCollector()
mimikatz_info = mimikatz_collector.get_logon_info()
if mimikatz_info:
if "credentials" in self.info:
self.info["credentials"].update(mimikatz_info)
self.info["mimikatz"] = mimikatz_collector.get_mimikatz_text()
LOG.info('Mimikatz info gathered successfully')
else:
LOG.info('No mimikatz info was gathered')
LOG.info("Gathering mimikatz info")
try:
credentials = WindowsCredentialCollector.get_creds()
if credentials:
if "credentials" in self.info:
self.info["credentials"].update(credentials)
self.info["mimikatz"] = credentials
LOG.info('Mimikatz info gathered successfully')
else:
LOG.info('No mimikatz info was gathered')
except Exception as e:
LOG.info(f"Pypykatz failed: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace Mimikatz with pypykatz (or with a generic name that's not tied to a specific implementation) in the name, log, and info field name :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improving naming consistency is a valid point. Regarding renaming mimikatz to pypykatz - on high level it makes most sense to keep mimikatz, because it's well known and it's purpose is clear. On caller level (actual commented code) we don't care how mimikatz cred gathering is implemented, via dll or some kind of python module.

from typing import Dict


class WindowsCredential:
Copy link
Contributor

Choose a reason for hiding this comment

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

Credentials in considered a mass noun, so I think this class should be renamed to WindowsCredentialsSet (and WindowsCredentialCollector -> WindowsCredential**s**Collector)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm... Credential (singular) is a valid word (not like scissors for example). In terms of English, I agree. In terms of programming, a class or an object should be in singular form, plural implies an iterable.

Comment on lines 83 to 84
for test_dict in test_dicts:
self.assertTrue(test_dict in results)
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be mistaken but I think you can do this with assert set(test_dicts) <= set(results) which might be more efficient. Not critical at all, just a nice Pythonic way to do it 🐍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dicts are not hashable, so native dict can't be used in set. I converted it to even more pythonic way though :)

def cred_list_to_cred_dict(creds: List[WindowsCredential]):
cred_dict = {}
for cred in creds:
# Lets not use "." and "$" in keys, because it will confuse mongo.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still true?

starting in MongoDB 3.6, the server permits storage of field names that contain dots (i.e. .) and dollar signs (i.e. $)

From Mongo reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For pymongo - yes
image

Copy link
Contributor

@ShayNehmad ShayNehmad left a comment

Choose a reason for hiding this comment

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

LGTM

@VakarisZ VakarisZ merged commit 0ec5259 into develop Jun 8, 2020
@VakarisZ VakarisZ deleted the feature/pypykatz branch June 8, 2020 12:21
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.

Mimikatz dll outdated
2 participants