building automation for metasploit using dockerfiles

  amazon-ec2, dockerfile, metasploit

I have a machine in AWS in ec2, which has a docker server installed.
I want to use the following image: phocean/msf in order to automate metasploit functionality.
for example to first thing i want to do is to scan for ports over a target machine using this exploit: auxiliary/scanner/portscan/tcp in msfconsole.
if you try to run phocean/msf image in a container you will see that it has a script that initializes msfconsole, so if you just run ./msfconsole then it should start running inside the container. so I was trying to build this docker file:

FROM phocean/msf

CMD ./msfconsole

CMD use auxiliary/scanner/portscan/tcp

CMD set RHOSTS "target server ip"

CMD set PORTS 1-10000

CMD run

but it seems to be failing and I don’t understand why. I also tried to use RUN ./msfconsole and ENTRYPOINT ./msfconsole but it doesn’t seem to work either.

This is the output of building this image:

docker build -t scanports:latest .
Sending build context to Docker daemon  8.192kB
Step 1/6 : FROM phocean/msf
 ---> b213be903b78
Step 2/6 : CMD ./msfconsole
 ---> Running in c8d0cf57259e
Removing intermediate container c8d0cf57259e
 ---> 22aad0f5bd1c
Step 3/6 : CMD use auxiliary/scanner/portscan/tcp
 ---> Running in 1a291c909cbd
Removing intermediate container 1a291c909cbd
 ---> 0c2ef3efa07e
Step 4/6 : CMD set RHOSTS {server_ip}
 ---> Running in 21aed86c8da0
Removing intermediate container 21aed86c8da0
 ---> 5b1911c8405b
Step 5/6 : CMD set PORTS 1-10000
 ---> Running in fe2e142738eb
Removing intermediate container fe2e142738eb
 ---> e01fb1d4cc6f
Step 6/6 : CMD run
 ---> Running in ba28db71ead8
Removing intermediate container ba28db71ead8
 ---> 529fec548bc1
Successfully built 529fec548bc1
Successfully tagged scanports:latest

this is the output of container when i try to run it:

docker run --rm scanports
/bin/sh: 1: run: not found

can anybody help?
of course if I do it manually it works just fine. I am just missing something in the dockerfile and i don’t understand what.

Thanks

Source: Dockerfile Questions

LEAVE A COMMENT