-->

  • TryHackMe XXE walkthrough XML Extensible Entity







    [Task 1] Deploy the VM



    An XML External Entity (XXE) attack is a vulnerability that abuses features of XML parsers/data. It often allows an attacker to interact with any backend or external systems that the application itself can access and can allow the attacker to read the file on that system. They can also cause Denial of Service (DoS) attack or could use XXE to perform Server-Side Request Forgery (SSRF) inducing the web application to make requests to other applications. XXE may even enable port scanning and lead to remote code execution. TryHackMe XXE walkthrough XML Extensible Entity

    There are two types of XXE attacks: in-band and out-of-band (OOB-XXE).
    1) An in-band XXE attack is the one in which the attacker can receive an immediate response to the XXE payload.


    2) out-of-band XXE attacks (also called blind XXE), there is no immediate response from the web application and attacker has to reflect the output of their XXE payload to some other file or their own server.





    [Task 2] eXtensible Markup Language



    Before we move on to learn about XXE exploitation we'll have to understand XML properly.


    What is XML?


    XML (eXtensible Markup Language) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. It is a markup language used for storing and transporting data.




    Why we use XML?


    1. XML is platform-independent and programming language independent, thus it can be used on any system and supports the technology change when that happens.


    2. The data stored and transported using XML can be changed at any point in time without affecting the data presentation.


    3. XML allows validation using DTD and Schema. This validation ensures that the XML document is free from any syntax error.


    4. XML simplifies data sharing between various systems because of its platform-independent nature. XML data doesn’t require any conversion when transferred between different systems.



    Syntax

    Every XML document mostly starts with what is known as XML Prolog.

    <?xml version="1.0" encoding="UTF-8"?>


    Above the line is called XML prolog and it specifies the XML version and the encoding used in the XML document. This line is not compulsory to use but it is considered a `good practice` to put that line in all your XML documents.


    Every XML document must contain a `ROOT` element.



    Ex:


    <?xml version="1.0" encoding="UTF-8"?>
    <mail>
       <to>falcon</to>
       <from>feast</from>
       <subject>About XXE</subject>
       <text>Teach about XXE</text>
    </mail>




    In the above example the <mail> is the ROOT element of that document and <to>, <from>, <subject>, <text> are the children elements. If the XML document doesn't have any root element then it would be consideredwrong or invalid XML doc.


    Another thing to remember is that XML is a case sensitive language. If a tag starts like <to> then it has to end by </to> and not by something like </To>(notice the capitalization of T)


    Like HTML we can use attributes in XML too. The syntax for having attributes is also very similar to HTML.


    Ex: <text category = "message">You need to learn about XXE</text>


    In the above example category is the attribute name and message is the attribute value.




    #1 Full form of XML

    Ans :- Extensible Markup Language



    #2 Is XML case sensitive?   

    Ans :- yes

       
    #3 Is it compulsory to have XML prolog in XML documents? 

    Ans :- no


     
    #4 Can we validate XML documents against so schema?  

    Ans :- yes



    #5 How can we specify XML version and encoding in XML document?

    Ans :- XML Prolog




    [Task 3] DTD



    Before we move on to start learning about XXE we'll have to understand what is DTD in XML.


    DTD stands for Document Type Definition. A DTD defines the structure and the legal elements and attributes of an XML document.


    Let us try to understand this with the help of an example. Say we have a file named note.dtd with the following content:



    <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]>



    Now we can use this DTD to validate the information of some XML document and make sure that the XML file conforms to the rules of that DTD.

    Ex: Below is given an XML document that uses note.dtd



    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE note SYSTEM "note.dtd">
    <note>
        <to>falcon</to>
        <from>feast</from>
        <heading>hacking</heading>
        <body>XXE attack</body>
    </note>



    So now let's understand how that DTD validates the XML. Here's what all those terms used in note.dtd mean



    •     !DOCTYPE note -  Defines a root element of the document named note
    •     !ELEMENT note - Defines that the note element must contain the elements: "to, from, heading, body"
    •     !ELEMENT to - Defines the to element to be of type "#PCDATA"
    •     !ELEMENT from - Defines the from element to be of type "#PCDATA"
    •     !ELEMENT heading  - Defines the heading element to be of type "#PCDATA"
    •     !ELEMENT body - Defines the body element to be of type "#PCDATA"
    •     NOTE: #PCDATA means parseable character data.
    •    
    •    
       
       
       
    #1 With what extension do you save a DTD file?

    Ans :- DTD



    #2 How do you define a new ELEMENT?


    Ans :- !ELEMENT


    #3 How do you define a ROOT element?

    Ans :- !DOCTYPE



    #4 How do you define a new ENTITY?


    Ans :- !ENTITY



    [Task 4] XXE payload



    Now we'll see some XXE payload and see how they are working.



    1) The first payload we'll see is very simple. If you've read the previous task properly then you'll understand this payload very easily.



    <!DOCTYPE replace [<!ENTITY name "feast"> ]>
     <userInfo>
      <firstName>falcon</firstName>
      <lastName>&name;</lastName>
     </userInfo>




    As we can see we are defining a ENTITY called name and assigning it a value feast. Later we are using that ENTITY in our code.


    2) We can also use XXE to read some file from the system by defining an ENTITY and having it use the SYSTEM keyword


    <?xml version="1.0"?>
    <!DOCTYPE root [<!ENTITY read SYSTEM 'file:///etc/passwd'>]>
    <root>&read;</root>


    Here again, we are defining an ENTITY with the name read but the difference is that we are setting it value to `SYSTEM` and path of the file.


    If we use this payload then a website vulnerable to XXE(normally) would display the content of the file /etc/passwd.


    In a similar manner, we can use this kind of payload to read other files but a lot of times you can fail to read files in this manner or the reason for failure could be the file you are trying to read.





    [Task 5] Exploiting




    Now let us see some payloads in action. The payload that I'll be using is the one we saw in the previous task.




    1) Let's see how the website would look if we'll try to use the payload for displaying the name.












    On the left side, we can see the burp request that was sent with the URL encoded payload and on the right side we can see that the payload was able to successfully display name falcon feast





    2) Now let's try to read the /etc/passwd








    #1 Try to display your own name using any payload.

    #2 See if you can read the /etc/passwd



    #3 What is the name of the user in /etc/passwd

    Ans :- falcon



    #4 Where is falcon's SSH key located?


    #5 What are the first 18 characters for falcon's private key

    Ans :- MIIEogIBAAKCAQEA7




    Disclaimer



    This was written for educational purpose and pentest only.
    The author will not be responsible for any damage ..!
    The author of this tool is not responsible for any misuse of the information.
    You will not misuse the information to gain unauthorized access.
    This information shall only be used to expand knowledge and not for causing  malicious or damaging attacks. Performing any hacks without written permission is illegal ..!


    All video’s and tutorials are for informational and educational purposes only. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. We believe that it is impossible to defend yourself from hackers without knowing how hacking is done. The tutorials and videos provided on www.hackingtruth.in is only for those who are interested to learn about Ethical Hacking, Security, Penetration Testing and malware analysis. Hacking tutorials is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used.


    All tutorials and videos have been made using our own routers, servers, websites and other resources, they do not contain any illegal activity. We do not promote, encourage, support or excite any illegal activity or hacking without written permission in general. We want to raise security awareness and inform our readers on how to prevent themselves from being a victim of hackers. If you plan to use the information for illegal purposes, please leave this website now. We cannot be held responsible for any misuse of the given information.



    - Hacking Truth by Kumar Atul Jaiswal



    I hope you liked this post, then you should not forget to share this post at all.
    Thank you so much :-)






  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.