[ Dreamhack ] - welcome
https://dreamhack.io/wargame/challenges/27
welcome
Description 이 문제는 서버에서 작동하고 있는 서비스(welcome)의 바이너리와 소스 코드가 주어집니다. "접속 정보 보기"를 눌러 서비스 정보를 얻은 후 플래그를 획득하세요. 서버로부터 얻은 플래
dreamhack.io
#include <stdio.h>
int main(void) {
FILE *fp;
char buf[0x80] = {};
size_t flag_len = 0;
printf("Welcome To DreamHack Wargame!\n");
fp = fopen("/flag", "r");
fseek(fp, 0, SEEK_END);
flag_len = ftell(fp);
fseek(fp, 0, SEEK_SET);
fread(buf, 1, flag_len, fp);
fclose(fp);
printf("FLAG : ");
fwrite(buf, 1, flag_len, stdout);
}
서버 연결만 하면 되는 문제였다...


문제는 해결했으나 복붙이 왜 안될까요...
구글에 쳐보고 해보라는대로 다 해보았는데 안돼요...
그냥 손으로 쳐서 했습니다...
[ Dreamhack ] - baby bof
https://dreamhack.io/wargame/challenges/974
baby-bof
Description Simple pwnable 101 challenge Q. What is Return Address? Q. Explain that why BOF is dangerous.
dreamhack.io
위에 문제가 너무 쉬워서 하나 더 풀어보았습니다.
이름부터 BOF 문제 :))
// gcc -o baby-bof baby-bof.c -fno-stack-protector -no-pie
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
void proc_init ()
{
setvbuf (stdin, 0, 2, 0); setvbuf (stdout, 0, 2, 0);
setvbuf (stderr, 0, 2, 0);
}
void win ()
{
char flag[100] = {0,};
int fd;
puts ("You mustn't be here! It's a vulnerability!");
fd = open ("./flag", O_RDONLY);
read(fd, flag, 0x60);
puts(flag);
exit(0);
}
long count;
long value;
long idx = 0;
int main ()
{
char name[16];
// don't care this init function
proc_init ();
printf ("the main function doesn't call win function (0x%lx)!\n", win);
printf ("name: ");
scanf ("%15s", name);
printf ("GM GA GE GV %s!!\n: ", name);
printf ("| addr\t\t| value\t\t|\n");
for (idx = 0; idx < 0x10; idx++) {
printf ("| %lx\t| %16lx\t|\n", name + idx *8, *(long*)(name + idx*8));
}
printf ("hex value: ");
scanf ("%lx%c", &value);
printf ("integer count: ");
scanf ("%d%c", &count);
for (idx = 0; idx < count; idx++) {
*(long*)(name+idx*8) = value;
}
printf ("| addr\t\t| value\t\t|\n");
for (idx = 0; idx < 0x10; idx++) {
printf ("| %lx\t| %16lx\t|\n", name + idx *8, *(long*)(name + idx*8));
}
return 0;
}

문제를 실행시켜보면 win 함수의 주소를 알려주고, name을 입력하라고 한다.
코드를 보면 scanf("15s", name);으로 name을 입력 받고 있기 때문에 일단 15글자 아무거나 입력해주었다.

첫번째, 두번째 줄을 보면 1의 아스키코드의 16진수값인 31일이 들어있음을 알 수 있고,
이 두 줄에 name의 배열 값이 저장되어 있다는 것을 알 수 있다.
printf ("hex value: ");
scanf ("%lx%c", &value);
printf ("integer count: ");
scanf ("%d%c", &count);
for (idx = 0; idx < count; idx++) {
*(long*)(name+idx*8) = value;
}
main함수 중 이 부분을 보면
name이 저장된 다음 줄부터 count만큼 value 값으로 수정되는 것을 알 수 있다.
즉, count를 2이상, value는 win 함수의 주소 값인 0x40125b로 입력하면
다른 값들이 수정되는 BOF를 발생시킬 수 있다.

포너블이 어렵지만 재밌다....
'ETC > EVI$ION' 카테고리의 다른 글
| EVI$ION 러닝 세션 과제 - #2 (4/6) (1) | 2024.04.06 |
|---|---|
| EVI$ION 정규 세션 과제 - #3 (0) | 2024.04.04 |
| EVI$ION 웹 CTF 제작 - #1 (0) | 2024.03.31 |
| EVI$ION 정규 세션 과제 - #2 (0) | 2024.03.28 |
| EVI$ION 정규 세션 과제 - #1 (0) | 2024.03.21 |