pwn的学习9 mistake

pwnable.kr   mistake

首先查看文件 

首先看 code

mistake.c


#include <stdio.h>
#include <fcntl.h>

#define PW_LEN 10
#define XORKEY 1

void xor(char* s, int len){
        int i;
        for(i=0; i<len; i++){
                s[i] ^= XORKEY;
        }
}

int main(int argc, char* argv[]){

        int fd;
        if(fd=open("/home/mistake/password",O_RDONLY,0400) < 0){
                printf("can't open password %d\n", fd);
                return 0;
        }

        printf("do not bruteforce...\n");
        sleep(time(0)%20);

        char pw_buf[PW_LEN+1];
        int len;
        if(!(len=read(fd,pw_buf,PW_LEN) > 0)){
                printf("read error\n");
                close(fd);
                return 0;
        }

        char pw_buf2[PW_LEN+1];
        printf("input password : ");
        scanf("%10s", pw_buf2);

        // xor your input
        xor(pw_buf2, 10);

        if(!strncmp(pw_buf, pw_buf2, PW_LEN)){
                printf("Password OK\n");
                system("/bin/cat flag\n");
        }
        else{
                printf("Wrong Password\n");
        }

        close(fd);
        return 0;
}

题目的提示 是 hint : operator priority

也就是说 优先级问题

首先看代码

if(fd=open("/home/mistake/password",O_RDONLY,0400)< 0)

这句代码中,<的优先级大于=

所以先进行比较,后进行赋值,而open打开一个文件,任何情况下返回都不会小于0,因此比较之后就等于0,fd=0了,

read函数来说,fd=0就是从标准输入读入,因此实际上buf1就是用户自己输入的10个字节。所以就简单了。

//来自大佬博客https://blog.csdn.net/qq_20307987/article/details/51314187
 

因为异或 是可逆的

     if(!strncmp(pw_buf, pw_buf2, PW_LEN)){
                printf("Password OK\n");
                system("/bin/cat flag\n");
        }

也就是要求 两者相同。。。

所以

先输入10个0

因为0000000000 ^ 1111111111 = 1111111111

所以在input password再输入1111111111

猜你喜欢

转载自blog.csdn.net/qq_35396598/article/details/85799586
今日推荐