错误描述
昨天下午在macOS上用pwntools 的asm时遇到了错误,但是在ubuntu 16.04的docker上用没问题。具体来看一下报错log:
以context.arch='i386'为例:
[ERROR] There was an error running ['/usr/local/bin/i386-unknown-linux-gnu-as', '-64', '-o', '/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step2', '/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1']:
It had the exitcode 1.
It had this on stdout:
/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1: Assembler messages:
/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1:7: Error: operand type mismatch for `push'
[ERROR] An error occurred while assembling:
1: .section .shellcode,"awx"
2: .global _start
3: .global __start
4: _start:
5: __start:
6: .intel_syntax noprefix
7: push ebp
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pwnlib/asm.py", line 665, in asm
_run(assembler + ['-o', step2, step1])
File "/usr/local/lib/python2.7/site-packages/pwnlib/asm.py", line 383, in _run
log.error(msg)
File "/usr/local/lib/python2.7/site-packages/pwnlib/log.py", line 417, in error
raise PwnlibException(message % args)
PwnlibException: There was an error running ['/usr/local/bin/i386-unknown-linux-gnu-as', '-64', '-o', '/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step2', '/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1']:
It had the exitcode 1.
It had this on stdout:
/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1: Assembler messages:
/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1:7: Error: operand type mismatch for `push'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/pwnlib/context/__init__.py", line 1392, in setter
return function(*a)
File "/usr/local/lib/python2.7/site-packages/pwnlib/asm.py", line 710, in asm
log.exception("An error occurred while assembling:\n%s" % lines)
File "/usr/local/lib/python2.7/site-packages/pwnlib/asm.py", line 665, in asm
_run(assembler + ['-o', step2, step1])
File "/usr/local/lib/python2.7/site-packages/pwnlib/asm.py", line 383, in _run
log.error(msg)
File "/usr/local/lib/python2.7/site-packages/pwnlib/log.py", line 417, in error
raise PwnlibException(message % args)
pwnlib.exception.PwnlibException: There was an error running ['/usr/local/bin/i386-unknown-linux-gnu-as', '-64', '-o', '/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step2', '/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1']:
It had the exitcode 1.
It had this on stdout:
/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1: Assembler messages:
/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwn-asm-6E6Ipm/step1:7: Error: operand type mismatch for `push'
同样context.arch='amd64'时异常大概如下:
pwnlib.exception.PwnlibException: There was an error running ['/usr/bin/as', '-64', '-o', '/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwntools-asm-81g_ao1r/step2', '/var/folders/0v/tcx3rx295llfksr_20z65nhr0000gn/T/pwntools-asm-81g_ao1r/step1']:
发现都是在调用/usr/bin/as或者/usr/local/bin/i386-unknown-linux-gnu-as出错了。
解决办法:
参考pwntools官方文档。安装相应的binutils即可。
http://docs.pwntools.com/en/stable/install.html
export ARCH='amd64'
brew install https://raw.githubusercontent.com/Gallopsled/pwntools-binutils/master/osx/binutils-$ARCH.rb