ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • narnia 3
    OverTheWire 2015. 9. 21. 04:02

    심볼릭으로 푸는데 어떤경로에 어떤유저가 푼 파일이있어서 그냥 setuid걸린 바이너리로 플래그를봤다..

    실력이 늘지않으니까 코드설명을 하자면 


    int main(int argc, char **argv){

     

            int  ifd,  ofd;

            char ofile[16] = "/dev/null";

            char ifile[32];

            char buf[32];

     

            if(argc != 2){

                    printf("usage, %s file, will send contents of file 2 /dev/null\n",argv[0]);

                    exit(-1);

            }

     

            /* open files */

            strcpy(ifile, argv[1]);

            if((ofd = open(ofile,O_RDWR)) < 0 ){

                    printf("error opening %s\n", ofile);

                    exit(-1);

            }

            if((ifd = open(ifile, O_RDONLY)) < 0 ){

                    printf("error opening %s\n", ifile);

                    exit(-1);

            }

     

            /* copy from file1 to file2 */

            read(ifd, buf, sizeof(buf)-1);

            write(ofd,buf, sizeof(buf)-1);

            printf("copied contents of %s to a safer place... (%s)\n",ifile,ofile);

     

            /* close 'em */

            close(ifd);

            close(ofd);

     

            exit(1);

    }


    요론데 만약에 우리가 인자로 주는 파일이 열리면 밑에 read함수로 들어가는데, 버퍼를 입력받고 그 버퍼를 출력시킨다.

    ofile을 오버플로우시켜주면된다.


    심볼릭링크를 좀만 쓰면풀리는문제이다


    thaenohtai

    'OverTheWire' 카테고리의 다른 글

    narnia5  (1) 2015.09.24
    narnia 4  (0) 2015.09.21
    narnia2  (0) 2015.04.29
    narnia1  (0) 2015.04.29
    narnia0  (0) 2015.04.29

    댓글

Designed by Tistory.