shellcode实践&理解
C语言源码格式
#include<unistd.h>
#include<stdlib.h>
char *buf[]={"/bin/sh",NULL};
void main()
{
execve("/bin/sh",buf,0);
exit(0);
}
gcc retsh.c -o retsh
./retsh

汇编代码形式
Int 0x80软中断调用
第一步,就是需要将系统调用号加入到eax中。
第二步,ebx用于保存函数调用的第一个参数(ecx存放第二个参数,edx存放第三个参数,esi存放第四个参数,edi存放第五个参数)
如果参数个数超过5个,那么就必须将参数数组存储在内存中,而且必须将该数组的地址存储在ebx中。
一旦加载寄存器之后,就会调用int 0x80 汇编指令来发出软中断,强迫内核暂停手头上的工作并处理该中断。
section .text
global _start
_start:
xor eax,eax
push eax
push 0x68732f2f
push 0x6e69622f
mov ebx,esp
push eax
push ebx
mov ecx,esp
xor edx,edx
mov al,0xb
int 0x80
nasm -f elf shelcodeAsm.asm
ld -m elf_i386 -s -o shellcodeAsm.o shellcodeAsm
./shellcodeAsm


技能掌握
nasm -f elf retsh.asm #会生成.o文件
ld -o retsh retsh.o #生成可执行文件
ld -m elf_i386 -s -o file.o file #平台不匹配的时候;制定生成x86文件
gdb binary
readelf #可以看到汇编文件的.text段等地址;于是可以通过"b*address"下断点,单步调试
si/s
ni/n
0x68732f2f和0x6e69622f对应的是'b''i''n''s''h''/'这些字符的Ascii码;并不是从系统中获取的
本文分享shellcode的实践与理解,介绍了C语言源码格式和汇编代码形式,重点讲解了Int 0x80软中断调用,包括将系统调用号加入eax,用ebx等寄存器保存参数,加载寄存器后调用int 0x80指令发出软中断,最后提及技能掌握。
560

被折叠的 条评论
为什么被折叠?



