Sunday, June 14, 2015

Tinker Tailor Soldier Spy - How to detect a router in your network

Imagine you are an administrator of the network shown on the diagram. All you have is an access to router R1. You suspect that user U1 is not just a computer, but the router with configured NAT. This means unauthorized devices in your network. How would you prove and fight it?

In this post I will describe you the technique based on TCP timestamps and how with the help of those you could detect NAT in your network.

About TCP timestamps

TCP timestamps option consist of two 4-bytes fields:
  • The timestamp Value field (TSval) contains the current value of the timestamp clock of the TCP sending the option.
  • Timestamp Echo Reply (TSecr) - this field is only valid if the ACK bit is set in the TCP header. If it is valid, it echos a timestamp value that was sent by the remote TCP in the TSval field of a Timestamps option.
TSval is the one we will work with. Each OS implementation increment this value at a specific rate. So it is possible to infer the system uptime from the timestamp option if the targeted OS is known.

For Linux timer rate is defined during kernel compilation and usually equals 250. So if you see smth like this in tcpdump:

09:29:18.663124 IP 192.168.0.12.54793 > 8.8.8.8.53: Flags [S], seq 3386060712, win 29200, options [mss 1460,sackOK,TS val 3659526 ecr 0,nop,wscale 7], length 0

I know that 192.168.0.12 is a linux machine, so its uptime would be approximately: 3659526/250/60/60 ~ 4 hours

Another good and important thing about TSval - it is usually not changed by Network Address Translation.

Theory

By monitoring the traffic on R1 you should:
  • Create a list of timestamps received from U1
  • Based on the idea that two hosts behind a NAT have a distinctive timestamp because they can’t have the same uptime, unless they have been booted within the same millisecond, distinguish two or more hosts.

First steps and visual contact

I ran tcpdump with the following flags to collect the timestamps (192.168.0.12 is my router):

tcpdump -c 100000 -w nat.timestamp.dump -i eth0 src host 192.168.0.12 and tcp

Then with a simple python script and scapy I've created the list which looks like this:

1434112464.25 9135849
1434112464.44 101360108
1434112464.44 101360108
1434112464.44 101360111
...

The value on the left is a timestamp of the capture, the value of the right is TSval of the captured packet. Here is how graph looks (date on X-axis, TSval on Y-axis):


You can see that there are two distinctive TSvals, which means that there are at least two different hosts behind this router. Cool, right?

Catch the spy

Automatic detection is quite tricky in our situation. And that is why:
  • As we already know various operating systems calculate TSval differently.
  • User might modify TSvals on the router.
We can't fight with the second option, but with the first we still have some chances. Timestamps can be represented as a linear function:

TSval = IncBySec * sec + In

IncBySec differs in different operating systems. In - is an initial timestamp value. In all OSes it equals zero, whereas in Windows it is random (that is why it is not possible to calculate an uptime of a Windows host based on TSval). 

We need a technique to overcome operating systems limitations. For instance, we could do the following:

A = TSval_1 - TSval_2 / S1 - S2

Where TSval_1 and TSval_2 are the timestamps gathered at time S1 and S2. 

Now, all we need is to find how many increments do we have. The amount of increments will give us the amount of hosts.

Saturday, June 6, 2015

SSL/TLS security overview of forex web cabinets

Recently, I saw few reports on how banks doing with SSL/TLS security. Reports included internet-banking portals from various countries. For instance: UK, The Netherlands, even Russia.

As I work in forex industry, I decided to have a look how they are doing. Qualys SSL Test tool was used.

First of all, I'd like to say, that sometimes it was really hard to find a user portal/cabinet/etc. on some broker pages. Really guys, do something about it. Hiding it won't make it more secure.

Report date: 06 May 2015
Forex brokers are sorted in alphabetical order.

