pwntools是一個CTF框架和漏洞利用開發庫,用Python開發,由rapid設計,旨在讓使用者簡單快速的編寫exploit。
pwntools對Ubuntu 12.04和14.04的支持最好,但是絕大多數的功能也支持Debian, Arch, FreeBSD, OSX, 等等。
安裝前確保安裝了Binutils、Capstone、Python Development Headers等系統庫
官方文檔:http://docs.pwntools.com/en/stable/
-----------------------
本文將基於Kali Rolling 64位安裝,Ubuntu64位安裝也是類似的(畢竟pwntools對Ubuntu支持是最好的)。
暫時不會有windows安裝法。
關於kali2 32位或者其他32位系統也是很難弄,本文后面會有一番折騰(但也不是所有功能都可以用)
0x00 不定時的更新補充
-= 2018年1月補充 =-
現在安裝方法可以很簡單:
pip install pwntools
這里py2.7的版本推薦py2.7.12或以上,總之py2.7.5或py2.7.6等老版本不用嘗試安裝,否則會有各種報錯。
諸如:
SyntaxError: unqualified exec is not allowed in function 'make_function' it contains a nested function with free variables
-= 2019年5月補充 =-
在ubuntu上pip安裝,建議先
apt-get install -y python-dev python-pip libffi-dev libssl-dev pip install -U setuptools pip install cryptography==2.4.2
-= 2020年4月補充 =-
pip安裝的各種報錯
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment total -= 1 TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
由於國內網速的原因,推薦換個清華源
pip install pwntools -i https://pypi.tuna.tsinghua.edu.cn/simple/
報錯:
File "<string>", line 1, in <module> IOError: [Errno 2] No such file or directory: '/tmp/pip-build-jbiHJq/unknown/setup.py' ---------------------------------------- Failed building wheel for unknown
此乃一個bug,無視它即可,重新執行語句就不報錯了。
如再報錯:
AssertionError: zipp>=0.5 .dist-info directory not found
這是zipp在清華源下找不到相對應的版本,推薦個國外源piwheels
pip install pwntools -i https://www.piwheels.org/simple/
-= 2019年10月補充 =-
pwntools支持python3
apt-get update apt-get install python3 python3-pip python3-dev git libssl-dev libffi-dev build-essential python3 -m pip install --upgrade pip python3 -m pip install --upgrade git+https://github.com/Gallopsled/pwntools.git@dev3
(如果有各種報錯,歡迎留言)
-----------------------
0x01 安裝Capstone
Capstone disassembly/disassembler framework: Core (Arm, Arm64, M68K, Mips, PPC, Sparc, SystemZ, X86, X86_64, XCore) + bindings (Python, Java, Ocaml)
在終端輸入
git clone https://github.com/aquynh/capstone cd capstone make make install
(這里很順利)
0x02 安裝pwntools
在終端輸入
git clone https://github.com/Gallopsled/pwntools cd pwntools python setup.py install
如果沒報錯,並且終端輸入python進入其交互模式后,輸入import pwn回車后沒報錯,差不多就好了。
這時候再嘗試pwntools的asm功能
>>> pwn.asm("xor eax,eax") '1\xc0'
如果有正確輸出,即說明這個功能是可以用的,到這里就算安裝完成。
(如果想了解更多asm可以訪問: http://docs.pwntools.com/en/stable/asm.html)
0x03 安裝pwntools時出現的各種錯誤
Err1:
fatal error: openssl/e_os2.h: 沒有那個文件或目錄
要解決這個問題,只需要安裝OpenSSL 開發包
apt-get install libssl-dev
Err2:
error: Installed distribution pyasn1 0.1.7 conflicts with requirement pyasn1>=0.1.8
把pyasn1(ASN.1 library for Python)更新即可
git clone https://github.com/etingof/pyasn1 cd pyasn1 python setup.py install
0x04 使用asm功能報錯
[!] Your local binutils won't be used because architecture 'i686' is not supported. [!] Could not find 'as' installed for ContextType() Try installing binutils for this architecture: https://pwntools.readthedocs.org/en/latest/install/binutils.html
大概就是Binutils庫不支持i686這種32位架構(Binutils 是一組開發工具,包括連接器,匯編器和其他用於目標文件和檔案的工具。)
我訪問了里面的鏈接地址,下面是里面的安裝方法:
apt-get install software-properties-common apt-add-repository ppa:pwntools/binutils apt-get update apt-get install binutils-$ARCH-linux-gnu # $ARCH is your target architecture (e.g., arm, mips64, vax, etc.).
我在kali2 32位執行到第2句會報
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Kali/sana
誒- -。傷感,然后我看那鏈接里后面的一個sh,里面寫得不好(rm后還能tar解壓。。),即使我修改后運行sh也解決不了這個asm問題。
在我絕望的時候,我覺得可以去github找找,果然讓我找到了一個pwntools-binutils項目
git clone https://github.com/Gallopsled/pwntools-binutils cd ubuntu chmod +x install_all.sh ./install_all.sh arm #your architecture
項目里面ubuntu文件夾有一個install.sh和install_all.sh,但我試了./install.sh arm找不到安裝包后,我就只好嘗試./install_all.sh arm安裝所有。
這一試,也讓我知道Binutils庫目前支持的架構。
以下的安裝包是存在的(其架構也是被支持的):
binutils-aarch64-linux-gnu
binutils-mips-linux-gnu
binutils-powerpc-linux-gnu
而下面這些安裝包暫時是不存在:
binutils-alpha-linux-gnu
binutils-arm-linux-gnu
binutils-avr-linux-gnu
binutils-cris-linux-gnu
binutils-hppa-linux-gnu
binutils-ia64-linux-gnu
binutils-m68k-linux-gnu
binutils-mips64-linux-gnu
binutils-msp430-linux-gnu
binutils-powerpc64-linux-gnu
binutils-s390-linux-gnu
binutils-sparc-linux-gnu
binutils-vax-linux-gnu
binutils-xscale-linux-gnu
binutils-i386-linux-gnu
binutils-x86_64-linux-gnu
所以暫時不被支持的架構下是無法安裝好Binutils庫,也就無法使用asm功能。
0x05 等pcat以后更新:)