Upload files to "Modules"
This commit is contained in:
@ -385,14 +385,21 @@ TCODES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
ANSI_ESCAPE_REGEX = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
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):
|
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)
|
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:
|
if clean:
|
||||||
# Remove ANSI escape codes if clean output is requested
|
# Remove HTML tags for clean output
|
||||||
return ANSI_ESCAPE_REGEX.sub('', formatted_item)
|
formatted_item = re.sub(r'<[^>]+>', '', formatted_item)
|
||||||
|
|
||||||
return formatted_item
|
return formatted_item
|
Reference in New Issue
Block a user