basic_exploitation_001
·
Wargame/Dreamhack
#include #include #include #include void alarm_handler() { puts("TIME OUT"); exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(30); } void read_flag() { system("cat /flag"); } int main(int argc, char *argv[]) { char buf[0x80]; initialize(); gets(buf); return 0; } 앞선 문제와 다르게 이번에는 gets로 문자열을 입력받는다. 또한 read_flag ..
basic_exploitation_000
·
Wargame/Dreamhack
서버에 접속해서 실제로 값을 넣어보면 접속 시마다 buf의 주소가 변경되는 것을 보아 ASLR 즉, 랜덤 스택 보호 기법이 걸려있음을 알 수 있다. ┌──(kali㉿kali)-[~/Downloads/1] └─$ nc host3.dreamhack.games 13445 buf = (0xfff4d778) a ┌──(kali㉿kali)-[~/Downloads/1] └─$ nc host3.dreamhack.games 13445 buf = (0xffa4f748) a 코드를 보면 #include #include #include #include void alarm_handler() { puts("TIME OUT"); exit(-1); } void initialize() { setvbuf(stdin, NULL, _ION..
Return Address Overwrite
·
Wargame/Dreamhack
lecture와 연계된 기본적인 bof 문제이다. // Name: rao.c // Compile: gcc -o rao rao.c -fno-stack-protector -no-pie #include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } void get_shell() { char *cmd = "/bin/sh"; char *args[] = {cmd, NULL}; execve(cmd, args, NULL); } int main() { char buf[0x28]; init(); printf("Input: "); scanf("%s", buf); return 0; } shell을 실행시켜주는 get_shell 함수가 있..
[App-System] ELF x86 - Stack buffer overflow basic 4
·
Wargame/Root me
1. intro 2. code 및 분석 2.1. code #include #include #include #include struct EnvInfo { char home[128]; char username[128]; char shell[128]; char path[128]; }; struct EnvInfo GetEnv(void) { struct EnvInfo env; char *ptr; if((ptr = getenv("HOME")) == NULL) { printf("[-] Can't find HOME.\n"); exit(0); } strcpy(env.home, ptr); if((ptr = getenv("USERNAME")) == NULL) { printf("[-] Can't find USERNAME.\n..
[App-System] ELF x86 - Stack buffer overflow basic 3
·
Wargame/Root me
1. intro 2. code 및 분석 2.1. code #include #include #include #include #include void shell(void); int main() { char buffer[64]; int check; int i = 0; int count = 0; printf("Enter your name: "); fflush(stdout); while(1) { if(count >= 64) printf("Oh no...Sorry !\n"); if(check == 0xbffffabc) shell(); else { read(fileno(stdin),&i,1); switch(i) { case '\n': printf("\a"); break; case 0x08: count--; print..
[App-System] ELF x64 - Stack buffer overflow - basic
·
Wargame/Root me
1. intro 2. code 및 분석 2.1. code #include #include #include #include #include /* gcc -o ch35 ch35.c -fno-stack-protector -no-pie -Wl,-z,relro,-z,now,-z,noexecstack */ void callMeMaybe(){ char *argv[] = { "/bin/bash", "-p", NULL }; execve(argv[0], argv, NULL); } int main(int argc, char **argv){ char buffer[256]; int len, i; scanf("%s", buffer); len = strlen(buffer); printf("Hello %s\n", buffer); r..
[App-System] ELF x86 - Stack buffer overflow basic 2
·
Wargame/Root me
1. intro 2. code & 분석 #include #include #include #include void shell() { setreuid(geteuid(), geteuid()); system("/bin/bash"); } void sup() { printf("Hey dude ! Waaaaazzaaaaaaaa ?!\n"); } void main() { int var; void (*func)()=sup; char buf[128]; fgets(buf,133,stdin); func(); } 우선 envi. config.에 NX, Heap exec가 걸려있다. 추후에 이에 대해서 다시 한번 정리하기로하고, 간단히 이야기하자면 buffer 내에 의미 있는 코드가 입력되더라도 실행되지는 않게 막아주는 보호 기..
[App-System] ELF x86 - Stack buffer overflow basic 1
·
Wargame/Root me
1. intro 2. code & 분석 #include #include int main() { int var; int check = 0x04030201; char buf[40]; fgets(buf,45,stdin); printf("\n[buf]: %s\n", buf); printf("[check] %p\n", check); if ((check != 0x04030201) && (check != 0xdeadbeef)) printf ("\nYou are on the right way!\n"); if (check == 0xdeadbeef) { printf("Yeah dude! You win!\nOpening your shell...\n"); setreuid(geteuid(), geteuid()); system(..