-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Add support for LoongArch64 payloads #20682
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
base: master
Are you sure you want to change the base?
Conversation
|
@bcoles Thanks for your contribution, Do you think is worth considering adding it to mettle? We have couple of architecture I want us to get rid of because they are unused (ARMBE for example) and PPC because is broken so this should give us a space to throw in new arch, I was already thinking about RISC-V and maybe this one. I've seen this |
Support for RISC-V is worth adding to mettle. Whether support for LoongArch would be useful remains to be seen. Loongson have had several attempts at using and extending MIPS prior to the development of their own ISA. LoongArch is gaining popularity and has political backing. It seems likely to me that LoongArch will be more popular than its MIPS-based predecessors and ultimately replace them in China, but whether LoongArch will ever see widespread adoption outside of China is unclear. There's also the tiny issue of export restrictions which may never be lifted.
This looks like a LoongISA chip which is MIPS based. For LoongArch you'll want a Loongson 3A5000+. |
Ok thanks a lot @bcoles for sharing your thoughts, I'll go ahead and test this PR. Cheers! |
Add support for LoongArch64 payloads. Includes Linux Reboot payload for testing.
Tested on:
Note:
syscallfailure or callexit. This saves a few bytes.rebootis a privileged syscall.elf-so, I gave up trying to make a working shared object that plays nicely with the LoongArch dynamic loader. Getting this to work may require modifying our ELF patching code inMsf::Util::EXE.to_exe_elfto patchDT_INIT- which is significant scope creep for this PR. Instead I took the lazy option: the LoongArch SO template is almost identical to ouraarch64andriscv64letemplates, and the generatedelf-sofile will work when executed directly (./payload.so) but will fail when loaded withLD_PRELOAD.Motivation
This PR lays the foundation for further development of LoongArch payloads.
AI summary:
The Linux kernel has supported LoongArch since 2022. gcc and musl already support compiling for LoongArch.
The list of popular Linux distros supporting LoongArch is growing, with Debian, Gentoo, Slackware, and Fedora offering experimental builds, and Alpine offering official support. See also: Are We Loong Yet?
LoongArch based development boards / SBCs and consumer-grade laptops are slowly entering the market.
The changes introduced in this PR wire up msfvenom and Metasploit interfaces to support LoongArch, with a simple test payload and spec test, which should greatly assist with subsequent development.
Verification
Linux Reboot Payload
Generate a Linux Reboot payload (with optional 100 byte NOP sled):
./msfvenom -n 100 --format elf -p linux/loongarch64/reboot > reboot.elfExecute the payload with QEMU (I suggest doing this within an emulated Linux environment):
/home/user/qemu/build/qemu-loongarch64 -strace ./rebootsudo /home/user/qemu/build/qemu-loongarch64 -strace ./rebootSource:
Hardware
I don't have real hardware, but QEMU should be sufficient. I'm not sure your chances of buying LoongArch hardware outside of China, but you could try:
Emulation
Note that apparently QEMU 7.2.0+ is required:
A few distros offer LoongArch builds, but I've had mixed results with building them. Below are my recipes for working systems. YYMV - I built these a few years ago.
Loong Arch Linux
Alpine Linux
Use the commented
-driveline at the bottom to boot from ISO to complete the install process. Then comment the line again to boot the installed system.You may (or may not) need the
u-boot-qemuandopensbipackages (apt install u-boot-qemu opensbi).References