BrokerURLScoreSSL3SSL2SHA1TLS1.2DHRC4FSPOODLEHeartbleedFreakLogjamCCSHSTSOSCP
Admiral Marketshttps://tr.admiralmarkets.comС-++-----++++--
Alfa-Forexhttps://my.alfa-forex.ruB++++-++++++++-
Alparihttps://my.alpari.comA+++++++++++++++
AMarketshttps://office.aforextrading.comA-++-+++-+++++--
Ayondohttps://social.ayondo.comB-++++--+++++-+
BCS Forexhttps://login.forex-bcs.ruB++++-++++++++-
CitiFXhttps://web.citifxpro.comС++--+--++++++-
DeltaTradehttps://delta.tradeB++++-+++++++--
Dukascopyhttps://live-login.dukascopy.comB++++---+++++--
EasyForexhttps://secure.easy-forex.comB+++++--+++++--
Etorohttps://openbook.etoro.comB+++++-++++++--
Exnesshttps://www.exness.comA+++++++++++++++
FBShttps://my.fbs.ruС-+++-+--++++--
Fibohttps://mtclient.fibo.ruB++++-+++++++--
Finamhttps://cabinet1.whotrades.comС-+-+--+-++++-+
FinFXhttps://www.finfx.fiA++++++++++++-+
Forex4Youhttps://account.forex4you.orgA++++++++++++--
ForexClubhttps://secure.fxclub.orgA++++++++++++--
ForexTimehttps://my.forextime.comA++++++++++++--
FX-Trendhttps://fx-trend.comB++-++-++++++--
FXCMhttps://www.myfxcm.comA++++++++++++--
FXDDhttps://secure.fxdd.comB++++-+++++++--
FxOpenhttps://my.fxopen.ruA++-+++++++++-+
FxProhttps://direct.fxpro.comA-++-+++-+++++--
GFThttps://dealbookweb.live.gftforex.comF--------+-++--
GKFXhttps://my.gkfx.ruС-+++-+++++++--
Grand Capitalhttps://grandcapital.ruA+++++++++++++++
IGhttps://www.ig.comB++-++--+++++--
InstaForexhttps://cabinet.instaforex.comС+++----+++++--
Iron FXhttps://www.ironfx.comB+++++--+++++--
LionStonehttps://account.lionstone.co.ukB++++-+-++++++-
Lite Forexhttps://secure.liteforex.comB++-+-+++++++--
Masterforexhttps://mfxbroker.comС-++-+--+++++--
Mayzus.comhttps://secure.mayzus.comF-+-+-+--+++---
NasBrokerhttps://my.nas-broker.comA++++++++++++-+
NordFxhttps://account.nordfx.comA++-+++++++++--
Oandahttps://fxtrade.oanda.comB++++--++++++--
RoboForexhttps://my.roboforex.ruA++-+++++++++--
SaxoBankhttps://ru.saxobank.com/loginB+++++--+++++--
Swissquotehttps://wt.swissquote.comB++++-+-+++++--
Teletradehttps://my.teletrade-dj.comF--+-----+-++--
ThinkForexhttps://portal.thinkforex.comA-++++++-+++++--
VTB24https://lk.olb.ruF-+--++--++++--
WelTradehttps://secured.weltrade.ru/signinB++++---+++++--
Youtradehttps://www.youtradefx.com/loginС-++-+--+++++--
BrokerURLScoreSSL3SSL2SHA1TLS1.2DHRC4FSPOODLEHeartbleedFreakLogjamCCSHSTSOSCP

The full table could be found here.

Frankly speaking, I'm quite surprised. The things are not so bad with these forex guys. Maybe it is because their industry is moving pretty fast and they must be as flexible as possible.

I've added OSCP just for fun, to have a look if somebody is using it and again was surprised :)

What conclusions can we draw from this report:

  • There are still some brokers who use SSLv3 and even SSLv2. And that is bad. This means they do not care about security at all. With SSLv3 POODLE is almost always there. Bad again.
  • Many brokers still use weak DH keys (512 and 786 bits). That is not a serious security flaw, but still.
  • Perfect Forward Secrecy is a must nowdays. Does not matter that your key is safe now. Some day it might leak to the web.
  • We all love Ronald Rivers, but RC4 must not be used. Have a look at RFC 7465.
  • As for SHA1 certificates - that is just the matter of time. Almost all CAs are issuing SHA256 now. The certs will expire eventually.
  • We may see, that recently discovered Logjam and Freak vulnerabilities are pretty rear in our report. IT security became very popular after Heartbleed was announced. Give a security issue a name and it will be closed in a second.
  • As for HSTS (HTTP Strict Transport Security) - that is remarkable, how few brokers are using this feature.
In my humble opinion SSL/TLS is a basis of web security and it is configured pretty easily (even when you don't know what you're doing). There are lots of examples all over the Internet. What other security issues might broker have if one of the most significant things is not configured properly. Forex brokers should give it a thought.