Skip to content

Instantly share code, notes, and snippets.

@brmzkw
Created November 9, 2020 13:28
Show Gist options
  • Save brmzkw/b08ce9b617bcf1296daf54be3123f3b3 to your computer and use it in GitHub Desktop.
Save brmzkw/b08ce9b617bcf1296daf54be3123f3b3 to your computer and use it in GitHub Desktop.
Reverse shell
Infra:
- laptop
- server
- container where commands can be executed
Steps:
- install and run ssh on the container
apt-get update && apt-get install -y ssh
mkdir /run/sshd
/usr/sbin/sshd
- create an account on server
adduser reverse
su reverse
ssh-keygen
cp /home/reverse/.ssh/id_rsa.pub /home/reverse/.ssh/authorized_keys
chown 644 /home/reverse/.ssh/authorized_keys
- the container needs to be configured to connect to the server
copy /home/reverse/.ssh/id_rsa to the container at /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no -tt -i ~/.ssh/id_rsa -R 9999:localhost:22 reverse@<server ip>
- configure contaienr to accept your key
copy your laptop ~/.ssh/id_rsa.pub and add it to container /root/.ssh/authorized_keys
- connect to the container
ssh <server_ip> -A
ssh -p 9999 root@localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment