<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Diego Vicedo on Medium]]></title>
        <description><![CDATA[Stories by Diego Vicedo on Medium]]></description>
        <link>https://medium.com/@th4jouke?source=rss-adbe9685cea1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QcHbxwnHswm1hQNCzEt5hA.jpeg</url>
            <title>Stories by Diego Vicedo on Medium</title>
            <link>https://medium.com/@th4jouke?source=rss-adbe9685cea1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:49:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@th4jouke/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reversing and Decrypting a case of KiXtart]]></title>
            <link>https://medium.com/@th4jouke/reversing-and-decrypting-a-case-of-kixtart-7ecc4350dd6a?source=rss-adbe9685cea1------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ecc4350dd6a</guid>
            <category><![CDATA[passwords]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[pentesting]]></category>
            <dc:creator><![CDATA[Diego Vicedo]]></dc:creator>
            <pubDate>Wed, 04 Apr 2018 16:00:34 GMT</pubDate>
            <atom:updated>2018-04-04T16:00:34.650Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Some time ago, I ran into a weird file that caught my attention. In particular, the file was in an unreadable text form with the extension “.KX”, in a very common directory called “netlogon” on one of the Domain Controllers. My first impression was that the file was encrypted and it may be used for some sensitive and necessary task done by sysadmins.</p><p>The file with the “.KX” extension was created by a tool called KiXtart:</p><p><em>“ [..] KiXtart is a free-format scripting language and has rich built-in functionality for easy scripting.[..]”</em></p><p>There is a functionality in KiXtart called “Pre-tokenizing script”; this feature takes a regular, clear text script, converts it to so-called ‘tokens’ and stores the result as a new file. There is a note on the official document that says very clearly that:</p><p><em>“[..]The level of security provided by tokenizing a script qualifies as </em><strong><em>‘obsfucation’</em></strong><em>. In practical terms this means that tokenized scripts are perfectly safe from attempts at viewing or changing them by regular end users. However, tokenized scripts are </em><strong><em>not safe </em></strong><em>from attacks by people </em><strong><em>with enough time and determination</em></strong><em> on their side. As a rule, you should never store any valuable or sensitive data, such as </em><strong><em>administrative passwords</em></strong><em>[..]”</em></p><p>I decided to know how this tool work, only out of curiosity, to know how this kind of “obfuscation” was built and try to pick some of code to return the script that I saw on the Domain Controller back to clear-text. Who knows, maybe I could juice out some information from this file.</p><h3>Analysis</h3><p>The command taken from the official documentation to use the pre-tokenize feature on Kix is:<br><em>KIX32 demo.kix /t</em></p><p>If we run this command our plaintext file will be encrypted, and the output will overwrite the same file (in this case we use “Test.KX” instead of “demo.kix”).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*yfuZbNyywiRaGTJf3ktQHQ.png" /><figcaption>A) “Test.KX” file after encryption</figcaption></figure><blockquote>There are some of function that KiXtart use to set the context and encrypt the cleartext file. On a very high level these are:</blockquote><blockquote>1) <strong>CryptAcquireContext():<br> </strong><em>It’s used for create a handler to a specific Key Container.</em><br>2) <strong>CryptCreateHash(): <br></strong><em>The CryptCreateHash function initiates the hashing of a stream of data. It creates and returns to the calling application a handle to a cryptographic service provider (CSP) hash object</em><br>3) <strong>CryptHashData():<br> </strong><em>The CryptHashData function adds data to a specified hash object. This function and CryptHashSessionKey can be called multiple times to compute the hash of long or discontinuous data streams.</em><br>4) <strong>CryptDerivateKey():<br></strong><em>The CryptDeriveKey function generates cryptographic session keys derived from a base data value. This function guarantees that when the same cryptographic service provider (CSP) and algorithms are used, the keys generated from the same base data are identical.</em><br>5) <strong>CryptDecrypt():</strong><em>The CryptDecrypt function decrypts data previously encrypted by using the CryptEncrypt function.</em></blockquote><blockquote>All these function are included on the “advapi32” DLL.<br>The before detailed functions are used in this specific order.</blockquote><p>If we download the software from the official page, and disassemble the executable called “KiX32.exe”, we will see the first function responsible of setting the context. <br>CryptAcquireContext() is used to create a handler to a specific Key Container. There is a lot of information about this function, but the most important thing here is that it use the “MS_DEF_PROV” Cryptographic Provider like we see on the following screenshot that show the instructions before calling it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*YCLCiAeJ1utchxop1xuhLw.png" /><figcaption>B) Instructions before CryptAcquireContext() call</figcaption></figure><p>After the Context was established, we see the following flow responsible of encrypting our cleartext:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*KpccBoDgYaev7qLnbb8l8Q.png" /><figcaption>C) CryptCreateHash() and CryptHashData() being used</figcaption></figure><p>This seems like once the Hash Object is created by calling CryptCreateHash(), Kix adds some kind of data to the Hash Object, using the CryptHashData() function. But, what for? To decrypt the data? Not yet, see what happened next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*FmuFCh2WKAVBbF872Z_Pyw.png" /><figcaption>D) Continuing the previous flow</figcaption></figure><p>If we see the screenshot above, we can observe that the data added to the Hash Object is actually a Key. The most simple way of realizing this, is, of course, the message “Failed to hash <strong>password</strong>”, but you can observe, that in the next step, the function that is called (once that parameters is pushed to the stack) is CryptDeriveKey(). We know that this function derives a session key from a base data value, in this case, this base data value is the previous key added to the Hash Object.</p><p>If we see carefully figure C and D, we can observe that there are two “main” flows, one of them is the case when a password wasn’t defined, and arrive from the first call to the CryptHashData() (Figure C). The second flow arrive from the second CryptHashData() call (Figure D), this is the case when a user set a specific password.</p><p>Henceforth, we refer specifically to the <strong>first case</strong>.<br>Here comes the most important thing to know how to decrypt the “pre-tokenized” file in the case of a sysadmin not specify a password:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*KBh39BN7_HtF6IYl79zuEw.png" /><figcaption>E) Observe the value of the dwDataLen parameter</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*FGc7ynPkU8EijhGlNu7U7Q.png" /><figcaption>F) Observe the content of the EDX register(pbData parameter in this case)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*OpjdIQufEn3p3MbsKK3pgg.png" /><figcaption>G) CryptDeriveKey() and CryptDecrypt() flow</figcaption></figure><p>If we look carefully the screenshots above, we see that Kix takes the length of 10h from the raw file(Image E), but with an offset of 7 respect to the start of the file (some of these bytes are used to know the version of the software and if a file was protected by a explicit password or not) before calling the CryptHashData() function.</p><p>This means that, in the case of users <strong>not using an explicit password</strong> to protect their files, Kix creates a random key that will be added on a specific offset inside the same file that will be encrypted. This key will be added to the Hash Object using the CryptHashData() function, and It will be used to derive a session key using the CryptDeriveKey() function, that finally will be used to decrypt the file using the <em>CryptDecrypt() </em>function.</p><p>Finally, here is the source code of the decrypt tool, but if you want the compiled version, you can download from the references. It was useful for my because due to misuse of the tool by sysadmins, we were able to obtain one domain privilege account. There are a lot of easier and faster ways to get the same thing, but, you know, we like to disarm things to learn.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/adf7fc09404d1e65f174fd8497e64e1d/href">https://medium.com/media/adf7fc09404d1e65f174fd8497e64e1d/href</a></iframe><h3>References:</h3><ul><li><a href="http://www.kixtart.org/">http://www.kixtart.org/</a></li><li><a href="https://github.com/dvicedo/KiXtart-Decrypt">https://github.com/dvicedo/KiXtart-Decrypt</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ecc4350dd6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>