[pwnable.kr] lotto 풀이

2021. 3. 24. 03:50·Write-Up/pwnable.kr
반응형
#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;
}

char형으로 받아서 ascii code로 들어가니 숫자를 넣지말고

ascii code표를 보고 1~45사이 값을 겹치게 6개 넣어주자

여러번 시도하자

 

 

sorry mom... I FORGOT to check duplicate numbers... :(

 

반응형

'Write-Up > pwnable.kr' 카테고리의 다른 글

[pwnable.kr] cmd2 풀이  (0) 2021.03.24
[pwnable.kr] cmd1 풀이  (0) 2021.03.24
[pwnable.kr] blackjack 풀이  (0) 2021.03.24
[pwnable.kr] coin1 풀이  (0) 2021.03.21
[pwnable.kr] shellshock 풀이  (0) 2021.03.21
'Write-Up/pwnable.kr' 카테고리의 다른 글
  • [pwnable.kr] cmd2 풀이
  • [pwnable.kr] cmd1 풀이
  • [pwnable.kr] blackjack 풀이
  • [pwnable.kr] coin1 풀이
Penguin Dev
Penguin Dev
What does the Penguin say?
    글쓰기 관리
  • Penguin Dev
    Pengha!
    Penguin Dev
  • 전체
    오늘
    어제
    • 분류 전체보기 (152)
      • Java & Spring (5)
      • System Hacking (4)
      • Algorithm (8)
        • Sorting algorithm (3)
      • Python (6)
      • Web (2)
        • Web Hacking & Security (2)
      • Write-Up (108)
        • pwnable.kr (17)
        • HackCTF (16)
        • 해커스쿨 FTZ (21)
        • LOB(lord of bufferoverflow) (19)
        • LOS (lord of sql injection) (28)
        • XSS-game (6)
        • Webhacking.kr (1)
      • SUA (19)
        • 오픈소스 보안 (19)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    SpringBoot
    sqlinjection
    computeifabsent()
    lord of bufferoverflow
    쿠폰발급
    DB정리
    thread-safe
    AQS
    LOB
    코드트리
    putval()
    reentrantlock실습
    enumerate #list comprehension
    Java
    ConcurrentHashMap
    hashmap vs concurrenthashmap
    CountDownLatch
    spring
    spring boot
    ReentrantLock
    동시성처리
    코드트리조별과제
    nop sled
    tabat
    computeifpresent
    Lock
    concurrenthashmap vs hashmap
    동시성
    computeifpresent()
    computeifabsent
  • 최근 댓글

  • 반응형
  • hELLO· Designed By정상우.v4.10.3
Penguin Dev
[pwnable.kr] lotto 풀이
상단으로

티스토리툴바