Guest User

Untitled

a guest
Feb 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import scapy.all as scapy
  3. scapy.conf.verb=0
  4. import os
  5. import socket
  6.  
  7. hostip= "192.168.2.1" #raw_input("Digite la direccion IP del destino: ")
  8. #print "El equipo al cual se hara el escaneo es: " + hostip
  9. port=input("Digite el puerto a revisar: ")
  10.  
  11. ifname="wlan0" #raw_input("\nIngresar Interface por donde se realizara el ataque wlan0 o eth0: ")
  12. fin,fout = os.popen4("ip route list dev "+ifname +" | grep default | awk '{print $3}'")
  13. result = fout.read()
  14. gw_IP=result.strip()
  15. gwip=str(gw_IP)
  16.  
  17. pkt_arp = scapy.ARP()
  18. myether = pkt_arp.hwsrc
  19. mi_IP = pkt_arp.psrc
  20. gwether=scapy.getmacbyip(str(gw_IP))
  21. hostether=scapy.getmacbyip(hostip)
  22.  
  23. print "host ip: " +hostip
  24. print "mi ip:" +mi_IP
  25.  
  26. print "###############[TCP CONNECT SCAN]#######################\n"
  27. paquete = (scapy.Ether(src=myether, dst=hostether)/scapy.IP(dst=hostip)/scapy.TCP(sport=scapy.RandShort(), dport=port))
  28. resp = scapy.srp1(paquete,timeout=1) #send and wait first replay
  29. if not resp or resp.getlayer(scapy.TCP).flags != 0x12:
  30. print str(port)+":Puerto Cerrado\n"
  31. else:
  32. print str(port)+":Puerto Abierto\n"
  33. #END TCP-SCAN
  34.  
  35. print "###############[SYN CONNECT SCAN]#########################\n"
  36. paquete = (scapy.Ether(src=myether, dst=gwether)/scapy.IP(dst=hostip)/scapy.TCP(sport=scapy.RandShort(), dport=port, flags='S'))
  37. resp = scapy.srp1(paquete, timeout=3) #send and wait first replay
  38. if not resp:
  39. print str(port)+":Puerto Filtrado"
  40. else:
  41. if resp.getlayer(scapy.TCP).flags == 0x12 or resp.getlayer(scapy.TCP).flags == 2 :
  42. print str(port)+":Puerto Abierto\n"
  43. else:
  44. print str(port)+":Puerto Cerrado\n"
  45. #END-SYN SCAN
  46.  
  47. print "###############[FIN CONNECT SCAN]#########################\n"
  48. paquete = (scapy.Ether(src=myether, dst=gwether)/scapy.IP(dst=hostip)/scapy.TCP(sport=scapy.RandShort(),dport=port, flags='F'))
  49. resp = scapy.srp1(paquete, timeout=3) #send and wait first replay
  50. if not resp:
  51. print str(port)+":Puerto Abierto | filtrado\n"
  52. else:
  53. if resp.getlayer(scapy.TCP).flags == 0x14 or resp.getlayer(scapy.TCP).flags == 4:
  54. print str(port)+":Puerto Cerrado\n"
  55. else:
  56. print str(port)+":Puerto Abierto | no filtrado\n"
  57. #END-FIN SCAN
  58.  
  59. print "###############[XMAS TREE CONNECT SCAN]#######################\n"
  60. paquete = (scapy.Ether(src=myether, dst=gwether)/scapy.IP(dst=hostip)/scapy.TCP(sport=scapy.RandShort(),dport=port, flags='FPU'))
  61. resp = scapy.srp1(paquete, timeout=3) #send and wait first replay
  62. if not resp or resp.getlayer(scapy.TCP).flags != 0x14 or resp.getlayer(scapy.TCP).flags !=1:
  63. print str(port)+":Puerto Abierto|filtrado\n"
  64. else:
  65. print str(port)+":Puerto Cerrado\n"
  66. #resp.show(); #paquete from hostip
  67. #END-XMAS TREE
  68.  
  69. print "###############[NULL CONNECT SCAN]#######################\n"
  70. paquete = (scapy.Ether(src=myether, dst=gwether)/scapy.IP(dst=hostip)/scapy.TCP(sport=scapy.RandShort(),dport=port, flags=0x00))
  71. resp = scapy.srp1(paquete, timeout=3) #send and wait first replay
  72. if not resp:
  73. print str(port)+":Puerto Abierto | filtrado\n"
  74. else:
  75. print str(port)+":Puerto Cerrado\n"
  76. #resp.show(); #paquete from hostip
  77. #END NULL-SCAN
  78.  
  79. print "###############[UDP CONNECT SCAN]#######################\n"
  80. paquete = (scapy.Ether(src=myether, dst=gwether)/scapy.IP(dst=hostip)/scapy.UDP(sport=scapy.RandShort(),dport=port))
  81. resp = scapy.srp1(paquete, timeout=3) #send and wait first replay
  82. if not resp:
  83. print str(port)+":Puerto Abierto | filtrado\n"
  84. else:
  85. print str(port)+":Puerto Cerrado\n"
  86. #END UDP SCAN
  87.  
  88.  
  89. print "########### [ IDLE SCAN ] ################################\n"
  90. objetivoip="192.168.2.204"
  91. objetivoether=scapy.getmacbyip(objetivoip)
  92. print
  93.  
  94. paquete = (scapy.Ether(dst=gwether)/scapy.IP(src=mi_IP, dst=gwip)/scapy.TCP(sport=scapy.RandShort(), dport=port, flags='SA'))
  95. resp = scapy.srp1(paquete) #send and wait first replay
  96. #resp.show(); #paquete from hostip
  97. a=resp.getlayer(scapy.IP).id
  98. print "ip id 1: " +str(a)
  99. #####################################################################
  100. paquete2 = (scapy.Ether(dst=objetivoether)/scapy.IP(src=gwip, dst=objetivoip)/scapy.TCP(sport=scapy.RandShort(),dport=port, flags='S'))
  101. resp2 = scapy.srp1(paquete, timeout=1) #send and wait first replay
  102. #####################################################################
  103. paquete = (scapy.Ether(dst=gwether)/scapy.IP(src=mi_IP, dst=gwip)/scapy.TCP(sport=scapy.RandShort(), dport=port, flags='SA'))
  104. resp = scapy.srp1(paquete) #send and wait first replay
  105. #resp.show(); #paquete from hostip
  106. b=resp.getlayer(scapy.IP).id
  107. #####################################################################
  108. print "ip id 2: " +str(b)
  109. c=b-a
  110. if c>=2:
  111. print "Puerto Abierto\n"
  112. else:
  113. print "Puerto Cerrado\n"
Add Comment
Please, Sign In to add comment