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

Intercepting Communication: src and dst checks #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
38 changes: 27 additions & 11 deletions intercepting-communication/run
Original file line number Diff line number Diff line change
Expand Up @@ -472,25 +472,37 @@ class RawPacketHost(UnmanagedHost):

class EtherPacketHost(RawPacketHost):
def check_packet(self, packet):
user_host = self.network.hosts[0]
return (
"Ether" in packet and
packet["Ether"].src == user_host.mac and
packet["Ether"].dst == self.mac and
packet["Ether"].type == 0xFFFF
)


class IPPacketHost(RawPacketHost):
def check_packet(self, packet):
user_host = self.network.hosts[0]
return (
"IP" in packet and
"Ether" in packet and "IP" in packet and
packet["Ether"].src == user_host.mac and
packet["Ether"].dst == self.mac and
packet["IP"].src == user_host.ip and
packet["IP"].dst == self.ip and
packet["IP"].proto == 0xFF
)


class TCPPacketHost(RawPacketHost):
def check_packet(self, packet):
user_host = self.network.hosts[0]
return (
"TCP" in packet and
"Ether" in packet and "IP" in packet and "TCP" in packet and
packet["Ether"].src == user_host.mac and
packet["Ether"].dst == self.mac and
packet["IP"].src == user_host.ip and
packet["IP"].dst == self.ip and
packet["TCP"].sport == 31337 and
packet["TCP"].dport == 31337 and
packet["TCP"].seq == 31337 and
Expand All @@ -505,7 +517,11 @@ class TCPHandshakeHost(RawPacketHost):
self.seq = None

def check_packet(self, packet):
if ("IP" in packet and "TCP" in packet["IP"] and len(packet["IP"].layers()) == 2 and
user_host = self.network.hosts[0]
if ("Ether" in packet and "IP" in packet and "TCP" in packet and len(packet["IP"].layers()) == 2 and
packet["Ether"].src == user_host.mac and
packet["Ether"].dst == self.mac and
packet["IP"].src == user_host.ip and
packet["IP"].dst == self.ip and
packet["TCP"].sport == 31337 and
packet["TCP"].dport == 31337 and
Expand Down Expand Up @@ -536,7 +552,10 @@ class TCPHandshakeHost(RawPacketHost):

self.seq = (self.seq + 1) & (2**32 - 1)

if ("IP" in packet and "TCP" in packet["IP"] and len(packet["IP"].layers()) == 2 and
if ("Ether" in packet and "IP" in packet and "TCP" in packet and len(packet["IP"].layers()) == 2 and
packet["Ether"].src == user_host.mac and
packet["Ether"].dst == self.mac and
packet["IP"].src == user_host.ip and
packet["IP"].dst == self.ip and
packet["TCP"].sport == 31337 and
packet["TCP"].dport == 31337 and
Expand All @@ -548,19 +567,16 @@ class TCPHandshakeHost(RawPacketHost):


class ARPHost(RawPacketHost):
@property
def check_host(self):
return self.network.hosts[0]

def check_packet(self, packet):
user_host = self.network.hosts[0]
WHO_HAS = 1
IS_AT = 2
return (
"Ether" in packet and "ARP" in packet["Ether"] and len(packet["Ether"].layers()) == 2 and
packet["Ether"].src == self.check_host.mac and
packet["Ether"].src == user_host.mac and
packet["ARP"].op == IS_AT and
packet["ARP"].hwsrc == self.check_host.mac and
packet["ARP"].psrc == self.check_host.ip
packet["ARP"].hwsrc == user_host.mac and
packet["ARP"].psrc == user_host.ip
)


Expand Down