Created
July 11, 2019 09:16
-
-
Save frikky/33b4159aed078ac5f157d62fff9b74d9 to your computer and use it in GitHub Desktop.
Taking a screenshot in Netcraft using your own credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def screenshot(username, password, takedownurl, proxies): | |
if not isinstance(proxies, list) or len(proxies) == 0: | |
print("Proxies should be a list of countrynames e.g. [us,en]") | |
return "" | |
if len(username) == 0 or len(password) == 0: | |
print("Username and password has to be defined") | |
return "" | |
if len(takedownurl) == 0: | |
print("The url to take down needs to be defined") | |
return "" | |
homepage = "https://takedown.netcraft.com" | |
loginhost = "https://sso.netcraft.com" | |
screenshoturl = "https://screenshot.netcraft.com/index.cgi" | |
# Imitate firefox | |
headers = { | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" | |
} | |
auth = (username, password) | |
print("Making new session with CSRF tokens etc, imitating firefox (:") | |
client = requests.Session() | |
ret = client.get(homepage) | |
csrf_token = "" | |
for line in ret.text.split("\n"): | |
if "csrf_token" in line: | |
token_prefix = line.split(" ")[7] | |
csrf_token = token_prefix.split("=")[1][1:-1] | |
break | |
if not csrf_token: | |
print("Didn't find any csrf token") | |
return "" | |
logindata = { | |
"csrf_token": csrf_token, | |
"destination": "https://takedown.netcraft.com/", | |
"credential_0": username, | |
"credential_1": password | |
} | |
print("Logging in with user %s" % username) | |
newret = client.post("%s/login" % loginhost, data=logindata, headers=headers, cookies=client.cookies) | |
if len(client.cookies) <= 1: | |
print("RAW: %s\n\nMissing cookies after login: %s" % newret.text, newret.status_code) | |
return "" | |
screenshotparams = { | |
"url": takedownurl, | |
"type": "interface", | |
"level": "customer", | |
"proxy_cc": ",".join(proxies), | |
"proxy_single": "1" | |
} | |
print("Taking screenshot of %s" % takedownurl) | |
ret = client.post(screenshoturl, data=screenshotparams, headers=headers) | |
if ret.status_code != 200: | |
print("RAW: %s\n\nBad status code: %d", ret.text, ret.status_code) | |
return "" | |
imageurl = ret.headers.get("Screenshot") | |
# Logging out | |
print("Logging out of user %s" % username) | |
client.post("%s/logout" % loginhost, data=logindata, headers=headers, cookies=client.cookies) | |
return imageurl | |
# Old way, but apparently it's also in the headers | |
# Keeping it here in case of more variables that we want | |
#print(ret.headers) | |
# | |
#imageurl = "" | |
#for line in ret.text.split("\n"): | |
# if "var image" in line: | |
# lineitems = line.split(" ") | |
# for item in lineitems: | |
# if item.startswith("\""): | |
# imageurl = item[1:-2] | |
# break | |
# | |
# break | |
# | |
#print(imageurl) | |
if __name__ == "__main__": | |
username = "" | |
password = "" | |
takedownurl = "" | |
proxies = ["us"] | |
image = screenshot(username, password, takedownurl, proxies) | |
if not image: | |
print("Couldn't take screenshot?") | |
else: | |
print(image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment