【发布时间】:2019-05-08 22:29:32
【问题描述】:
我在 Debian 上尝试编译以下 ASM 代码,但在 ld 和 gcc 上都有问题。
uname -a: Linux kali 4.18.0-kali3-amd64 #1 SMP Debian 4.18.20-2kali2 (2018-11-30) x86_64 GNU/Linux
我首先运行:nasm -f elf shellcode.asm
这完全没有问题。
GCC 问题...
命令:gcc -m32 -o key shellcode.o
错误:
/usr/bin/ld: shellcode.o: in function `_start':
shellcode.asm:(.text+0x0): multiple definition of `_start'; /usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib32/Scrt1.o:(.text+0x0): first defined here
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib32/Scrt1.o: in function `_start':
(.text+0x28): undefined reference to `main'
/usr/bin/ld: shellcode.o: in function `_start':
shellcode.asm:(.text+0xbc): relocation truncated to fit: R_386_PC8 against `*UND*'
collect2: error: ld returned 1 exit status
我也试过ld。
命令:ld -m elf_i386 -s -o key shellcode.o
错误...
ld: shellcode.o: in function `_start':
shellcode.asm:(.text+0xbc): relocation truncated to fit: R_386_PC8 against `*UND*'
后者似乎不太充满错误,并指出 ASM 语法存在问题。
那么我的问题是,这些命令中哪一个是正确的,我做错了什么?
shellcode.asm
global _start
_start:
xor eax,eax
push eax
push dword 0x76767975
push dword 0x22717172
push dword 0x22737972
push dword 0x77207922
push dword 0x78272079
push dword 0x27277976
push dword 0x77707470
push dword 0x22777272
push dword 0x22277622
push dword 0x79727473
push dword 0x27727377
push dword 0x75747078
push dword 0x70227479
push dword 0x75222073
push dword 0x24747176
push dword 0x74782324
push dword 0x72727320
push dword 0x27762779
push dword 0x20277777
push dword 0x22207573
push dword 0x70247827
push dword 0x70277479
push dword 0x24712379
push dword 0x77742027
push dword 0x76242379
push dword 0x22702270
push dword 0x73762577
push dword 0x24752272
push dword 0x20277172
push dword 0x23712720
push dword 0x72722478
push dword 0x70252723
push esp
pop esi
mov edi,esi
mov edx,edi
cld
mov ecx,0x80
mov ebx,0x41
xor eax,eax
push eax
lodsb
xor eax,ebx
stosb
loop 0xb7
push esp
pop esi
int3
db 0x0a
【问题讨论】:
-
你为什么要做
loop 0xb7。在您希望循环返回的位置放置一个标签,并将该标签与loop指令一起使用。这就是重定位错误的原因。有点不清楚您首先要使用loop指令做什么。 -
您是在组装,而不是在编译。编译用于高级语言,这些语言被编译成汇编,然后汇编成十六进制。
-
@MichaelPetch 谢谢你。该代码是使用 gdb 提取密钥的挑战的一部分,因此这只是提供的示例。我会按照您的建议进行编辑
-
感谢您澄清这一点,@Rob