-
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
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
|
| def install_persistence | ||
| @plugin_dir ||= get_plugin_dir | ||
|
|
||
| payload_name = CGI.escape(datastore['PAYLOAD_NAME']) || Rex::Text.rand_text_alpha((rand(6..13))) |
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.
| payload_name = CGI.escape(datastore['PAYLOAD_NAME']) || Rex::Text.rand_text_alpha((rand(6..13))) | |
| payload_name = CGI.escape(datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha((rand(6..13)))) |
If you leave the PAYLOAD_NAME blank, it passes it to CGI.escape which fails. This is a bit hacky, but it is a quick change that ensure CGI.escape will always get a string.
Release NotesAdds a persistence module for Notepad++ by adding a malicious plugin to Notepad++, as it blindly loads and executes DLLs from its plugin directory on startup. |
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