Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def _build_pkt(self, fields, ops):
- pkt_out = packet.Packet()
- pkt_ipv4 = pkt_out.get_protocol(ipv4.ipv4)
- pkt_icmp = pkt_out.get_protocol(icmp.icmp)
- def addIPv4(pkt_out, fields):
- pkt_out.add_protocol(ipv4.ipv4(dst=fields['dstip'],
- version = 4,
- header_length = 5,
- tos = 0,
- total_length = 0,
- identification = fields['id'],
- flags=0x02,
- ttl = 63,
- proto = fields['proto'],
- csum = 0,
- option = None,
- src=fields['srcip']))
- return pkt_out
- def addARP(pkt_out,fields):
- pkt_out.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
- src_mac=fields['srcmac'],
- src_ip=fields['srcip'],
- dst_mac=fields['dstmac'],
- dst_ip=fields['dstip']))
- return pkt_out
- pkt_out.add_protocol(ethernet.ethernet(ethertype=fields['ethtype'],
- dst=fields['dstmac'],
- src=fields['srcmac']))
- # Add if ARP
- if 'arp' in fields['ptype']:
- pkt_out.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
- src_mac=fields['srcmac'],
- src_ip=fields['srcip'],
- dst_mac=fields['dstmac'],
- dst_ip=fields['dstip']))
- # Add if IPv4
- if 'ipv4' in fields['ptype']:
- pkt_out = addIPv4(pkt_out,fields)
- # Add if ICMP
- if 'icmp' in fields['ptype']:
- pkt_out = addIPv4(pkt_out,fields)
- pkt_out.add_protocol(icmp.icmp(type_=icmp.ICMP_ECHO_REPLY,
- code=icmp.ICMP_ECHO_REPLY_CODE,
- csum=0,
- data=None))
- # Add if UDP
- if 'udp' in fields['ptype']:
- #pkt_out = addARP(pkt_out,fields)
- pkt_out = addIPv4(pkt_out,fields)
- pkt_out.add_protocol(udp.udp(dst_port=fields['dstport'],
- csum = 0,
- total_length = 0,
- src_port=fields['srcport']))
- # Add if TCP
- if 'tcp' in fields['ptype']:
- pkt_out = addIPv4(pkt_out,fields)
- pkt_out.add_protocol(tcp.tcp(dst_port=fields['dstport'],
- bits=fields['bits'],option=fields['opt'],
- src_port=fields['srcport']))
- #Add covert channel information
- if fields['com'] != None:
- pkt_out.add_protocol(fields['com'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement