본문 바로가기

wargame/bandit

Level 13 → Level 14

Level Goal

The password for the next level is stored in /etc/bandit_pass/bandit14 and can only be read by user bandit14. For this level, you don’t get the next password, but you get a private SSH key that can be used to log into the next level. Note: localhost is a hostname that refers to the machine you are working on
비밀번호는 사용자 bandit14로만 읽을 수 있는 /etc/bandit_pass/bandit14에 저장되어 있다 이번 단계에선 비밀번호를 얻진 않지만 다음 단계로 로그인할 때 사용되는 private SSH 키를 얻을 수 있다 NOTE: localhost 는 당신이 작업 중인 머신을 가리키는 hostname이다

Code

bandit13@bandit:~$ ls
sshkey.private
bandit13@bandit:~$ cat sshkey.private
# 내용 출력(RSA private key임을 알 수 있었다)
bandit13@bandit:~$ man ssh
bandit13@bandit:~$ man ssh
bandit13@bandit:~$ ssh -i ~/sshkey.private bandit14@bandit.labs.overthewire.org -p 2220 # 1차 시도 실패
bandit13@bandit:~$ man ssh
bandit13@bandit:~$ man ssh
bandit13@bandit:~$ ls
sshkey.private
bandit13@bandit:~$ ssh -i ~/bandit13/sshkey.private bandit14@bandit.labs.overthewire.org -p 2220 # 2차 시도 실패
Warning: Identity file /home/bandit13/bandit13/sshkey.private not accessible: No such file or directory.
bandit13@bandit:~$ man ssh
bandit13@bandit:~$ ssh -i ~/sshkey.private bandit14@bandit.labs.overthewire.org -p 2220 # 3차 시도 실패
ssh: connect to host bandit.labs.overthewire.org port 2220: Connection timed out
bandit13@bandit:~$ man ssh
bandit13@bandit:~$ man ssh
bandit13@bandit:~$ ssh -i ~/sshkey.private bandit14@localhost # 4차 시도 성공
Could not create directory '/home/bandit13/.ssh'.
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:98UL0ZWr85496EtCRkKlo20X3OPnyPSB5tB5RPbhczc.
Are you sure you want to continue connecting (yes/no)? yes
#접속
bandit14@bandit:~$ cd /etc/bandit_pass/bandit14
-bash: cd: /etc/bandit_pass/bandit14: Not a directory
bandit14@bandit:~$ cd /etc/bandit_pass
bandit14@bandit:/etc/bandit_pass$ cat bandit14
#비밀번호

앞에서 ssh의 개념을 날로 쌓아서 그런지 처음에는 이번 문제를 어디서 해결해야 하는지 감이 오지 않았다. 우선 문제에서 참고 하라던 사이트에서 기본적인 ssh 지식을 익혔다. 하지만 추상적인 내용+영어 콤보로 다양하게 검색을 하였다. ssh key 활용 예시, ssh에서 키 인증으로 로그인 하는 법을 명령어 위주로 잘 정리한 글, 공개키 인증 과정을 잘 정리한 글에서 키를 이용하여 로그인 하는 방식을 좀 더 구체적으로 공부하였다. 배운 내용을 정리하자면

  1. 암호는 보안상의 취약점이 있다
  2. 그 대용으로 공개키 인증(public key authentication) 방식을 사용하는데 그 방식은 다음과 같다
  3. ssh-keygen 명령어를 이용하여 rsa 방식의 개인 키와 공개 키를 생성한다
  4. 그럼 id_rsa 라는 개인 키 파일과 id_rsa.pub이라는 공개 키가 생성되는데 접속하고자 하는 서버 계정 ~/.ssh/authorized_keys 파일에 공개 키 값을 저장한다
  5. 현재 서버의 개인 키와 원격 서버의 공개키 값이 조합되어 암호 없이 ssh 접속이 가능해진다
이 단계에서는 개인키로 다음 단계에 로그인한 후 비밀번호를 알아내야겠다고 계획을 세웠다. 검색 도중 ssh명령어의 i 옵션을 발견하여 manual을 참고하여 문제를 해결하였다. 다만 ssh 명령어를 사용할 때 user@주소는 실행되지 않고 user@hostname만이 실행이 되었다. 문제에서 제시한대로 localhost를 입력하면 해결할 수 있었지만 주소를 입력하면 실행이 되지 않아서 혼란스러웠다.
참고1   참고2

#ssh -i

'wargame > bandit' 카테고리의 다른 글

Level 15 → Level 16  (0) 2019.02.20
Level 14 → Level 15  (0) 2019.02.20
Level 12 → Level 13  (0) 2019.02.20
Level 11 → Level 12  (0) 2019.02.20
Level 10 → Level 11  (0) 2019.02.20