본문 바로가기

Wargame/Bandit

[ Docker ] Bandit Wargame 만들기 - 26번 문제 ( 27 / 33 )

1. Bandit26 목표

Good job getting a shell! Now hurry and grab the password for bandit27

Commands you may need to solve this level
ls

 

2. Bandit26 구현

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

cat <<'BANDIT_TMP' > /tmp/bandit27-do.c
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    uid_t euid = geteuid();
    setresuid(euid, euid, euid);
    // system("id");

    char *arr=malloc(1000*sizeof(char));

    int i;

    for(i=1;i<argc;i++)
    {
        strcat(arr,argv[i]);
        strcat(arr," ");

        strcat(arr,"\0");
    }

    FILE *fp = NULL;
    char line[10240];

    if((fp = popen(arr, "r")) == NULL) {
        return 1;
    }

    while(fgets(line, 10240, fp) != NULL) {
        printf("%s", line);
    }

    pclose(fp);
    return 0;
}
BANDIT_TMP

gcc -o /home/bandit26/bandit27-do /tmp/bandit27-do.c

useradd bandit27 && echo -e "upsNCc7vzaRDx6oZC6GiR6ERwe1MowGB\nupsNCc7vzaRDx6oZC6GiR6ERwe1MowGB" | passwd bandit27

chown bandit27:bandit26 /home/bandit26/bandit27-do

chmod 755 /home/bandit27

chown root:root /home/bandit27

echo upsNCc7vzaRDx6oZC6GiR6ERwe1MowGB > /etc/bandit_pass/bandit27

chown bandit27:bandit27 /etc/bandit_pass/bandit27

chmod 400 /etc/bandit_pass/bandit27

chmod 4750 /home/bandit26/bandit27-do

 

3. Bandit26 문제풀의

# bandit25 로 설정한 패스워드를 입력하여 접속한다.
# iCi86ttT4KSNe1armKiwbQNmB3YJP3q4
ssh -oStrictHostKeyChecking=no bandit25@localhost -p 2220

stty rows 15 cols 15

# bandit26로 접속한다.
ssh -oStrictHostKeyChecking=no -p 2220 -i /home/bandit25/bandit26.sshkey bandit26@localhost

# v키를 눌러서 편집모드
v

# 기본 쉘을 /usr/bin/showtext에서 /bin/bash로 변경
:set shell=/bin/bash

# 기본 쉘에 접속
:shell

# 기본 rows와 cols 로 변경
stty rows 42 cols 139

# 저장된 파일 확인
ls

# 19번 문제와 동일
# 패스워드 확인
/home/bandit26/bandit27-do cat /etc/bandit_pass/bandit27