본문 바로가기

wargame/bandit

Level 16 → Level 17

Level Goal

The credentials for the next level can be retrieved by submitting the password of the current level to a port on localhost in the range 31000 to 32000. First find out which of these ports have a server listening on them. Then find out which of those speak SSL and which don’t. There is only 1 server that will give the next credentials, the others will simply send back to you whatever you send to it.
다음 단계를 위한 증명서은 현재 단계의 비밀번호를 31000 에서 32000 범위의 localhost에 있는 포트에 제출하면 검색할 수 있다. 우선 이 포트들 중에서 서버 수신 대기 중인 포트를 찾아라. 그리고 SSL을 이용하고 있는지 아닌지 발견해라. 오로지 한 서버만이 다음 증명서를 가지고 있고 나머지는 단순히 당신이 보낸 것을 다시 송신하고 있을 것이다.

Code

bandit16@bandit:~$  nmap -T4 -p 31000-32000 -sV localhost # 조건에 맞는 서버 검사

Starting Nmap 7.40 ( https://nmap.org ) at 2019-02-24 03:43 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00025s latency).
Not shown: 998 closed ports
PORT      STATE SERVICE     VERSION
31518/tcp open  ssl/echo
31790/tcp open  ssl/unknown # 포트의 범위 내에 server listening 중이므로 open이고, echo가 아닌 ssl이므로 선택함
31960/tcp open  echo
bandit16@bandit:~$ openssl s_client -connect localhost:31790
# 정보 출력
# 현재 단계 비밀번호 입력
# RSA 개인키 출력됨
# RSA 개인키 부분만 긁어서 복사
bandit16@bandit:/tmp$ cat > qnftm # 개인키 복사
-----BEGIN CERTIFICATE-----
MIICBjCCAW+gAwIBAgIELHlSDDANBgkqhkiG9w0BAQUFADAUMRIwEAYDVQQDDAls
b2NhbGhvc3QwHhcNMTkwMTEzMTkzNDMwWhcNMjAwMTEzMTkzNDMwWjAUMRIwEAYD
VQQDDAlsb2NhbGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ4UdWRN
ZmKD+47wp9PM6kCsCLM6u3WD1ByGlnJn3HeILlCxId2oaklGkOx/BzYcX8m0U+wU
XrC8/lC0o1YHfgfCaVht4ubhmrlD4iUnY7pABtIsrIdLgz/Ee54121GG2+ZZfmpq
mMytFoWyHSQUNFtavUMPYkzNCI8FO7GiLIZrAgMBAAGjZTBjMBQGA1UdEQQNMAuC
CWxvY2FsaG9zdDBLBglghkgBhvhCAQ0EPhY8QXV0b21hdGljYWxseSBnZW5lcmF0
ZWQgYnkgTmNhdC4gU2VlIGh0dHBzOi8vbm1hcC5vcmcvbmNhdC8uMA0GCSqGSIb3
DQEBBQUAA4GBAEtU/dx2IFDG7q3IcOmYkrvzHlmUKMXPiQqJgim/nzAo89is3A2B
S9+oWaaCX+Z5Hz97h7nJNFQHTjpoKKP0wS7ZqdpXFXFOVa4rD12hPEebqE/fCPiC
bOoJkI78ZtUg3fbal8XPHyQK4QcOfgfVAIjSgoUfiNJYQz+0Yqh6EMEp
-----END CERTIFICATE-----
^C
bandit16@bandit:/tmp$ ssh -i qnftm bandit17@localhost # 다음 단계로 가기 위해서 개인키 사용 시도1
Could not create directory '/home/bandit16/.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
Failed to add the host to the list of known hosts (/home/bandit16/.ssh/known_hosts).
This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'qnftm' are too open.
It is required that your private key files are NOT accessible by others. # 다른 사람이 접근하면 안 된다고 함
This private key will be ignored.
Load key "qnftm": bad permissions
bandit16@bandit:/tmp$ ls -l qnftm # 접근권한 확인
-rw-r--r-- 1 bandit16 root 761 Feb 24 04:07 qnftm
bandit16@bandit:/tmp$ chmod go-r qnftm # 접근권한 변경
bandit16@bandit:/tmp$ ls -l qnftm
-rw------- 1 bandit16 root 761 Feb 24 04:07 qnftm
bandit16@bandit:/tmp$ ssh -i qnftm bandit17@localhost # 다음 단계로 가기 위해서 개인키 사용 시도2
Could not create directory '/home/bandit16/.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
Failed to add the host to the list of known hosts (/home/bandit16/.ssh/known_hosts).
This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

Enter passphrase for key 'qnftm': # passphrase를 입력하라고 해서 enter 입력함
bandit17@localhost's password: # 비밀번호를 입력하라고 함
Authentication failed. # 인증 실패
bandit13@bandit:~$ ls # 앞에서 풀었던 문제 다시 접근
sshkey.private
bandit13@bandit:~$ file * # 개인키 파일의 타입 확인
sshkey.private: PEM RSA private key # ASCII text가 아님을 확인함_개인키를 복사함을 안 됨을 깨달음
bandit16@bandit:~$ openssl s_client -connect localhost:31790 > /tmp/tmp9988
depth=0 CN = localhost
verify error:num=18:self signed certificate
verify return:1
depth=0 CN = localhost
verify return:1
cluFn7wTiGryunymYOu4RcffSxQluehd # 현재 단계의 비밀번호 입력함
bandit16@bandit:~$ cat /tmp/tmp9988
# openssl s_client -connect localhost:31790 명령어를 입력하였을 때 결과 값이 출력됨
bandit16@bandit:~$ file /tmp/tmp9988 # 개인키를 넣은 파일의 타입 확인
/tmp/tmp9988: ASCII text
bandit16@bandit:~$ cd /tmp
bandit16@bandit:/tmp$ ls -l tmp9988 # 접근권한 확인
-rw-r--r-- 1 bandit16 root 4349 Feb 24 04:30 tmp9988
bandit16@bandit:/tmp$ chmod go-r tmp9988 # 접근권한 변경
bandit16@bandit:/tmp$ ssh -i /tmp/tmp9988 bandit17@localhost # 다음 단계로 가기 위해서 개인키 사용 시도3
bandit17@bandit:~$ cd /etc/bandit_pass # 성공함
bandit17@bandit:/etc/bandit_pass$ cat bandit17
#비밀번호

문제에서 특별한 포트를 출력해야 하므로 관련된 명령어인 nmap과 옵션 사용하여 원하는 서버 포트를 발견하였다. 비밀번호를 포트에 제출하기 위하여 openssl 명령어를 사용하였고 결과로 증명서(RSA 개인키)를 받았다 RSA 개인키를 이용하여 다음 단계에 로그인하였다 다만 주의해야 할 것은 개인키 내용을 복사해서 접근하면 안 된다는 것이다 개인키를 복사한 파일과 개인키 파일은 형식이 달랐다
+) 개인키를 제출해야하므로 파일을 제출하는 nc 명령어도, ssl 암호화를 사용하여 제출하는 openssl 명령어도 아닌 ssh -i 명령어를 이용하였다.
+) nmap 옵션1   nmap 옵션2   nmap 옵션3

#nmap #ssh -i

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

Level 18 → Level 19  (0) 2019.02.24
Level 17 → Level 18  (0) 2019.02.24
Level 15 → Level 16  (0) 2019.02.20
Level 14 → Level 15  (0) 2019.02.20
Level 13 → Level 14  (0) 2019.02.20