Skip to content

Instantly share code, notes, and snippets.

@Wind010
Last active November 26, 2023 00:36
Show Gist options
  • Select an option

  • Save Wind010/1afdb98798651fa612475aa1f828b7d6 to your computer and use it in GitHub Desktop.

Select an option

Save Wind010/1afdb98798651fa612475aa1f828b7d6 to your computer and use it in GitHub Desktop.
Hack-the-Box: Racecar PWN challenge flag decoder
#!/usr/bin/env python3
import re
import sys
def main(payload=None):
if payload is None:
payload = input("Enter exfiltrated memory addresses: ")
raw_flag = payload.split()
# Split into two character substrings: '0x48656c6c6f' into ['0x', '48', '65', '6c', '6c', '6f']
# as part of 2d-list.
raw_flag = [re.findall('..', item) for item in raw_flag]
# Iterate the characters in reverse order since we're popping off the stack.
# Ignore the the '0x' signififier for the memory address.
# Each two character hexadecimal (base16) string is converted to the corresponding ASCII leter.
flag_list = [''.join(chr(int(char, 16)) for char in chars[::-1] if char != '0x') for chars in raw_flag]
flag = ''.join(flag_list)
# Using regex to extract the substring starting with HTB{ and ending with }
match = re.search(r'HTB\{.*?\}', flag)
if match:
print(match.group())
else:
print("Flag with format HTB{***} not found: We have this: " + flag)
if __name__ == "__main__":
if len(sys.argv) > 1:
main(sys.argv[1])
else:
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment