How to Use a Hosts Ip on a Docker Container?

I am running a metasploitable2 docker container on a server. Here is the docker command to create this docker container:

docker run --name victumb-it tleemcjr/metasploitable2:latest sh -c "/bin/services.sh && bash" --security-opt apparmor=unconfined -privileged true --network host

I then ran an exploit on Kali linux container on a different server targeting the docker image, however it failed.

use exploit/unix/ftp/vsftpd_234_backdoor
msf5 exploit(unix/ftp/vsftpd_234_backdoor) > set RHOST 134.122.105.88
RHOST => 134.122.105.88
msf5 exploit(unix/ftp/vsftpd_234_backdoor) > run

[-] 134.122.105.88:21 - Exploit failed [unreachable]: Rex::ConnectionTimeout The connection timed out (134.122.105.88:21).

I am confused as to why this exploit failed. Due to the --network host i thought that the traffic would be mirrored into the container. Is their anyway to fix this networking error, so that the hack is successful?

Here is the tutorial I was loosely following:

1 Answer

Because the option --network host should be placed before the image

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

This should work:

docker run --name victumb-it --network host --security-opt apparmor=unconfined --privileged tleemcjr/metasploitable2:latest sh -c "/bin/services.sh && bash"

Here sh is the command, and everything after that is arguments passed to sh command.

The docker run options like --network, --security-opt and --privileged are placed before the image.


If you run docker inspect container_id you'll see at the Args key the arguments passed to the command. It means they are not arguments to docker run.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest