Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import requests
import json
import re
import time
import random
machine = "machine (like Irked)"
server = "server (like eu-free-1)"
api_token = "access token for HTB RESTful API (like MpkzFFRaZyP3xd0BKCavc8a5m23y72OvcwXONjNdgYOvXijLfOBev6ajKq6z)"
request_headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246" }
get_shoutbox_url = "{}".format(api_token)
post_shout_url = "{}".format(api_token)
reset_pattern = re.compile("\[(.+?)\]\s(.+?)\srequested a reset on {}\s\[{}\]\s\[Type (\/cancel \d+?) within two minutes to cancel the reset\]".format(machine, server))
def write_log(message, success=True):
log_template = "[{}] {}"
flag = "+" if success else "-"
print log_template.format(flag, message)
def get_shoutbox(old_shouts):
r =, headers=request_headers)
data = json.loads(r.text)
success = int(data['success'])
if not success:
raise Exception(r.text)
shouts = data['html']
html_pattern = re.compile('<.*?>')
new_shouts = [re.sub(html_pattern, '', item) for item in shouts if re.sub(html_pattern, '', item) not in old_shouts]
return new_shouts
def cancel_reset(cancel_message):
r =, headers=request_headers, data = {"text": cancel_message})
data = json.loads(r.text)
success = int(data['success'])
return success
def random_sleep():
sleep_seconds = random.randint(10, 30)
write_log("Waiting random delay - {} seconds".format(sleep_seconds), success=True)
old_shoutbox = []
while True:
shoutbox = get_shoutbox(old_shoutbox)
if len(shoutbox):
for e in shoutbox:
matches = reset_pattern.match(e)
if matches:
date =
name =
cancel_string =
write_log("Detected reset from '{}'".format(name), success=True)
if cancel_reset(cancel_string):
write_log("Reset canceled!")
write_log("Could not cancel reset of '{}' - did somebody cancel it before us?".format(name), success=False)
old_shoutbox = old_shoutbox + shoutbox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment