1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| from pwn import * from pwn import p64, p32, u32, u64, p8, p16
if_32: bool = False if_debug: bool = False pg = p32 if if_32 else p64 ug = u32 if if_32 else u64 context(log_level="debug", arch="i386" if if_32 else "amd64", os="linux") p=remote("47.97.58.52",40010)
def send_after_clean(content: bytes = b"", until: bytes = None, timeout: float = 0.05, no_show: bool = True): if until is not None: p.recvuntil(flat(until)) else: received = p.clean(timeout) if not no_show: print(f"[$]received:\n{received.decode('UTF-8')}") p.send(flat(content))
def sendline_after_clean(content: bytes = b"", until: bytes = None, timeout: float = 0.05, no_show: bool = True): send_after_clean([content, p.newline], until, timeout, no_show)
def interactive_after_clean(timeout: int = 0.05, no_show: bool = True): received = p.clean(timeout) if not no_show: print(f"[$]received:\n{received}") p.interactive()
def formula_compute(formula: bytes, precise: bool = False): if isinstance(formula, bytes): formula = formula.decode("UTF-8") formula = formula.strip() formula = formula.strip("\n") formula = formula.replace("x", "*") formula = formula.replace("^", "**") formula = formula.replace("÷", "/") if not precise: formula = formula.replace("//", "/") formula = formula.replace("/", "//") return bytes(str(eval(formula)), encoding="UTF-8")
for i in range(100): question = p.recvuntil(b".") answer = formula_compute(question) sendline_after_clean(answer, "answer:")
interactive_after_clean()
|