前两天在pwnable.kr上看到这样一道题:
I made a skeleton interface for one time password authentication system.
I guess there are no mistakes.
could you take a look at it?
hint : not a race condition. do not bruteforce.
ssh otp@pwnable.kr -p2222 (pw:guest)
是通过/dev/urandom 来实现一次一秘的架构,代码如下,本人愚钝,没有发现漏洞,求高手指教启发。
代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
int main(int argc, char* argv[]){
char fname[128];
unsigned long long otp[2];
if(argc!=2){
printf("usage : ./otp [passcode]\n");
return 0;
}
int fd = open("/dev/urandom", O_RDONLY);
if(fd==-1) exit(-1);
if(read(fd, otp, 16)!=16) exit(-1);
close(fd);
sprintf(fname, "/tmp/%llu", otp[0]);
FILE* fp = fopen(fname, "w");
if(fp==NULL){ exit(-1); }
fwrite(&otp[1], 8, 1, fp);
fclose(fp);
printf("OTP generated.\n");
unsigned long long passcode=0;
FILE* fp2 = fopen(fname, "r");
if(fp2==NULL){ exit(-1); }
fread(&passcode, 8, 1, fp2);
fclose(fp2);
if(strtoul(argv[1], 0, 16) == passcode){
printf("Congratz!\n");
system("/bin/cat flag");
}
else{
printf("OTP mismatch\n");
}
unlink(fname);
return 0;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!