002 - Advanced SSH
002 - Advanced SSH
1
SSH and more possibilities
2
SSH authentication
• Logging in we can use:
– Password
– SSH key pair
– Certificates
– MFA (multi-factor auth.)
3
SSH key pairs
• Asymmetric encryption
– Private key remains on your "source" host.
– Public key distributed to all "target" hosts.
• Login uses your private key to encrypt a secret,
– Which the target host verifies with your pubkey.
5
You try!
• Now you can login with the private key!
$ ssh -i ~/.ssh/id_rsa tess@ubuntu
6
Scary stuff!
• SSH can be used to setup port forwards.
– Both forward (outbound, from the source)
– And reverse (inbound, from the target)
– X11 as a special use-case
– SOCKS5 proxy for fun-and-profit
7
SSH port forwarding
• Let's access a web server behind NAT!
8
SSH port forwarding
• On your Fedora VM run:
$ cd ~/Downloads
$ echo "Secrets!" > index.html
$ python3 -m http.server 8000
9
SSH port forwarding
• Let’s lay some pipes!
10
SSH port forwarding
• Defining a port forward with -L:
– <local port>:<target host>:<target port>
• This means:
– SSH to the remote host, then build a forward.
– Traffic will flow through the remote SSH box.
11
SSH port forwarding
• On your host OS run (adjust guest IP):
$ ssh -L 8080:10.0.2.15:8000 tess@fedoravm
12
SSH reverse port forward
• Even scarier…
13
SSH reverse port forwarding
• For example:
– You working at the office, with secret stuff.
– You SSH from work to your home PC.
– You setup a reverse port forward, to the secrets.
– You accessing work secrets, at home.
14
SSH reverse port forwarding
• On your host OS install & run an sshd.
• Find your host OS IP address.
• On the Fedora VM run:
$ ssh -R 8080:10.0.2.15:8000 tess@laptop
15
SOCKS5 proxy
16
SOCKS5 proxy
• On your host OS run:
$ ssh -D 3128 tess@fedoravm
17
X11 tunneling
18
X11 Tunneling
• This requires an X11 server on your host OS.
– XQuartz on Mac,
– XMing or MobaXterm on Windows
• On your host OS run:
$ ssh -Y tess@fedoravm "xclock"
19
The SSH bible: CPH
• Brennon Thomas’ awesome book.
• Free for students.
• Explains all cool SSH options.
21
Setup
• Ensure that you have two Linux VMs.
• And that you have an account on both.
22
Assignment
• Double-check that SSHd runs on both servers.
• Generate a new key pair on one of the accounts.
– Make it type ECDSA, with a password.
– Setup its pub.key for authentication on the other VM.
– Test your SSH key authentication.
23
Assignment
• Start "eval $(ssh-agent)".
• Add / load the private key you generated into the
running "ssh-agent", with the "ssh-add" command.
– This should ask your password once.
• Try SSH-ing to the other VM again.
– This should not ask your password.
24
LAB: Restricted SSH
25
Assignment
• Reconfigure "sshd_config" on one of the VMs,
– So it will only allow group "sshusers" to login.
• Give your own account the new group "sshusers"
• Restart the SSH daemon and test that you can login.
– Also make sure that another user cannot.
26
LAB: SSH as proxy
27
Can you perform:
• An NMap portscan,
– Of your Linux VM,
– From your host OS?
– For example to find your Python httpd on port 8000.
28
Hints
• You will need "proxychains" or "proxychains-ng".
• SOCKS is best suited for TCP connect scans, use "-sT".
• First limit to known-open ports (like 8000).
• A ping will fail, so use "-Pn".
29
Solution
• Let SSH open a SOCKS5 proxy, with "-D 3128"
• Configure proxychains to use:
– socks5 localhost 3128
30
Reference materials
31
Resources
• VirtualBox networking modes
• Stop making shell aliases for SSH!
• Download Putty
• Download WinSCP
• SSH keys for dummies
• Cyber Plumber’s Handbook
32