Pwnstar
Pwnable.kr lotto 본문
13번째 로또
접속
이것도 전 문제같은 게임 형식의 문제일 것 같아 바로 실행해봤다.
이렇게 1번 로또 실행, 2번 도움말, 3번 종료가 있다
1번을 누르면,
6개의 수를 입력하라는 문구가 있다. 뭐...이것도 랜덤 값 맞추는 그런 문제일 것 같다.
이렇게 숫자가 틀리면 bad luck...이라는 문구가 뜬다. 이제 소스코드를 확인해보자.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
unsigned char submit[6];
void play(){
int i;
printf("Submit your 6 lotto bytes : ");
fflush(stdout);
int r;
r = read(0, submit, 6);
printf("Lotto Start!\n");
//sleep(1);
// generate lotto numbers
int fd = open("/dev/urandom", O_RDONLY);
if(fd==-1){
printf("error. tell admin\n");
exit(-1);
}
unsigned char lotto[6];
if(read(fd, lotto, 6) != 6){
printf("error2. tell admin\n");
exit(-1);
}
for(i=0; i<6; i++){
lotto[i] = (lotto[i] % 45) + 1; // 1 ~ 45
}
close(fd);
// calculate lotto score
int match = 0, j = 0;
for(i=0; i<6; i++){
for(j=0; j<6; j++){
if(lotto[i] == submit[j]){
match++;
}
}
}
// win!
if(match == 6){
system("/bin/cat flag");
}
else{
printf("bad luck...\n");
}
}
void help(){
printf("- nLotto Rule -\n");
printf("nlotto is consisted with 6 random natural numbers less than 46\n");
printf("your goal is to match lotto numbers as many as you can\n");
printf("if you win lottery for *1st place*, you will get reward\n");
printf("for more details, follow the link below\n");
printf("http://www.nlotto.co.kr/counsel.do?method=playerGuide#buying_guide01\n\n");
printf("mathematical chance to win this game is known to be 1/8145060.\n");
}
int main(int argc, char* argv[]){
// menu
unsigned int menu;
while(1){
printf("- Select Menu -\n");
printf("1. Play Lotto\n");
printf("2. Help\n");
printf("3. Exit\n");
scanf("%d", &menu);
switch(menu){
case 1:
play();
break;
case 2:
help();
break;
case 3:
printf("bye\n");
return 0;
default:
printf("invalid menu\n");
break;
}
}
return 0;
}
play 함수에 보면 submit 배열에 내가 입력한 수가 들어가고, lotto 배열에 랜덤값이 들어간다.
근데 이 부분을 보면 for문을 6번씩 2중으로 도니까 36번을 도는데 lotto 한 문자와 내가 입력한 문자 하나만 맞으면 match가 6씩 올라가는 셈이다.
근데 그 match가 6이면 플래그를 볼 수 있다. 그러니까 6문자 중에 더도말고 덜도 말고 한글자만 일치해야한다.
그래서 무작정 111111을 계속 입력해봤다.
근데 아무리 해도 플래그가 안뜨길래 이상해서 코드를 다시 살펴봤는데
흠....아스키코드 값으로 1~45만이어야 하는거였다.
그런데 어차피 1부터 32까지는 입력할 수 있는 값이 아니고 ! 나 #$%^&*이런 문자들을 입력해야하는 것 같다.
그래서 ######를 계속 입력해보았다.
12번만에 플래그 획득!!
끗
'Pwnable.kr > Toddler's Bottle' 카테고리의 다른 글
Pwnable.kr unlink (0) | 2020.03.20 |
---|---|
Pwnable.kr uaf (0) | 2020.03.17 |
Pwnable.kr blackjack (0) | 2020.03.16 |
Pwnable.kr coin1 (0) | 2020.03.16 |
Pwnable.kr shellshock (0) | 2020.03.16 |
Comments