Skip to content

Commit

Permalink
feat(pwn/srand): 添加附件源码
Browse files Browse the repository at this point in the history
  • Loading branch information
13m0n4de committed Oct 18, 2024
1 parent df216a7 commit 0782410
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions challenges/pwn/srand/build/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CC = gcc
CFLAGS = -Wall -Wextra -Wpedantic -no-pie -m64

TARGET = game

all: $(TARGET)

$(TARGET): $(TARGET).c
$(CC) $(CFLAGS) -o $@ $<

clean:
rm -f $(TARGET)
53 changes: 53 additions & 0 deletions challenges/pwn/srand/build/src/game.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAX_NUMBER 99999

void init() {
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
}

void banner() {
printf(" ___ * * ** ** ___ ____ ____ \n");
printf("/ **)( \\/ )( )( )/ **)(_ *)( *__)\n");
printf("\\__ \\ \\ / )(__)(( (__ )( )__) \n");
printf("(___/ \\/ (______)\\___) (__) (__) \n");
printf("\n");
printf("Welcome to the SVUCTF HELLOWORLD 2024!\n");
printf("\n");
}

void game() {
int secret_number = rand() % MAX_NUMBER + 1;
int guess;

printf("I've thought of a number between 1 and %d.\n", MAX_NUMBER);
printf("You have only one chance to guess this number. Good luck!\n\n");
printf("Please enter your guess: ");

if (scanf("%d", &guess) != 1) {
printf("Invalid input, game over.\n");
return;
}

if (guess == secret_number) {
printf("\nCongratulations! You've guessed the number %d!\n",
secret_number);
system("/bin/sh");
} else {
printf(
"\nSorry, you didn't guess correctly. The right number was %d.\n",
secret_number);
}
}

int main() {
srand(time(NULL));
init();
banner();
game();
return 0;
}

0 comments on commit 0782410

Please sign in to comment.