#include<stdio.h> #include<stdlib.h> intmain(int argc,char *argv[]){ int leak1=atoi(argv[1]); int leak2=atoi(argv[2]); for (unsignedint seed=0; seed<=0xffffffff; seed++) { srand(seed); int v5=rand(); int v9_1=rand(); int v9_2=rand(); if (v9_1==leak1&&v9_2==leak2) { printf("%d\n",v5); for (int i=0; i<10; i++) { printf("%d\n",rand()); } break; } } return0; }
然后就是执行和获取c代码的数据
1
gcc 1.c -o 1
1 2 3
result = subprocess.check_output( ['/home/voyager/1', leak1, leak2]).decode().strip().split("\n") #subprocess.check_out是获取其二进制输出,decode()是将其转换为字符串,strip()是去掉空格和换行,split("\n")是按“\n”来分割成列表
获取leak
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
from pwn import * from LibcSearcher import* context(arch = "amd64", os = "linux",log_level = "debug")
#r = remote("node7.anna.nssctf.cn", 21888) r=process("./flag") elf=ELF("./flag") r.recvuntil(b"Let's play a gamble game.\n") r.sendline(str(1)) r.recvuntil(b"No, the correct number is: ") leak1=r.recvuntil(b"\n").decode() print(leak1) r.sendline(str(1)) r.recvuntil(b"No, the correct number is: ") leak2=r.recvuntil(b"\n").decode() print(leak2) gdb.attach(r) r.interactive()
from pwn import * from LibcSearcher import* context(arch = "amd64", os = "linux",log_level = "debug")
#r = remote("node7.anna.nssctf.cn", 21888) r=process("./flag") elf=ELF("./flag") r.recvuntil(b"Let's play a gamble game.\n") r.sendline(str(1)) r.recvuntil(b"No, the correct number is: ") leak1=r.recvuntil(b"\n").decode() print(leak1) r.sendline(str(1)) r.recvuntil(b"No, the correct number is: ") leak2=r.recvuntil(b"\n").decode() print(leak2) result = subprocess.check_output(['/home/voyager/1', leak1, leak2]).decode().strip().split("\n") print(result)
v5 = int(result[0]) numbers=[int(x) for x in result[1:]] #去掉v5 for i inrange(10): r.sendline(str(numbers[i]).encode()) r.recvuntil(b'Bingo.\n')