Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disasm() doesn't work for context.arch='sparc64' #1564

Closed
meithecatte opened this issue Jun 6, 2020 · 7 comments · Fixed by #1603
Closed

disasm() doesn't work for context.arch='sparc64' #1564

meithecatte opened this issue Jun 6, 2020 · 7 comments · Fixed by #1603

Comments

@meithecatte
Copy link
Contributor

~$ python3
Python 3.8.3 (default, May 14 2020, 11:03:12)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
>>> context(arch='sparc')
>>> asm('nop')
b'\x01\x00\x00\x00'
>>> disasm(_)
'   0:   01 00 00 00     nop'
>>>
~$ python3 - DEBUG
Python 3.8.3 (default, May 14 2020, 11:03:12)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
>>> context(arch='sparc64')
>>> asm('nop')
[DEBUG] cpp -C -nostdinc -undef -P -I/home/kuba/.local/lib/python3.8/site-packages/pwnlib/data/includes /dev/stdin
[DEBUG] Assembling
    .section .shellcode,"awx"
    .global _start
    .global __start
    _start:
    __start:
    nop
[DEBUG] /usr/bin/sparc64-linux-gnu-as -EB -64 -o /tmp/pwn-asm-wq5065ol/step2 /tmp/pwn-asm-wq5065ol/step1
[DEBUG] /usr/bin/sparc64-linux-gnu-objcopy -j .shellcode -Obinary /tmp/pwn-asm-wq5065ol/step3 /tmp/pwn-asm-wq5065ol/step4
b'\x01\x00\x00\x00'
>>> disasm(_)
[DEBUG] /usr/bin/sparc64-linux-gnu-objcopy -I binary -O elf64-sparc -B sparc64 --set-section-flags .data=code --rename-section .data=.text -w -N * /tmp/pwn-disasm-0m495_e1/step1 /tmp/pwn-disasm-0m495_e1/step2
[ERROR] There was an error running ['/usr/bin/sparc64-linux-gnu-objcopy', '-I', 'binary', '-O', 'elf64-sparc', '-B', 'sparc64', '--set-section-flags', '.data=code', '--rename-section', '.data=.text', '-w', '-N', '*', '/tmp/pwn-disasm-0m495_e1/step1', '/tmp/pwn-disasm-0m495_e1/step2']:
    It had the exitcode 1.
    It had this on stdout:
    /usr/bin/sparc64-linux-gnu-objcopy: architecture sparc64 unknown

[ERROR] An error occurred while disassembling:
    b'\x01\x00\x00\x00'
    Traceback (most recent call last):
      File "/home/kuba/.local/lib/python3.8/site-packages/pwnlib/asm.py", line 785, in disasm
        _run(objcopy + [step1, step2])
      File "/home/kuba/.local/lib/python3.8/site-packages/pwnlib/asm.py", line 382, in _run
        log.error(msg)
      File "/home/kuba/.local/lib/python3.8/site-packages/pwnlib/log.py", line 417, in error
        raise PwnlibException(message % args)
    pwnlib.exception.PwnlibException: There was an error running ['/usr/bin/sparc64-linux-gnu-objcopy', '-I', 'binary', '-O', 'elf64-sparc', '-B', 'sparc64', '--set-section-flags', '.data=code', '--rename-section', '.data=.text', '-w', '-N', '*', '/tmp/pwn-disasm-0m495_e1/step1', '/tmp/pwn-disasm-0m495_e1/step2']:
    It had the exitcode 1.
    It had this on stdout:
    /usr/bin/sparc64-linux-gnu-objcopy: architecture sparc64 unknown

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kuba/.local/lib/python3.8/site-packages/pwnlib/context/__init__.py", line 1441, in setter
    return function(*a, **kw)
  File "/home/kuba/.local/lib/python3.8/site-packages/pwnlib/asm.py", line 795, in disasm
    log.exception("An error occurred while disassembling:\n%s" % data)
  File "/home/kuba/.local/lib/python3.8/site-packages/pwnlib/asm.py", line 785, in disasm
    _run(objcopy + [step1, step2])
  File "/home/kuba/.local/lib/python3.8/site-packages/pwnlib/asm.py", line 382, in _run
    log.error(msg)
  File "/home/kuba/.local/lib/python3.8/site-packages/pwnlib/log.py", line 417, in error
    raise PwnlibException(message % args)
pwnlib.exception.PwnlibException: There was an error running ['/usr/bin/sparc64-linux-gnu-objcopy', '-I', 'binary', '-O', 'elf64-sparc', '-B', 'sparc64', '--set-section-flags', '.data=code', '--rename-section', '.data=.text', '-w', '-N', '*', '/tmp/pwn-disasm-0m495_e1/step1', '/tmp/pwn-disasm-0m495_e1/step2']:
It had the exitcode 1.
It had this on stdout:
/usr/bin/sparc64-linux-gnu-objcopy: architecture sparc64 unknown


>>> pwnlib.version
'4.1.1'
@meithecatte
Copy link
Contributor Author

mips64 and powerpc64 are also affected.

@meithecatte
Copy link
Contributor Author

meithecatte commented Jun 7, 2020 via email

@meithecatte
Copy link
Contributor Author

@zachriggle Bump. I think you closed this by mistake.

@zachriggle zachriggle reopened this Jun 16, 2020
@zachriggle
Copy link
Member

Yep not sure what happened. If you know why this is failing, a pull request would be nice!

@meithecatte
Copy link
Contributor Author

Sorry, I didn't have the time to investigate this properly yet.

@heapcrash
Copy link
Collaborator

Can you take a look at #1603 and see if that fixes the issue for you?

@meithecatte
Copy link
Contributor Author

I can confirm that it indeed made this work. The fix makes me wonder whether this will properly assemble for 64 bits, but I couldn't come up with a simple way to test this, so I will assume that this is handled by the bfd name.

heapcrash added a commit to heapcrash/pwntools that referenced this issue Jun 28, 2020
heapcrash added a commit that referenced this issue Jun 28, 2020
* [asm] Fix disasm() for mips64, powerpc64, sparc64

Closes #1564

* [asm] Add tests for disasm on mips/powerpc/sparc 64-bit

* [asm] Find powerpc, sparc, mips utilities even for 64-bit variants

* [asm] Remove leftover debug trace

* [ci] Add Sparc64 binutils

* [changelog] Add entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants