Advertisement
febrezo

yasbeck.py. Crawling servers to check if they contain a file

Dec 3rd, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.84 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. ##==============================================================================
  3. ##                                                                              
  4. ##    Copyright 2012 Félix Brezo (febrezo @ www.felixbrezo.com)                
  5. ##                                                                              
  6. ##    This program is free software: you can redistribute it and/or modify      
  7. ##    it under the terms of the GNU General Public License as published by      
  8. ##    the Free Software Foundation, either version 3 of the License, or        
  9. ##    (at your option) any later version.                                      
  10. ##                                                                              
  11. ##    Sira is distributed in the hope that it will be useful,                  
  12. ##    but WITHOUT ANY WARRANTY; without even the implied warranty of            
  13. ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
  14. ##    GNU General Public License for more details.                              
  15. ##                                                                              
  16. ##    You should have received a copy of the GNU General Public License        
  17. ##    along with yasbeck.py.  If not, see <http://www.gnu.org/licenses/>.  
  18. ##                                                                              
  19. ##    Additional comments by the author:                                        
  20. ##    ----------------------------------                                        
  21. ##      En.:    This script was coded for educational purpouses only.          
  22. ##              The use or missuse of this script is responsible of the final  
  23. ##                user.                                                        
  24. ##              The author condemns any illegal use of this script and          
  25. ##                encourages its users to pursue and inform the corresponding  
  26. ##                authorities about any illegal use of it.                      
  27. ##      Es.:    Este script ha sido codificado solamente con fines educativos.  
  28. ##              El uso o mal uso de este script es responsabilidad única de    
  29. ##                su usuario final.                                            
  30. ##              El autor condena cualquier uso ilegal de este script e insta    
  31. ##                a sus usuarios a poner en mano de la justicia cualquier uso  
  32. ##                ilegal del mismo.                                    
  33. ##                                                                              
  34. ##==============================================================================
  35. ## USO                                     
  36. ## ---                                 
  37. ## usage: yasbeck.py [-h] -d <DEFACEMENT_FILE> -s <SITES_FILE> [-q] [--version]
  38. ##                                     
  39. ## Yasbeck - App. para verificaci?n de defacements.            
  40. ## optional arguments:
  41. ##   -h, --help            show this help message and exit
  42. ##   -d <DEFACEMENT_FILE>, --defacement <DEFACEMENT_FILE>
  43. ##                         URI del fichero de defacement.
  44. ##   -p <IP>:<PORT>, --proxy <IP>:<PORT>
  45. ##                         para usar la configuración de un proxy dado en el
  46. ##                         formato <IP>:<PORT>.
  47. ##   -q, --quiet           para no mostrar ninguna salida en la consola.
  48. ##   -s <SITES_FILE>, --sites <SITES_FILE>
  49. ##                         para determinar el fichero donde se encuentran las
  50. ##                         URIS a comprobar.
  51. ##   -t, --tor             para usar la configuración del proxy de Tor. Tor
  52. ##                         tiene que haber sido lanzado previamente.
  53. ##   --version             show program's version number and exit
  54. ##
  55. ##==============================================================================
  56. ## Limitaciones                                
  57. ## ------------                                
  58. ## Probado sobre Python 2.7.2.
  59. ## Verifica si las URL del fichero .txt contienen el mismo que ha sido pasado  
  60. ##  por parámetro empleando calculando su Hash MD5. Esto garantiza que los    
  61. ##  sites que contengan un fichero con dicho Hash siguen siendo vulnerables
  62. ##  pero no garantiza que existan otros sites que no lo tengan que lo sigan
  63. ##  siendo (por ejemplo, porque tengan un fichero similar, pero no     
  64. ##  exactamente igual. De esta manera, los no etiquetados como [HACKEADOS]  
  65. ##  manifiestan alguno de los siguientes comportamientos: o muestran una    
  66. ##  página de error o no responden a las peticiones.          
  67. ## Este script no está libre de errores y es sólo una muestra de la gran  
  68. ##  cantidad de sitios que no han dado respuesta a los ataques del día 30.
  69. ## Se usa MD5 por meras cuestiones de reutilización de código.           
  70. ## Huelga decir que el autor condena cualquier ataque que viole las libertades 
  71. ##  de la red. El robo de credenciales y el acceso ilegítimo a servidores 
  72. ##  ajenos conforman una de estas activiades.              
  73. ##==============================================================================
  74. ## Notas adicionales:                              
  75. ## ------------------                              
  76. ## A las 19:35 GMT del día 3 de diciembre 278/319 sitios seguían mostrando la web
  77. ##  inyectada por xPerf3cti0n.html                     
  78. ## El script tiene de nombre yasbeck.py en honor de la actirz protagonista de  
  79. ##  la Máscara (The Mask, 1994)                       
  80. ##==============================================================================
  81.  
  82. import sys
  83. import argparse
  84. import random
  85. import getpass
  86. import hashlib
  87. import os
  88. from datetime import datetime
  89.  
  90. # definimos el argparser
  91. parser = argparse.ArgumentParser(description='Yasbeck - App. para verificación de defacements.', prog='yasbeck.py')
  92. # definimos el método de entrada como grupo exclusivo
  93. #entradas = parser.add_mutually_exclusive_group(required=True)
  94. # añadimos las funciones posibles
  95. #funciones.add_argument('-c', '--cifrar',  required=False, action='store_true', default=False, help='para indicar operaciones de cifrado.')
  96. #funciones.add_argument('-d', '--descifrar', required=False, action='store_true', default=False, help='para indicar operacioens de descifrado.')
  97. parser.add_argument('-d', '--defacement', metavar='<DEFACEMENT_FILE>', required=True, action='store', help = 'URI del fichero de defacement.')
  98. parser.add_argument('-p', '--proxy', metavar='<IP>:<PORT>',required=False, action='store', help='para usar la configuración de un proxy dado en el formato <IP>:<PORT>.')
  99. parser.add_argument('-q', '--quiet', required=False, action='store_true', default=False, help = 'para no mostrar ninguna salida en la consola.')
  100. parser.add_argument('-s', '--sites', metavar='<SITES_FILE>', required=True, action='store', help='para determinar el fichero donde se encuentran las URIS a comprobar.')
  101. parser.add_argument('-t', '--tor', required=False, action='store_true',default=False, help='para usar la configuración del proxy de Tor.')
  102. parser.add_argument('--version', action='version', version='%(prog)s 1.0')
  103. args = parser.parse_args()
  104.  
  105. from cStringIO import StringIO
  106. import urllib2
  107.    
  108. def md5Checksum(filePath):
  109.     fh = open(filePath, 'rb')
  110.     m = hashlib.md5()
  111.     while True:
  112.         data = fh.read(8192)
  113.         if not data:
  114.             break
  115.         m.update(data)
  116.     return m.hexdigest()
  117.  
  118. if __name__ == "__main__":
  119.     if not args.quiet:
  120.         print "Iniciando yasbeck.py..."
  121.  
  122.     ## Generamos el hash del fichero original
  123.     if not args.quiet:
  124.         print "Intentando generar hash de la password pasada por parámetro..."
  125.  
  126.     md5_orig=md5Checksum(args.defacement)
  127.     print 'The MD5 checksum of the file is', md5_orig
  128.    
  129.     ## configurando proxy de tor
  130.     if args.tor:
  131.         print "Tor"
  132.         proxy= urllib2.ProxyHandler({'http':'127.0.0.1:8118'})
  133.         opener = urllib2.build_opener(proxy)
  134.         urllib2.install_opener(opener)
  135.     ## configurando proxy
  136.     elif args.proxy:
  137.         print "Proxy"
  138.         proxy= urllib2.ProxyHandler({'http':args.proxy})
  139.         opener = urllib2.build_opener(proxy)
  140.         urllib2.install_opener(opener)
  141.  
  142.     ## Contador
  143.     hackedSites=0
  144.    
  145.     if not args.quiet:
  146.         print "Buscando todas las URIS supuestamente defaceadas..."
  147.     f = open(args.sites,"r")
  148.     listaSites=f.readlines()
  149.     f.close
  150.  
  151.     current =0
  152.     for url in listaSites:
  153.         print "Procesando:\t", url.split("\n")[0]
  154.         current+=1
  155.         try:
  156.             resource = urllib2.urlopen(url)
  157.             now = datetime.now()
  158.             filename=str(now.year)+"-"+str(now.month)+"-"+str(now.day)+"_"+str(now.hour)+"-"+str(now.minute)+"-"+str(now.second)+".png"
  159.             filename="temp"+str(current)+".html"
  160.             output= open(filename,"wb")
  161.             output.write(resource.read())
  162.             output.close()
  163.             actual=md5Checksum(filename)
  164.  
  165.             if actual ==md5_orig:
  166.                 print "\t[HACKED]\t", actual, "\t==\t", md5_orig
  167.                 hackedSites+=1;
  168.             else:
  169.                 print "\t[Recovered]\t", actual, "\t!=\t", md5_orig,"\n"
  170.             print "Siguen (al menos) hackeados:\t"+str(hackedSites)+"/"+str(current)+"\n"
  171.         except IOError as e:
  172.             print "\t[IOError]","\n"
  173.             print "Siguen (al menos) hackeados:\t"+str(hackedSites)+"/"+str(current)+"\n"
  174.     print "En total siguen (al menos) hackeados:\t"+str(hackedSites)+"/"+str(len(listaSites))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement