私はasmを初めて使い、/ bin/bashにsyscallを実行しようとしています。しかし、私は現在、次のような問題に遭遇しています:アセンブリexecve/bin/bash(x64)
私のコードは、その第一引数の長さが8バイト未満、すなわち「/ binに/ SH」または「/ binに/ LS」で任意のexecveの呼び出しのために働く:
.section .data
name: .string "/bin/sh"
.section .text
.globl _start
_start:
#third argument of execve, set to NULL
xor %rdx, %rdx
#push nullbyte to the stack
pushq %rdx
#push /bin/sh to the stack
pushq name
#copy stack to rdi, 1st arg of execve
mov %rsp, %rdi
#copy 59 to rax, defining syscall number for execve
movq $59, %rax
#3rd arg of execve set to NULL
movq $0, %rsi
syscall
何を私に困惑することは、私がスタックにし、「/ binに」「/ bashの」pushqし、部品に文字列を分割しようとした私はそれが
name: .string "/bin/bash"
で動作するように得ることができないということです、何も私を可能にするようですそれを動作させるために、毎回「不正な命令」エラーが出ます。私は間違って何をしていますか?
ノンワーキングコード:
.section .data
name: .string "/bin/bash"
.section .text
.globl _start
_start:
#third argument of execve, set to NULL
xor %rdx, %rdx
#push nullbyte to the stack
pushq %rdx
#push /bin/sh to the stack
pushq name
#copy stack to rdi, 1st arg of execve
mov %rsp, %rdi
#copy 59 to rax, defining syscall number for execve
movq $59, %rax
#3rd arg of execve set to NULL
movq $0, %rsi
syscall
その他の非作業コード:
.section .data
.section .text
.globl _start
_start:
#third argument of execve, set to NULL
xor %rdx, %rdx
#push nullbyte to the stack
pushq %rdx
#push /bin/bash to the stack
pushq $0x68
pushq $0x7361622f
pushq $0x6e69622f
#copy stack to rdi, 1st arg of execve
mov %rsp, %rdi
#copy 59 to rax, defining syscall number for execve
movq $59, %rax
#3rd arg of execve set to NULL
movq $0, %rsi
syscall
あなたは**非を表示するために忘れてしまいましたワーキング**コード。また、デバッガの使用を忘れてしまった。スタックが逆に動作することを忘れているかもしれません。そして、おそらく、 'push' **は常に8バイトを書き込むことを忘れていました。したがって、最後の部分(最初に押す部分)を除いて、文字列を8バイト部分に分割する必要があります。 – Jester
明らかに '.data'に文字列がある場合、それをスタックにコピーする必要はありません。そのアドレスを直接使用して、それを使って完了することができます。 – Jester
関数のX86_64 ABI呼び出し規約を見てきましたか?それは、物事が間違って起こっている場所を把握するのに役立ちます。 –