Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(331): fix json conversion #366

Merged
merged 5 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions pyrdp/convert/ExportedPDUStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,27 @@ class ExportedPDUStream(PCAPStream):
def __init__(self, client: str, server: str, packets: PacketList):
super().__init__(client, server)
self.packets = packets
self.n = 0

def __len__(self):
return len(self.packets)

def __iter__(self):
return self.parsePDUs()
return self

def parsePDUs(self):
"""
Generator function that parses Exported PDUs from Wireshark and outputs them.
"""

n = 0
def __next__(self):

while True:
if n >= len(self):
if self.n >= len(self):
raise StopIteration

packet = self.packets[n]
packet = self.packets[self.n]
src = ".".join(str(b) for b in packet.load[12:16])
dst = ".".join(str(b) for b in packet.load[20:24])
data = packet.load[60:]
n += 1
self.n += 1

if any(ip not in self.ips for ip in [src, dst]):
continue
continue # Skip packets not meant for this stream.

yield PCAPStream.output(data, packet.time, src, dst)
return PCAPStream.output(data, packet.time, src, dst)
obilodeau marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 10 additions & 5 deletions pyrdp/convert/PCAPConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from progressbar import progressbar
from scapy.layers.inet import TCP
from scapy.layers.tls.record import TLS
from pyrdp.convert.pyrdp_scapy import *

from pyrdp.convert.Converter import Converter
from pyrdp.convert.ExportedPDUStream import ExportedPDUStream
from pyrdp.convert.TLSPDUStream import TLSPDUStream
from pyrdp.convert.PCAPStream import PCAPStream
from pyrdp.convert.RDPReplayer import RDPReplayer
from pyrdp.convert.TLSPDUStream import TLSPDUStream
from pyrdp.convert.pyrdp_scapy import *
from pyrdp.convert.utils import tcp_both, getSessionInfo, findClientRandom, createHandler, canExtractSessionInfo


Expand Down Expand Up @@ -106,12 +106,17 @@ def processStream(self, startTimeStamp: int, stream: PCAPStream):

print(f"[*] Processing {stream.client} -> {stream.server}")

for data, timeStamp, src, _ in progressbar(stream):
replayer.setTimeStamp(timeStamp)
replayer.recv(data, src == stream.client)
try:
for data, timeStamp, src, _dst in progressbar(stream):
replayer.setTimeStamp(timeStamp)
replayer.recv(data, src == stream.client)
except StopIteration:
# Done processing the stream.
pass

try:
replayer.tcp.recordConnectionClose()
handler.cleanup()
except struct.error:
sys.stderr.write("[!] Couldn't close the session cleanly. Make sure that --src and --dst are correct.")

Expand Down