Last active
December 14, 2016 12:55
-
-
Save 0xjac/3968633d0796ad8062ace4f7af5c81bc to your computer and use it in GitHub Desktop.
Revisions
-
0xjac revised this gist
Dec 14, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,6 @@ class EasyPort(Packet): def client(args): p = (Ether(dst=arp_table[args.destination]) / IP(dst=args.destination, proto=17) / UDP(chksum=0, sport=12345, dport=args.port) / -
0xjac revised this gist
Dec 12, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,15 +40,15 @@ def handle(pkt): num_valid = pkt[EasyTrace].num_valid print("EasyTrace of length {} (num_valid)".format(num_valid)) if hasattr(pkt, 'load'): for i, port in enumerate(reversed(pkt.load[:num_valid])): print("{}. port = {}".format(i, str(ord(port)))) elif num_valid: print("Malformed packet: num_valid={} but no ports present".format(num_valid)) else: print "No ports (num_valid={})".format(num_valid) def server(iface): sniff(iface=iface, prn=lambda pkt: handle(pkt)) -
0xjac revised this gist
Dec 12, 2016 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,6 @@ from scapy.all import IP, UDP, Packet, XIntField, XByteField, bind_layers, Ether, sendp, sniff class EasyTrace(Packet): PROTOCOL = 0xFD @@ -62,7 +60,6 @@ def main(): parser.add_argument("-i", "--interface", default='eth0', help="bind to specified interface") parser.add_argument("-p", "--port", type=int, default=EasyTrace.PORT, help="UDP destination Port") parser.add_argument("-d", "--destination", help="IP address of the destination") parser.add_argument("-m", "--message", default="", help="Packet payload") args = parser.parse_args() -
0xjac revised this gist
Dec 12, 2016 . No changes.There are no files selected for viewing
-
0xjac revised this gist
Dec 12, 2016 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,9 +23,7 @@ class EasyPort(Packet): bind_layers(UDP, EasyTrace, dport=EasyTrace.PORT) arp_table = {"10.0.0.1": "00:00:00:00:00:01", "10.0.0.2": "00:00:00:00:00:02", "10.0.0.3": "00:00:00:00:00:03"} def client(args): -
0xjac created this gist
Dec 12, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ #!/usr/bin/env python import argparse import sys from scapy.all import IP, UDP, Packet, XIntField, XByteField, bind_layers, Ether, sendp, sniff from util import gen_ips, gen_macs class EasyTrace(Packet): PROTOCOL = 0xFD PORT = 0x6901 name = "EasyTrace" fields_desc = [XIntField("num_valid", 0x0)] class EasyPort(Packet): name = "EasyPort" fields_desc = [XByteField("port", 0x1)] bind_layers(IP, UDP, proto=EasyTrace.PROTOCOL) bind_layers(UDP, EasyTrace, dport=EasyTrace.PORT) def gen_arp_table(size): return {ip: mac for ip, mac in zip(gen_ips(start_ip='10.0.0.1', range=size), gen_macs(start_mac='00:00:00:00:00:01', range=size))} def client(args): arp_table = gen_arp_table(args.arp) p = (Ether(dst=arp_table[args.destination]) / IP(dst=args.destination, proto=17) / UDP(chksum=0, sport=12345, dport=args.port) / args.message) p.show() sendp(p, iface=args.interface) def handle(pkt): pkt.show() if IP in pkt and pkt.proto == EasyTrace.PROTOCOL: num_valid = pkt[EasyTrace].num_valid print("EasyTrace of length {} (num_valid)".format(num_valid)) if hasattr(pkt, 'load'): width = len(pkt.load[:num_valid]) for i, port in enumerate(reversed(pkt.load[:num_valid])): print("{:>}. port = {}".format(i, str(ord(port)))) elif num_valid: print("Malformed packet: num_valid={} but no ports present".format(num_valid)) else: print "No ports (num_valid={})".format(num_valid) def server(iface): sniff(iface=iface, prn=lambda pkt: handle(pkt)) def main(): parser = argparse.ArgumentParser(description='receiver and sender to test P4 program') parser.add_argument("-s", "--server", help="run as server", action="store_true") parser.add_argument("-c", "--client", help="run as client", action="store_true") parser.add_argument("-i", "--interface", default='eth0', help="bind to specified interface") parser.add_argument("-p", "--port", type=int, default=EasyTrace.PORT, help="UDP destination Port") parser.add_argument("-d", "--destination", help="IP address of the destination") parser.add_argument("-a", "--arp", type=int, default=12, help="Size of the arp table") parser.add_argument("-m", "--message", default="", help="Packet payload") args = parser.parse_args() if args.server: server(args.interface) elif args.client: if args.destination is None: print "Missing destination IP address" parser.print_help() sys.exit(1) client(args) else: parser.print_help() if __name__ == '__main__': main()