Skip to content

Instantly share code, notes, and snippets.


xct/ Secret

Last active November 20, 2022 22:22
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xct/9b60d9255afe400dd0ce7bb774e613ec to your computer and use it in GitHub Desktop.
SquareCTF 2022 Yara Challenge "Yet Another Reversing Activity"
#!/usr/bin/env python3
import subprocess
# Author: @xct_de
# Challenge:
flag = ""
flag = "flag{" # checkpoint
baseline = ""
for j in range(32):
l = len(flag)
for i in range(0x20,0x7F,1):
# write flag file, bruting last char
f = open('./out', 'w')
f.write(flag + chr(i))
# count instructions
p = subprocess.Popen("valgrind --tool=callgrind /usr/bin/yara -C flag.yarc out 2>&1 | grep refs | cut -d ' ' -f11", stdout=subprocess.PIPE, shell=True)
output = p.communicate()[0].rstrip(b"\n")
output = int(output.decode().replace(",",""))
if i == 0x20:
baseline = output
# count as hit if more than a few instructions difference (valgrind is not perfect)
elif abs(baseline-output)>10:
flag += chr(i)
print(f"Found: {chr(i)} ({output})")
print(f"Flag: {flag}")
if l == len(flag):
print("Whoops, try again")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment