c - 如何用特定的返回地址溢出缓冲区?
问题描述
这是给我的一个数组:
char overflow[16]="\xEF\xBE\xAD\xDE\xEF\xBE\xAD\xDE"
"\xEF\xBE\xAD\xDE\xEF\xBE\xAD\xDE";
这是地址:"0x1234B000"
如何编辑上面的数组以溢出并将返回地址更改为上面的新地址?
解决方案
这实际上取决于堆栈上的内容,这决定了您必须至少覆盖多少字节。函数参数和局部变量会妨碍堆栈指针,这是你试图覆盖的正确吗?我会说用 1k 相同的重复字节模式溢出它,并使用 gdb 或其他一些调试器来获取堆栈跟踪。
例 1。(您需要写入数组 sizeof(int) 字节才能到达堆栈指针。)
void testFunction(int arg0){
char overflow[16] = {0};
char HUGE_ARRAY[10000] = {0};// what does the stack look like in this case? This giant block of memory should be on the stack AFTER your target array
//do something that allows the user to overflow the overflow array for w/e reason
}
例 2。(您需要写入数组 sizeof(int) bytes + 10000 bytes 才能到达堆栈指针。)
void testFunction(int arg0){
char HUGE_ARRAY[10000] = {0};// what does the stack look like in this case? This giant block of memory should be on the stack BEFORE your target array.
char overflow[16] = {0};
//do something that allows the user to overflow the overflow array for w/e reason
}
如果您知道目标环境(例如 sizeof int 已知),函数参数的数量和类型,以及当您输入您试图覆盖的堆栈指针的函数时弹出堆栈的局部变量的数量和类型,那么您理论上可以写入函数堆栈指针的确切字节。
或者,您可以通过将 0x00 值写入溢出缓冲区并每次增加 PAST 16 个字节的距离来解决此问题,直到出现段错误。段错误后,您就找到了函数的堆栈指针。
通常,堆栈通过按以下顺序弹出以下内容而增长:返回地址-> 函数参数-> 本地。
在您的情况下,您可能可以通过编写比您需要的更多的字节来测试它。(只要在堆栈上弹出溢出之前分配给此函数堆栈的 <4k 就可以工作)
for (offset = 0; offset < 1000; offset++){
(int)(*overflow + 4 + offset) = 0x1234B000;
}
总帐。
推荐阅读
- javascript - 命名空间没有导出的成员“用户”Angularfire 2
- html - 高度 100% 绝对不工作
- oracle11g - 在 sql developer 中连接到创建的数据库 11g
- javascript - 在 Javascript 中遵循此规则从数组中获取前 2 名团队
- python - Django 数据库迁移错误
- vba - 从外部 VBS 运行时,宏 PowerPoint 幻灯片不自动前进
- html - Bootstrap 4 - 表格中特定单元格的边框颜色
- r - gap.boxplot 产生的图形与 boxplot 不同
- java - 根据参数的顺序执行命令
- angular - 如何在 Angular 5 中创建“私有组件路由”