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

Add new SMB module to get the PowerShell history on all the users #341

Merged
merged 8 commits into from
Sep 24, 2024

Conversation

357384n
Copy link
Contributor

@357384n 357384n commented Jun 11, 2024

Hey,

I've added a pretty basic module to get the Powershell History of all the users on specified targets. Once get it the module will check some keywords that could contain credentials and display them.
You also can export the entire Powershell History with the following option: -o export=enable.
If you do that a file like {IP}.powershell_history.txt will be writen in your current path.

Running the module:
image

By default the export option is disable but can be very interesting during a pentest so if you want to manually analyze them juste do like below:

image

@NeffIsBack
Copy link
Contributor

Thanks for the PR!

357384n added 4 commits June 18, 2024 11:13
First commit 

Signed-off-by: Sébastien Miguel <43112303+357384n@users.noreply.github.com>
Add export feature and some keywords

Signed-off-by: Sébastien Miguel <43112303+357384n@users.noreply.github.com>
Add the path to output file in the output

Signed-off-by: Sébastien Miguel <43112303+357384n@users.noreply.github.com>
add description to module option

Signed-off-by: Sébastien Miguel <43112303+357384n@users.noreply.github.com>
Copy link
Contributor

@NeffIsBack NeffIsBack left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, great idea! :)

Please fix the ruff errors (check with poetry run ruff check . --preview). Most of them can be fixed by ruff itself: poetry run ruff check . --preview --fix

Working so far:
image

nxc/modules/powershell_history.py Outdated Show resolved Hide resolved
nxc/modules/powershell_history.py Outdated Show resolved Hide resolved
nxc/modules/powershell_history.py Outdated Show resolved Hide resolved
nxc/modules/powershell_history.py Outdated Show resolved Hide resolved
nxc/modules/powershell_history.py Outdated Show resolved Hide resolved
@NeffIsBack NeffIsBack added reviewed code Label for when a static code review was done tested labels Sep 1, 2024
@NeffIsBack NeffIsBack self-assigned this Sep 1, 2024
Mercury0 added a commit to Mercury0/NetExec that referenced this pull request Sep 12, 2024
Merged from NetExec PR Pennyw0rth#341

Custom changes from original submission:
- moved powershell history command and sensitive keywords to Class-level constants
- added reusable handle_error func to centralize error logging
- refactored export logic to use NXC_PATH
- added validation for connection to check if it's None before executing PowerShell command. Avoids downstream issues if connection is invalid.
- improved options parsing so boolean comparisons are case-insensitive
- removed analyze_history loop and replaced with list comprehension
- removed execute_command method, which was a wrapper for connection.execute(). connection.execute() is now called directly in get_powershell_history.


Signed-off-by: Mercury0 <mfox05@gmail.com>
Copy link
Contributor

@NeffIsBack NeffIsBack left a comment

Choose a reason for hiding this comment

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

Fixed some stuff, LGTM now:
image

@NeffIsBack
Copy link
Contributor

@357384n do you have a twitter handle i could mention in a post?

@357384n
Copy link
Contributor Author

357384n commented Sep 23, 2024

@357384n do you have a twitter handle i could mention in a post?

Hey @NeffIsBack, I don't sorry, hope it can be usefull for others during some pentest :)

@NeffIsBack
Copy link
Contributor

@357384n do you have a twitter handle i could mention in a post?

Hey @NeffIsBack, I don't sorry, hope it can be usefull for others during some pentest :)

No problem, i will mention your name anyway :)
I definitely think it will! It's a great addition, thanks again for the contribution.

@NeffIsBack NeffIsBack merged commit 04a695f into Pennyw0rth:main Sep 24, 2024
5 checks passed
@mpgn mpgn added this to the v1.3.0 milestone Sep 29, 2024
@Dfte
Copy link
Contributor

Dfte commented Oct 11, 2024

Hey guys! I watched this module and realized that it is doing a powershell command execution. It doesn't matter in most env's but wouldn't it be better to crawl directories and files via simple smb commands ?

Otherwise we should definitely set the opsec attribute to false (for what it's worth).

Great module anyway!!

@Dfte
Copy link
Contributor

Dfte commented Oct 11, 2024

See #444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new module reviewed code Label for when a static code review was done tested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants