Advertisement
infodox

FireWalk.py

Nov 14th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. from scapy import *
  5. conf.verb=0
  6.  
  7. if len(sys.argv) != 3:
  8.     print "Usage: ./firewalk.py <target> <dport>"
  9.     print "Tells you if a port is firewalled"
  10.     sys.exit(1)
  11.  
  12. dest=sys.argv[1]
  13. port=sys.argv[2]
  14.  
  15. ttl = 0
  16.  
  17. def mkicmppacket():
  18.     global ttl
  19.     ttl = ttl + 1
  20.     p = IP(dst=dest, ttl=ttl)/ICMP()
  21.     return p
  22.  
  23. def mktcppacket():
  24.     global ttl, dest, port
  25.     ttl = ttl + 1
  26.     p = IP(dst=dest, ttl=ttl)/TCP(dport=int(port), flags="S")
  27.     return p
  28.  
  29. res = sr1(mkicmppacket())
  30. while res.type == 11:
  31.     res = sr1(mkicmppacket())
  32.     print "+"
  33.  
  34. nat_ttl = ttl
  35. # Since we now know our minimum TTL, we don't need to reset TTL to zero
  36. # We do need to decrease TTL or otherwise mkpacket will increase it again
  37. # which would result in every port being detected as forwarded
  38. ttl = ttl - 1
  39.  
  40. res = sr1(mktcppacket())
  41. while res.proto == 1 and res.type == 11:
  42.     res = sr1(mktcppacket())
  43.  
  44. if res.proto != 6:
  45.     print "Error"
  46.     sys.exit(1)
  47.  
  48. if nat_ttl == ttl: print "Not NATed (" + str(nat_ttl) + ", " + str(ttl) + ")"
  49. else: print "This port is NATed. firewall TTL is " + str(nat_ttl) + ", TCP port TTL is " + str(ttl)
  50.  
  51. sys.exit(0)
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement