2012-12-24 87 views
0

我今天大會開始,以創建殼code.The ASM是個好人,過了一段時間我創造了這個:我是否需要Shellcode的特定訂單?將此代碼轉換爲shellcode時,我做錯了什麼?

[SECTION .text] 

global _start 


_start: 

     call ender 

     starter: 
     mov al, 4 
     mov bl, 1 
     pop ecx 
     mov dl, 21 
     int 0x80 

     xor eax, eax 
     mov al, 1 
     xor ebx,ebx 
     int 0x80 

     ender: 
     call starter 
     db 10,'Shellcode forever!',10 ,10 

哪些行之有效:

Shellcode forever! 

[email protected]:~/Desktop# clear;nasm -f elf test.asm;ld -s -o test test.o;./test 

所以然後我用「objdump的-d測試」,並得到這個:

test:  file format elf32-i386 


Disassembly of section .text: 

08048060 <.text>: 
8048060: e8 11 00 00 00   call 0x8048076 
8048065: b0 04     mov $0x4,%al 
8048067: b3 01     mov $0x1,%bl 
8048069: 59      pop %ecx 
804806a: b2 15     mov $0x15,%dl 
804806c: cd 80     int $0x80 
804806e: 31 c0     xor %eax,%eax 
8048070: b0 01     mov $0x1,%al 
8048072: 31 db     xor %ebx,%ebx 
8048074: cd 80     int $0x80 
8048076: e8 ea ff ff ff   call 0x8048065 
804807b: 0a 53 68    or  0x68(%ebx),%dl 
804807e: 65      gs 
804807f: 6c      insb (%dx),%es:(%edi) 
8048080: 6c      insb (%dx),%es:(%edi) 
8048081: 63 6f 64    arpl %bp,0x64(%edi) 
8048084: 65 20 66 6f    and %ah,%gs:0x6f(%esi) 
8048088: 72 65     jb  0x80480ef 
804808a: 76 65     jbe 0x80480f1 
804808c: 72 21     jb  0x80480af 
804808e: 0a 0a     or  (%edx),%cl 

但是當我把它變成的shellcode:

char code[] = "\xe8\x11\x00\x00\x00\xb0\x04\xb3\x01\x59\xb2\x15\xcd\x80\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xea\xff\xff\xff\x0a\x53\x68\x65\x6c\x6c\x63\x6f\x64\x65\x20\x66\x6f\x72\x65\x76\x65\x72\x21\x0a\x0a"; 

它沒有工作。我做錯了什麼?

+0

你是怎麼把它變成shellcode的?有沒有你沒有關心的任何endinanness問題? –

+0

也許嘗試使用nasm2shell,將NASM,GNU as和二進制文件直接轉換爲shellcode的as2shell或bin2shell可能是值得的。 http://blog.markloiseau.com/wp-content/uploads/2012/06/bin2shell.tar。gz –

+0

好吧,我試試看:p –

回答

1

這就是問題所在:

nasm -f elf test.asm 

ELF是二進制格式,這是罰款生成可執行和的原因是你的獨立測試工作,但shellcode的來自原始格式,而不是漂亮的東西,作爲標題,部分等。

以得到所述原始字節,所有你需要做的是與bin替換elf

nasm -f bin test.asm 

這將使用您指定的助記符產生原始對象。爲了讓生活更容易爲我自己,我一般包括:

[bits 32] 

[bits 64] 
在彙編文件

,以獲得正確的架構。

更改爲直接二進制輸出中斷鏈接可執行測試,因爲鏈接器鏈接ELF兼容對象,而不是二進制的原始塊。對此沒有解決方法 - 但沒有理由不能生成此編譯版本和二進制版本。

在Linux系統上,我一般不打擾直接掛鉤,而是用一個小試驗檯,看起來像這樣:

#include <stdio.h> 
#include <stdint.h> 

#include <sys/types.h> 
#include <sys/mman.h> 
#include <sys/stat.h> 
#include <unistd.h> 

#define PAGE_SIZE 4096U 

uint8_t buffer[] = { 
    0xeb, 0x01, 0x90, ... 
}; 

typedef int (* func)(); 

int main(int argc, char** argv) 
{ 
    func f; 
    mprotect((void*)((size_t)&buffer[0] & ~(PAGE_SIZE -1)), 
      2*PAGE_SIZE, PROT_READ | PROT_EXEC); 
    f = (func) &buffer[0]; 
    f(); 
    return 0; 
} 

,我有時會修改不同的情況下,例如我介紹相關的複製環境。要開始使用它,編譯:

gcc -z execstack -fno-stack-protector -std=gnu99 -o testshell testshell.c 

這個運行execstack,使您的二進制可執行堆棧,這不是一個現實的目標環境,但嘿,這測試,並關閉堆棧保護,這將再次出現在目標上,但會阻礙基礎發展。

+0

THANKs soooo much。 –

+0

@Red_Hat沒問題:) – 2013-07-27 10:14:30

相關問題