Skip to content

A Python-based lab demo of Microsoft 365 Direct Send, showing how spoofed internal-looking emails can bypass filtering in a controlled environment.

Notifications You must be signed in to change notification settings

mgstate/directsend-python

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Direct Send Abuse POC (Python)

Author: Farzan Karimi (@jumpycastle)
License: MIT


πŸ“– Overview

This script provides a Python-based implementation of how Microsoft 365 Direct Send can be abused to craft emails that look internal but are sent without authentication.

  • What is Direct Send?
    Direct Send allows devices or apps (e.g., printers, scanners, scripts) to send mail into a Microsoft 365 tenant via the smart host
    <tenant>.mail.protection.outlook.com without logging in.

  • Why is this risky?
    Because no credentials are required and the From: address can be spoofed, an attacker’s message routed through Microsoft infrastructure may appear as internal-to-internal traffic, bypassing filters and third-party security.

Direct Send Abuse POC (Python)

⚠️ Safety Notice
This code is for authorized testing or lab use only. Do not aim it at live tenants. It won't end well.


πŸ›  Features

  • Build a MIME email with:
    • Spoofed From: and To: headers
    • Subject, HTML body template, optional attachment
    • Placeholders in the body ({{target}}, {{sender}}, {{link}})
  • Send mail to an SMTP server ({{smtp target})

πŸš€ Setup

1. Create a simple HTML body

Save as body.html:

<html><body>
  <p>When you get a moment please call me back at 555-555-5555.</p>
</body></html>

2. Usage

 py directsend.py --To "{{target}}@email.com" --From "{{sender}}@email.com" --Subject "Urgent Message" --Body ./test.html --smtp {{company}}.mail.protection.outlook.com
  --smtp localhost

3. Arguments

-t, --To β†’ Recipient address (e.g., [email protected])
-f, --From β†’ Spoofed sender address (e.g., [email protected])
-s, --Subject β†’ Subject line
-b, --Body β†’ Path to HTML body file (supports placeholders)
-a, --Attach β†’ Optional file to attach
--smtp β†’ SMTP server (use localhost for lab)

4. Remediation

  • Best move β†’ turn off Direct Send
  • If you can’t: lock it down to the few /IP ranges that need it
    • With Mimecast β†’ use the Lockdown Connector
    • Without β†’ tighten DMARC to reject, enforce SPF hardfail, add anti-spoofing policies, and pin to known egress IPs

About

A Python-based lab demo of Microsoft 365 Direct Send, showing how spoofed internal-looking emails can bypass filtering in a controlled environment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.7%
  • HTML 3.3%