zepek_al

Joomla! Plugins/Exploits Auto-Updating Scanner

Nov 9th, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.53 KB | None | 0 0
  1. # Joomla! Plugins/Exploits Auto-Updating Scanner
  2. # Author: @Zepek, <live:zepek_al>
  3.  
  4. # This is a simple auto-updating Joomla! Plugins Scanner which is able to find exploits related to previously found components.
  5. # It uses the csv file provided by the Exploit-DB team and an extra plugins' list from Metasploit, but it is totally indipendent from this last one.
  6. # TOR Proxy tunnel is available.
  7.  
  8. # [FLOODING] If the target is protected by flooding requests the script won't be successful clearly.
  9.  
  10. # Script's Programming Language support: Python 2.7.*
  11.  
  12. # *******************************************************************************************************************************************
  13. # WARNING: You could have not installed some of the required libraries but it will install them for you PROVIDED you run the script as root.
  14. #          Besides you need to install pip in order to get missing libraries quickly.
  15. # *******************************************************************************************************************************************
  16. #!/usr/bin/python
  17. # -*- coding: utf-8 -*-
  18. import os
  19. import csv
  20. import sys
  21. import time
  22. import urllib
  23.  
  24. try:
  25.     import requests
  26. except ImportError:
  27.     print "[!] 'requests' library not found. Installing it automatically using pip.."
  28.     time.sleep(0.5)
  29.     os.system("pip install requests")
  30.     import requests
  31.  
  32. import codecs
  33.  
  34. try:
  35.     import socks
  36. except ImportError:
  37.     print "[!] socks.pyc not found. Downloading it automatically.."
  38.     time.sleep(0.5)
  39.     urllib.urlretrieve ("https://github.com/alyssafrazee/randomcalendars/blob/master/httplib2/socks.pyc?raw=true", "socks.pyc")
  40.     import socks
  41.    
  42. import socket
  43.  
  44. try:
  45.     import shutil
  46. except ImportError:
  47.     print "[!] 'shutil' library not found. Installing it automatically using pip.."
  48.     time.sleep(0.5)
  49.     os.system("pip install shutil")
  50.     import shutil
  51.  
  52. import urllib2
  53. import argparse
  54.  
  55. try:
  56.     from termcolor import colored
  57. except ImportError:
  58.     print "[!] 'termcolor' library not found. Installing it automatically using pip.."
  59.     time.sleep(0.5)
  60.     os.system("pip install termcolor")
  61.     from termcolor import colored
  62.  
  63. useTor   = False
  64. Update   = True
  65. tor_port = 9150
  66. tor_addr = "127.0.0.1"
  67. compFile = "comptotest.txt"
  68. expFile  = "exp-db_files.csv"
  69. csvURL = "https://raw.githubusercontent.com/offensive-security/exploit-database/master/files.csv"
  70. metasploitURL = "https://raw.githubusercontent.com/rapid7/metasploit-framework/master/data/wordlists/joomla.txt"
  71. found = []
  72.  
  73. def getComponents():
  74.     global found
  75.  
  76.     with open(expFile,"r") as f:
  77.         for line in f:
  78.             if("com_" in line and "Joomla" in line):
  79.                 split = line.split(" ")
  80.                 for w in split:
  81.                     w = w.strip()
  82.                     if((w.startswith("com_") or w.startswith("'com_")) and w not in found):
  83.                         if(w[0] == '\''):
  84.                             w = w[1:len(w)-1]
  85.                         found.append(w)
  86.                         break
  87.  
  88.     found = set(found)
  89.     of = open(compFile,"w")
  90.     i = 0
  91.     for f in found:
  92.         i += 1
  93.         print "[%s] %s" %(i,f)
  94.         of.write(f+"\n")
  95.     of.close()
  96.  
  97. def getExploitDbList():
  98.     response = urllib2.urlopen(csvURL)
  99.     of = open(expFile,"w")
  100.     cr = csv.reader(response)
  101.     for row in cr:
  102.         of.write(str(row)+"\n")
  103.     of.close()
  104.  
  105. def getMetasploitList():
  106.     global found
  107.  
  108.     try:
  109.         response = requests.get(metasploitURL).text
  110.     except:
  111.         return
  112.        
  113.     nlsplit = response.split("\n")
  114.     for s in nlsplit:
  115.         if("com_" in s):
  116.             start = s.find('com_')
  117.             compToAdd = ""
  118.             for x in range(start,len(s)):
  119.                 if(CharOrNumber(s[x])):
  120.                     compToAdd = "%s%s" %(compToAdd,s[x])
  121.                 else:
  122.                     break
  123.             found.append(compToAdd)
  124.  
  125. def CharOrNumber(c):
  126.     if(c.isalpha() or str(c).isdigit() or c == '_'):
  127.         return True
  128.     return False
  129.  
  130. def extractExploits(foundComp):
  131.     exploits = []
  132.  
  133.     with open(expFile,"r") as f:
  134.         for line in f:
  135.             for comp in foundComp:
  136.                 if(comp in line and "Joomla" in line and CharOrNumber(line[line.find(comp)+len(comp)]) is False):
  137.                     exploits.append(line.strip())
  138.  
  139.     exploits = set(exploits)
  140.     return exploits
  141.  
  142. def checkTor(inp):
  143.     global tor_addr
  144.     global tor_port
  145.  
  146.     if(":" not in inp and "." not in inp):
  147.         print "\n[!] Invalid TOR proxy syntax (it must be 'tor_addr:tor_port'). Using '%s:%s' as default." %(tor_addr,tor_port)
  148.         time.sleep(1)
  149.         return
  150.  
  151.     split = inp.split(":")
  152.     tor_addr = split[0]
  153.     tor_port = split[1]
  154.  
  155.  
  156. print "\nJoomla! Components/Exploits Auto-Updating Scanner"
  157. print "Author: @Zepek, <live:zepek_al>\n"
  158. time.sleep(0.7)
  159.  
  160. parser = argparse.ArgumentParser(description="")
  161. parser.add_argument("--target", type=str, help="Enter the target to scan",required=True)
  162. parser.add_argument("--tor_proxy", type=str, help="Enable the tool to use the TOR proxy",default="None")
  163. parser.add_argument("--no_update",help="Disable the update from github. You need to provide your own comptotest.txt and exp-db_files.csv files",
  164.     action='store_true',default=False)
  165. args = parser.parse_args()
  166.  
  167. target = args.target
  168.  
  169. if(args.tor_proxy != "None"):
  170.     checkTor(args.tor_proxy)
  171.  
  172.     socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, tor_addr, tor_port)
  173.     socket.socket = socks.socksocket
  174.  
  175. if("http" not in target[:4]):
  176.     target = "http://%s" %target
  177. if(target[len(target)-1] != '/'):
  178.     target = "%s/" %target
  179.  
  180. headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0'}
  181. toCheck = ["<h1>Not Found</h1>","<title> 404 - Page not found</title>","\"center error-404\""]
  182. foundComp = []
  183.  
  184. if(args.no_update is False):
  185.     print "Downloading Metasploit list.."
  186.     getMetasploitList()
  187.     print "Downloading Exploit-db csv list.."
  188.     getExploitDbList()
  189.  
  190.     time.sleep(1)
  191.     print "\nUpdating Joomla! components.."
  192.     getComponents()
  193.     print ""
  194.  
  195. else:
  196.     if(os.path.isfile("comptotest.txt") is False):
  197.         print "\n[-] '%s' not found. You must provide a file containing the Joomla! components to scan for." %compFile
  198.         compFile = raw_input("[*] Components List file -> ")
  199.     if(os.path.isfile("exp-db_files.csv") is False):
  200.         print "\n[-] '%s not found. You must provide a csv file containing the exploit-db list." %expFile
  201.         expFile = raw_input("[*] Exploit-db list file -> ")
  202.  
  203. bad_resp = requests.get("%scomponents/impo5sIblexXxD35" %target).text
  204. i = 0
  205.  
  206. with open(compFile,"r") as f:
  207.     for line in f:
  208.         i += 1
  209.         line = line.strip()
  210.         if(len(line) > 0 and line != "com_"):
  211.             print "[%s] Testing '%s'" %(i,line)
  212.             url = "%scomponents/%s" %(target,line) 
  213.             #print url
  214.             try:
  215.                 r = requests.get(url,headers=headers,timeout=10)
  216.                 Valid = True
  217.                 for c in toCheck:
  218.                     if(c in r.text):
  219.                         Valid = False
  220.                         break
  221.                 if(r.status_code != 404 and Valid and (r.url == url or r.url == "%s/" %url)
  222.                     and len(r.text) < 5000 and r.text != bad_resp):
  223.                     foundComp.append(line)
  224.                     print "%s [FOUND]" %line
  225.             except:
  226.                 pass
  227.  
  228. print "\nJoomla! components found [%s]: \n" %len(foundComp)
  229. print "----------------------------"
  230. for comp in foundComp:
  231.     print comp
  232. print "----------------------------\n"
  233.  
  234. exploits = extractExploits(foundComp)
  235. print "\nJoomla! exploits found [%s]: \n" %len(exploits)
  236.  
  237. for comp in foundComp:
  238.     print colored("\n%s:\n" %comp,"red")
  239.     for exp in exploits:
  240.         if(comp in exp):
  241.             split = exp.split(",")
  242.             code = split[1].split("/")
  243.             code = code[len(code)-1].split(".")[0]
  244.             output = "%s  [https://www.exploit-db.com/exploits/%s/]" %(split[2],code)
  245.             print '-' * len(output)
  246.             print output
  247.             print '-' * len(output)
  248.  
  249. if(len(foundComp) == 0):
  250.     print "\n[-] Probably the website has some kind of Flooding protection or it redirects all the requests we send to /components!"
  251.  
  252. print ""
  253.  
  254. if(Update):
  255.     os.remove("%s" %compFile)
  256.     os.remove("%s" %expFile)
Advertisement
Add Comment
Please, Sign In to add comment