Featured image of post PWN! PWN! PANG! Part2 --- 工具的使用

PWN! PWN! PANG! Part2 --- 工具的使用

我要告诉你一个秘密,只有聪明的人才能看到哦qaq

PWN! PWN! PANG! Part2

前言

说完了前面那些基础 (貌似一点也不基础) 知识,今天再来谈谈工具

由于我们研究的是Linux下的PWN,接下来的操作请在Linux下进行


只有Windows怎么办?

小Tip:某些Linux发行版(例如Kali)可以在官网找到现成的虚拟机文件下载,如果你没有安装过虚拟机 (或懒得安装) ,可以试试这种方式

  • 方案二:使用WSL2(怎么说呢,WSL2虽说占空间小,而且有了GUI,但配置其实挺麻烦)

PWNDBG

pwndbg是Linux GDB的一个专门为PWN设计的一个插件, 能有助于我们调戏调试程序

pwndbg

安装

一般Linux都会预装gdb吧= =,不过还是扯一下安装方法好了

Deb 系

sudo apt install gdb

yum系 快去用Debian 逃)

sudo yum -y install centos-release-scl
sudo yum-config-manager --enable rhel-server-rhscl-7-rpms
sudo yum -y install devtoolset-7
scl enable devtoolset-7 bash

安装pwndbg

git clone https://github.com/pwndbg/pwndbg.git
cd pwndbg
./setup.sh

安装踩坑记

注意:pwndbg这个目录请不要删除或随意移动位置,否则可能会导致pwndbg无法正常启动

如果安装后或系统更新后无法正常启动的话,请检查路径问题

sudo vi ~/.gdbinit

输入命令后应该能看到一行

source 其他内容/pwndbg/gdbinit.py

记得把source之后的内容改成你pwndbg文件夹里gdbinit.py的路径

Tip:如果你想不用pwndbg的话,去掉这一行即可


用法

大部分用法都和gdb的差不多,这里列举几个经常用的

b 函数名 #断点断在某个函数处
b *一个地址 #断点断在某个地址
r        #运行
n        #执行下一条指令或者跳过一个函数
s        #进入函数
q        #退出gdb

至于pwndbg的特殊功能嘛= =,可以通过指令pwndbg查看

pwndbg指令

PWNTOOLS

这个呢,是python的一个用来pwn的第三方库

安装

直接上命令

pip install pwntools

没有pip? 赶紧去装python3!!!(这个大部分Linux也应该预装了= = )

使用

就和一般的python库一样用嘛= =

from pwn import *

再说几个常用的命令吧.qaq(其他的用到再说),当然你最好可以看看文档

io = process("./程序名")  #类似与用PWNTools“监听”本地一个程序,之后就用io这个变量来负责数据的收发
io.send("内容") #发送数据(结尾不自动加换行符)
io.sendline("内容")  #发送一行数据(结尾自动加上换行符)
io.recv()
io.recvline() #接收数据,和前面两个函数同理
# 注意,在之后PWN的过程中一定要根据目标程序的输入/输出函数来判断前四个指令的使用,这种细微的差别也可能导致无法getshell
io.interactive()  #切换至交互模式,我们可以尽情享用得到的Shell了

PWN?PWN! 一起来实战吧

实战目的: 熟悉pwntools的使用

如果你没使用之前的集成环境, 请点这里下载题目

大家可以自己先试试,大概应该能想到怎么做了吧XD


我们先运行看看这个小程序是什么来头 逃)

PS: 如果终端提示权限不够,请给程序加上可执行权限

chmod +x tools

小程序长这样纸

输出

Pwntools is such an awesome python module, right?
Tell you a secret (only smart baby can see it) :
Maybe I will tell you again when you clever than ELSEpush ......

程序说:Pwntools是一个很好用的python模块,要告诉我们一个聪明人才能看见的小秘密

还挑衅是吧

咳咳,那怎样才能看到所谓的小秘密呢qaq,直接运行肯定看不到()

根据所学知识和程序输出,我们可以判断出应该通过pwntools查看

$ python3                  
Python 3.9.9 (main, Jan 12 2022, 16:10:51) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
>>>

既然程序没有输入,只有输出,那么只有使用recv()或recvline()函数了qaq

EXP:

from pwn import *
io = process("./tools")
io.recvline()
io.recvline()
io.recvline()

整个过程展示:

$ python3                  
Python 3.9.9 (main, Jan 12 2022, 16:10:51) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
>>> io = process("./tools")
[x] Starting local process './tools'
[+] Starting local process './tools': pid 108320
>>> io.recvline()
[*] Process './tools' stopped with exit code 0 (pid 108320)
b'Pwntools is such an awesome python module, right?\n'
>>> io.recvline()
b'Tell you a secret (only smart baby can see it) :\n'
>>> io.recvline()
b'ZmxhZ3tuMHRfZjRzdGVyX3Q2YW5feTB1fQo=\rMaybe I will tell you again when you clever than ELSEpush ......\n'
>>> 

PWNed!


The END= =

To Be Continued…

突然发现自己真的挖了个好大的坑= ((

Licensed under CC BY-NC-SA 4.0
For a better open source community!
Built with Hugo
主题 StackJimmy 设计