There was an error running [‘/usr/bin/as‘, ‘-32‘, ‘-o‘, ‘/tmp/pwn-asm-2.. pwntools amd64.sh()出现错误

在进行pwn题目解答时,使用frompwnimport*导入模块并尝试生成shellcode时,遇到了一个错误,错误涉及到汇编器/as在处理-32选项时的错误,包括operandsizemismatchformov等。问题出在没有正确设置环境arch为amd64。添加context.arch=amd64后,错误得到解决,成功生成了shellcode。
摘要由CSDN通过智能技术生成

今天做pwn题的时候突然报错

from pwn import *

shellcode = asm(shellcraft.amd64.sh())

[ERROR] There was an error running ['/usr/bin/as', '-32', '-o', '/tmp/pwn-asm-2a_arm3i/step2', '/tmp/pwn-asm-2a_arm3i/step1']:
    It had the exitcode 1.
    It had this on stdout:
    /tmp/pwn-asm-2a_arm3i/step1: Assembler messages:
    /tmp/pwn-asm-2a_arm3i/step1:11: Error: operand size mismatch for `mov'
    /tmp/pwn-asm-2a_arm3i/step1:13: Error: too many memory references for `mov'
    /tmp/pwn-asm-2a_arm3i/step1:22: Error: too many memory references for `add'
    /tmp/pwn-asm-2a_arm3i/step1:24: Error: too many memory references for `mov'
    
[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: .p2align 0
       8:     /* execve(path='/bin///sh', argv=['sh'], envp=0) */
       9:     /* push b'/bin///sh\x00' */
      10:     push 0x68
      11:     mov rax, 0x732f2f2f6e69622f
      12:     push rax
      13:     mov rdi, rsp
      14:     /* push argument array ['sh\x00'] */
      15:     /* push b'sh\x00' */
      16:     push 0x1010101 ^ 0x6873
      17:     xor dword ptr [rsp], 0x1010101
      18:     xor esi, esi /* 0 */
      19:     push rsi /* null terminate */
      20:     push 8
      21:     pop rsi
      22:     add rsi, rsp
      23:     push rsi /* 'sh\x00' */
      24:     mov rsi, rsp
      25:     xor edx, edx /* 0 */
      26:     /* call execve() */
      27:     push 11 /* 0x3b */
      28:     pop rax
      29:     syscall
    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/site-packages/pwnlib/asm.py", line 704, in asm
        _run(assembler + ['-o', step2, step1])
      File "/usr/local/lib/python3.6/site-packages/pwnlib/asm.py", line 422, in _run
        log.error(msg, *args)
      File "/usr/local/lib/python3.6/site-packages/pwnlib/log.py", line 439, in error
        raise PwnlibException(message % args)
    pwnlib.exception.PwnlibException: There was an error running ['/usr/bin/as', '-32', '-o', '/tmp/pwn-asm-2a_arm3i/step2', '/tmp/pwn-asm-2a_arm3i/step1']:
    It had the exitcode 1.
    It had this on stdout:
    /tmp/pwn-asm-2a_arm3i/step1: Assembler messages:
    /tmp/pwn-asm-2a_arm3i/step1:11: Error: operand size mismatch for `mov'
    /tmp/pwn-asm-2a_arm3i/step1:13: Error: too many memory references for `mov'
    /tmp/pwn-asm-2a_arm3i/step1:22: Error: too many memory references for `add'
    /tmp/pwn-asm-2a_arm3i/step1:24: Error: too many memory references for `mov'
    
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/pwnlib/context/__init__.py", line 1578, in setter
    return function(*a, **kw)
  File "/usr/local/lib/python3.6/site-packages/pwnlib/asm.py", line 750, in asm
    log.exception("An error occurred while assembling:\n%s" % lines)
  File "/usr/local/lib/python3.6/site-packages/pwnlib/asm.py", line 704, in asm
    _run(assembler + ['-o', step2, step1])
  File "/usr/local/lib/python3.6/site-packages/pwnlib/asm.py", line 422, in _run
    log.error(msg, *args)
  File "/usr/local/lib/python3.6/site-packages/pwnlib/log.py", line 439, in error
    raise PwnlibException(message % args)
pwnlib.exception.PwnlibException: There was an error running ['/usr/bin/as', '-32', '-o', '/tmp/pwn-asm-2a_arm3i/step2', '/tmp/pwn-asm-2a_arm3i/step1']:
It had the exitcode 1.
It had this on stdout:
/tmp/pwn-asm-2a_arm3i/step1: Assembler messages:
/tmp/pwn-asm-2a_arm3i/step1:11: Error: operand size mismatch for `mov'
/tmp/pwn-asm-2a_arm3i/step1:13: Error: too many memory references for `mov'
/tmp/pwn-asm-2a_arm3i/step1:22: Error: too many memory references for `add'
/tmp/pwn-asm-2a_arm3i/step1:24: Error: too many memory references for `mov'

然后发现原来是要设置环境,也就是加上 context.arch = 'amd64'

from pwn import *

content.arch = 'amd64'
shellcode = asm(shellcraft.amd64.sh())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值