SlideShare a Scribd company logo
SSH Tunneling Recipes


      Developer Toolbox Series
         Rafael Luque, OSOCO
Contents


1   SSH tunneling & common uses

2   Local port forwarding

3   Remote port forwarding

4   Dynamic port forwarding

5   X forwarding

6   Some useful tools
Protocol tunneling


One network protocol —the delivery
protocol— encapsulates a different
payload protocol.
                        — Wikipedia
SSH tunneling


A secure shell (SSH) tunnel consists of
an encrypted tunnel created through a
SSH protocol connection.
                          — Wikipedia
Common uses



 To securely connect to a remote host and
    have your network traffic encrypted
Common uses



 To securely connect to a remote host and
    have your network traffic encrypted

 • You are on a public, non secure, non trusted or unencrypted
   network.
 • You use an insecure protocol like POP3, IMAP, SMTP, FTP,
   telnet, etc.
Common uses




 To bypass local network restrictions and
          monitoring services
Common uses




    Internet censorship circumvention
Map of cyber-censorship
Common uses




   Open backdoors to allow outbound
  connections to hosts behind a firewall
Common uses




          X11 forwarding
Common uses




  Access services bound to the loopback
                interface
Contents


1   SSH tunneling & common uses

2   Local port forwarding

3   Remote port forwarding

4   Dynamic port forwarding

5   X forwarding

6   Some useful tools
Local port forwarding



   Local port forwarding (aka outgoing
tunneling) forwards traffic coming to a local
      port to a specified remote port
Local port forwarding

    Recipe #1: Access a remote service behind a firewall




    ssh -fN -L <localport>:localhost:<remoteport> user@external




The service is available on the loopback interface only.
Local port forwarding

    Recipe #1: Access a remote service behind a firewall




    ssh -fN -L <localport>:localhost:<remoteport> user@external




The service is available on the loopback interface only.
Local port forwarding

    Recipe #1: Access a remote service behind a firewall




    ssh -fN -L <localport>:localhost:<remoteport> user@external




The service is available on the loopback interface only.
Local port forwarding

Recipe #2: Access a remote service from any host behind the
                        firewall




     ssh -fN -L 0.0.0.0:<localport>:localhost:<remoteport> user@external

or
     ssh -fN -g -L <localport>:localhost:<remoteport> user@external
Local port forwarding

Recipe #2: Access a remote service from any host behind the
                        firewall




     ssh -fN -L 0.0.0.0:<localport>:localhost:<remoteport> user@external

or
     ssh -fN -g -L <localport>:localhost:<remoteport> user@external
Local port forwarding

   Recipe #3: Access a remote service visible from the ssh
                          server




    ssh -fN -L <localport>:external2:<remoteport> user@external




The service is available on the loopback interface only.
Local port forwarding

   Recipe #3: Access a remote service visible from the ssh
                          server




    ssh -fN -L <localport>:external2:<remoteport> user@external




The service is available on the loopback interface only.
Local port forwarding

   Recipe #3: Access a remote service visible from the ssh
                          server




    ssh -fN -L <localport>:external2:<remoteport> user@external




The service is available on the loopback interface only.
Local port forwarding

     Recipe #4: Access a remote service visible from the ssh
             server for any host behind the firewall




     ssh -fN -L 0.0.0.0:<localport>:external2:<remoteport> user@external

or
     ssh -fN -g -L <localport>:external2:<remoteport> user@external
Local port forwarding

     Recipe #4: Access a remote service visible from the ssh
             server for any host behind the firewall




     ssh -fN -L 0.0.0.0:<localport>:external2:<remoteport> user@external

or
     ssh -fN -g -L <localport>:external2:<remoteport> user@external
Contents


1   SSH tunneling & common uses

2   Local port forwarding

3   Remote port forwarding

4   Dynamic port forwarding

5   X forwarding

6   Some useful tools
Remote port forwarding



