问题描述
基本上我正在尝试使用程序集执行命令 /bin/ls
,但不幸的是我失败了:
Basically I am trying to execute the command /bin/ls
using assembly, but unfortunately I am failing:
SECTION .data
buf: db "Hello", 5
SECTION .text
global _start
_start:
xor eax, eax
mov edx, eax
push edx
mov eax, 0x736c2f2f ; "sl/"
push eax
mov eax, 0x6e69622f ; "nib/"
push eax
mov ebx, esp
push edx
mov eax, 0x2f
push eax
mov ecx, esp
mov eax, 11
xor edx, edx
int 0x80
mov eax, 1
int 0x80
但是如果我将 mov eax, 11
更改为 mov eax, 4
并在 xor edx 之后添加
.它确实打印 mov edx, 7
, edx/bin/ls
But If I change the mov eax, 11
to mov eax, 4
and add mov edx, 7
after xor edx, edx
. It do print /bin/ls
谁能指出我犯的错误?使用 nasm -g -f elf -F dwarf ./shell.asm && 编译代码ld -m elf_i386 -o shell shell.o
而我的弧是 Linux kali 5.2.0-kali2-amd64 #1 SMP Debian 5.2.9-2kali1 (2019-08-22) x86_64 GNU/Linux
Can anyone point the mistake I am making?Compiling the code with nasm -g -f elf -F dwarf ./shell.asm && ld -m elf_i386 -o shell shell.o
and my arc is Linux kali 5.2.0-kali2-amd64 #1 SMP Debian 5.2.9-2kali1 (2019-08-22) x86_64 GNU/Linux
推荐答案
发现问题,正如@Jestor 指出的(谢谢),我需要将执行文件存储在 ebx
和所有参数包括 ecx
中的文件名并将 edx
设置为 null,如下所示:
Found the problem, as pointed by @Jestor (thank you), I needed to store the executing file at ebx
and all the arguments including the filename in ecx
and set edx
to null as below:
SECTION .data
buf: db "./", 0
SECTION .text
global _start
_start:
xor eax, eax
xor edx, edx
push eax
push long 0x736c2f2f ; "sl/"
push long 0x6e69622f ; "nib/"
mov ebx, esp
push eax
push byte 0x2f
mov esi, esp
push eax
push esi
push ebx
mov ecx, esp
mov eax, 0x0b
int 0x80
mov eax, 1
int 0x80
在我工作的 shell 之后,ecx
如下所示:
after my working shell, the ecx
looked like below:
(gdb) x/50x $ecx
0xffffd370: 0xffffd384 0xffffd37c 0x00000000 0x0000002f
0xffffd380: 0x00000000 0x6e69622f 0x736c2f2f 0x00000000
这篇关于使用程序集执行系统命令(bash)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!