Trisul Network Analytics Blog

Tech tips and tricks from the world of network traffic and security monitoring

SSH is an incredibly powerful protocol whose footprint needs to be monitored closely in enterprises. The most common use of SSH is for totally legitimate purposes like terminal (ssh) or for file transfer (scp,sftp). Many users also use the less well known port forwarding feature of SSH to create ‘tunnels’. SSH tunnels bore through firewalls, NATs, and are almost totally opaque to Network Security Monitoring tools like Trisul, Bro, Suricata, Snort, and others. SSHv2 even has SOCKS5 support – this allows anyone to setup a full SOCKS5 proxy outside your network and hide all HTTP activity from the prying eyes of NSM tools. With HTTPS/SSL, security tools can get atleast a look at the unencrypted certificates and perform checks, with SSH everything goes dark right after the initial capabilities exchange.

There are two types of SSH tunnels. The forward tunnel allows an insider to get on the outside bypassing the NSM and Firewall/NAT sentries. The reverse tunnel allows an outsider to get on the inside. The reverse tunnel is also called an autossh tunnel after the popular tool used to setup and maintain this connection.

Reverse SSH tunnel allows someone to log on to an outside machine and pop up on the inside!

3 ways in which SSH tunnels create blind spots for monitoring

Here are the top three ways in which SSH tunnels create blind spots for NSM tools

single flow : when you are monitoring on the perimeter SSH tunnels show up as a single flow while they multiplex several SSH or SFTP channels. So you miss that flow level insight.

dynamic forwarding used as proxy using dynamic port forwarding users can proxy web traffic through the encrypted tunnel. This pretty much defeats every policy control you have at the boundary.

24×7 access into your network : reverse ssh tunnels can give outsiders persistent presence into deep parts of your inside network. Autossh is a very advanced tool that maintains the tunnel and keeps it from timing out.

It is quite obvious that any monitoring platform needs to help organizations stay right on top of SSH. Lets see what can be done.

Tracking and detection of SSH tunnels

In any large organization SSH is going to be pervasive. Therefore any naive SSH flow monitoring is going to be dominated by legitimate business applications. Here are some techniques we use in Trisul, you should be able to adapt these to your own toolchain.

We create a SSH Flow Tracker to first get baseline visibility and then to incrementally refine the tracking until we get a workable list of suspect flows. Flow Tracking is a streaming algorithm which plugs into the flows stream and continously snapshots Top-K every minute. There are several built-in Top-K algorithms (volume, upload, download, duration, based on ports, IPs, subnets, netflow). You can even write a fully customized tracker using the flowtracker LUA script ).

Flow tracker used to track long running SSH flows (sorted by duration)

When you first enter a unmapped network, you need to build a baseline statistical and flow profile first. Statistical visibility includes actual bandwidth of SSH traffic, servers, clients, gateways, number of SSH flows, number of concurrent SSH flows , scanning activity, etc. Then you need to step down one level into flow visibility. Identify the normal SSH flows, the elephant flows, the long running but low traffic flows, flows that involved scanners, malicious hosts,etc.

Here we explain how we can use a ‘flow tracker’ to build a baseline model and then refine it in three steps and then end with a discussion of detection of SSH tunnels.

Visibility stage 1 : Use a “SSH Flow Tracker” – track Top-K SSHflows by volume – this gives you a baseline idea of very large elephant SSH flows. Most of them will be normal business activity that is okay. If you dont even have this insight, you are basically running blind.

Visibility stage 2 : Use a “SSH Duration Tracker” – track Top-K SSHflows by duration – this gives you a really good idea of very long lived streams. Once again many of them will be legitimate business activity. That is okay – we will refine them and create a whitelist. Malicious Reverse SSH tunnels will typically not transmit much data as they “lie in wait” for the attacker to log in. They will be kept alive only because of ‘autossh’ keepalives. So right off the bat if you see long lived flows with very low traffic you can mark them for investigation. You can also create trackers for SSH flows by upload if you want to dig deeper.

Once you have the baseline normal visibility we need to feedback knowledge gained from (1) and (2) into the realtime part of Trisul. To do this

Visibility stage 3 : Use “SSH Trackers but use a whitelist” – in addition to the two trackers above you create yet another trackers using the flowtrackerLUAAPI that would track “All SSH flows by duration that arent whitelisted”. It is not that difficult because the whitelists can be automatically generated from (1) and (2). For example you can identify host pairs or subnet pairs that constitute normal traffic.

Detection 1 : “Add detection” – In addition to the deep visibility above, if you can automatically detect SSH tunnels that would give you immediate rewards.

In the next section, we show how you can plug in the detection part using a simple example.

Detecting SSH tunnels using traffic analysis

Recently I came across a great presentation by John B Althouse III [ link ] where he used Bro (bro.org) to detect SSH tunnels carrying TTY (terminal) using traffic analysis.

The key insight found by the author is : if you observe the packet lengths of keystrokes attached to SSH you notice the following.

the exact lengths depend on the encryption block size and the HMAC algorithm + implementation of clients and servers.

each keystroke is echoed back, so we can use that fact to tighten it up a bit

If you can rig a NSM tool to detect consecutive tunnel packet sizes of Server:76, Client:76,S:76,C:76,S:76,C:76 this is almost certainly a person typing in an interactive terminal on an SSH tunnel and getting echoed back. There you have it.

This is a traffic analysis attack essentially. OpenSSH does not implement the “random padding” feature of RFC4253 The secure shell protocol which says " the insertion of variable amounts of ‘random padding’ may help thwart traffic analysis". Until they fix that we can use this technique to detect tunnels.

rev-ssh.lua

You can think of Trisul roughly as Bro but with LUA and an emphasis on traffic metering and streaming analytics. The LUAAPI lets you hook into TCP reassembly , HTTP file extraction, and a number of other points.

Flow tagging allows you to generate a ‘tag stream’ that are merged with the main “flows stream” and persisted at the end of a time window. Flow tags are nothing but text labels that are attached to flows. You can then search for flow by the tag value.

Tags are arbitrary labels attached to flow. Showing a search tag=REVSSH in the Explore Flows tool

Conclusion

We think traffic and flow visibility is a very important part of Network Security Monitoring. As encryption spreads throughout the network we are going to need more and more of statistical and flow based approaches to gain insights into the network. You also need a real time API so you can plug in knowledge learnt from earlier “hunting expeditions”.

Getting started

If you want to get started on the Trisul platform and play with the scripting API, all you have to do is