# qwqoro/mail-injection architecture

> Architecture diagram of the GitHub repository qwqoro/mail-injection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/qwqoro/mail-injection
- Repository: https://github.com/qwqoro/mail-injection

## Overview

##### Project type and purpose
- This repository is a set of sample, purposefully-vulnerable web applications demonstrating various E-Mail Injection vulnerabilities (CRLF Injection in SMTP/IMAP, Arbitrary Command-Flag Injection, Improper Input Validation).
- It is not a single monolithic full-stack app but a collection of four independent backend implementations (NodeJS, PHP, Python-IMAP, Python-SMTP) each paired with a minimal static frontend.

##### File structure
- Top-level:
- HaHacking_Mail-Injection.pdf / slides-PHDays.pdf – research artifacts.
- README.md – project overview & instructions.
- images/ – screenshots and GIF.
- nodejs/, php/, python-imap/, python-smtp/ – four sample apps.
- Each sample app:
- public/ – static assets (index.html, index.css, plus messages.html for IMAP example).
- app.js or app.py / index.php & send.php – HTTP server code and email-submission endpoints.
- No databases; relies on external mail services (SMTP via Postfix, IMAP via Dovecot).

##### README for additional insights
- It lists each environment, the framework/language used, and the specific vulnerability demonstrated.
- Usage instructions reveal dependencies: Express + smtp-client; PHP mail(); Flask + imaplib; Flask + email + smtplib.
- It requires configuring a local domain (hahacking.local), an SMTP server, and an IMAP server.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Browser["User's Web Browser"]:::external
    DNS["hahacking.local DNS"]:::external

    %% Backend Samples Container
    subgraph "Backend Samples"
        direction TB
        subgraph "NodeJS SMTP Sample"
            direction TB
            FE_Node["Static Frontend"]:::frontend
            BE_Node["NodeJS/Express SMTP Backend"]:::backend
        end
        subgraph "PHP SMTP Sample"
            direction TB
            FE_PHP["Static Frontend"]:::frontend
            BE_PHP["PHP Backend"]:::backend
        end
        subgraph "Python IMAP Sample"
            direction TB
            FE_IMAP["Static Frontend"]:::frontend
            BE_IMAP["Flask IMAP Backend"]:::backend
        end
        subgraph "Python SMTP Sample"
            direction TB
            FE_SMTP["Static Frontend"]:::frontend
            BE_SMTP["Flask SMTP Backend"]:::backend
        end
    end

    %% External Mail Services
    SMTP["SMTP Server\n(Postfix)"]:::mail
    IMAP["IMAP Server\n(Dovecot)"]:::mail

    %% Documentation
    subgraph "Documentation"
        direction TB
        README["README.md"]:::doc
        PDF["HaHacking_Mail-Injection.pdf"]:::doc
        Slides["slides-PHDays.pdf"]:::doc
    end

    %% Connections: DNS and Browser to Backends and Frontends
    Browser --> DNS
    DNS --> BE_Node
    DNS --> BE_PHP
    DNS --> BE_IMAP
    DNS --> BE_SMTP

    Browser -->|HTTP| FE_Node
    Browser -->|HTTP| FE_PHP
    Browser -->|HTTP| FE_IMAP
    Browser -->|HTTP| FE_SMTP

    FE_Node --> BE_Node
    FE_PHP --> BE_PHP
    FE_IMAP --> BE_IMAP
    FE_SMTP --> BE_SMTP

    %% Backend to Mail Servers
    BE_Node -->|SMTP| SMTP
    BE_PHP -->|SMTP| SMTP
    BE_SMTP -->|SMTP| SMTP
    BE_IMAP -->|IMAP| IMAP

    %% Responses back to Browser
    BE_Node -->|HTTP Response| Browser
    BE_PHP -->|HTTP Response| Browser
    BE_IMAP -->|HTTP Response| Browser
    BE_SMTP -->|HTTP Response| Browser

    %% Click Events
    click FE_Node "https://github.com/qwqoro/mail-injection/blob/main/nodejs/public/index.html"
    click BE_Node "https://github.com/qwqoro/mail-injection/blob/main/nodejs/app.js"
    click FE_PHP "https://github.com/qwqoro/mail-injection/blob/main/php/index.css"
    click BE_PHP "https://github.com/qwqoro/mail-injection/blob/main/php/index.php"
    click FE_IMAP "https://github.com/qwqoro/mail-injection/blob/main/python-imap/public/index.html"
    click BE_IMAP "https://github.com/qwqoro/mail-injection/blob/main/python-imap/app.py"
    click FE_SMTP "https://github.com/qwqoro/mail-injection/blob/main/python-smtp/public/index.html"
    click BE_SMTP "https://github.com/qwqoro/mail-injection/blob/main/python-smtp/app.py"
    click README "https://github.com/qwqoro/mail-injection/blob/main/README.md"
    click PDF "https://github.com/qwqoro/mail-injection/blob/main/HaHacking_Mail-Injection.pdf"
    click Slides "https://github.com/qwqoro/mail-injection/blob/main/slides-PHDays.pdf"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,stroke-width:1px;
    classDef backend fill:#E6FFEA,stroke:#239a3b,stroke-width:1px;
    classDef mail fill:#FFF4D0,stroke:#d45f00,stroke-width:1px,shape:cylinder;
    classDef external fill:#F0F0F0,stroke:#888,stroke-width:1px;
    classDef doc fill:#F7F7F7,stroke:#AAA,stroke-width:1px,stroke-dasharray: 5 5;
```
