Everything is hacked.

There is no 100 % security.

Tools/Docker

Docker Install

Kai_HT 2023. 12. 18. 14:01

https://subicura.com/generated/assets/article_images/2017-01-19-docker-guide-for-beginners-1/docker-logo-800-b3c79c1cb.png

CVE 실습을 위해 개인 웹 서버만으론 한계가 존재하는 것으로 판단하여 도커환경을 구축해 펜테스트 환경 구성을 하며 도커 설치 방법 및 세팅한 것을 정리하고자 하여 작성하게 되었다.

설치 환경 : Ubuntu 22.04.2 LTS Version. (GNU/Linux 5.15.0-86-generic x86_64)


1. 도커 설치 전 리눅스 업데이트 실시.

kai_ht@localhost:~$ sudo apt-get update

[sudo] password for kai_ht:
Hit:1 http://kr.archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://kr.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Hit:3 http://kr.archive.ubuntu.com/ubuntu jammy-backports InRelease
Get:4 http://kr.archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Fetched 229 kB in 5s (48.5 kB/s)
Reading package lists... Done

2. 도커에서 사용될 인증서 설치 
→ 본인은 이미 botcert 를 사용하고 있어 해당 버전에 대한 업데이트를 실시하지 않았다.

kai_ht@localhost:~$ sudo apt-get install ca-certificated curl gnupg

Setting up apache2 (2.4.52-1ubuntu4.7) ...

Configuration file '/etc/apache2/apache2.conf'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** apache2.conf (Y/I/N/O/D/Z) [default=N] ? n
Installing new version of config file /etc/apache2/apache2.conf ...

Configuration file '/etc/apache2/conf-available/security.conf'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** security.conf (Y/I/N/O/D/Z) [default=N] ? n
Installing new version of config file /etc/apache2/conf-available/security.conf ...

Configuration file '/etc/apache2/mods-available/dir.conf'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** dir.conf (Y/I/N/O/D/Z) [default=N] ?

Configuration file '/etc/apache2/mods-available/mime.conf'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** mime.conf (Y/I/N/O/D/Z) [default=N] ? n

Configuration file '/etc/apache2/sites-available/000-default.conf'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** 000-default.conf (Y/I/N/O/D/Z) [default=N] ? n

3. Keyring 파일 설치

kai_ht@localhost:~$ sudo install -m 0755 -d /etc/apt/keyrings
kai_ht@localhost:~$

4. Ubuntu 버전 도커 다운로드

kai_ht@localhost:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
kai_ht@localhost:~$

5. 도커 키링 파일, 권한 설정

kai_ht@localhost:~$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
kai_ht@localhost:~$

6. 레포지토리 내 APT 소스 설정

kai_ht@localhost:~$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
kai_ht@localhost:~$

7. 리눅스 apt 업데이트를 통한 세팅 마무리

kai_ht@localhost:~$ sudo apt-get update
Get:1 https://download.docker.com/linux/ubuntu jammy InRelease [48.8 kB]
Hit:2 http://kr.archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://kr.archive.ubuntu.com/ubuntu jammy-updates InRelease
Get:4 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [23.0 kB]
Hit:5 http://kr.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:6 http://kr.archive.ubuntu.com/ubuntu jammy-security InRelease
Fetched 71.8 kB in 5s (14.6 kB/s)
Reading package lists... Done
kai_ht@localhost:~$

8. 도커 설치

kai_ht@localhost:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

kai_ht@localhost:~$

9. 도커 설치유무 확인을 위한 hello-world 도커 이미지 실행

kai_ht@localhost:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

kai_ht@localhost:~$

10. 시스템 내 도커 유저그룹 생성 확인

kai_ht@localhost:~$ cat /etc/group | grep docker
docker:x:999:
kai_ht@localhost:~$

11. 일반 사용자에 대한 도커 사용권한 추가 (본인 계정 - kai_ht)

kai_ht@localhost:~$ sudo usermod -a -G docker kai_ht
kai_ht@localhost:~$

참고 :