<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Onlyhirocan on Medium]]></title>
        <description><![CDATA[Stories by Onlyhirocan on Medium]]></description>
        <link>https://medium.com/@onlyhirocan?source=rss-8453a7db5099------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*4ZmmjQaLo57olfx9</url>
            <title>Stories by Onlyhirocan on Medium</title>
            <link>https://medium.com/@onlyhirocan?source=rss-8453a7db5099------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 07:27:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@onlyhirocan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What I Learned From a Deep Dive Into Email Attacks]]></title>
            <link>https://medium.com/@onlyhirocan/what-i-learned-from-a-deep-dive-into-email-attacks-8aea7dbd4b5c?source=rss-8453a7db5099------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aea7dbd4b5c</guid>
            <dc:creator><![CDATA[Onlyhirocan]]></dc:creator>
            <pubDate>Tue, 18 Aug 2026 21:46:58 GMT</pubDate>
            <atom:updated>2026-08-18T21:46:58.000Z</atom:updated>
            <content:encoded><![CDATA[<p><em>I spent my evenings this week working through a detailed guide on email security. The document covered everything from how SMTP works to how attackers bypass MFA and steal data.</em></p><p>But I did not want to just read it and move on. I forced myself to map the concepts to my own environment. I wanted to test whether my understanding of email security actually matched how these attacks work under the hood.</p><p>Here is what I learned, what I built, and how I changed my approach.</p><h3>Why I Did This</h3><p>Email remains the number one initial access vector. The Verizon DBIR consistently shows over 68% of breaches involve the human element, with phishing as the dominant delivery mechanism. But the attacks are not what they were five years ago.</p><p>Modern phishing is sophisticated. Attackers use adversary-in-the-middle proxies that defeat MFA. They abuse legitimate cloud services so SPF and DKIM pass. They register malicious OAuth apps that grant persistent API access. They build phishing kits with antibot logic that evades sandboxes.</p><p>I wanted to understand these mechanics at the protocol level, not just the conceptual level.</p><h3>The Protocol Foundation I Had to Relearn</h3><p>I realized early that I had been treating email authentication as a black box. I would look at the Authentication-Results header, see “SPF: Pass, DKIM: Pass, DMARC: Pass,” and move on. I did not really understand what those results meant or what they did not cover.</p><h3>The Envelope vs. The Header</h3><p>Every email has two distinct sender addresses.</p><p>The MAIL FROM (also called the Return-Path or envelope sender) is used by SMTP for bounce routing. SPF checks this address against the sending IP.</p><p>The From header is what the user sees in their mail client. DMARC checks whether this domain aligns with the SPF or DKIM domains.</p><p>These two addresses can be different. That gap is where spoofing lives.</p><p>An attacker can set the envelope sender to a domain they control, which passes SPF, while setting the From header to your CEO’s email address. The user sees the CEO. The email lands in the inbox. This is display name spoofing with a technical twist.</p><h3>What I Changed</h3><p>I stopped trusting the Authentication-Results header at face value. I started reading the raw headers manually, tracing the Received chain from bottom to top to find the true originating IP. I started comparing the Return-Path against the From header for every suspicious email.</p><p>More importantly, I built a specific check that looks for spf=pass combined with dmarc=fail when the From domain matches my organization&#39;s domain. This specific mismatch indicates an attacker using a legitimate email service to spoof my domain.</p><h3>The OAuth Persistence Mechanic I Was Ignoring</h3><p>This was the biggest shift in my understanding.</p><h3>How OAuth Consent Phishing Works</h3><p>An attacker registers a malicious application in Azure AD. Any Microsoft account can do this. They craft a consent URL that requests permissions like Mail.Read, Files.ReadWrite, and offline_access.</p><p>They send this URL in a phishing email with a lure: “Click to authorize the new document sharing tool.”</p><p>The victim clicks. They see Microsoft’s real consent dialog. They click Accept. Microsoft redirects to the attacker’s callback URL with an authorization code.</p><p>The attacker exchanges this code for an access token and a refresh token. The refresh token is valid indefinitely until explicitly revoked.</p><h3>Why This Scared Me</h3><p>I realized my incident response mental model was completely inadequate. I would reset the compromised user’s password, block the offending IP, and close the ticket. This does nothing against OAuth consent phishing.</p><p>The attacker does not need the password. They have a refresh token that survives the password reset. They can keep calling the Microsoft Graph API, reading emails, exfiltrating files, and sending emails as the victim.</p><p>The refresh token is the persistence mechanism. I was not revoking it.</p><h3>What I Changed</h3><p>I changed how I think about containment.</p><p>Revoking all refresh tokens now happens before I touch the password. The password reset is cleanup, not containment.</p><p>The specific command:</p><p>text</p><pre>Revoke-AzureADUserAllRefreshToken -UserId &quot;victim@company.com&quot;</pre><p>I also turned on admin consent requirements for all OAuth applications in my tenant. Users can no longer approve apps on their own. Every new OAuth consent request goes to an admin for review. This is a configuration change that takes five minutes and closes a persistence pathway I was ignoring.</p><h3>The AiTM Proxy Detection Gap</h3><p>Adversary-in-the-Middle phishing kits like Evilginx2 work differently from static phishing pages. They are reverse proxies, not static HTML.</p><h3>How AiTM Works</h3><p>The victim clicks a link that goes to the attacker’s proxy server. The proxy server relays all traffic between the victim and the real Microsoft login page. The victim sees a real login page. They enter their credentials. They approve the MFA prompt. The proxy captures the session cookie.</p><p>The attacker now has a valid session. They do not need to brute force the password. They do not need to bypass MFA. They captured the session after MFA was completed.</p><h3>The Indicators</h3><p>In Azure AD sign-in logs, AiTM attacks show up as:</p><ul><li>UserAgent: a legitimate browser (the victim’s real browser proxied through)</li><li>IP Address: the attacker’s server IP, not the victim’s home IP</li><li>Conditional Access: “MFA satisfied” because the full session was proxied</li><li>Post-auth activity within seconds: inbox rule creation, OAuth app consent</li></ul><p>Normal users do not create inbox forwarding rules seconds after logging in. This behavioral pattern is the detection signal.</p><h3>What I Built</h3><p>I wrote a Sentinel query that looks for successful sign-ins immediately followed by:</p><ul><li>Inbox rule creation (OperationName: New-InboxRule)</li><li>OAuth app consent (OperationName: Consent to application)</li><li>Mail forwarding rule changes</li></ul><p>The query correlates these events and alerts when the pattern appears. It does not rely on IP reputation or known malicious domains. It relies on behavioral anomaly.</p><h3>The Phishing Kit Internals I Had Never Seen</h3><p>This section was fascinating. I had never actually looked inside a phishing kit. The document walked through the file structure, the configuration files, and the evasion logic.</p><h3>The Kit Structure</h3><p>A typical phishing kit is a ZIP archive with:</p><ul><li>index.php: the fake login page</li><li>login.php: the credential capture logic</li><li>config.php: the attacker’s operational configuration</li><li>antibot.php: the evasion logic</li></ul><h3>What I Found in config.php</h3><p>This file contains the attacker’s real data. It is the fingerprint.</p><p>The configuration includes:</p><ul><li>Email exfiltration addresses</li><li>Telegram bot tokens and chat IDs</li><li>Redirect URLs</li><li>VPN and datacenter blocking logic</li></ul><h3>The Telegram Pivot</h3><p>Modern phishing kits exfiltrate credentials via Telegram in real-time. The bot token and chat ID are hardcoded in config.php.</p><p>I built a simple enrichment script that extracts these tokens from suspected phishing kits and queries api.telegram.org/bot[TOKEN]/getMe. If the token is still active, it returns the bot username and other metadata.</p><p>This is active intelligence gathering. It requires authorization. But when authorized, it provides a persistent identifier across campaigns.</p><h3>The Antibot Evasion</h3><p>Phishing kits actively evade sandboxes and security scanners.</p><p>They block:</p><ul><li>Known crawler user agents (Googlebot, Bingbot, URLscan)</li><li>Datacenter IP ranges (Google Cloud, AWS, Azure)</li><li>Tor exit nodes</li><li>VPN and datacenter IPs</li><li>Specific countries</li><li>Non-business hours</li></ul><p>If you scan a phishing page from an AWS IP at midnight UTC, you get redirected to the real Microsoft login page. The kit appears clean. This is why static scanning fails.</p><h3>What I Built</h3><p>I modified my URL analysis workflow to use residential proxies for scanning. I also time my scans to match business hours in the target region. It is not perfect, but it catches more than scanning from a datacenter IP at 3 AM.</p><h3>The Gateway Bypasses I Was Missing</h3><h3>HTML Smuggling</h3><p>HTML smuggling uses legitimate HTML5 APIs to reconstruct a malicious file inside the browser after the email gateway has scanned the email.</p><p>The email contains only JavaScript. There is no attachment for the gateway to scan. The file only exists after the JavaScript executes in the browser.</p><p>The JavaScript decodes a base64 payload, creates a Blob object, and triggers a download. The victim sees a file downloading. The gateway saw only HTML.</p><p>I built a simple detection script that scans HTML emails for large base64 strings inside script tags. It decodes them and checks for magic bytes (MZ for executables, PK for ZIP archives). If it finds either, the email gets quarantined.</p><h3>ISO and Disk Image Bypass</h3><p>Attackers were using ISO images to bypass Mark-of-the-Web protection. Windows automatically mounts ISO images on double-click. Files inside the ISO did not inherit the MOTW flag that triggers SmartScreen warnings.</p><p>Microsoft patched this, but attackers have moved to other archive formats like 7z that still bypass MOTW in some scenarios.</p><p>I updated our gateway configuration to treat ISO, IMG, and VHD files as high-risk. They require manual review before delivery.</p><h3>The Unicode Trick</h3><p>Unicode contains control characters that reverse text display direction. Attackers use the right-to-left override character (U+202E) to make malicious filenames appear benign.</p><p>A file named invoice_[RLO]cod.exe displays as invoice_exe.doc in Windows Explorer. The user sees a Word document. The system sees an executable.</p><p>I built a check that strips all Unicode direction-override characters from filenames at the gateway level. It is a simple string filter, but it closes an evasion technique I was unaware of.</p><h3>The Legal and Chain of Custody Lesson</h3><p>The document covers something most technical people ignore: legal and compliance requirements.</p><p>When a phishing incident escalates, evidence preservation matters. You may need to hand the raw email to law enforcement. You may need to prove what you removed for regulatory reporting under GDPR (72-hour notification window) or SEC requirements (4 business days for material incidents).</p><h3>What I Changed</h3><p>I restructured my SOAR playbook. The first action is now:</p><ol><li>Place a litigation hold on the mailbox</li><li>Hash the raw .eml file and store the SHA256 in the ticket</li><li>Preserve the email in write-protected evidence storage</li><li>Then execute the soft-delete</li></ol><p>Speed does not matter if you cannot prove what you removed. The extra few seconds for preservation is a worthwhile tradeoff.</p><h3>The Red Team vs. Real Attacker Blindspot</h3><p>This was a subtle lesson.</p><p>Our internal red team uses GoPhish for phishing simulations. We had whitelisted the X-Mailer: gophish header to avoid alert fatigue.</p><p>The document pointed out that real attackers can download GoPhish and use the same header to blend in.</p><p>I removed the X-Mailer whitelist entirely. Our simulation detection now relies on a combination of the sending IP pool and the DKIM selector specific to our authorized simulation tools.</p><p>If an email looks like a simulation but lacks the specific DKIM signature, it is treated as a high-severity incident.</p><h3>What I Actually Learned</h3><p>Reading the theory was useful. The real learning came from translating concepts into actionable checks. I wrote a few small scripts, tweaked configuration settings, and changed how I prioritize response steps.</p><h3>The OAuth Lesson Was the Biggest Shift</h3><p>I used to think resetting a password was containment. I now understand that revoking tokens is containment. The password reset is just cleanup.</p><p>This is not a subtle distinction. It is the difference between stopping the attack and letting the attacker maintain persistence through a refresh token.</p><h3>The Gateway Blindspot Lesson</h3><p>I assumed our email gateway caught everything. It did not.</p><p>It missed HTML smuggling. It missed QR codes in PDFs. It missed Unicode filename tricks. It missed authorized-sender abuse through legitimate ESPs.</p><p>The gateway is a tool. It is not a complete solution. It needs to be supplemented with custom detection logic that maps to specific bypass techniques.</p><h3>The Assumption Lesson</h3><p>This entire exercise was about questioning assumptions.</p><p>I assumed SPF passing meant the email was safe. It did not account for authorized-sender abuse.</p><p>I assumed resetting a password ended an attack. It did not account for OAuth refresh tokens.</p><p>I assumed our gateway caught everything. It did not.</p><p>The document gave me the theory. The real work was testing that theory against my own environment and closing the gaps I found.</p><h3>What I Built</h3><p>Here is a summary of the specific things I built or changed:</p><p>1. SPF/DMARC mismatch filter</p><p>Flags emails where SPF passes but DMARC fails when the From domain matches my organization’s domain. Catches authorized-sender abuse.</p><p>2. OAuth consent monitoring query</p><p>Hunts for new OAuth app consents with dangerous scopes and correlates them with sign-in logs from unfamiliar locations.</p><p>3. Admin consent requirement</p><p>Turned on admin consent for all OAuth applications. Users cannot approve apps on their own.</p><p>4. Refresh token revocation step</p><p>Added token revocation to the incident playbook. Executed before password reset.</p><p>5. HTML smuggling detection script</p><p>Scans HTML emails for large base64 strings, decodes them, and checks for PE executable or ZIP magic bytes.</p><p>6. QR code extraction from PDFs</p><p>Extracts QR codes from PDF attachments, decodes the URLs, and checks domain registration age.</p><p>7. Unicode direction override filter</p><p>Strips all Unicode direction-override characters from filenames at the gateway level.</p><p>8. Evidence preservation in SOAR playbook</p><p>Places litigation hold, hashes raw email, and stores evidence before deletion.</p><h3>What I Would Do Differently Next Time</h3><p>If I did this exercise again, I would start with a different approach.</p><p>I spent time building detection logic. I should have spent more time validating the logic against historical incidents. How many emails would this have caught? How many false positives would it generate?</p><p>I also should have talked to the red team earlier. They are running simulations that mimic these exact techniques. Testing detection logic against simulation traffic is safer than testing against real attacks.</p><h3>The Bottom Line</h3><p>Email attacks have evolved. The defenses need to evolve too.</p><p>SPF, DKIM, and DMARC are not enough. They are necessary, but they are insufficient. Attackers have found ways to work around them.</p><p>OAuth consent phishing bypasses authentication entirely. It is not a credential attack. It is an authorization attack. The traditional controls do not apply.</p><p>AiTM proxies defeat MFA. The attacker does not need to bypass MFA. They just relay the session through their proxy.</p><p>Gateways are blind to certain evasion techniques. HTML smuggling, QR codes in PDFs, and Unicode filename tricks are not caught by standard scanning.</p><p>The answer is not one tool. It is a combination of:</p><ul><li>Protocol-level understanding</li><li>Custom detection logic</li><li>Behavioral anomaly hunting</li><li>Incident response playbooks that match the attack mechanics</li><li>Evidence preservation for legal and regulatory compliance</li></ul><p>I learned more from this exercise than I have from any training course in the last year. The difference was forcing myself to build something, change something, or question something. Reading is passive. Building is active. Active learning sticks.</p><p><em>This post is based on my personal research and learning. The specific tools and configurations reflect my environment and may not apply directly to yours. Always test detection logic against your own data before deploying to production.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aea7dbd4b5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>