Skip to content

Instantly share code, notes, and snippets.

@atz
Created November 19, 2021 00:04
Show Gist options
  • Save atz/7b7d22cf3ef9a846225c255806c59cb5 to your computer and use it in GitHub Desktop.
Save atz/7b7d22cf3ef9a846225c255806c59cb5 to your computer and use it in GitHub Desktop.
suricata-update net.py section usefully allows setting arbitrary HTTP headers. This is a minimal extraction and adaptation of lines allowing execution.
import re
def is_header_clean(header):
if len(header) != 2:
return False
name, val = header[0].strip(), header[1].strip()
if re.match( r"^[\w-]+$", name) and re.match(r"^[\w\s -~]+$", val):
return True
return False
url = ("https://example.com/feed", "Authorization: Basic YXR6QGNvcmVsaWdodC5jb206bXlwYXNzd29yZA==")
if isinstance(url, tuple):
header = url[1].split(":") if url[1] is not None else None
if header and is_header_clean(header=header):
name, val = header[0].strip(), header[1].strip()
print("Setting HTTP header %s to %s" % (name, val))
elif header:
print("Header not set as it does not meet the criteria")
url = url[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment