Pwn with File结构体(二)
前言
本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274
最新版的 libc
中会对 vtable
检查,所以之前的攻击方式,告一段落。下面介绍一种,通过修改 _IO_FILE
实现任意地址读和任意地址写的方式。
正文
_IO_FILE
通过这些指针,来读写数据。
如果我们修改了它们,然后通过一些文件读写函数时,我们就能实现 任意地址读写。
任意地址读
代码示例
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
FILE *fp;
char *msg = "hello_file";
char *buf = malloc(100);
read(0, buf, 100);
fp = fopen("key.txt", "rw");
// 设置 flag 绕过 check
fp->_flags &= ~8;
fp->_flags |= 0x800;
// _IO_write_base write数据的起始地址, _IO_write_ptr write数据的终止地址
fp->_IO_write_base = msg;
fp->_IO_write_ptr = msg + 6;
//绕过检查
fp->_IO_read_end = fp->_IO_write_base;
// write 的目的 文件描述符, 1 --> 标准输出
fp->_fileno = 1;
fwrite(buf, 1, 100, fp);
return 0;
}
任意地址写
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
FILE *fp;
char msg[100];
char *buf = malloc(100);
fp = fopen("key.txt", "rw");
// 设置 flag 绕过 check
fp->_flags &= ~4;
// _IO_buf_base buffer 的起始地址, _IO_buf_end buffer 的终止地址
// fread 先把数据读入 [_IO_buf_base, _IO_buf_end] 形成的 buffer
// 然后复制到目的 buffer
fp->_IO_buf_base = msg;
fp->_IO_buf_end = msg + 100;
// 设置 文件描述符, 0---> stdin, 从标准输入读数据
fp->_fileno = 0;
fread(buf, 1, 6, fp);
puts(msg);
puts(buf);
return 0;
}
利用 stdin / stdout 任意地址写/ 读
puts
, scanf
等一批系统函数默认使用的 stdin
, stdout
,stderr
等结构体进行操作,通过修改这些结构体的内容,可以更方便的实现任意地址读,任意地址写。
stdin
也是 _IO_FILE
结构体
#include <stdio.h>
#include <stdlib.h>
int global_val = 0xaabbccdd;
int main(int argc, char * argv[])
{
FILE *fp;
int var;
fp = stdin;
fp->_flags &= ~4;
fp->_IO_buf_base = stdout;
fp->_IO_buf_end = stdout + 100;
scanf("%d",&var);
printf("0x%x\n", global_val);
return 0;
}
运行之
成功修改 stdout
结构体
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
FILE *fp;
char *msg = "hello_stdout";
char *buf = malloc(100);
fp = stdout;
// 设置 flag 绕过 check
fp->_flags &= ~8;
fp->_flags |= 0x800;
// _IO_write_base write数据的起始地址, _IO_write_ptr write数据的终止地址
fp->_IO_write_base = msg;
fp->_IO_write_ptr = msg + 12;
//绕过检查
fp->_IO_read_end = fp->_IO_write_base;
// write 的目的 文件描述符, 1 --> 标准输出
fp->_fileno = 1;
puts("<----->this is append on msg ");
return 0;
}
成功读到了, msg
的内容。
参考:
https://www.slideshare.net/AngelBoy1/play-with-file-structure-yet-another-binary-exploit-technique
Pwn with File结构体(二)的更多相关文章
- Pwn with File结构体(一)
前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 利用 FILE 结构体进行攻击,在现在的 ctf 比赛中也经常出现 ...
- Pwn with File结构体(四)
前言 前面几篇文章说道,glibc 2.24 对 vtable 做了检测,导致我们不能通过伪造 vtable 来执行代码.今天逛 twitter 时看到了一篇通过绕过 对vtable 的检测 来执行代 ...
- Pwn with File结构体(三)
前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 前面介绍了几种 File 结构体的攻击方式,其中包括修改 vtab ...
- Pwn with File结构体之利用 vtable 进行 ROP
前言 本文以 0x00 CTF 2017 的 babyheap 为例介绍下通过修改 vtable 进行 rop 的操作 (:-_- 漏洞分析 首先查看一下程序开启的安全措施 18:07 haclh@u ...
- Linux_Struct file()结构体
struct file结构体定义在/linux/include/linux/fs.h(Linux 2.6.11内核)中,其原型是:struct file { /* * f ...
- Linux--struct file结构体
struct file(file结构体): struct file结构体定义在include/linux/fs.h中定义.文件结构体代表一个打开的文件,系统中的每个打开的文件在内核空间都有一个关联的 ...
- 2018.5.2 file结构体
f_flags,File Status Flag f_pos,表示当前读写位置 f_count,表示引用计数(Reference Count): dup.fork等系统调用会导致多个文件描述符指向同一 ...
- fd与FILE结构体
文件描述符 fd 概念:文件描述符在形式上是一个非负整数.实际上,它是一个索引值,指向内核为每一个进程所维护的该进程打开文件的记录表.当程序打开一个现有文件或者创建一个新文件时,内核向进程返回一个文件 ...
- file结构体中private_data指针的疑惑
转:http://www.360doc.com/content/12/0506/19/1299815_209093142.shtml hi all and barry, 最近在学习字符设备驱动,不太明 ...
随机推荐
- 【xsy3423】党² 线段树+李超线段树or动态半平面交
本来并不打算出原创题的,此题集CF542A和sk的灵感而成,算个半原创吧. 题目大意: 给定有$n$个元素的集合$P$,其中第$i$个元素中包含$L_i,R_i,V_i$三个值. 给定另一个有$n$个 ...
- Yarn 和 Npm 命令行切换 摘录
原文作者: @Gant Laborde原文地址: https://shift.infinite.red/np...中文翻译: @文蔺译文地址:http://www.wemlion.com/2016/n ...
- 【转载】 C#中数组、ArrayList和List三者的区别
原文地址:http://blog.csdn.net/zhang_xinxiu/article/details/8657431 在C#中数组,ArrayList,List都能够存储一组对象,那么这三者到 ...
- java_sql_Batch_批处理
java JDBC 进行sql语句的批处理的两种方法示例代码.表是oracle数据库里的dept表,为了看清逻辑关系,把异常都throws 出去. package com.ayang.jdbc; i ...
- Android 开发工具类 04_KeyBoardUtils
打开或关闭软键盘: 1.打卡软键盘: 2.关闭软键盘. import android.content.Context; import android.view.inputmethod.InputMet ...
- sql server数据行号
select ROW_NUMBER() over(order by createTime desc) as RowNum,NoticeContent,CreateTime from PTS_Notic ...
- C/C++ -- Gui编程 -- Qt库的使用 -- 标准对话框
-----mywidget.cpp----- #include "mywidget.h" #include "ui_mywidget.h" #include & ...
- NodeJS require a global module/package in linux
https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package 1 export NODE_P ...
- Chapter 3 Phenomenon——18
My intuition flickered; the doctor was in on it. 我的直觉告诉我:这个医生也参与了. 我灵光一闪:这医生熟悉内情. "I'm afraid t ...
- java学习-struts基础(一)
struts发展 struts是Apache软件基金会赞助的一个开源项目,是一个基于Java EE的MVC开源实现. 它为Servlet/JSP技术的应用提供技术框架2001.7--Struts1正式 ...