-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
12 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,30 +1,61 @@ | ||
# -*- coding: binary -*- | ||
|
||
module Msf | ||
# This module provides methods for persisting on a target system. Mainly initialization | ||
# options. | ||
module Exploit::Local::Persistence | ||
def initialize(info = {}) | ||
@persistence_service = Rex::Sync::Event.new(auto_reset=false) | ||
super( | ||
update_info( | ||
info, | ||
'DefaultOptions' => { | ||
# leaving this commented out, we don't want a wfs delay so that the module | ||
# will run forever. | ||
# 'WfsDelay' => 25 * 60 * 60, # 25hrs | ||
'AllowNoCleanup' => true # don't delete our persistence after we get a shell | ||
}, | ||
'DefaultOptions' => {}, | ||
# https://github.com/rapid7/metasploit-framework/pull/19676#discussion_r1907594308 | ||
'Stance' => Msf::Exploit::Stance::Passive | ||
# 'Passive' => true # XXX when set, ignores wfsdelay and immediately exists after last command | ||
'Stance' => Msf::Exploit::Stance::Passive, | ||
'Passive' => true, | ||
'Actions' => [ | ||
[ 'INSTALL', { 'Description' => 'Install the persistence' } ], | ||
[ 'CLEANUP', { 'Description' => 'Cleanup the persistence' } ] | ||
], | ||
'DefaultAction' => 'INSTALL' | ||
) | ||
) | ||
|
||
register_advanced_options( | ||
[ | ||
OptString.new('WritableDir', [true, 'A directory where we can write files', '']) | ||
OptString.new('WritableDir', [true, 'A directory where we can write files', '/tmp/']), | ||
OptBool.new('CleanUpPersistence', [true, 'Remove the installed persistence at the end of the module', false]) | ||
] | ||
) | ||
end | ||
|
||
def exploit | ||
|
||
case action.name.upcase | ||
when 'INSTALL' | ||
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 | ||
|
||
@persistence_service.wait if run_as_background | ||
|
||
cleanup_persistence if datastore['CleanUpPersistence'] | ||
|
||
when 'CLEANUP' | ||
|
||
# call cleanup_persistence | ||
# must be declared inside the persistence module | ||
cleanup_persistence | ||
end | ||
end | ||
|
||
def install_persistence | ||
# to be overloaded by the module | ||
end | ||
|
||
def cleanup | ||
# this is done by the action | ||
end | ||
end | ||
end | ||
end |