Remote port forwarding (aka incoming
tunneling) forwards traffic coming to a
 remote port to a specified local port
Remote port forwarding

 Recipe #5: Access a service behind a firewall from the ssh
                          server




    ssh -fN -R <remoteport>:localhost:<localport> user@external



The service is available on the loopback interface only.
Remote port forwarding

 Recipe #5: Access a service behind a firewall from the ssh
                          server




    ssh -fN -R <remoteport>:localhost:<localport> user@external



The service is available on the loopback interface only.
Remote port forwarding

 Recipe #5: Access a service behind a firewall from the ssh
                          server




    ssh -fN -R <remoteport>:localhost:<localport> user@external



The service is available on the loopback interface only.
Remote port forwarding

   Recipe #6: Access a service behind a firewall from any
          external host with access to the ssh server




     ssh -fN -R 0.0.0.0:<remoteport>:localhost:<localport> user@external


Edit /etc/ssh/sshd_config at ssh server to allow the client to select the address to which
the forwarding is bound:
     GatewayPorts clientspecified
Remote port forwarding

   Recipe #6: Access a service behind a firewall from any
          external host with access to the ssh server




     ssh -fN -R 0.0.0.0:<remoteport>:localhost:<localport> user@external


Edit /etc/ssh/sshd_config at ssh server to allow the client to select the address to which
the forwarding is bound:
     GatewayPorts clientspecified
Remote port forwarding

  Recipe #7: Access a service in a host accesible by the ssh
                client from the ssh server




    ssh -fN -R <remoteport>:internal2:<localport> user@external



The service is available on the loopback interface only.
Remote port forwarding

  Recipe #7: Access a service in a host accesible by the ssh
                client from the ssh server




    ssh -fN -R <remoteport>:internal2:<localport> user@external



The service is available on the loopback interface only.
Remote port forwarding

  Recipe #7: Access a service in a host accesible by the ssh
                client from the ssh server




    ssh -fN -R <remoteport>:internal2:<localport> user@external



The service is available on the loopback interface only.
Remote port forwarding

  Recipe #8: Access a service in a host accesible by the ssh
      client from any host with access to the ssh server




     ssh -fN -R 0.0.0.0:<remoteport>:internal2:<localport> user@external


Edit /etc/ssh/sshd_config at server to allow the client to select the address to which the
forwarding is bound:
     GatewayPorts clientspecified
Remote port forwarding

  Recipe #8: Access a service in a host accesible by the ssh
      client from any host with access to the ssh server




     ssh -fN -R 0.0.0.0:<remoteport>:internal2:<localport> user@external


Edit /etc/ssh/sshd_config at server to allow the client to select the address to which the
forwarding is bound:
     GatewayPorts clientspecified
Contents


1   SSH tunneling & common uses

2   Local port forwarding

3   Remote port forwarding

4   Dynamic port forwarding

5   X forwarding

6   Some useful tools
SOCKS


SOCKS is an Internet protocol that
routes network packets between a
client and server through a proxy
server
                           — Wikipedia
SSH dynamic port forwarding


 •   SSH dynamic port forwarding allows the user to
     create a local SOCKS proxy.
 •   Free the user from the limitations of connecting
     only to a predefined remote port and server.
 •   Circumvention tool allowing to bypass Internet
     filtering to access content otherwise blocked by
     governments, workplaces and schools.
Dynamic port forwarding with SOCKS

              Recipe #9: Setup a SOCKS proxy




    ssh -fN -D <proxyport> user@sshserver

To allow any internal host to use the proxy:
    ssh -fN -D 0.0.0.0:<proxyport> user@sshserver
Dynamic port forwarding with SOCKS

              Recipe #9: Setup a SOCKS proxy




    ssh -fN -D <proxyport> user@sshserver

To allow any internal host to use the proxy:
    ssh -fN -D 0.0.0.0:<proxyport> user@sshserver
Contents


1   SSH tunneling & common uses

2   Local port forwarding

