-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Adds notepad++ persistence module for Windows #20685
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
base: master
Are you sure you want to change the base?
Adds notepad++ persistence module for Windows #20685
Conversation
|
Thanks for your pull request! Before this can be merged, we need the following documentation for your module: |
|
This was on my list 😂. Lemme know when it's ready to test and I'll handle it |
| fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname + payload_name + '.dll', payload_exe) | ||
|
|
||
| vprint_status("Payload (#{payload_exe.length} bytes) uploaded on #{sysinfo['Computer']} to #{payload_pathname}") | ||
| @clean_up_rc << "rm \"#{payload_pathname.gsub('\\', '/')}\"\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if payload_pathname contains "?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a new API for handling this type of thing, it could be used here https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/base/sessions/windows_escaping.rb#L38
| info, | ||
| 'Name' => 'Notepad++ Plugin Persistence', | ||
| 'Description' => %q{ | ||
| This module create persistence by adding malicious plugin to Notepad++. The application does not perform any checks on plugins its loading. The module drops malicious DLL into plugin directory. Upon starting the Notepad++, malicious DLL gets loaded and executed. This creates persistence mechanism as the DLL will get loaded upon every run of application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This module create persistence by adding malicious plugin to Notepad++. The application does not perform any checks on plugins its loading. The module drops malicious DLL into plugin directory. Upon starting the Notepad++, malicious DLL gets loaded and executed. This creates persistence mechanism as the DLL will get loaded upon every run of application. | |
| This module create persistence by adding a malicious plugin to Notepad++, as it blindly loads and executes DLL from its plugin directory on startup, meaning that the payload will be executed every time Notepad++ is launched. |
| return CheckCode::Safe("Unable to write to #{@plugin_dir}") unless writable?(@plugin_dir) | ||
| rescue RuntimeError | ||
| filename = @plugin_dir + '\\' + Rex::Text.rand_text_alpha((rand(6..13))) | ||
| write_file(@plugin_dir, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| write_file(@plugin_dir, '') | |
| write_file(filename, '') |
Think this may have been a typo
| rescue RuntimeError | ||
| filename = @plugin_dir + '\\' + Rex::Text.rand_text_alpha((rand(6..13))) | ||
| write_file(@plugin_dir, '') | ||
| if exists? @plugin_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if exists? @plugin_dir | |
| if exists? filename |
similar to the above
|
|
||
| fail_with(Failure::UnexpectedReply, 'Error while creating malicious plugin directory') unless session.fs.dir.mkdir(payload_pathname) | ||
|
|
||
| fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname + payload_name + '.dll', payload_exe) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname + payload_name + '.dll', payload_exe) | |
| fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname + '.dll', payload_exe) |
I think payload_pathname already includes payload_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it does, but the module creates plugin subdirectory called payload_name and it creates payload_name.dll inside that new subdirectory
|
|
||
| vprint_good("Writing payload to #{payload_pathname}") | ||
|
|
||
| fail_with(Failure::UnexpectedReply, 'Error while creating malicious plugin directory') unless session.fs.dir.mkdir(payload_pathname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is session.fs compatible with shell sessions?
| fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname + payload_name + '.dll', payload_exe) | ||
|
|
||
| vprint_status("Payload (#{payload_exe.length} bytes) uploaded on #{sysinfo['Computer']} to #{payload_pathname}") | ||
| @clean_up_rc << "rm \"#{payload_pathname.gsub('\\', '/')}\"\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a new API for handling this type of thing, it could be used here https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/base/sessions/windows_escaping.rb#L38
|
| end | ||
|
|
||
| def install_persistence | ||
| @plugin_dir ||= get_plugin_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a validation check here to make sure that the payload arch matches the notepad++ arch before we go about writing the file to disk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
| if sysinfo['Architecture'] != payload_instance.arch.first |
I think it would be safe to assume the notepad binary would be the same as the host at this point, but to be sure, you could check the binary.
This adds new persistence module for Windows - Notepad++ persistence.
Work in progressVulnerable Application
This module create persistence by adding a malicious plugin to Notepad++, as it blindly loads and
executes DLL from its plugin directory on startup,meaning that the payload will be executed every time Notepad++ is launched.
The payload will have same privileges as user executing Notepad++.
Verification Steps
use exploit/windows/persistence/notepad++_persistenceset session #runOptions
PAYLOAD_NAME
Name of the payload file. Defaults to
<random>.dllScenarios
Windows 10
Original shell
Persistence