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

ARM XOR encoder not decoding the whole payload #1948

Open
peace-maker opened this issue Aug 16, 2021 · 0 comments
Open

ARM XOR encoder not decoding the whole payload #1948

peace-maker opened this issue Aug 16, 2021 · 0 comments

Comments

@peace-maker
Copy link
Member

After manually applying #1923 I noticed that the arm xor encoder is broken for longer payloads.

decoder = """
adr r8, payload
mov r4, #%(length)s
adr r6, xor_cacheflush
loop:
cmp r4, #%(maximum)s
bxhi r6
sub r4, r4, #%(length)s
ldrb r5, [r8, r4]
eor r5, r5, #%(key)s
strb r5, [r8, r4]
add r4, r4, #%(length)s + 1
b loop
xor_cacheflush:
%(cacheflush)s
payload:
"""

maximum is hardcoded to 256, so it only decodes maximum - length bytes instead of all of length.
My quick fix was to set maximum = len(raw_bytes)*2, but I'm not sure if that violates some guarantees for the blacklist.

Test:

from pwn import *
context.arch = 'arm'

arm_shellcode = asm(shellcraft.execve('/bin/sh', ['/bin/sh', '-c', 'ls -la'], 0))
arm_shellcode = encoder.encode(arm_shellcode, avoid=b'\x00\n')

exe = ELF.from_bytes(arm_shellcode)
io = process(['/usr/bin/qemu-arm', exe.path])
io.interactive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants