Advertisement
Guest User

Untitled

a guest
May 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. def _build_pkt(self, fields, ops):
  2. pkt_out = packet.Packet()
  3. pkt_ipv4 = pkt_out.get_protocol(ipv4.ipv4)
  4. pkt_icmp = pkt_out.get_protocol(icmp.icmp)
  5.  
  6. def addIPv4(pkt_out, fields):
  7. pkt_out.add_protocol(ipv4.ipv4(dst=fields['dstip'],
  8. version = 4,
  9. header_length = 5,
  10. tos = 0,
  11. total_length = 0,
  12. identification = fields['id'],
  13. flags=0x02,
  14. ttl = 63,
  15. proto = fields['proto'],
  16. csum = 0,
  17. option = None,
  18. src=fields['srcip']))
  19. return pkt_out
  20.  
  21. def addARP(pkt_out,fields):
  22. pkt_out.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
  23. src_mac=fields['srcmac'],
  24. src_ip=fields['srcip'],
  25. dst_mac=fields['dstmac'],
  26. dst_ip=fields['dstip']))
  27. return pkt_out
  28.  
  29. pkt_out.add_protocol(ethernet.ethernet(ethertype=fields['ethtype'],
  30. dst=fields['dstmac'],
  31. src=fields['srcmac']))
  32. # Add if ARP
  33. if 'arp' in fields['ptype']:
  34. pkt_out.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
  35. src_mac=fields['srcmac'],
  36. src_ip=fields['srcip'],
  37. dst_mac=fields['dstmac'],
  38. dst_ip=fields['dstip']))
  39. # Add if IPv4
  40. if 'ipv4' in fields['ptype']:
  41. pkt_out = addIPv4(pkt_out,fields)
  42.  
  43. # Add if ICMP
  44. if 'icmp' in fields['ptype']:
  45. pkt_out = addIPv4(pkt_out,fields)
  46.  
  47. pkt_out.add_protocol(icmp.icmp(type_=icmp.ICMP_ECHO_REPLY,
  48. code=icmp.ICMP_ECHO_REPLY_CODE,
  49. csum=0,
  50. data=None))
  51. # Add if UDP
  52. if 'udp' in fields['ptype']:
  53. #pkt_out = addARP(pkt_out,fields)
  54. pkt_out = addIPv4(pkt_out,fields)
  55. pkt_out.add_protocol(udp.udp(dst_port=fields['dstport'],
  56. csum = 0,
  57. total_length = 0,
  58. src_port=fields['srcport']))
  59.  
  60. # Add if TCP
  61. if 'tcp' in fields['ptype']:
  62. pkt_out = addIPv4(pkt_out,fields)
  63. pkt_out.add_protocol(tcp.tcp(dst_port=fields['dstport'],
  64. bits=fields['bits'],option=fields['opt'],
  65. src_port=fields['srcport']))
  66.  
  67. #Add covert channel information
  68. if fields['com'] != None:
  69. pkt_out.add_protocol(fields['com'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement