Skip to content

Instantly share code, notes, and snippets.

@AmunRha
Created June 25, 2021 19:58
Show Gist options
  • Save AmunRha/c734cf68c973aad103f88f7fcde02fef to your computer and use it in GitHub Desktop.
Save AmunRha/c734cf68c973aad103f88f7fcde02fef to your computer and use it in GitHub Desktop.
This is an alternative way to solve the X MAS CTF 2019 challenge Discount VMProtect by instrumenting the binary with the help of intel pintools
import os
import string
START_CHAR = "|"
POSSIBLE_CHARS = "|" + string.digits + "}{_-" + string.ascii_uppercase + string.ascii_lowercase
def get_count(cmd):
pipe = os.popen(cmd)
pipe.readline()
count = pipe.readline().split()[1]
return int(count, 0)
# Uncomment for Debug statements
def main():
cmd = f'echo "{START_CHAR}" | ../../../pin -t obj-intel64/inscount0.so -- ~/VM'
count_prev = get_count(cmd)
flag = ""
j = 0
while True:
if "X-MAS{" in flag and "}" in flag:
break
i = POSSIBLE_CHARS[j]
j+=1
cmd = f'echo "{flag}{i}" | ../../../pin -t obj-intel64/inscount0.so -- ~/VM'
if i == "|":
count_prev = get_count(cmd)
#print(f"[*] Trying char: {flag}{i} | Instruction Count: {count_prev}")
continue
count = get_count(cmd)
#print(f"[*] Trying char: {flag}{i} | Instruction Count: {count}")
if count == count_prev:
continue
elif count != count_prev and 50 < abs(count-count_prev):
flag += i
#print(f"[!] Flag character found!")
print(f"[!] Flag: {flag}\n")
j = 0
print(f"[+] Final Flag: {flag}")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment