Files
college-pentesting/bot.py
2018-11-24 05:56:26 +01:00

111 lines
3.3 KiB
Python

#import urllib
#
#password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
#
#top_level_url = "http://192.168.1.119"
#password_mgr.add_password(None, top_level_url, "admin", "Azerty123")
#
#handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
#
#opener = urllib.request.build_opener(handler)
#
#opener.open("http://192.168.1.119")
#
#urllib.request.install_opener(opener)
#
#temp = urllib.request.urlopen("http://192.168.1.119")
import urllib.request
import base64
import requests
def getReq(url, user, passw, headers=None):
try:
req= urllib.request.Request(url)
credentials = ('%s:%s' % (user, passw))
encoded_credentials = base64.b64encode(credentials.encode('ascii'))
req.add_header('Authorization', 'Basic %s' % encoded_credentials.decode("ascii"))
if headers:
for h in headers:
req.add_header(h[1], h[2])
with urllib.request.urlopen(req) as response:
return str(response.read())
except urllib.error.HTTPError as e:
return str(e)
def postReq(url, user, passw, data, headers=None):
try:
d = urllib.parse.urlencode(data, quote_via=urllib.parse.quote_plus).encode('utf-8')
req= urllib.request.Request(url)
credentials = ('%s:%s' % (user, passw))
encoded_credentials = base64.b64encode(credentials.encode('ascii'))
req.add_header('Authorization', 'Basic %s' % encoded_credentials.decode("ascii"))
if headers:
for h in headers:
req.add_header(h[0], h[1])
print(req.headers)
print(req.get_full_url())
with urllib.request.urlopen(req) as response:
return str(response.read())
except urllib.error.HTTPError as e:
return str(e)
base_url = "http://192.168.1.119/"
username = "admin"
password = "Azerty123"
data = {
"ReplySuccessPage":"home.htm",
"ReplyErrorPage":"home.htm",
"WebLanguage":"4",
"ConfigSystemLanguage":"Save"
}
#headers = {
# "Host": "192.168.1.119",
# "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0",
# "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
# "Accept-Language": "en-US,en;q=0.5",
# "Accept-Encoding": "gzip, deflate",
# "Referer": "http://192.168.1.119/home.htm",
# "Content-Type": "application/x-www-form-urlencoded",
# "Content-Length": "87",
# "Connection": "keep-alive",
# "Upgrade-Insecure-Requests": "1"
#}
headers = [
("Host","192.168.1.119"),
("User-Agent","Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"),
("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
("Accept-Language","en-US,en;q=0.5"),
("Accept-Encoding","gzip, deflate"),
("Referer","http://192.168.1.119/home.htm"),
("Content-Type","application/x-www-form-urlencoded"),
("Content-Length","87"),
("Connection","keep-alive"),
("Upgrade-Insecure-Requests","1")
]
posturl = "/home.thm"
print("post request on setSystemLanguage:\n " + postReq("http://192.168.1.119"+posturl,username,password,data, headers))
#print("\n\n\n")
#data = {"ReplySuccesPage":";ls","ReplyErrorPage":";ls"}
#posturl = ""
#
#print("post request on index:\n "+postReq(base_url, username, password, data))