SlideShare a Scribd company logo
(mis)Trusting and (ab)Using SSH
          Tips and Tricks for Pentesters and Sysadmins




                                Herman Duarte <hcoduarte@gmail.com>
                                Bruno Morisson <morisson@genhex.org>
Monday, July 2, 12                                                 1
About us
                     Bruno Morisson                        Herman Duarte
                     <morisson@genhex.org>                 <hcoduarte@gmail.com>
                     http://genhex.org/~mori/



         I do security stuff @ INTEGRITY S.A.      InfoSEC addict @ INTEGRITY S.A.




             @morisson                             @hdontwit
             http://www.linkedin.com/in/morisson   http://www.linkedin.com/in/hcoduarte


Monday, July 2, 12                                                                        2
In the beginning of times...

                Telnet
                r* services (rlogin, rsh)
                Weak (or no) authentication
                Communication in clear




Monday, July 2, 12                            3
In the beginning of times...

                Sniffing
                Interception
                Hijacking
                Man-In-The-Middle
                ...




Monday, July 2, 12                       4
Enter the Dragon^WSSH




Monday, July 2, 12                           5
SSH* features
                Key agreement (DH)
                Encrypted communications (C&I from CIA)
                Multiple authentication options (password, public keys,
                kerberos, etc...)
                Channel Multiplexing
                Port Forwarding
                VPN
                ...and so much more!
                                             * for this talk SSH==SSHv2
Monday, July 2, 12                                                        6
Monday, July 2, 12   7
SSH 101- The Basics
                                    Session Multiplexing, TCP forwarding,
                     Connection     socket forwarding, sftp subsystem, etc
      SSH




                     User Auth    User Authentication (password, Pubkey, etc)



                                   Key Agreement (DH), Host auth, Integrity,
                     Transport             Encryption, Re-Keying



                        TCP


                         IP

Monday, July 2, 12                                                              8
SSH 101- The Basics

                              Encrypted Channel Setup


                                User Authentication

                     Client         Connection
                                                        Server




Monday, July 2, 12                                               9
SSH 101- The Basics
           User authentication methods:
                GSSAPI
                Host-Based
                Public Key
                Challenge-Response
                Password




Monday, July 2, 12                        10
Password Authentication

                                Encrypted Channel Setup
                     Client                                  Server
                                  username, use password


                                            OK


                                        Password


                                       Auth Ok / NOk              passwd
                          ssh                              sshd
                                                                    file




Monday, July 2, 12                                                         11
If the server is compromised...


                sshd binary is changed with one that logs passwords
                keylogger is installed on the server


                           ..the password is compromised!




Monday, July 2, 12                                                    12
PublicKey Authentication

                                     Encrypted Channel Setup
                          Client                                   Server
                                       username, use publickey


                                                 OK


                                              Signature


                                            Auth Ok / NOk               authorized
                     id_dsa    ssh                               sshd     _keys




Monday, July 2, 12                                                                   13
DEMO




Monday, July 2, 12          14
What if I have a lot of keys, or login a lot ??




Monday, July 2, 12                                           15
SSH Agent
                                 Encrypted Channel Setup
                      Client                                       Server
                                   username, use publickey


                                             OK


                                          Signature


                                        Auth Ok / NOk
                Agent      ssh                                 sshd



                                                             authorized
                 id_dsa                                        _keys




Monday, July 2, 12                                                          16
What if I SSH into other servers ??




Monday, July 2, 12                                    17
SSH Agent Forwarding

                No need to copy private key to other servers
                Key is kept on the original source host
                Agent is forwarded, using a tunnel
                Passwordless!




Monday, July 2, 12                                             18
SSH Agent Forwarding
             Client           Transport
                                                 Server #1           Transport
                                                                                       Server #2
                              Connection                            Connection

                           Interactive Shell

                           Agent Forwarding
                                                                  Interactive Shell




     Agent           ssh                        sshd        ssh                        sshd



                                               authorized                             authorized
      id_dsa
                                                 _keys                                  _keys




Monday, July 2, 12                                                                                 19
Control Master


                Connection multiplexing allows for multiple sessions on
                one connection
                It’s fast
                No need for extra authentication




Monday, July 2, 12                                                        20
DEMO




Monday, July 2, 12          21
Caveat Emptor(s)

                You must trust the server(s)
                What if the server was compromised ?
                Can SSH Agent be abused ?
                Can Control Master be abused ?




Monday, July 2, 12                                     22
DEMO




Monday, July 2, 12          23
Help us Obi Wan




                     You’re our only hope!
Monday, July 2, 12                           24
Freak on a Leash

              When adding keys to ssh-agent use ssh-add with:


                     -t <secs> to set a maximum lifetime on the identities being
                     added to the agent
                     -c to indicate that identities being added should be subject to
                     confirmation before being used for auth




Monday, July 2, 12                                                                     25
Freak on a Leash


                     ssh-agent queries /usr/libexec/ssh-askpass for
                     confirmation
                     “ssh-add -c -t 3600 < /dev/null” makes ssh-add
                     use env var SSH_ASKPASS to query for passphrase




Monday, July 2, 12                                                     26
DEMO




Monday, July 2, 12          27
But we still need passwords!

                     If you su / sudo, you still type your password...
                     What if we could use the SSH Agent for sudo ?
                                     Yes we can! :)




Monday, July 2, 12                                                       28
DEMO




Monday, July 2, 12          29
Paranoia is reality on a finer scale




Monday, July 2, 12                              30
Monday, July 2, 12   31
Using SSH w/o using SSH
                                      (but still using SSH)



                     ssh -W trusted:22 untrusted


   Open socket to trusted Server...

    ...through an untrusted Server




Monday, July 2, 12                                            32
Using SSH w/o using SSH
                                        (but still using SSH)


                                            Connect to the socket created


   ssh -o “ProxyCommand ssh -a -W trusted:22 untrusted” trusted

             Disable Agent Forwarding

 Open Socket to trusted via untrusted


    Just for user and key validation




Monday, July 2, 12                                                          33
Using SSH w/o using SSH
                                     (but still using SSH)
             Client        Transport
                                          Untrusted
                                            Owned                          Trusted
                           Connection
                                        -W (Open Socket to Server #2)
                                               Transport
                                               Connection
                                             Interactive Shell




     Agent           ssh                      sshd                       sshd



                                            authorized                  authorized
      id_dsa
                                              _keys                       _keys

Monday, July 2, 12                                                                   34
DEMO




Monday, July 2, 12          35
Control your SSH
                .ssh/config

                Host trusted1 trusted2 trusted3
                ForwardAgent yes
                ProxyCommand ssh -a -W %h:22 untrusted.server.com


                Host *
                ControlMaster no
                ForwardAgent no
                PasswordAuthentication no
                HashKnownHosts yes


Monday, July 2, 12                                                  36
Live long and prosper




Monday, July 2, 12                           37
References
                RTFM :)
                RFCs
                4251-4256,4335,4344,4345,4419,4432,4462,4716,56
                56
                http://www.linuxjournal.com/article/9566
                http://pamsshagentauth.sourceforge.net/
                http://www.jedi.be/blog/2010/08/27/ssh-tricks-the-
                usual-and-beyond/


Monday, July 2, 12                                                   38

More Related Content

PPTX
Unsecuring SSH
PPTX
Pwning the Enterprise With PowerShell
PDF
Les attaques MITM
ODP
Expanding Asterisk with Kamailio
PDF
Web Application Firewall Tercih Rehberi
PPTX
Reverse shell
PDF
Nessus Software
PPTX
Metasploit For Beginners
Unsecuring SSH
Pwning the Enterprise With PowerShell
Les attaques MITM
Expanding Asterisk with Kamailio
Web Application Firewall Tercih Rehberi
Reverse shell
Nessus Software
Metasploit For Beginners

What's hot (20)

PPTX
Server hardening
PDF
Hunting for Credentials Dumping in Windows Environment
PPTX
Introduction to Public Key Infrastructure
PDF
CNIT 126: Ch 2 & 3
PDF
Carlos García - Pentesting Active Directory [rooted2018]
PDF
Trust No One - Zero Trust on the Akamai Platform
PDF
Using Kamailio for Scalability and Security
PDF
PHDays 2018 Threat Hunting Hands-On Lab
PPT
Introduction to Web Application Penetration Testing
PDF
Pwning mobile apps without root or jailbreak
PPTX
OWASP Top 10 - Day 1 - A1 injection attacks
PDF
Privilege escalation from 1 to 0 Workshop
PDF
Kamailio - SIP Routing in Lua
PPTX
Threat Hunting with Splunk
PDF
PDF
F5 TLS & SSL Practices
PPTX
(Ab)Using GPOs for Active Directory Pwnage
PDF
Linux Networking Explained
PDF
오픈 소스를 활용한 캐쥬얼 게임 서버 프레임워크 개발
Server hardening
Hunting for Credentials Dumping in Windows Environment
Introduction to Public Key Infrastructure
CNIT 126: Ch 2 & 3
Carlos García - Pentesting Active Directory [rooted2018]
Trust No One - Zero Trust on the Akamai Platform
Using Kamailio for Scalability and Security
PHDays 2018 Threat Hunting Hands-On Lab
Introduction to Web Application Penetration Testing
Pwning mobile apps without root or jailbreak
OWASP Top 10 - Day 1 - A1 injection attacks
Privilege escalation from 1 to 0 Workshop
Kamailio - SIP Routing in Lua
Threat Hunting with Splunk
F5 TLS & SSL Practices
(Ab)Using GPOs for Active Directory Pwnage
Linux Networking Explained
오픈 소스를 활용한 캐쥬얼 게임 서버 프레임워크 개발
Ad

Similar to (Mis)trusting and (ab)using ssh (20)

PDF
Open ssh cheet sheat
PDF
SSH how to 2011
PPTX
Secure SHell
PPT
Presentation nix
PPT
Presentation nix
PPT
Secure shell ppt
PDF
tutorial-ssh.pdf
PDF
An introduction to SSH
PPT
Ssh
PPT
Introduction to SSH
PDF
SSH.pdf
PDF
PPTX
PPTX
Ssh (The Secure Shell)
PDF
OpenSSH: keep your secrets safe
PDF
Windowshadoop
KEY
Intro to SSH
PDF
Dssh @ Confidence, Prague 2010
PDF
Understanding ssh
PDF
sshGate - OSCON 2011
Open ssh cheet sheat
SSH how to 2011
Secure SHell
Presentation nix
Presentation nix
Secure shell ppt
tutorial-ssh.pdf
An introduction to SSH
Ssh
Introduction to SSH
SSH.pdf
Ssh (The Secure Shell)
OpenSSH: keep your secrets safe
Windowshadoop
Intro to SSH
Dssh @ Confidence, Prague 2010
Understanding ssh
sshGate - OSCON 2011
Ad

More from morisson (7)

PDF
Security asap
PDF
Mobile Securty - An Oxymoron?
PDF
PDF
The Thing That Should Not Be
PDF
Honeypot Farms using Ethernet Bridging over a TCP Connection
PPTX
Virtualization & Security
PDF
Crash Course In Brain Surgery
Security asap
Mobile Securty - An Oxymoron?
The Thing That Should Not Be
Honeypot Farms using Ethernet Bridging over a TCP Connection
Virtualization & Security
Crash Course In Brain Surgery

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
KodekX | Application Modernization Development
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
NewMind AI Weekly Chronicles - August'25 Week I
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf

