#!/bin/bash
# ---------------------------------------------------------------
#  SCENARIO D - Misconfiguration: spoof delivered
# ---------------------------------------------------------------
#
#  Flow:  swaks → direct to receiver-mta
#  Domain: misconf.lab (has p=none)
#
#  MAIL FROM: <attacker@evil.lab>
#  From:      Admin <admin@misconf.lab>
#  To:        bob@receiver.lab
#  DKIM:      none
#
#  Expected results on receiver-mta:
#    SPF  = none   (evil.lab has no SPF record)
#    DKIM = none   (no signature)
#    DMARC= fail   (From=misconf.lab, no aligned SPF/DKIM)
#    Action: DELIVERED (misconf.lab policy is p=none)
#
#  Sender's DMARC policy dictates receiver action.
#  If p=none, DMARC failures are logged but mail is delivered.
# ---------------------------------------------------------------

set -e

echo ""
echo "-----------------------------------------------"
echo "    SCENARIO D - Misconfiguration (p=none)     "
echo "       Spoof delivered but logged fail         "
echo "-----------------------------------------------"

swaks \
    --to bob@receiver.lab \
    --from attacker@evil.lab \
    --h-From "Admin <admin@misconf.lab>" \
    --h-Subject "Scenario D: Spoofed email from misconf.lab (p=none)" \
    --body "This email is spoofing misconf.lab.\nDMARC will FAIL due to alignment mismatch.\nHowever, because misconf.lab has p=none, this email should be DELIVERED." \
    --server 10.0.0.20 \
    --port 25 \
    --timeout 30

echo ""
echo " -- Scenario D sent. Check bob's mailbox. --"
echo " -- Expected: Delivered. Headers: dmarc=fail (p=none) --"
echo ""
