def replay(): packet = IP(dst="127.0.0.1", chksum=0) / UDP( dport=1812, sport=RandShort(), chksum=0) for payload in extract_payload(product_path): packet[UDP].payload = payload del packet[IP].chksum del packet[UDP].chksum packet.show2() send(packet, iface="lo0") time.sleep(1)
def postcondition(packet): from scapy.all import IP pkt = IP(packet.get_payload()) if pkt.haslayer('IP'): del pkt['IP'].chksum del pkt['IP'].len if pkt.haslayer('TCP'): del pkt['TCP'].chksum if pkt.haslayer('ICMP'): del pkt['ICMP'].chksum pkt.show2() packet.raw = bytes(pkt) return packet
def tryInterfaces(self, ifaces): try: from scapy.all import sr1 ## we want this check to be blocking except: log.msg("This test requires scapy: www.secdev.org/projects/scapy") raise SystemExit ifup = {} while ifaces: for ifname, ifaddr in ifaces: log.debug("Currently testing network capabilities of interface" + "%s by sending a packet to our address %s" % (ifname, ifaddr)) try: pkt = IP(dst=ifaddr)/ICMP() ans, unans = sr(pkt, iface=ifname, timeout=self.timeout) except Exception, e: raise PermissionsError if e.find("Errno 1") else log.err(e) else: ## xxx i think this logic might be wrong log.debug("Interface test packet\n%s\n\n%s" % (pkt.summary(), pkt.show2())) if ans.summary(): log.info("Received answer for test packet on interface" +"%s :\n%s" % (ifname, ans.summary())) ifup.update(ifname, ifaddr) else: log.info("Our interface test packet was unanswered:\n%s" % unans.summary())
def main(): if len(sys.argv) < 3: print('Usage: ./send.py <src_ip> <dst_ip>') exit(1) src_ip = sys.argv[1] dst_ip = sys.argv[2] iface = get_if() pkt = IP(src=src_ip, dst=dst_ip) pkt.show2() try: while True: send(pkt, iface=iface) sleep(1) except KeyboardInterrupt: pass