SSH
Last updated
Was this helpful?
Last updated
Was this helpful?
-L
always attaches the tunnel to a port from the box that the command is run.
Example:
Authenticate to host1, giving you access to host1's ports.
Create tunnel to host1's port 22 from the attacker port 12345.
Create dynamic tunnel to .21.1's port 22.
Set local port 11111 to tunnel to .1.2's port 22
Make the local port 11111 a dynamic tunnel to port 22 on the .1.2 (The internal side)
Using the dynamic tunnel in local port 11111, reach through the .1.2 to reach the next hop, .1.99's port 22.
Make local port 22222 a dynamic port and authenticate to 1.99's port 22. From here you can keep going.
Firewall is blocking port 22 on the First Hop. Telnet is open. Use that to gain access, then ssh back to the Attack Box.
1a. From the First Hop TELNET session, setup a Reverse tunnel to the attackers port 11111 that reaches back to First Hop's port 22.
This reverse tunnel is reaching through the firewall back to the attacker, opening a tunnel to the First Hop's port 22.
This tunnel is connected to First Hop's port 22 but an SSH session has not yet been created.
Authenticate and connect to the local port 11111 which is connected to port 22 on First Hop.
Creates a dynamic tunnel through the firewall to port 22 on First Hop.
Use dynamic tunnel on local port 11111 to reach through the First Hop and reach Second Hop's port 22. Attach that tunnel to local port 22222.
Make local port 22222 tunnel dynamic and create SSH session to Second Hop.
Use local port 22222 tunnel to reach Third Hop's port 22. Attach that tunnel to port 33333.
Make local port 33333 tunnel dynamic and create SSH session to Third Hop.
Create tunnel and SSH session to First Hop's port 22.
Create tunnel from attackers localport 11111 through First Hop's port 22 to Second Hop's port 23 (TELNET).
Telnet to Second Hop's port 23 through the tunnel on local 11111.
3a. From Telnet Session on Second Hop, create an SSH session back to the First Hop's SSH port and attach a reverse tunnel to First Hop's port 22222 that connects to Second Hop's port 22.
Create a tunnel from Attacker's port 33333 that connects to First Hop's port 22222, which is connected to Second Hop's port 22.
Using local port 33333, create a dynamic tunnel and SSH session to Second Hop's port 22.
Using local port 33333, create a local tunnel to Third Hop's port 22 and attach it to local port 44444.
Using local port 44444, create a dynamic tunnel and SSH session to Third Hop's port 22.
SSH dynamic tunnel to First Hop's port 22.
Local tunnel from Attacker's local port 11111 through First Hop's port 22 to Second Hop's port 22.
Using local port 11111, create dynamic tunnel and SSH session to Second Hop's port 22.
Using Attacker's local port 11111 create a tunnel to Third Hop's port 23 and attach it to Attacker's local port 22222.
Using Attacker's local port 22222 create TELNET session to Third Hop.
5a. From the TELNET session from the Third Hop, create a reverse tunnel that connects Second Hop's port 33333 to Third Hop's port 22.
From Attacker's local port 11111 (which is a tunnel to Second Hop's port 22) create a tunnel to Second Hop's port 33333 (which is the Reverse tunnel that connects to Third Hop's port 22) and attach it to Attacker's local port 44444.
Using Attacker's local port 44444 which is a tunnel all the way through the firewall to Third Hop, create a dynamic tunnel and an SSH session to Third Hop.
When you setup the Dynamic -D
tunnel, it allows you to run proxychains and execute commands from the connected host.
Proxychains explicitly allows TCP and DNS (by allowing DNS, it inherently also allows UDP, since DNS uses both).
This means ping
does not work over proxychains because it uses ICMP.
Proxychains can run local scripts as if they were on the connected computer.
In the above tunneling examples, each time a new hop was accessed, that tunnel was converted to a dynamic tunnel. At that point, you can run any of the following as if it was coming from the connected device:
Generate keys. When prompted for location to save just press enter to leave default, can do the same for password.
After generating ssh key look for public key in your .ssh folder. Your public key will have .pub as the extension
The entire output is your public key, make sure when uploading you copy everything.
Pave the way to upload your key:
Find out what account is running the web sever/commands.
Locate user's home dir in /etc/passwd. Make sure the user has a login shell.
Check home dir for .ssh dir. If it's not there, make it.
Echo ssh key to the authorized_keys file in the users .ssh folder.
Verify key has been uploaded successfully.
Now you can login as whoever's account you planted the key. If prompted for a password something went wrong.
Using SSH Keys:
Bring private key to localhost
On your box:
You can run commands immediately on login using the commands below.
These were used in a challenge to defeat a script in the .bashrc file that immediately logged me out of ssh session.