3.NetWork
3.NetWork
nmap
bandit13@bandit:~$ nmap -sT localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 06:39 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00034s latency).
Not shown: 994 closed ports
PORT STATE SERVICE
22/tcp open ssh
1111/tcp open lmsocialserver
1840/tcp open netopia-vo2
4321/tcp open rwhois
8000/tcp open http-alt
30000/tcp open ndmps
//
___________________________________________________________________________________
___________________
// Level 13 PWD : wbWdlBxEir4CaE8LaPhauuOo6pwRmrDw
//
___________________________________________________________________________________
___________________
2. ssh
SSH 공개키 접속
//.1 클라이언트 키 쌍 생성
아래 명령어를 이용하여 RSA 알고리즘 키 쌍 생성
$ ssh-keygen -t rsa
별 다른 설정이 필요하지 않으므로, 엔터를 계속 누르면 현재 로그인되어있는 사용자의 홈디렉토리 .ssh 폴더 밑에 키 쌍이 생성 됨
//.2 공개키 전송
리눅스계열에서는 공개키를 복사하는 명령어 ssh-copy-id 를 사용
$ ssh-copy-id USER@remote-host
예) $ ssh-copy-id [email protected]
-i 옵션을 사용하지 않으면, 현재 로그인 되어있는 계정의 .ssh/id_rsa.pub 파일을 전송 (기본값)
공개키 파일이 다른 경로에 있다면 -i 옵션을 이용하여 별도의 경로를 지정해야 함
$ ssh-copy-id -i /home/test/key/key.pub [email protected]
윈도우에서는 ssh 와 cat 을 이용한 명령어 조합을 이용
윈도우: USER_NAME\.ssh\id_rsa
리눅스: USER_NAME/.ssh/id_rsa
만약 개인키의 위치가 다르거나 AWS 의 pem 파일인 경우 -i 옵션 이용
//
___________________________________________________________________________________
___________________
login as: bandit13
Pre-authentication banner message from server:
| _ _ _ _
| | |__ __ _ _ __ __| (_) |_
| | '_ \ / _` | '_ \ / _` | | __|
| | |_) | (_| | | | | (_| | | |_
| |_.__/ \__,_|_| |_|\__,_|_|\__|
|
|
| This is an OverTheWire game server.
| More information on http://www.overthewire.org/wargames
|
End of banner message from server
[email protected]'s password:
Welcome to OverTheWire!
If you find any problems, please report them to the #wargames channel on
discord or IRC.
For your convenience we have installed a few useful tools which you can find
in the following locations:
bandit13@bandit:~$ ls -al
total 24
drwxr-xr-x 2 root root 4096 Apr 23 18:04 .
drwxr-xr-x 70 root root 4096 Apr 23 18:05 ..
-rw-r--r-- 1 root root 220 Jan 6 2022 .bash_logout
-rw-r--r-- 1 root root 3771 Jan 6 2022 .bashrc
-rw-r--r-- 1 root root 807 Jan 6 2022 .profile
-rw-r----- 1 bandit14 bandit13 1679 Apr 23 18:04 sshkey.private
!!! You are trying to log into this SSH server with a password on port 2220 from
localhost.
!!! Connecting from localhost is blocked to conserve resources.
!!! Please log out and log in again.
Welcome to OverTheWire!
If you find any problems, please report them to the #wargames channel on
discord or IRC.
For your convenience we have installed a few useful tools which you can find
in the following locations:
bandit14@bandit:~$ ls -al
total 24
drwxr-xr-x 3 root root 4096 Apr 23 18:04 .
drwxr-xr-x 70 root root 4096 Apr 23 18:05 ..
-rw-r--r-- 1 root root 220 Jan 6 2022 .bash_logout
-rw-r--r-- 1 root root 3771 Jan 6 2022 .bashrc
-rw-r--r-- 1 root root 807 Jan 6 2022 .profile
drwxr-xr-x 2 root root 4096 Apr 23 18:04 .ssh
bandit14@bandit:~$ cd .ssh
bandit14@bandit:~/.ssh$ ls -al
total 12
drwxr-xr-x 2 root root 4096 Apr 23 18:04 .
drwxr-xr-x 3 root root 4096 Apr 23 18:04 ..
-rw-r----- 1 bandit14 bandit14 396 Apr 23 18:04 authorized_keys
bandit14@bandit:~/.ssh$ ls -al authorized_keys
-rw-r----- 1 bandit14 bandit14 396 Apr 23 18:04 authorized_keys
bandit14@bandit:~/.ssh$ cd ~
bandit14@bandit:~$ ls -al
total 24
drwxr-xr-x 3 root root 4096 Apr 23 18:04 .
drwxr-xr-x 70 root root 4096 Apr 23 18:05 ..
-rw-r--r-- 1 root root 220 Jan 6 2022 .bash_logout
-rw-r--r-- 1 root root 3771 Jan 6 2022 .bashrc
-rw-r--r-- 1 root root 807 Jan 6 2022 .profile
drwxr-xr-x 2 root root 4096 Apr 23 18:04 .ssh
bandit14@bandit:~$ nmap localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-18 07:05 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00016s latency).
Not shown: 994 closed ports
PORT STATE SERVICE
22/tcp open ssh
1111/tcp open lmsocialserver
1840/tcp open netopia-vo2
4321/tcp open rwhois
8000/tcp open http-alt
30000/tcp open ndmps --> nc 명령포트 (브로커포트)
//
___________________________________________________________________________________
___________________
3. nc 명령어
Localhost 는 호스트 이름이고 IP 주소는 '127.0.0.1'입니다. 이러한 서비스를 실행하는 동일한 장치에서 네트워크 서비스에 액세스하는
데 사용됩니다.
nc 또는 netcat 네트워크 연결을 통해 데이터를 읽고 쓸 수 있는 명령입니다. TCP 및 UDP 연결에 사용할 수 있습니다. 네트워크의 서비스에
클라이언트로 연결하기 위한 명령 구문은 다음과 같습니다 nc <host> <port>. 들어오는 패킷을 수신하는 서버를 생성하기 위한 명령은 다음과
같습니다 nc -l <port>.
해결책
먼저 bandit14 의 비밀번호를 찾아야 합니다. 이전 레벨에서는 비밀번호가 /etc/bandit_pass/bandit14 에 있다고 명시했습니다 .
1
2
4. chmod 권한변경
rw-r--r-- 로 표시되는 부분이 부여된 권한을 나타내는데 3 개씩 끊어서 보면
앞에 3 개가 user 즉 소유자(owner)의 권한이고,
중간에 3 개는 group 에 대한 권한,
마지막 3 개가 others 에 대한 권한이 됩니다.
SSH authorized_keys 특징
authorized_keys 파일 경로 default path 경로는 각 계정의 ~/.ssh/authorized_keys 에 있음.
만약 인증서를 통한 접속 시도가 없었다면 authorized_keys 파일은 존재하지 않음.
public key 정보
authorized_keys 파일의 각 line 에는 하나의 public key 정보가 포함됨.
SSH 프로토콜 버전 2 의 경우 public key 유형은 ''ssh-dss'' 또는 ''ssh-rsa'' 2 가지가 있음.
public key 정보는 base64 encoding 되어서 저장됨.
authorized_keys 주석 처리
빈 줄과 '#'으로 시작하는 줄은 주석으로 무시됨.
[1] 권한 빼주기
① $ cd ~
② $ chmod 700 .
⇒ 홈 디렉토리의 권한을 700 으로 변경 //Owner 가 아닌 Group 이나 Other 쪽에 쓰기 권한이 있으면 안된다.
③ $ chmod 700 .ssh
④ $ cd .ssh
⑤ $ chmod 600 authorized_keys
이제 재접속해보자...
//
___________________________________________________________________________________
___________________
// Level 14 PWD : fGrHPx402xGC7U7rXKDaxiWFTOiF0ENq
//
___________________________________________________________________________________
___________________
//
___________________________________________________________________________________
___________________
// Level 15 PWD : jN2kgmIXJ6fShzhT2avhotn4Zcka6tnt
//
___________________________________________________________________________________
___________________
참고로 s_client 란
openssl 명령으로 운영중인 웹서버의 SSL 인증서 정보를 살펴 보는 SSL 에 대해 매우 유용한 진단도구이다.
s_client 는 SSL/TLS 를 사용하는 원격 호스트에 접속하기 위한 일반적인 SSL/TLS client 를 구현하는 명령어이다.
서버에 연결하기 위해서는 위에처럼 host 와 port 를 적어야한다.
bandit15@bandit:~$ ls -al
total 24
drwxr-xr-x 2 root root 4096 Apr 23 18:04 .
drwxr-xr-x 70 root root 4096 Apr 23 18:05 ..
-rw-r----- 1 bandit15 bandit15 33 Apr 23 18:04 .bandit14.password
-rw-r--r-- 1 root root 220 Jan 6 2022 .bash_logout
-rw-r--r-- 1 root root 3771 Jan 6 2022 .bashrc
-rw-r--r-- 1 root root 807 Jan 6 2022 .profile
closed
bandit15@bandit:~$
//
___________________________________________________________________________________
___________________
// Level 16 PWD : JQttfApK4SeyHwDlI9SXGR50qclOAil1
//
___________________________________________________________________________________
___________________