3   Remote port forwarding

4   Dynamic port forwarding

5   X forwarding

6   Some useful tools
X forwarding
 • Using X, you can run remote X applications that open their
   windows on your local display.
 • The X protocol is insecure and wide open to snoopers.
 • SSH X forwarding makes the communication secure by tunneling
   the X protocol:

  ssh -X user@server xclock
Contents


1   SSH tunneling & common uses

2   Local port forwarding

3   Remote port forwarding

4   Dynamic port forwarding

5   X forwarding

6   Some useful tools
autossh

autossh is a program to start a copy of ssh and
monitor it, restarting it as necessary should it die or
stop passing traffic.


    autossh -M <port>[:echo_port] [-f] [SSH OPTIONS]
sslh


sslh makes it possible to connect to an SSH server or
an OpenVPN on port 443 while still serving HTTPS
on that port.
Port knocking


port knocking is a method of externally opening ports on
a firewall by generating a connection attempt on a set of
prespecified closed ports. Once a correct sequence of
connection attempts is received, the firewall rules are
dynamically modified to allow the host which sent the
connection attempts to connect over specific port(s).
                                            — Wikipedia
Port knocking


        (A) client cannot connect to
        application listening on port n
        (B) client cannot establish connection
        to any port
Port knocking


        (1,2,3,4) client connects to a
        well-defined set of ports in a sequence
        that contains an encrypted message
        by sending SYN packets; client has a
        priori knowledge of the port knocking
        daemon and its configuration, but
        receives no acknowledgement during
        this phase because firewall rules
        preclude any response
Port knocking


        (A) server process (a port knocking
        daemon) intercepts connection
        attempts and interprets (decrypts and
        decodes) them as comprising an
        authentic "port knock"; server carries
        out specific task based on content of
        port knock, such as opening port n to
        client
Port knocking


        (A) client connects to port n and
        authenticates using applications
        regular mechanism
knockd


knockd is a port-knock server. It listens to all traffic on
an ethernet interface, looking for special "knock"
sequences of port-hits.
References



 • SSH: The Secure Shell:
   http://docstore.mik.ua/orelly/networking_2ndEd/ssh/index.htm

 • autossh:
   http://www.harding.motd.ca/autossh/

 • sslh:
   http://www.rutschle.net/tech/sslh.shtml

 • Port knocking:
   http://www.portknocking.org/

 • knockd:
   http://www.zeroflux.org/projects/knock
Picture credits




  • Cover photo by twicepix:
    http://www.flickr.com/photos/twicepix/2825051329/

  • The map of the cyber-censorship by Reporters Without Borders:
    http://march12.rsf.org/en/
This work is licensed under a Creative Commons
Attribution-NonCommercial-ShareAlike 3.0 Unported License.
SSH Tunneling Recipes
Developer Toolbox Series




OSOCO
Rafael Luque

More Related Content

PDF
SSH Tunneling Recipes
PPTX
Ssh tunnel
PPT
Ssh
KEY
Intro to SSH
PDF
Nessus scan report using the defualt scan policy - Tareq Hanaysha
PPTX
TELNET and SSH by MUSTAFA SAKHAI
PDF
An introduction to SSH
ODP
September Ethereum Berlin Workshop
SSH Tunneling Recipes
Ssh tunnel
Ssh
Intro to SSH
Nessus scan report using the defualt scan policy - Tareq Hanaysha
TELNET and SSH by MUSTAFA SAKHAI
An introduction to SSH
September Ethereum Berlin Workshop

What's hot (20)

