Skip to content

Instantly share code, notes, and snippets.

@adityatelange
Created May 31, 2022 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityatelange/3a71a6f3b3ec24ae32394c9f4fd89f3f to your computer and use it in GitHub Desktop.
Save adityatelange/3a71a6f3b3ec24ae32394c9f4fd89f3f to your computer and use it in GitHub Desktop.
This script helps VIP users download all the write-ups from HTB
import requests, time
print('Beginning file download with requests')
# get app token here https://app.hackthebox.com/profile/settings
token = ''
def downloadWU(x):
url = 'https://www.hackthebox.com/api/v4/machine/writeup/{}'.format(x)
r = requests.get(url,
headers={
"authority": "www.hackthebox.com",
"authorization": "Bearer {}".format(token),
"cache-control": "no-cache",
"pragma": "no-cache",
"referer": "https://app.hackthebox.com/",
"origin": "https://app.hackthebox.com/",
"accept": "application/json, text/plain, */*",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"accept-language": "en-US,en;q=0.9"
}
)
# Retrieve HTTP meta-data
if r.status_code == 200:
filename = r.headers["Content-Disposition"].split("=")[1]
with open("{}{}".format(x, filename), 'wb') as f:
f.write(r.content)
print(x, filename)
return True
elif r.status_code == 404:
print(x, r.status_code)
return True
else:
# 429
print("sleeping for 50 sec")
time.sleep(50)
return False
remains= []
for x in range(54,500):
if not downloadWU(x):
remains.append(x)
time.sleep(7)
print(remains)
time.sleep(50)
for x in remains:
if not downloadWU(x):
remains.append(x)
time.sleep(7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment