def udp_craft(pkt, mac, fp): try: ether = Ether() ether.src = mac ether.dst = pkt[Ether].dst ether.type = 0x800 except IndexError: ether = None ip = IP() ip.src = pkt[IP].dst ip.dst = pkt[IP].src ip.ttl = int(fp.probe['U1']['TTL'], 16) ip.flags = fp.probe['U1']['DF'] ip.len = 56 ip.id = 4162 icmp = ICMP() icmp.type = 3 icmp.unused = 0 icmp.code = 13 # code 3 for reply iperror = IPerror() iperror.proto = 'udp' iperror.ttl = 0x3E iperror.len = fp.probe['U1']['RIPL'] iperror.id = fp.probe['U1']['RID'] ripck_val = fp.probe['U1']['RIPCK'] if ripck_val == 'G': pass elif ripck_val == 'Z': iperror.chksum = 0 else: iperror.chksum = pkt[IP].chksum udperror = UDPerror() udperror.sport = pkt[UDP].sport udperror.dport = pkt[UDP].dport udperror.len = pkt[UDP].len if fp.probe['U1']['RUCK'] == 'G': udperror.chksum = pkt[UDP].chksum else: udperror.chksum = fp.probe['U1']['RUCK'] try: ipl = int(fp.probe['U1']['IPL'], 16) except KeyError: ipl = None data = pkt[Raw].load fin_pkt = ip / icmp / iperror / udperror / data if ether is None else ether / ip / icmp / iperror / udperror / data return fin_pkt
def IP_layer(attributes): layer3 = IP() layer3.version = attributes['version'] layer3.ihl = attributes['ihl'] layer3.tos = attributes['tos'] layer3.len = attributes['len'] layer3.id = attributes['id'] layer3.flags = attributes['flags'] layer3.frag = attributes['frag'] layer3.ttl = attributes['ttl'] layer3.proto = attributes['proto'] layer3.src = attributes['src'] layer3.dst = attributes['dst'] return layer3
ip_source[index] = "" for i in ip_src: if i.isdigit(): ip_source[index] = str(ip_source[index]) + str(i) else: index += 1 ip_source[index] = "" print(ip_source) print(ip_dest) ip_header.version = 4 ip_header.ihl = ip_hdr_len // 4 ip_header.tos = 0x0 ip_header.len = (ip_hdr_len + udp_pkt_len) ip_header.id = 0 ip_header.flags = 0 ip_header.frag = 0 ip_header.ttl = 64 ip_header.proto = 17 #ip_header.chksum= 0x7ce6 ip_header.src = ip_src ip_header.dst = ip_dst del ip_header.chksum ip_header = ip_header.__class__(str(ip_header)) #ip_header.show2() #print("-------------------------------------") #hexdump((ip_header.version << 4) | ip_header.ihl) #print(ip_header.version << 4)