PPTX
Secure Shell(ssh)
PDF
SSH - Secure Shell
PPT
Secure shell protocol
PDF
openssh portforwarding and linux firewall
PDF
Meeting 5.2 : ssh
PDF
Network telnet ssh
PPTX
14 network tools
PPTX
Telnet & SSH Configuration
PPT
Module 3 Scanning
PPT
Introduction to SSH
PDF
Using Secure Shell on Linux: What Everyone Should Know
PPTX
Secure shell
PPTX
Secure SHell
PPT
Ssh And Rlogin
PPT
Secure shell ppt
PPT
Bh usa-01-kaminsky
PPTX
Port forwarding
PPTX
Port forward
ODP
SSH Tunnel-Fu [NoVaH 2011]
PPT
Chapter10ccna
Secure Shell(ssh)
SSH - Secure Shell
Secure shell protocol
openssh portforwarding and linux firewall
Meeting 5.2 : ssh
Network telnet ssh
14 network tools
Telnet & SSH Configuration
Module 3 Scanning
Introduction to SSH
Using Secure Shell on Linux: What Everyone Should Know
Secure shell
Secure SHell
Ssh And Rlogin
Secure shell ppt
Bh usa-01-kaminsky
Port forwarding
Port forward
SSH Tunnel-Fu [NoVaH 2011]
Chapter10ccna
Ad

Viewers also liked (17)

PDF
Sive Formazione - corsi formazione 2012
PDF
Understanding Java Dynamic Proxies
PDF
Brunello imprese a caccia d'innovazione
PDF
Il successo nella trattativa per gli acquisti: con il Neuromarketing
PDF
Catalogo alta formazione
PDF
Catalogo corsi Sive Formazione 2012
PDF
XSS Countermeasures in Grails
PDF
Corso Rspp - Responsabili del servizio prevenzione e protezione
PDF
Corso Lean Office
PPTX
Cognitivism team6
PDF
Corsi Sive Formazione 2011: corsi di formazione a Venezia
PDF
LUMINARY magazine Dec15
PDF
Grails vs XSS: Defending Grails against XSS attacks
PDF
Catalogo Corsi Sive Formazione 2013
PDF
Trattativa acquisti
PPTX
Cara membuat telepon kaleng
Sive Formazione - corsi formazione 2012
Understanding Java Dynamic Proxies
Brunello imprese a caccia d'innovazione
Il successo nella trattativa per gli acquisti: con il Neuromarketing
Catalogo alta formazione
Catalogo corsi Sive Formazione 2012
XSS Countermeasures in Grails
Corso Rspp - Responsabili del servizio prevenzione e protezione
Corso Lean Office
Cognitivism team6
Corsi Sive Formazione 2011: corsi di formazione a Venezia
LUMINARY magazine Dec15
Grails vs XSS: Defending Grails against XSS attacks
Catalogo Corsi Sive Formazione 2013
Trattativa acquisti
Cara membuat telepon kaleng
Ad

Similar to SSH Tunneling Recipes (20)

PDF
Up and Running SSH Service - Part 2
PDF
Advanced open ssh
PPTX
SSH Tunneling
PDF
tutorial-ssh.pdf
PDF
Building Security Acсess to Remote Devices
PDF
Unit 13 network client
ODP
Nagios Conference 2013 - Leland Lammert - Nagios in a Multi-Platform Enviornment
PPT
Remote1
PDF
Ssh cookbook
PDF
Ssh cookbook v2
PDF
Defeating The Network Security Infrastructure V1.0
PDF
FreeBSD, ipfw and OpenVPN 2.1 server
PDF
Windowshadoop
PDF
OpenSSH: keep your secrets safe
PDF
OpenShift v3 Internal networking details
ODP
HAProxy scale out using open source
PDF
Enabling and configuring SSH Access on linux system
PPTX
Remote Accesserver, Introduction(Part1).pptx
PDF
OpenSSH tricks
PDF
How to install Setup & Configure SSH Jump Server on a Linux box
Up and Running SSH Service - Part 2
Advanced open ssh
SSH Tunneling
tutorial-ssh.pdf
Building Security Acсess to Remote Devices
Unit 13 network client
Nagios Conference 2013 - Leland Lammert - Nagios in a Multi-Platform Enviornment
Remote1
Ssh cookbook
Ssh cookbook v2
Defeating The Network Security Infrastructure V1.0
FreeBSD, ipfw and OpenVPN 2.1 server
Windowshadoop
OpenSSH: keep your secrets safe
OpenShift v3 Internal networking details
HAProxy scale out using open source
Enabling and configuring SSH Access on linux system
Remote Accesserver, Introduction(Part1).pptx
OpenSSH tricks
How to install Setup & Configure SSH Jump Server on a Linux box

