使用汇编程序执行系统命令(bash)?

问题描述 投票:0回答:1

基本上,我试图使用汇编来执行命令/bin/ls,但是不幸的是,我失败了:

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并在mov edx, 7之后添加xor edx, edx。它确实打印/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

linux assembly nasm
1个回答
1
投票

发现问题,如@Jestor指出的(谢谢),我需要将执行文件存储在ebx并将所有参数(包括文件名存储在ecx中,并将edx设置为null,如下所示:

© www.soinside.com 2019 - 2024. All rights reserved.