urlencode & urldecode (línea de comandos)

Recientemente me encargaron investigar sobre unos casos de inyección SQL. Mirando el log de apache puedo ver el query usado en el GET, pero aparece "codificado".

Haciendo uso de python creé un "wrapper" sencillo, para decodificar la URL y lo agregué como alias en mi ~/.bashrc para futuros usos.

Para esto, edité ~/.bashrc (en mi caso uso 'vi') y agregué las siguiente líneas:

## urlencode and urldecode command line wrapper
alias urldecode='python -c "import sys, urllib; print urllib.unquote_plus(sys.argv[1])"'

Este wrapper se usa así:

$ urldecode "GET /archive/index.php/t-144394-p-5.html?s=853e564ab16ef3a0deba62705e2f9838%20and%28select%201%20from%28select%20count%28*%29%2Cconcat%28%28select%20%28select%20%28SELECT%20distinct%20concat%28file_priv%2C0x27%2C0x7e%29%20FROM%20mysql.user%20%20LIMIT%200,1%29%29%20from%20information_schema.tables%20limit%200%2C1%29%2Cfloor%28rand%280%29*2%29%29x%20from%20information_schema.tables%20group%20by%20x%29a%29%20and%201%3D1 HTTP/1.0"
Y el resultado es:
GET /archive/index.php/t-144394-p-5.html?s=853e564ab16ef3a0deba62705e2f9838 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(file_priv,0x27,0x7e) FROM mysql.user  LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 HTTP/1.0
Tenemos la cadena decodificada. Vieron las comillas? No olviden poner la cadena entre comillas.

Como tip, se puede hacer algo similar para codificar cadenas. El alías sería así:

alias urlencode='python -c "import sys, urllib; print urllib.quote_plus(sys.argv[1])"'

Y se usa exactamente igual.

Comments

Popular Posts