-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Persistence directory #19815
Open
h00die
wants to merge
84
commits into
rapid7:master
Choose a base branch
from
h00die:persistence_dir
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,237
−2,060
Open
Persistence directory #19815
Changes from 67 commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
62b951d
move persistence files to their own folder
h00die b9539bb
rubocop persistence modules
h00die e3545f3
msftidy changes for persistence folder
h00die 8138fe1
finish renaming persistence docs
h00die d56d7ab
move persistence under exploit
h00die 9b7cc8f
modernization, updates, testing of apt_package_manager
h00die 1fbd81d
modernization, updates, testing of autostart
h00die 1877601
modernization, updates, testing of bash_profile
h00die 43244ca
create persistence lib to standardize options
h00die 5039513
modernization, updates, testing of cron
h00die 9de657e
modernization, updates, testing of persistence modules
h00die d57237e
modernization, updates, testing of motd
h00die a2179ab
modernization, updates, testing of rc.local
h00die 15cfde7
modernization, updates, testing of linux service
h00die c035123
modernization, updates, testing of linux yum module
h00die d65f2d4
further adjustments for persistence
h00die 7cfc28a
modernization, updates, testing of obsidian module
h00die e76aa56
modernization, updates, testing of launch_plist module
h00die a1a8c26
add link with lib
h00die 770930d
storing unfinished modules
h00die 20cdc45
wmi persistence module
h00die 1d19dc2
vss persistence
h00die faad050
sticky keys update
h00die 3607d5b
sticky keys update
h00die ca16ee2
sticky keys update
h00die cda0881
windows ssh keys update
h00die 74acdf2
feat: persistence mixin draft
dledda-r7 7542fa1
feat: draft bash_profile using persistence mixin
dledda-r7 772ac96
windows persistence service conversion
h00die 6b45fb3
feat: persistence mixin and bash_profile persistence
dledda-r7 7b45372
system_v persistence pulled out from service module
h00die 4af21a6
Merge remote-tracking branch 'origin/persistence_dir' into persistenc…
h00die 5a5e813
linux service persistence module split apart
h00die 186b74c
feat: persistence mixin cleanup via rc-file
dledda-r7 782bd3b
feat: bash_profile persistence cleanup rc-file
dledda-r7 57dd846
feat: apt_package_manager persistence cleanup rc-file
dledda-r7 e154902
feat: autostart persistence cleanup rc-file
dledda-r7 490e810
rename linux persistence services to inits
h00die 1da8e44
unix at persistence
h00die e62acab
s4u persistence module
h00die 3bbf381
windows registry persistence module
h00die 868775e
windows ps_persist
h00die 6e29418
process_exit_debugger udpates
h00die a17e152
persistence consistencies
h00die 5188b20
windows persistence moved to registry_vbs
h00die 2228190
windows persistence moved to registry_vbs
h00die c159660
windows persistence small fixes
h00die 5dee099
windows persistence_exe updates
h00die 3a079b1
windows persistence_exe updates
h00die 5c090d8
rubocop fixes
h00die e8fafed
fix notes metadata for unix at persistence
h00die c36f98a
create persistence suggester
h00die 7058546
create persistence suggester
h00die fb8e740
fixes for persistence checks
h00die 7d47bee
fix: add cleanup function persistence mixin
dledda-r7 4519ee9
fix: removed cleanup_persistence function in bash_profile
dledda-r7 5deede9
fix: cron persistence with new mixin and cleanup rc file
dledda-r7 1a74cb4
fix: init_openrc persistence with new mixin and cleanup rc file
dledda-r7 8c336f8
fix: init_systemd persistence with new mixin and cleanup rc file
dledda-r7 68a1008
fix: init_sysvinit persistence with new mixin and cleanup rc file
dledda-r7 c06e2ab
fix: motd and init_upstart persistence with new mixin and cleanup rc …
dledda-r7 b41aa6b
fix: rc_local persistence with new mixin and cleanup rc file
dledda-r7 d7b55e7
fix: sshkey persistence with new mixin and cleanup rc file
dledda-r7 b9141fc
fix: fix missing newline cleanup on init_systemd
dledda-r7 9ceb60d
fix: yum_package_manager persistence with new mixin and cleanup rc file
dledda-r7 0762a13
fix: obsidian persistence with new mixin and cleanup rc file
dledda-r7 c07e28f
fix: launch_plist persistence with new mixin and cleanup rc file
dledda-r7 7db3160
fix: at persistence with new mixin and cleanup rc file
dledda-r7 0ea714e
Merge remote-tracking branch 'origin/persistence_dir' into persistenc…
h00die 6589d78
working on autostart
h00die 78c7a96
working on autostart
h00die a935ce0
at(1) working
h00die d902ba8
autostart finished
h00die e2fd131
bash_profile finished
h00die 364d1a5
fix: s4u persistence with new mixin and cleanup rc file
dledda-r7 a3dcbf6
fix: process_exit_debugger persistence with new mixin and cleanup rc …
dledda-r7 37cd4c1
x: s4u persistence check method and cleanup fix
dledda-r7 fe6da60
fix: registry persistence with new mixin and cleanup rc file
dledda-r7 4fdd4ac
fix: vss persistence with new mixin and cleanup rc file
dledda-r7 0ecac47
fix: registry_vbs persistence with new mixin and cleanup rc file
dledda-r7 ce1835b
fix: persistence_exe persistence with new mixin and cleanup rc file
dledda-r7 f6159e2
fix: ps_persist persistence with new mixin and cleanup rc file
dledda-r7 a190de4
fix: service persistence with new mixin and cleanup rc file
dledda-r7 fa71e06
fix: persistence_exe install_persistence instead of run
dledda-r7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# -*- coding: binary -*- | ||
|
||
module Msf | ||
module Exploit::Local::Persistence | ||
def initialize(info = {}) | ||
@persistence_service = Rex::Sync::Event.new(auto_reset=false) | ||
@clean_up_rc = '' | ||
super( | ||
update_info( | ||
info, | ||
'DefaultOptions' => {}, | ||
# https://github.com/rapid7/metasploit-framework/pull/19676#discussion_r1907594308 | ||
'Stance' => Msf::Exploit::Stance::Passive, | ||
'Passive' => true | ||
) | ||
) | ||
|
||
register_advanced_options( | ||
[ | ||
OptString.new('WritableDir', [true, 'A directory where we can write files', '/tmp/']), | ||
OptBool.new('CleanUpRc', [true, 'Create a cleanup resource file.', true]) | ||
] | ||
) | ||
end | ||
|
||
def exploit | ||
run_as_background = !datastore['DisablePayloadHandler'] | ||
print_warning('Payload handler is disabled, the persistence will be installed only.') unless run_as_background | ||
|
||
# Call the install_persistence function | ||
# must be declared inside the persistence module | ||
install_persistence | ||
|
||
save_cleanup_rc if datastore['CleanUpRc'] && !@clean_up_rc.empty? | ||
|
||
@persistence_service.wait if run_as_background | ||
end | ||
|
||
def install_persistence | ||
# to be overloaded by the module | ||
end | ||
|
||
def save_cleanup_rc | ||
host = session.sys.config.sysinfo['Computer'] | ||
# Create Filename info to be appended to downloaded files | ||
filenameinfo = '_' + ::Time.now.strftime('%Y%m%d.%M%S') | ||
logs = ::File.join(Msf::Config.log_directory, 'persistence', Rex::FileUtils.clean_path(host + filenameinfo)) | ||
# Create the log directory | ||
::FileUtils.mkdir_p(logs) | ||
|
||
# logfile name | ||
clean_rc = logs + ::File::Separator + Rex::FileUtils.clean_path(host + filenameinfo) + '.rc' | ||
file_local_write(clean_rc, @clean_up_rc) | ||
print_status("Meterpreter-compatible Cleaup RC file: #{clean_rc}") | ||
|
||
report_note(host: host, | ||
type: 'host.persistance.cleanup', | ||
data: { | ||
local_id: session.sid, | ||
stype: session.type, | ||
desc: session.info, | ||
platform: session.platform, | ||
via_payload: session.via_payload, | ||
via_exploit: session.via_exploit, | ||
created_at: Time.now.utc, | ||
commands: @clean_up_rc | ||
}) | ||
end | ||
|
||
def cleanup | ||
end | ||
end | ||
end |
94 changes: 0 additions & 94 deletions
94
modules/exploits/linux/local/apt_package_manager_persistence.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
122 changes: 0 additions & 122 deletions
122
modules/exploits/linux/local/bash_profile_persistence.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ends up making folders that feel repetitive, for instance:
/root/.msf4/logs/persistence/111.111.1.11_20250204.4245/111.111.1.11_20250204.4245.rc
Maybe instead we should include the module name?
/root/.msf4/logs/persistence/111.111.1.11/apt_package_manager_20250204.4245.rc
feels a little better to me. I don't think we need the Time on both the folder and file, but you may run the same persistence multiple times on a host so that made me think putting it on the file instead of the folder may be better.
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.
Sounds good to add the module name on the
rc
file name, thinking how to do it from the mixin, but should be doable.