Upload files to "Modules"

This commit is contained in:
2024-11-29 01:03:47 -05:00
parent 683c145589
commit d1fc72ed12

View File

@ -385,14 +385,21 @@ TCODES = [
]
ANSI_ESCAPE_REGEX = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
TCODE_PATTERN = re.compile(r'(T\d{4}(\.\d{3})?)') # Matches T#### or T####.###
def get_random_tip_or_joke(clean=False):
# Pick a random tip or joke and assign a color
# Pick a random tip or joke
item = random.choice(TIPS + JOKES + TCODES)
formatted_item = f"{item}"
# Replace T-Codes with clickable links
def replace_tcode_with_link(match):
tcode = match.group(1)
return f'<a href="https://attack.mitre.org/techniques/{tcode}/" target="_blank">{tcode}</a>'
formatted_item = TCODE_PATTERN.sub(replace_tcode_with_link, item)
if clean:
# Remove ANSI escape codes if clean output is requested
return ANSI_ESCAPE_REGEX.sub('', formatted_item)
# Remove HTML tags for clean output
formatted_item = re.sub(r'<[^>]+>', '', formatted_item)
return formatted_item