Created
November 19, 2021 00:04
-
-
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.
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 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