Skip to content

Commit c2a979d

Browse files
committed
Land rapid7#9134, fix buggy handling of partial ingress packet data
2 parents a15b61a + d188982 commit c2a979d

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

lib/msf/base/sessions/meterpreter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ def bootstrap(datastore = {}, handler = nil)
147147
guid = [SecureRandom.uuid.gsub(/-/, '')].pack('H*')
148148
session.core.set_session_guid(guid)
149149
session.session_guid = guid
150-
# TODO: New statgeless session, do some account in the DB so we can track it later.
150+
# TODO: New stageless session, do some account in the DB so we can track it later.
151151
else
152-
# TODO: This session was either staged or previously known, and so we shold do some accounting here!
152+
# TODO: This session was either staged or previously known, and so we should do some accounting here!
153153
end
154154

155155
unless datastore['AutoLoadStdapi'] == false

lib/rex/post/meterpreter/packet_parser.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,28 @@ def reset
2727
end
2828

2929
#
30-
# Reads data from the wire and parse as much of the packet as possible.
30+
# Reads data from the socket and parses as much of the packet as possible.
3131
#
3232
def recv(sock)
33-
bytes_left = self.packet.raw_bytes_required
34-
35-
if bytes_left > 0
36-
raw = sock.read(bytes_left)
37-
if raw
33+
raw = nil
34+
if self.packet.raw_bytes_required > 0
35+
while (raw = sock.read(self.packet.raw_bytes_required))
3836
self.packet.add_raw(raw)
39-
else
40-
raise EOFError
37+
break if self.packet.raw_bytes_required == 0
4138
end
4239
end
4340

44-
if self.packet.raw_bytes_required == 0
45-
packet = self.packet
46-
reset
47-
return packet
41+
if self.packet.raw_bytes_required > 0
42+
if raw == nil
43+
raise EOFError
44+
else
45+
return nil
46+
end
4847
end
4948

50-
nil
49+
packet = self.packet
50+
reset
51+
packet
5152
end
5253

5354
protected

0 commit comments

Comments
 (0)