Advertisement
Guest User

Elephant BS [Bug Searcher] V 1.0 Beta

a guest
Sep 19th, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.67 KB | None | 0 0
  1. #!/usr/bin/py
  2. """
  3. Codeado por isseu (twitter.com/isseu)
  4. Grax CPH, DDLR, H-SEC
  5. 1.0 Beta 19/09/2011
  6. """
  7. import sys,re,argparse,os,fnmatch
  8. inputs = ["\$\_request","\$\_post","\$\_get","\$\_server\[[\"']php\_self[\"']","\$\_cookie"]
  9. bugs = [
  10.     ["(print|echo)(\s?\(\s?)?(%&1&%)","[\"']\s*[\+\.]\s*(%&1&%)",
  11.     "(file_include|include|require|include_once|require_once)(\b|\()+(%&1&%)\[",
  12.     "<\?=\t*(%&1&%)\[","(src|href)\=[\"']\<\?\s*(php)*\s*(echo|print|=)\s*\$_server\[[\"']php_self[\"']",
  13.     "phpinfo\(","(shell_exec|system|exec|popen|passthru|proc_open|pcntl_exec)\(",
  14.     "(eval|assert|create_function)\("
  15.     ]
  16.     ,
  17.     ["XSS","XSS/SQLI","LFI/RFI","XSS","XSS","DATA LEAK","CMD EXECUTION","CODE EXECUTION"]
  18. ]
  19. def Rojo(a):
  20.     if os.name=="posix": #linux
  21.         return "\33[31m"+a+"\033[0m"
  22.     else: #not linux
  23.         return a
  24.        
  25. def BuscarArchivosRecursivo(path,regex):
  26.     matches = []
  27.     for root, dirnames, filenames in os.walk(path):
  28.       for filename in fnmatch.filter(filenames, regex):
  29.           matches.append(os.path.join(root, filename))
  30.     return matches
  31.    
  32. def Escanear_Archivo(archivo,args):
  33.     nombre = False;
  34.     FILE = open(archivo,"r")
  35.     line = FILE.readline()
  36.     # Se reinician en cada archivo
  37.     variables = inputs[:]
  38.     # Cada linea
  39.     i = 1; # de linea
  40.     while line:
  41.         # Si se anade variable
  42.         if args.heuristic:
  43.             dat = re.search("^\s\$.*\s?\.?\s?=\s?(\".*\"\s*[\.\+]\s*)*\$_(get|post|request)",line,flags=re.IGNORECASE)
  44.             if dat:
  45.                 if nombre == False:
  46.                     print "[+] File: " + archivo
  47.                     nombre = True;
  48.                 variables.append("\$" + re.escape(dat.group(0)[1:dat.group(0).index("=")]))
  49.                 print "   [!] Watch var at line "+str(i)+": " + line.strip()
  50.  
  51.         # Cada bugs
  52.         for a in range(0,len(bugs[0])):
  53.             se = re.search((bugs[0][a]).replace("%&1&%","|".join(variables)),line,flags=re.IGNORECASE)
  54.             if se:
  55.                 if nombre==False:
  56.                     print "[+] File: "+archivo
  57.                     nombre = True;
  58.                 print "   "+Rojo("[!]")+" Line "+str(i)+": "+line.strip()+" ("+bugs[1][a]+")"
  59.         line = FILE.readline()
  60.         i+=1;
  61.        
  62. def Banner():
  63.     print """
  64.  ______ _            _                 _     ____   _____
  65. |  ____| |          | |               | |   |  _ \ / ____|
  66. | |__  | | ___ _ __ | |__   __ _ _ __ | |_  | |_) | (___  
  67. |  __| | |/ _ \ '_ \| '_ \ / _` | '_ \| __| |  _ < \___ \
  68. | |____| |  __/ |_) | | | | (_| | | | | |_  | |_) |____) |
  69. |______|_|\___| .__/|_| |_|\__,_|_| |_|\__| |____/|_____/ .py
  70.               | |                                        
  71.               |_|                                                  
  72. [+] Coded by """+Rojo("Isseu")
  73. def ShowExpressions():
  74.     print "[+] Regular expressions ("+str(len(bugs[0]))+"):"
  75.     for i in range(0,len(bugs[0])):
  76.         print "  \""+bugs[0][i]+"\"  ("+bugs[1][i]+")"
  77.        
  78. if __name__ == "__main__"
  79.     Banner()   
  80.    
  81.     parser = argparse.ArgumentParser(description='Found common errors in php scripts',epilog='Have Fun!')
  82.     parser.add_argument('PATH', type=str,help='File to analyze')
  83.     parser.add_argument('-e', type=str,help='Extensions to analyse (Default: php) example -e (php|plp)',metavar="php",default="php")
  84.     parser.add_argument('-he', '--heuristic', help='Work with heuristic, advanced',action='store_true')
  85.     parser.add_argument('-v', '--version', help='Show version', action='version', version='[+] %(prog)s 1.0 Beta')
  86.     parser.add_argument('-r', help='Show regex expressions', action='store_true')
  87.     args = parser.parse_args()
  88.     if(args.r):
  89.         ShowExpressions()
  90.     if(os.path.exists(args.PATH)==False):
  91.         print "PATH doesn't exist"
  92.         exit();
  93.     archivos = BuscarArchivosRecursivo(args.PATH,'*.'+args.e)
  94.    
  95.     print "[+] Scan Started ("+str(len(archivos))+" archivos)"
  96.     for i in range(0,len(archivos)):
  97.         Escanear_Archivo(archivos[i],args)
  98.     print "[+] Scan Finished"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement