Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. import sys
  4.  
  5. logging.basicConfig(level=logging.DEBUG)
  6. sys.path.insert(0, "./netzob-sygus/src/") # For Netzob
  7.  
  8. from netzob.all import *
  9.  
  10. # UDP symbol
  11. udp_src = Field(name='sport', domain=Raw(nbBytes=2))
  12. udp_dst = Field(name='dport', domain=Raw(nbBytes=2))
  13. udp_length = Field(name='length', domain=Raw(nbBytes=2, unitSize=AbstractType.UNITSIZE_16))
  14. udp_checksum = Field(name='checksum', domain=Raw(nbBytes=2, unitSize=AbstractType.UNITSIZE_16))
  15. udp_payload = Field(name='payload', domain=Raw(b"\x61\x61\x61\x61\x61\x0a"))
  16.  
  17. udp_header = [udp_src, udp_dst, udp_length, udp_checksum, udp_payload]
  18. udp_length.domain = Size(udp_header, dataType=Raw(nbBytes=2, unitSize=AbstractType.UNITSIZE_16), factor=1/float(8))
  19.  
  20. # Pseudo IP header
  21. ip_pseudo_saddr = Field(name='IP Source address', domain=IPv4("192.168.0.1"))
  22. ip_pseudo_daddr = Field(name='IP Destination address', domain=IPv4("192.168.0.2"))
  23. ip_pseudo_length = Field(name='UDP Length', domain=Size(udp_header, dataType=Raw(nbBytes=2, unitSize=AbstractType.UNITSIZE_16), factor=1/float(8)))
  24. ip_pseudo_zero = Field(name='Zero', domain=Raw(b"\x00"))
  25. ip_pseudo_proto = Field(name='Protocol', domain=Integer(value=17, unitSize=AbstractType.UNITSIZE_8))
  26.  
  27. ip_pseudo_header = Field(name='Pseudo IP header', isPseudoField=True)
  28. ip_pseudo_header.fields = [ip_pseudo_saddr, ip_pseudo_daddr, ip_pseudo_zero, ip_pseudo_proto, ip_pseudo_length]
  29.  
  30. udp_checksum.domain = InternetChecksum([ip_pseudo_header] + udp_header, dataType=Raw(nbBytes=2, unitSize=AbstractType.UNITSIZE_16))
  31.  
  32. udp_symbol = Symbol(name='UDP layer', fields=udp_header+[ip_pseudo_header])
  33.  
  34. print(udp_symbol._str_debug())
  35. dot = udp_symbol.generateDot()
  36. print(dot)
  37.  
  38. f = open("/tmp/plop.dot", 'w')
  39. f.write(dot)
  40. f.close
  41.  
  42. import subprocess
  43. subprocess.Popen("xdot /tmp/plop.dot", shell=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement