终于做了一部分pwnable这道题很有意思感觉不像pwn
连上去有3个文件一个c文件一个执行文件一个password
打开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;
}
逻辑很简单就是pw_buf和pw_buf2相等就对输出flag
pw_buf2等于你输入的异或10个1
但pw_buf我们不知道
这时候看到提示操作符的优先级就会想到‘’<‘’的优先级是大于‘=’的所以优先进行比较然后会赋值所以
fd=0
然后就和第一题一样了fd=0就是read函数IO流自己输入就可以输入pw_buf了
我们输入1111111111
password 输入 0000000000
0000000000^1111111111=1111111111
就可以得到flag了