(Mis)trusting and (ab)using ssh

  • 1. (mis)Trusting and (ab)Using SSH Tips and Tricks for Pentesters and Sysadmins Herman Duarte <hcoduarte@gmail.com> Bruno Morisson <morisson@genhex.org> Monday, July 2, 12 1
  • 2. About us Bruno Morisson Herman Duarte <morisson@genhex.org> <hcoduarte@gmail.com> http://genhex.org/~mori/ I do security stuff @ INTEGRITY S.A. InfoSEC addict @ INTEGRITY S.A. @morisson @hdontwit http://www.linkedin.com/in/morisson http://www.linkedin.com/in/hcoduarte Monday, July 2, 12 2
  • 3. In the beginning of times... Telnet r* services (rlogin, rsh) Weak (or no) authentication Communication in clear Monday, July 2, 12 3
  • 4. In the beginning of times... Sniffing Interception Hijacking Man-In-The-Middle ... Monday, July 2, 12 4
  • 6. SSH* features Key agreement (DH) Encrypted communications (C&I from CIA) Multiple authentication options (password, public keys, kerberos, etc...) Channel Multiplexing Port Forwarding VPN ...and so much more! * for this talk SSH==SSHv2 Monday, July 2, 12 6
  • 8. SSH 101- The Basics Session Multiplexing, TCP forwarding, Connection socket forwarding, sftp subsystem, etc SSH User Auth User Authentication (password, Pubkey, etc) Key Agreement (DH), Host auth, Integrity, Transport Encryption, Re-Keying TCP IP Monday, July 2, 12 8
  • 9. SSH 101- The Basics Encrypted Channel Setup User Authentication Client Connection Server Monday, July 2, 12 9
  • 10. SSH 101- The Basics User authentication methods: GSSAPI Host-Based Public Key Challenge-Response Password Monday, July 2, 12 10
  • 11. Password Authentication Encrypted Channel Setup Client Server username, use password OK Password Auth Ok / NOk passwd ssh sshd file Monday, July 2, 12 11
  • 12. If the server is compromised... sshd binary is changed with one that logs passwords keylogger is installed on the server ..the password is compromised! Monday, July 2, 12 12
  • 13. PublicKey Authentication Encrypted Channel Setup Client Server username, use publickey OK Signature Auth Ok / NOk authorized id_dsa ssh sshd _keys Monday, July 2, 12 13
  • 15. What if I have a lot of keys, or login a lot ?? Monday, July 2, 12 15
  • 16. SSH Agent Encrypted Channel Setup Client Server username, use publickey OK Signature Auth Ok / NOk Agent ssh sshd authorized id_dsa _keys Monday, July 2, 12 16
  • 17. What if I SSH into other servers ?? Monday, July 2, 12 17
  • 18. SSH Agent Forwarding No need to copy private key to other servers Key is kept on the original source host Agent is forwarded, using a tunnel Passwordless! Monday, July 2, 12 18
  • 19. SSH Agent Forwarding Client Transport Server #1 Transport Server #2 Connection Connection Interactive Shell Agent Forwarding Interactive Shell Agent ssh sshd ssh sshd authorized authorized id_dsa _keys _keys Monday, July 2, 12 19
  • 20. Control Master Connection multiplexing allows for multiple sessions on one connection It’s fast No need for extra authentication Monday, July 2, 12 20
  • 22. Caveat Emptor(s) You must trust the server(s) What if the server was compromised ? Can SSH Agent be abused ? Can Control Master be abused ? Monday, July 2, 12 22
  • 24. Help us Obi Wan You’re our only hope! Monday, July 2, 12 24
  • 25. Freak on a Leash When adding keys to ssh-agent use ssh-add with: -t <secs> to set a maximum lifetime on the identities being added to the agent -c to indicate that identities being added should be subject to confirmation before being used for auth Monday, July 2, 12 25
  • 26. Freak on a Leash ssh-agent queries /usr/libexec/ssh-askpass for confirmation “ssh-add -c -t 3600 < /dev/null” makes ssh-add use env var SSH_ASKPASS to query for passphrase Monday, July 2, 12 26
  • 28. But we still need passwords! If you su / sudo, you still type your password... What if we could use the SSH Agent for sudo ? Yes we can! :) Monday, July 2, 12 28
  • 30. Paranoia is reality on a finer scale Monday, July 2, 12 30
  • 32. Using SSH w/o using SSH (but still using SSH) ssh -W trusted:22 untrusted Open socket to trusted Server... ...through an untrusted Server Monday, July 2, 12 32
  • 33. Using SSH w/o using SSH (but still using SSH) Connect to the socket created ssh -o “ProxyCommand ssh -a -W trusted:22 untrusted” trusted Disable Agent Forwarding Open Socket to trusted via untrusted Just for user and key validation Monday, July 2, 12 33
  • 34. Using SSH w/o using SSH (but still using SSH) Client Transport Untrusted Owned Trusted Connection -W (Open Socket to Server #2) Transport Connection Interactive Shell Agent ssh sshd sshd authorized authorized id_dsa _keys _keys Monday, July 2, 12 34
  • 36. Control your SSH .ssh/config Host trusted1 trusted2 trusted3 ForwardAgent yes ProxyCommand ssh -a -W %h:22 untrusted.server.com Host * ControlMaster no ForwardAgent no PasswordAuthentication no HashKnownHosts yes Monday, July 2, 12 36
  • 37. Live long and prosper Monday, July 2, 12 37
  • 38. References RTFM :) RFCs 4251-4256,4335,4344,4345,4419,4432,4462,4716,56 56 http://www.linuxjournal.com/article/9566 http://pamsshagentauth.sourceforge.net/ http://www.jedi.be/blog/2010/08/27/ssh-tricks-the- usual-and-beyond/ Monday, July 2, 12 38