不要使用pip安装!
不要使用pip安装!
不要使用pip安装!
首先要保证你的电脑上装了homebrew,没装的自行搜索,这个都不装就别用Mac搞技术了。
直接敲命令:
brew install pwntools
回车之后就装好了。
安装完后会在/usr/local/Cellar/下生成pwntools文件夹,不用管它,我们只需要用到这个路径
/usr/local/Cellar/pwntools/3.12.2/libexec/lib/python2.7/site-packages
里面包含了pwntools所需要的各种python相关文件,终端中cd进入然后pwd复制路径
然后只需把这个文件夹添加到python的sys.path中,方法如下:
首先是Mac自带的python:
➜ ~ cd /Library/Python/2.7/site-packages
➜ site-packages sudo vim mypkpath.pth //自己把路径复制进去,esc+wq保存
➜ site-packages cat mypkpath.pth //看一下对不对,不看也无妨
/usr/local/Cellar/pwntools/3.12.2/libexec/lib/python2.7/site-packages
然后是brew安装的python,操作同上:
➜ ~ cd /usr/local/lib/python2.7/site-packages
➜ site-packages git:(master) ✗ vim mypkpath.pth
➜ site-packages git:(master) ✗ cat mypkpath.pth
/usr/local/Cellar/pwntools/3.12.2/libexec/lib/python2.7/site-packages
这里同时改了系统自带的和brew的,是为了防止下面出现莫名其妙的错误。
然后试验一下,没有报错就是正常:
➜ site-packages git:(master) ✗ python
Python 2.7.16 (default, Apr 12 2019, 15:32:40)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pwn
>>> pwn.asm("xor eax,eax")
'1\xc0'
>>>
如果报错,那么首先检查一下路径填的对不对:
import sys
list = sys.path
print(list)
#sys.path.append('/usr/local/Cellar/pwntools/3.12.2/libexec/lib/python2.7/site-packages')
#print(list)
from pwn import *
如果没问题,那么你需要安装二进制工具binutils:
还是用brew:
➜ ~ brew install https://raw.githubusercontent.com/Gallopsled/pwntools-binutils/master/osx/binutils-amd64.rb
安装完之后就好啦。
另附Mac上python的环境变量:
我用的ohmyzsh,所以环境变量在~/.zshrc中配置:
#brew安装的python2和python3
export PATH="/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH="/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
#系统的python,不同版本系统会不一样,我这里是最新的10.14.5,自带2.7.10
#不要跟brew安装的python2同时加,二选一
export PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"