Skip to content

Instantly share code, notes, and snippets.

@mrsndmn
Created April 12, 2020 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrsndmn/521b0903fdeb3a195114d2e81502d0b9 to your computer and use it in GitHub Desktop.
Save mrsndmn/521b0903fdeb3a195114d2e81502d0b9 to your computer and use it in GitHub Desktop.
import random
from ctypes import CDLL
libc = CDLL("libc.so.6")
asciiRange = 0x7E - 0x20
ans = []
with open("ctf.in110", 'r') as f:
for line in f:
data = list(line)
data = data[:-1]
# print(data)
for i, c in enumerate(data):
cur_seed = i + ord(c)
libc.srand(cur_seed)
not_ok = False
for j, cc in enumerate(data):
if j == i:
continue
rint = libc.rand() % asciiRange + 0x20
gen_char = chr(rint)
if cc != gen_char:
not_ok = True
break
if not not_ok:
ans.append(c)
break
print("".join(ans))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment