Skip to content

Commit

Permalink
fix reconnect bug
Browse files Browse the repository at this point in the history
  • Loading branch information
FunnyWolf committed Aug 30, 2023
1 parent 2697315 commit 17b6b15
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions data/meterpreter/meterpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,6 @@ def get_packet(self):
if self.communication_has_expired:
debug_print("get_packet pkt none expired")
self.request_retire = True
debug_print("get_packet pkt is None pass")
return None
self.communication_last = time.time()
return pkt
Expand Down Expand Up @@ -1140,7 +1139,7 @@ def _sock_cleanup(self, sock):
def _activate(self):
address, port = self.url[6:].rsplit(':', 1)
port = int(port.rstrip('/'))
timeout = max(self.communication_timeout, 30)
timeout = 60
if address in ('', '0.0.0.0', '::'):
try:
server_sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
Expand Down Expand Up @@ -1176,8 +1175,8 @@ def _get_packet(self):
first = self._first_packet
self._first_packet = False
if not select.select([self.socket], [], [], 0.5)[0]:
debug_print("select.select pass")
return bytes()
self.socket.settimeout(60)
packet = self.socket.recv(PACKET_HEADER_SIZE)
if len(packet) == 0: # remote is closed
self.request_retire = True
Expand All @@ -1187,13 +1186,9 @@ def _get_packet(self):
received = 0
header = packet[:4]
pkt_length = struct.unpack('>I', header)[0]
self.socket.settimeout(max(self.communication_timeout, 30))
self.socket.settimeout(60)
while received < pkt_length:
new_received = len(self.socket.recv(pkt_length - received))
if new_received == 0:
self.request_retire = True
return None
received += new_received
received += len(self.socket.recv(pkt_length - received))
self.socket.settimeout(None)
return self._get_packet()
return None
Expand All @@ -1209,15 +1204,15 @@ def _get_packet(self):
while len(rest) < pkt_length:
recv_data = self.socket.recv(pkt_length - len(rest))
if len(recv_data) == 0:
debug_print("recv_data len 0 retire")
self.request_retire = True
return None
debug_print("recv finish")
break
else:
rest += recv_data
# return the whole packet, as it's decoded separately
return packet + rest

def _send_packet(self, packet):
self.socket.settimeout(60)
self.socket.send(packet)

@classmethod
Expand Down

0 comments on commit 17b6b15

Please sign in to comment.