Recently uploaded (20)

PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
project resource management chapter-09.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
August Patch Tuesday
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Programs and apps: productivity, graphics, security and other tools
SOPHOS-XG Firewall Administrator PPT.pptx
project resource management chapter-09.pdf
cloud_computing_Infrastucture_as_cloud_p
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Web App vs Mobile App What Should You Build First.pdf
A comparative analysis of optical character recognition models for extracting...
1 - Historical Antecedents, Social Consideration.pdf
Unlocking AI with Model Context Protocol (MCP)
gpt5_lecture_notes_comprehensive_20250812015547.pdf
NewMind AI Weekly Chronicles - August'25-Week II
OMC Textile Division Presentation 2021.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
August Patch Tuesday
MIND Revenue Release Quarter 2 2025 Press Release
DP Operators-handbook-extract for the Mautical Institute
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Chapter 5: Probability Theory and Statistics
Getting Started with Data Integration: FME Form 101
Programs and apps: productivity, graphics, security and other tools

SSH Tunneling Recipes

  • 1. SSH Tunneling Recipes Developer Toolbox Series Rafael Luque, OSOCO
  • 2. Contents 1 SSH tunneling & common uses 2 Local port forwarding 3 Remote port forwarding 4 Dynamic port forwarding 5 X forwarding 6 Some useful tools
  • 3. Protocol tunneling One network protocol —the delivery protocol— encapsulates a different payload protocol. — Wikipedia
  • 4. SSH tunneling A secure shell (SSH) tunnel consists of an encrypted tunnel created through a SSH protocol connection. — Wikipedia
  • 5. Common uses To securely connect to a remote host and have your network traffic encrypted
  • 6. Common uses To securely connect to a remote host and have your network traffic encrypted • You are on a public, non secure, non trusted or unencrypted network. • You use an insecure protocol like POP3, IMAP, SMTP, FTP, telnet, etc.
  • 7. Common uses To bypass local network restrictions and monitoring services
  • 8. Common uses Internet censorship circumvention
  • 10. Common uses Open backdoors to allow outbound connections to hosts behind a firewall
  • 11. Common uses X11 forwarding
  • 12. Common uses Access services bound to the loopback interface
  • 13. Contents 1 SSH tunneling & common uses 2 Local port forwarding 3 Remote port forwarding 4 Dynamic port forwarding 5 X forwarding 6 Some useful tools
  • 14. Local port forwarding Local port forwarding (aka outgoing tunneling) forwards traffic coming to a local port to a specified remote port
  • 15. Local port forwarding Recipe #1: Access a remote service behind a firewall ssh -fN -L <localport>:localhost:<remoteport> user@external The service is available on the loopback interface only.
  • 16. Local port forwarding Recipe #1: Access a remote service behind a firewall ssh -fN -L <localport>:localhost:<remoteport> user@external The service is available on the loopback interface only.
  • 17. Local port forwarding Recipe #1: Access a remote service behind a firewall ssh -fN -L <localport>:localhost:<remoteport> user@external The service is available on the loopback interface only.
  • 18. Local port forwarding Recipe #2: Access a remote service from any host behind the firewall ssh -fN -L 0.0.0.0:<localport>:localhost:<remoteport> user@external or ssh -fN -g -L <localport>:localhost:<remoteport> user@external
  • 19. Local port forwarding Recipe #2: Access a remote service from any host behind the firewall ssh -fN -L 0.0.0.0:<localport>:localhost:<remoteport> user@external or ssh -fN -g -L <localport>:localhost:<remoteport> user@external
  • 20. Local port forwarding Recipe #3: Access a remote service visible from the ssh server ssh -fN -L <localport>:external2:<remoteport> user@external The service is available on the loopback interface only.
  • 21. Local port forwarding Recipe #3: Access a remote service visible from the ssh server ssh -fN -L <localport>:external2:<remoteport> user@external The service is available on the loopback interface only.
  • 22. Local port forwarding Recipe #3: Access a remote service visible from the ssh server ssh -fN -L <localport>:external2:<remoteport> user@external The service is available on the loopback interface only.
  • 23. Local port forwarding Recipe #4: Access a remote service visible from the ssh server for any host behind the firewall ssh -fN -L 0.0.0.0:<localport>:external2:<remoteport> user@external or ssh -fN -g -L <localport>:external2:<remoteport> user@external
  • 24. Local port forwarding Recipe #4: Access a remote service visible from the ssh server for any host behind the firewall ssh -fN -L 0.0.0.0:<localport>:external2:<remoteport> user@external or ssh -fN -g -L <localport>:external2:<remoteport> user@external
  • 25. Contents 1 SSH tunneling & common uses 2 Local port forwarding 3 Remote port forwarding 4 Dynamic port forwarding 5 X forwarding 6 Some useful tools
  • 26. Remote port forwarding Remote port forwarding (aka incoming tunneling) forwards traffic coming to a remote port to a specified local port
  • 27. Remote port forwarding Recipe #5: Access a service behind a firewall from the ssh server ssh -fN -R <remoteport>:localhost:<localport> user@external The service is available on the loopback interface only.
  • 28. Remote port forwarding Recipe #5: Access a service behind a firewall from the ssh server ssh -fN -R <remoteport>:localhost:<localport> user@external The service is available on the loopback interface only.
  • 29. Remote port forwarding Recipe #5: Access a service behind a firewall from the ssh server ssh -fN -R <remoteport>:localhost:<localport> user@external The service is available on the loopback interface only.
  • 30. Remote port forwarding Recipe #6: Access a service behind a firewall from any external host with access to the ssh server ssh -fN -R 0.0.0.0:<remoteport>:localhost:<localport> user@external Edit /etc/ssh/sshd_config at ssh server to allow the client to select the address to which the forwarding is bound: GatewayPorts clientspecified
  • 31. Remote port forwarding Recipe #6: Access a service behind a firewall from any external host with access to the ssh server ssh -fN -R 0.0.0.0:<remoteport>:localhost:<localport> user@external Edit /etc/ssh/sshd_config at ssh server to allow the client to select the address to which the forwarding is bound: GatewayPorts clientspecified
  • 32. Remote port forwarding Recipe #7: Access a service in a host accesible by the ssh client from the ssh server ssh -fN -R <remoteport>:internal2:<localport> user@external The service is available on the loopback interface only.
  • 33. Remote port forwarding Recipe #7: Access a service in a host accesible by the ssh client from the ssh server ssh -fN -R <remoteport>:internal2:<localport> user@external The service is available on the loopback interface only.
  • 34. Remote port forwarding Recipe #7: Access a service in a host accesible by the ssh client from the ssh server ssh -fN -R <remoteport>:internal2:<localport> user@external The service is available on the loopback interface only.
  • 35. Remote port forwarding Recipe #8: Access a service in a host accesible by the ssh client from any host with access to the ssh server ssh -fN -R 0.0.0.0:<remoteport>:internal2:<localport> user@external Edit /etc/ssh/sshd_config at server to allow the client to select the address to which the forwarding is bound: GatewayPorts clientspecified
  • 36. Remote port forwarding Recipe #8: Access a service in a host accesible by the ssh client from any host with access to the ssh server ssh -fN -R 0.0.0.0:<remoteport>:internal2:<localport> user@external Edit /etc/ssh/sshd_config at server to allow the client to select the address to which the forwarding is bound: GatewayPorts clientspecified
  • 37. Contents 1 SSH tunneling & common uses 2 Local port forwarding 3 Remote port forwarding 4 Dynamic port forwarding 5 X forwarding 6 Some useful tools
  • 38. SOCKS SOCKS is an Internet protocol that routes network packets between a client and server through a proxy server — Wikipedia
  • 39. SSH dynamic port forwarding • SSH dynamic port forwarding allows the user to create a local SOCKS proxy. • Free the user from the limitations of connecting only to a predefined remote port and server. • Circumvention tool allowing to bypass Internet filtering to access content otherwise blocked by governments, workplaces and schools.
  • 40. Dynamic port forwarding with SOCKS Recipe #9: Setup a SOCKS proxy ssh -fN -D <proxyport> user@sshserver To allow any internal host to use the proxy: ssh -fN -D 0.0.0.0:<proxyport> user@sshserver
  • 41. Dynamic port forwarding with SOCKS Recipe #9: Setup a SOCKS proxy ssh -fN -D <proxyport> user@sshserver To allow any internal host to use the proxy: ssh -fN -D 0.0.0.0:<proxyport> user@sshserver
  • 42. Contents 1 SSH tunneling & common uses 2 Local port forwarding 3 Remote port forwarding 4 Dynamic port forwarding 5 X forwarding 6 Some useful tools
  • 43. X forwarding • Using X, you can run remote X applications that open their windows on your local display. • The X protocol is insecure and wide open to snoopers. • SSH X forwarding makes the communication secure by tunneling the X protocol: ssh -X user@server xclock
  • 44. Contents 1 SSH tunneling & common uses 2 Local port forwarding 3 Remote port forwarding 4 Dynamic port forwarding 5 X forwarding 6 Some useful tools
  • 45. autossh autossh is a program to start a copy of ssh and monitor it, restarting it as necessary should it die or stop passing traffic. autossh -M <port>[:echo_port] [-f] [SSH OPTIONS]
  • 46. sslh sslh makes it possible to connect to an SSH server or an OpenVPN on port 443 while still serving HTTPS on that port.
  • 47. Port knocking port knocking is a method of externally opening ports on a firewall by generating a connection attempt on a set of prespecified closed ports. Once a correct sequence of connection attempts is received, the firewall rules are dynamically modified to allow the host which sent the connection attempts to connect over specific port(s). — Wikipedia
  • 48. Port knocking (A) client cannot connect to application listening on port n (B) client cannot establish connection to any port
  • 49. Port knocking (1,2,3,4) client connects to a well-defined set of ports in a sequence that contains an encrypted message by sending SYN packets; client has a priori knowledge of the port knocking daemon and its configuration, but receives no acknowledgement during this phase because firewall rules preclude any response
  • 50. Port knocking (A) server process (a port knocking daemon) intercepts connection attempts and interprets (decrypts and decodes) them as comprising an authentic "port knock"; server carries out specific task based on content of port knock, such as opening port n to client
  • 51. Port knocking (A) client connects to port n and authenticates using applications regular mechanism
  • 52. knockd knockd is a port-knock server. It listens to all traffic on an ethernet interface, looking for special "knock" sequences of port-hits.
  • 53. References • SSH: The Secure Shell: http://docstore.mik.ua/orelly/networking_2ndEd/ssh/index.htm • autossh: http://www.harding.motd.ca/autossh/ • sslh: http://www.rutschle.net/tech/sslh.shtml • Port knocking: http://www.portknocking.org/ • knockd: http://www.zeroflux.org/projects/knock
  • 54. Picture credits • Cover photo by twicepix: http://www.flickr.com/photos/twicepix/2825051329/ • The map of the cyber-censorship by Reporters Without Borders: http://march12.rsf.org/en/
  • 55. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • 56. SSH Tunneling Recipes Developer Toolbox Series OSOCO Rafael Luque