zoukankan      html  css  js  c++  java
  • 0day2安全——笔记4(修改临界变量)

    第二章

    修改临界变量

    #include <stdio.h>
    #include <string.h>
    #define PASSWORD "1234567"
    int verify_password(char *password){
        int flag;
        char buffer[8];
        flag = strcmp(password,PASSWORD);//flag需要为1才能溢出
        strcpy(buffer,password);//溢出点
        return flag;
    }
    void main(){
        int valid_flag;
        char password[1024];
        while(1){
            printf("Please input password: ");
            scanf("%s",password);
            valid_flag = verify_password(password);
            if(valid_flag){
                printf("Incorrect password!
    ");
            }
            else{
                printf("Congratulations!
    ");
                break;
            }
        }
    }

    溢出原理:使用strcpy函数没有验证buffer的长度是否超出范围,导致当buffer超过所给的地址,覆盖了返回局部变量flag

    突破验证分析:

    使strcmp的返回值为1,即ret=0x1。这样才能让buffer溢出截断符(x00)覆盖到flag的的低位上,使ret=0

    我们需要让输入的密码为8位且大于PASSWORD的值才能满足上诉要求

    进入OD,载入程序,中文引擎搜索(智能搜索)

    进入我们在程序中注释输入密码的地方,找到verify_password()函数

    按回车进入函数继续分析

     strcat函数就是我们要分析溢出过程的地方,我们在这里下一个断点,并运行程序

    我们输入8个q, 此时flag的值即为EAX的值1,即返回的是失败的步骤

     

    F7单步步入函数,分析溢出的过程得知password字符串qqqqqqqq分了3次赋值给了buffer,前二次分别给了qqqq,qqqq。第三次给了CCCCCC00(末尾的00是我们输入的8位后的截断符)

    分析得知变量flag和buffer的地址分别为0012FB20,0012FB18

     函数执行完后,即溢出的00替换掉了低位的01

     

  • 相关阅读:
    TortoiseGit保存用户名密码的方法
    nginx proxy优化
    tomcat优化
    mongodb 慢SQL查询
    iptables基础知识
    mongostat
    mongodb命令
    nginx libpcre.so.1: cannot open shared object file
    error while loading shared libraries: libmcrypt.so.4
    mongodb常见问题
  • 原文地址:https://www.cnblogs.com/luocodes/p/11892104.html
Copyright © 2011-2022 走看看