<?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 Azer Sebei on Medium]]></title>
        <description><![CDATA[Stories by Azer Sebei on Medium]]></description>
        <link>https://medium.com/@azer.sebei?source=rss-88588a343b03------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MqBYcbLpHsCEEoCGLCi85Q.jpeg</url>
            <title>Stories by Azer Sebei on Medium</title>
            <link>https://medium.com/@azer.sebei?source=rss-88588a343b03------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 22:20:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@azer.sebei/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[DIY WEB SERVER]]></title>
            <link>https://medium.com/@azer.sebei/diy-web-server-a457832fa1bc?source=rss-88588a343b03------2</link>
            <guid isPermaLink="false">https://medium.com/p/a457832fa1bc</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[website]]></category>
            <category><![CDATA[servers]]></category>
            <dc:creator><![CDATA[Azer Sebei]]></dc:creator>
            <pubDate>Wed, 30 Nov 2022 23:25:33 GMT</pubDate>
            <atom:updated>2022-11-30T23:34:12.247Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a guided walkthrough on how to create a server and run a webserver on it using your own computer and ISP.</p><p>Needed tools :</p><ul><li>Virtualbox</li><li>Ubuntu live server</li><li>Nginx (personal choice)</li><li>Docker ( personal choice and optional)</li><li>Your website (for testing)</li><li>A router with admin access</li></ul><h3>I-INSTALLING THE SERVER:</h3><p>Our first step is to install the <em>Ubuntu live server</em> into a virtualbox.</p><p><a href="https://ubuntu.com/download/server"></a></p><p>You can get it from the link above.</p><p>Create a new box with the settings of your choice and need and select the iso file we downloaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*Hs2FYLQC6fJen_zbrSMN_g.png" /></figure><p>You can use this guide to install the Server :</p><p><a href="https://hibbard.eu/install-ubuntu-virtual-box/">How to Install Ubuntu Server on VirtualBox</a></p><p>It’s a basic normal skip skip installation , at the end after rebooting the machine , you need to change the Network configuration :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*WitP-UayTVZmokyWEwoi-g.png" /></figure><p>Set the access mode to “Bridged”.</p><p>This will allow the machine to be granted a Private IP address next to everyone on the network.</p><p>192.162.1.X where X changes from device to device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*eU6yJRm9MPMR8RGqW0d2Qw.png" /></figure><p>Running<strong> ip a </strong>we can see that I have an a private IP set to<strong> 192.168.1.30 .</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*qfUuSYNNsLIXeEljBTx0Gg.png" /></figure><p>A simple python http server will allow me to verify if that’s truely the case :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*PcWipMXG26ldYAtLVdjiOQ.png" /></figure><p>Please run if any issues pop up:</p><pre>sudo apt update<br>sudo apt upgrade</pre><h3>I-CONFIGURATION</h3><p>After verifying that we are live and connected we can now start building our sever :</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —-</p><h4>DOCKER:</h4><p>I’ll be using docker for the sake of using other containers in the future for this server , you can use nginx directly on the server instead ( explained later).</p><p>First we need to install <strong>docker</strong> and pull a container image of <strong>nginx</strong> server.</p><p>Here is a cheat-sheet of docker commands :</p><iframe src="https://drive.google.com/viewerng/viewer?url=https%3A//docs.docker.com/get-started/docker_cheatsheet.pdf&amp;embedded=true" width="600" height="780" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8ac0b3bc791ed505554d04e81ee7136/href">https://medium.com/media/f8ac0b3bc791ed505554d04e81ee7136/href</a></iframe><p>And how to use the official NGINX image :</p><p><a href="https://www.docker.com/blog/how-to-use-the-official-nginx-docker-image/">How To Use the Official NGINX Docker Image - Docker</a></p><p><a href="https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/#:~:text=Maintaining%20Content%20and%20Configuration%20Files%20on%20the%20Docker%20Host&amp;text=Any%20change%20made%20to%20the,etc%2Fnginx%20in%20the%20container">https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/#:~:text=Maintaining%20Content%20and%20Configuration%20Files%20on%20the%20Docker%20Host&amp;text=Any%20change%20made%20to%20the,etc%2Fnginx%20in%20the%20container</a>. — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><h4>NGINX:</h4><p>Using <strong>Nginx </strong>directly to serve the website is quicker and easier ,</p><p><a href="https://ubuntu.com/tutorials/install-and-configure-nginx#4-setting-up-virtual-host">Install and configure Nginx | Ubuntu</a></p><p>This is the official Ubuntu guide on that but we will walkthrought this step by step :</p><p>First we need to install nginx into our machine :</p><pre>sudo apt install nginx</pre><p>Default page is placed in /var/www/html/ location. You can place your static pages here, or use virtual host and place it other location.</p><p>Navigating to /var/www/html/ I cloned my own website using git .</p><p><a href="https://github.com/Azer-prog/azersec">https://github.com/Azer-prog/azersec</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*JSw9OHYTMfnkY7JJrXeW_w.png" /></figure><p>This already built using jekyll and ready to be served to the web.</p><p>If you haven’t built yet you need to build and include the final version here .</p><p>To set up virtual host, we need to create file in /etc/nginx/sites-enabled/default</p><p>Please note that you can create another config file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*09hqMmKTlzg_Ptl3UW1hrA.png" /></figure><p>The config file looks like this , please modify the root and server_name to your liking, you can also alter the port .</p><p>— — —</p><p><strong>NOTE:</strong></p><p>Check if HTTP and HTTPS ports are allowed by your firewall rules with the following command:</p><p>firewall-cmd --list-all</p><p>If TCP port 80 is not in the list of open ports, allow them in firewalld rules via the following commands:</p><pre>firewall-cmd --permanent --zone=public --add-port=80/tcp</pre><p>Reload the firewall using this command:</p><p>firewall-cmd --reload</p><p>— — -</p><p>Next all we have to do now is :</p><pre>sudo service nginx restart</pre><p>To stop your web server, type:</p><pre>sudo systemctl stop nginx</pre><p>To start the web server when it is stopped, type:</p><pre>sudo systemctl start nginx</pre><p>If you are only making configuration changes, Nginx can often reload without dropping connections. To do this, type:</p><pre>sudo systemctl reload nginx</pre><p>Running the status command will give back a beautiful green “Active (running)”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*4MMLuWdji6y0IvBCRbPbvA.png" /></figure><p>Now visiting http://&lt;YOUR-IP&gt;:80/ will give back your website.</p><p>Congratulations you now have created a webserver running your webiste.</p><h3>II-GOING PUBLIC</h3><p>Now for the tricky part , how do I make this website accessible for everyone on the internet.</p><p>For now we are running on a private network that only people connected to it can visit our website on using our private IP address.</p><p>To go public we need to go beyond our Router and into the <strong>INTERNET.</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2G1ueMDgwxw%3Fstart%3D301%26feature%3Doembed%26start%3D301&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2G1ueMDgwxw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2G1ueMDgwxw%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/7fd937f52339a37e6a37e5d4fc90506d/href">https://medium.com/media/7fd937f52339a37e6a37e5d4fc90506d/href</a></iframe><p>This video is a great way to explain how our network is connected to the web , as all devices have the same PUBLIC IP address assigned to us by our ISP(Internet service provider), If someone wants to reach out to us using our public IP , the router doesn’t know to which device this request is assigned as we all have the same public address but different private ones.</p><p><a href="https://www.tunisia-sat.com/forums/threads/3938135/#post-1050860705">الدخول الى الروتر عن بعد.</a></p><p>Using this great old tunisiasat post to check how I can do this using my home router.</p><p>You can access your own router’s interface using 192.168.1.1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3XOC3CNgnUKp1IaNI0W_w.png" /></figure><p>Every request now to our public address is forworded to my machine’s private address , which is hosting our site.</p><p>So now visiting http://&lt;PUBLIC-IP&gt;:80/ from anywhere on the world will give back the hosted website.</p><p>Using zenhosting I can now just redirect <a href="http://server.azersebei.com/">http://server.azersebei.com/</a> to my router’s public address.</p><p>You can use : <a href="https://www.whatismyip.com/">https://www.whatismyip.com/</a> to get your public IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sb1yRNNNjJ4GPcV4EaPpCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dtjazit5xOt9xhiBB9hJFw.png" /></figure><p>And there you have it , my own hosting on my own laptop.</p><p>You can also ssh into the server from another box .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*l0RESccVVr9j5Y9uypoOzA.png" /></figure><p>This enviroment will be host to a devops project that will gradually turn vulnerable :)</p><p>Thank you TunisieTelecom for giving the public routers to build servers with :p .</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FH222yZmK4873vWKB7n%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FH222yZmK4873vWKB7n%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FH222yZmK4873vWKB7n%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="241" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b8b69309066dca2014bbfdc67f6bf87/href">https://medium.com/media/4b8b69309066dca2014bbfdc67f6bf87/href</a></iframe><p>— — — — —</p><p>No IP@ was leaked during this :) and no website is now running , this is all a matrix.</p><p>— — — — — —</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a457832fa1bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write up for THM “tomghost”]]></title>
            <link>https://medium.com/@azer.sebei/write-up-for-thm-tomghost-1ad83b5b89c2?source=rss-88588a343b03------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ad83b5b89c2</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Azer Sebei]]></dc:creator>
            <pubDate>Thu, 17 Nov 2022 17:24:23 GMT</pubDate>
            <atom:updated>2022-11-17T17:24:23.428Z</atom:updated>
            <content:encoded><![CDATA[<p>Room Link : <a href="https://tryhackme.com/room/tomghost">https://tryhackme.com/room/tomghost</a></p><h3>I-ENUMERATION</h3><p>Let’s start by running <em>nmap</em> on the target :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*-_zrlQ--hqWoho6j8mmDjw.png" /></figure><p>Nmap shows a running Apache tomcat on 8080 :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BGYAUZZahTE8uiJma9RKkA.png" /></figure><p>After some research turns out <strong>tomcat 9.0.30</strong> is vulnerable to G<strong>hostCat</strong> exploit , hence the name of the room ”Tomghost”.</p><p>It refers to CVE-2020–1938, a.k.a. the GhostCat vulnerability (<a href="https://nvd.nist.gov/vuln/detail/CVE-2020-1938">https://nvd.nist.gov/vuln/detail/CVE-2020-1938</a>).</p><p>“CVE-2020–1938 is a file read/inclusion vulnerability in the AJP connector in Apache Tomcat. This is enabled by default with a default configuration port of 8009. A remote, unauthenticated attacker could exploit this vulnerability to read web application files from a vulnerable server. In instances where the vulnerable server allows file uploads, an attacker could upload malicious JavaServer Pages (JSP) code within a variety of file types and trigger this vulnerability to gain remote code execution (RCE). Because AJP is enabled by default in the /conf/server.xml file in Apache Tomcat 6, 7, 8 and 9, all unpatched versions of Tomcat are vulnerable to Ghostcat.”</p><h3>II-EXPLOIT</h3><p>There are many exploits to use but I chose using msfconsole for stable use :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*evlC70LAmxuijZegoMheSQ.png" /></figure><p>All we have to do is set the RHOSTS t othe target host :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7bFhmnvySgeOP9nowE7BtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*rWO-bpp34PEUdL58F0WMdA.png" /></figure><p>The exploit got us back what seems to be an ssh cred for user skyfuck.</p><h3>III-LATERAL MOVEMENT</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*ShTjeOTfhZARZg99qRyAsQ.png" /></figure><p>Logging in as “skyfuck” will get us these two files.</p><p>We also have a user “merlin” that we can get the user.txt flag from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*YqJdUYLPcd2Su7Zi6eSAgA.png" /></figure><p>Now we need to become “merlin” as the user “skyfuck” seems very useless.</p><p>Getting back to the two files we found at /home/skyfuck we can see that we have a creds file with an ascii armour for it.</p><p><strong>pgp :</strong></p><p>“Pretty Good Privacy is an encryption program that provides cryptographic privacy and authentication for data communication. PGP is used for signing, encrypting, and decrypting texts, e-mails, files, directories, and whole disk partitions and to increase the security of e-mail communications”</p><p>We can simply decrypt the creds with the key after we import it using the gpg command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*D4OSBNqClB2sYvTJ9nVw4w.png" /></figure><p>Unfortunetly this is protected with a passphrase.</p><p>Let’s get the files to our lcoal machine using scp :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*Gkb81eHK_Ztii11uqo18tg.png" /></figure><p>Now we can use <em>gpg2john</em> to create a hash then crack it using <em>john</em> :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*F6Bxq8i61RVhdFbynUFiig.png" /></figure><p>and we get the passphrase to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*v0LCWOfefqZWvWFMqXIqzA.png" /></figure><p>Repeat the decryption now using the passphrase and we get the creds for “merlin”</p><p>Now we can sign in as user “merlin”</p><h3>II-PRIVESC</h3><p>Running sudo -l we can see that the root can run the zip binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*sA33mtAPybo3BzgG6KUl8Q.png" /></figure><p><a href="https://gtfobins.github.io/gtfobins/zip/">zip | GTFOBins</a></p><p>Searching for an exploit on GTFObins , we find a valid one to use for privesc :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*dfNy-UkJlM2zdfxK8ERCfQ.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FH222yZmK4873vWKB7n%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FH222yZmK4873vWKB7n%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FH222yZmK4873vWKB7n%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="241" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b8b69309066dca2014bbfdc67f6bf87/href">https://medium.com/media/4b8b69309066dca2014bbfdc67f6bf87/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ad83b5b89c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writeup for “VulnNet”]]></title>
            <link>https://medium.com/@azer.sebei/writeup-for-vulnnet-3aecab47c2ef?source=rss-88588a343b03------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aecab47c2ef</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Azer Sebei]]></dc:creator>
            <pubDate>Wed, 16 Nov 2022 22:14:21 GMT</pubDate>
            <atom:updated>2022-11-16T22:14:21.317Z</atom:updated>
            <content:encoded><![CDATA[<p>A walkthrough on the TryHackMe VulnNet machine.</p><p>LINK:<a href="https://tryhackme.com/room/vulnnet1">https://tryhackme.com/room/vulnnet1</a></p><h3><strong>I-Enumeration :</strong></h3><p>Starting <em>nmap </em>on the target using the following options :</p><ul><li><strong>sC</strong> : Equivalent to — script=default</li><li><strong>sV </strong>: Service Version scan</li><li><strong>Pn</strong> : No ping scan ( With this option, nmap continues to perform its function, as if the host is active)</li></ul><p>And we get these results :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*9LJwyfvpO49Dk8h38fk2GQ.png" /></figure><p>We have an<strong> SSH</strong> open on the usual 22 , and an <strong>Apache http</strong> on port 80.</p><h4><strong>Directory Enumeration:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CU6ScVmOkpDrh0491fWcJQ.png" /></figure><p>Using <strong>Gobuster </strong>we can find these directories under the host:</p><p>Let’s first check the website :</p><p>The website vulnnet.thm is a two page website :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ux56aY4D54Wnm4ZUmgGZ-w.png" /></figure><p><strong>HOME</strong> : There is nothing interesting on the home page , the button “GET STARTED” takes us to the LOGIN page.</p><p><strong>SIGN IN</strong> :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*qYJ-NL-A3tetWt5PNCVC6A.png" /></figure><p>I have tried some default creds for this page but nothing is granting me access.</p><p>The<strong> SIGN UP</strong> and <strong>Forgot Password </strong>are useless.</p><p>The first thing we notice is the parameters on the URL :</p><p><a href="http://10.10.146.42/login.html?login=azer&amp;password=azer">http://vulnnet.thm/login.html?login=azer&amp;password=azer</a></p><p>Maybe I can fuzz the login and password parameter and get access with a usernames and rockyou lists using<strong> BurpSuite</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*x_B3AR8KSamGKvGly6VbuQ.png" /></figure><p>Sending this to the Intruder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GOafBrCfJwJD2e3cxwSSCw.png" /></figure><p>After setting the payloads the lists , using a pitchfork attack , we can enumerate through the the two lists:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*LjSwczC0boOUklBKTzVF4g.png" /></figure><p>Unfortunately I couldn’t get any match so I got back to tinckering more on the directories :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*Ah0d4FNFszHgfZTCji-dGg.png" /></figure><p>The /js folder contains two weird JavaScript files , using a beautifier I noticed a sub domaine <strong>broadcast.vulnnet.thm.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*xkTK4yt3EXRH_Wl7aEINaQ.png" /></figure><p>After adding the subdomain to /etc/hosts :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*L_SvxDLGH03Rp5Y097TCwQ.png" /></figure><p>More Sign Ins and more creds.</p><p>Let’s check the seconds Js file :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*0nDMZa-y9STALVHd7chBJw.png" /></figure><p>Using the referer param I tested for an LFI :</p><p>“http://vulnnet.thm/index.php?referer=/etc/passwd”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*xwosZoLw9ICxe5-3dAqk9A.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FcyntNbcW2R7O2BKWEA%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FcyntNbcW2R7O2BKWEA%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FcyntNbcW2R7O2BKWEA%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="320" frameborder="0" scrolling="no"><a href="https://medium.com/media/5398da8fe37baa062ea0c218445b3b7b/href">https://medium.com/media/5398da8fe37baa062ea0c218445b3b7b/href</a></iframe><h3>II-EXPLOITING</h3><p>Now since we ahve an LFI , all I need to do is understand the hierchy of the apache folder system in order to get the creds used to protect the <strong>broadcast.vulnnet.thm.</strong></p><p><a href="https://www.howtogeek.com/devops/how-to-find-your-apache-configuration-folder/">How to Find Your Apache Configuration Folder</a></p><p>Using this I located the default conf files that is sitting at :</p><p>Using the LFI with this payload:</p><p><a href="http://10.10.146.42/index.php?referer=/etc/apache2/.htpasswd">http://10.10.146.42/index.php?referer=/etc/apache2/.htpasswd</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*luKtanYv3kUtGklxdv9hzw.png" /></figure><p>The password is hached and we can use John to find the plaintext :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*IietTbFUZvaIx8VCOJsjmA.png" /></figure><p>Using the creds we now have we can access <strong>broadcast.vulnnet.thm</strong> :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IlrCXXKCVGQMUngXop3H0Q.png" /></figure><p>Welcome to <strong>CLIPBUCKET.</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl41m1r1sGwrwp30jK%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl41m1r1sGwrwp30jK%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl41m1r1sGwrwp30jK%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="272" frameborder="0" scrolling="no"><a href="https://medium.com/media/8720fc88c8f8586c6b896f0ce44077ec/href">https://medium.com/media/8720fc88c8f8586c6b896f0ce44077ec/href</a></iframe><p>Clipbucket is an Open Source OTT, VOD and Enterprise Video Hosting Solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Ln4PvGM5RrkrDEcYNQ-hg.png" /></figure><p>And yes it costs alot of money , and yes that screenshot if from the official Clipbucket website.</p><p>Unfortunetly for them we are using the <strong>CLIPBUCKET v4.0</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*YJu4NYfJebkRZtE45rLgdw.png" /></figure><p>I found an exploit on this version using msfconsole.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*qzq1sD4EQsv32M3j3PIJgA.png" /></figure><p>The exploit is failing and I guess it’s due to the authentication on the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t8buLZJtDec4RDQ4QGiPPA.png" /></figure><p>Searchsploit gave back a result on the exploit :</p><p><a href="https://www.exploit-db.com/exploits/44250">OffSec&#39;s Exploit Database Archive</a></p><p>Followoing the insctructions on the exploit.db page , I downloaded a phph rev shell from :</p><p><a href="https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php">php-reverse-shell/php-reverse-shell.php at master · pentestmonkey/php-reverse-shell</a></p><p>I modified the rev shell to my Ip and port 4444 and uploaded the file as the exploit guided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LyoW_JKyaTYVsC9gUGQ4gw.png" /></figure><p>Now we need to browse to : <a href="http://developers:9972761drmfsls@broadcast.vulnnet.thm/actions/CB_BEATS_UPLOAD_DIR/">http://developers:9972761drmfsls@broadcast.vulnnet.thm/actions/CB_BEATS_UPLOAD_DIR/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*ryMEG9aVRNOIksnc7DcLGQ.png" /></figure><p>The rev shell we uploaded is that weird named php file , clicking on it will execute the code and get a rev shell back to our netcat listener , hopefully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*wCxfAMUZB8Cm6KdhqKJGMg.png" /></figure><p>And we have shell.</p><p><a href="https://book.hacktricks.xyz/generic-methodologies-and-resources/shells/full-ttys">Full TTYs | HackTricks</a></p><p>Using this Hacktricks page we can get a fully stable interactive shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*4GcG7jJciBRK4MbfSZZnjA.png" /></figure><p>Inside /home we have a user named : server-management</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*-NZ595jjFctTuH7YbcjDGw.png" /></figure><h3><strong>Lateral movement :</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*t1qjmUgyq7WX_XCEC3e1tw.png" /></figure><p>The user “server-management” owns the file /var/backups/ssh-backup.tar.gz</p><p>Navigating to the folder we can copy the backup to /tmp and extract it there.</p><p>We can now copy the id_rsa to our machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*noV83XbpGxQJfJEe2TT0bA.png" /></figure><p>Using ssh2john we convert the id_rsa to a hash that we can crack using john.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*613qtv6qc681sTxHMGNYEA.png" /></figure><p>Now we can crack the hach to have a password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*aaurA5KU1MBFVMuPE43WWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*ktHklWqPACtZ8jqZxIGFwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*6Yznx6zOlqpZbo0RVFnhTw.png" /></figure><p>We are now the user “server-management”</p><h3>Privesc:</h3><p>For the privesc part I looped around linpease and many other rabbit holes , I will just explain the intended way that finally worked :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*NcwgmfF9Cb2TPDu8XiEAEw.png" /></figure><p>What is a cron :</p><p>“The cron command-line utility is a job scheduler on Unix-like operating systems. Users who set up and maintain software environments use cron to schedule jobs, also known as cron jobs, to run periodically at fixed times, dates, or intervals.”</p><p>Using the command shown in the screenshot we can see waht “jobs” are schedueld to run and on what user they are running.</p><p>We can see <strong>backupsrv.sh</strong> script running under <strong>root</strong> every 2 minutes.</p><p>Let’s check the script:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*pgxSP3ZLx0v1qSFBlmivBw.png" /></figure><p>The script is backing up the Documents folder using tar to compress the archive.</p><p>We can use GTFObins to see if we can do anything with tar as we can’t write to the script directly.</p><p><a href="https://gtfobins.github.io/gtfobins/tar/">tar | GTFOBins</a></p><p><strong>backup_files=”*”</strong></p><p>There is a wildcard vuln here and we can exploit it by creating 2 files which names will be interpreted as options passed to the tar command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_WKSeXKeFA7Bf_Jskq8aIQ.png" /></figure><p>We set us a rev shell at port 9999 and we wait for the cron job to execute so we get our shell executed.</p><p>2 minutes later :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*khmfXJ_8MgOfWaCm4JItKg.png" /></figure><p>And there you have it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FH222yZmK4873vWKB7n%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FH222yZmK4873vWKB7n%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FH222yZmK4873vWKB7n%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="241" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b8b69309066dca2014bbfdc67f6bf87/href">https://medium.com/media/4b8b69309066dca2014bbfdc67f6bf87/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aecab47c2ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WriteUp for “Internal” box.]]></title>
            <link>https://systemweakness.com/writeup-for-tryhackme-internal-box-bf27d0a4b140?source=rss-88588a343b03------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf27d0a4b140</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[internal]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[pentesting]]></category>
            <dc:creator><![CDATA[Azer Sebei]]></dc:creator>
            <pubDate>Wed, 26 Oct 2022 23:55:03 GMT</pubDate>
            <atom:updated>2022-11-02T13:48:13.015Z</atom:updated>
            <content:encoded><![CDATA[<h4>TryHackMe</h4><p>A short writeup for the machine Internal <a href="https://medium.com/u/dc49a0a3cb16">TryHackMe</a>.</p><p>Room’s link : <a href="https://tryhackme.com/room/internal">https://tryhackme.com/room/internal</a></p><p>After setting up the weird almost always crashing VPN we deploy the machine and start with basic enumeration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*uhsQ-MNIRzQtfQ0p39Hu-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fY1lbrix8v1lutYScNugw.png" /></figure><h3><strong>I-ENUMERATION.</strong></h3><p>Starting nmap with the given address of the machine with the following options:</p><ul><li><strong>sC</strong> : Equivalent to — script=default</li><li><strong>sV </strong>: Service Version scan</li><li><strong>Pn</strong> : No ping scan ( With this option, nmap continues to perform its function, as if the host is active)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*dURUvDqJWxsHKu0t9xuapA.png" /></figure><p><strong>We get the following results :</strong></p><p>We have an SSH running on port 22 that we should be able to abuse later on (maybe).</p><p>We have an Apache server running on port 80 that we need to lookup.</p><p>We also have a port 668 that we will check in case we run into a deadend.</p><p><strong>Checking the web server :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9v59xbes6iqHAKxWg0K7kA.png" /></figure><p>Checking the server at port 80 only got back the Apache Default Page , we need more digging and more enumeration.</p><p><strong>WEB ENUMERATION:</strong></p><p>Using <strong>Gobuster </strong>we can brute-force URIs including directories and files :</p><pre>gobuster <strong>dir</strong> -w /home/kali/Downloads/SecLists-master/Discovery/Web-Content/raft-medium-directories.txt -u <a href="http://10.10.77.2/">http://10.10.77.2/</a> <strong>-s</strong> &quot;204,301,302,307,401,403&quot; <strong>-x</strong> php,py,sh,js,txt <br></pre><p><strong>-dir</strong> to run gobuster as directory/file enumeration mode as there is also <strong>vhost </strong>for<strong> </strong>VHOST enumeration mode.</p><p><strong>-w </strong>is for the wordlist , I used the SecLists one that you can get from here :<strong> </strong><a href="https://github.com/danielmiessler/SecLists">https://github.com/danielmiessler/SecLists</a></p><p><strong>-s </strong>for status-codes that we want to see back</p><p><strong>-x</strong> for extentions we are looking for ( at this point we are looking for anything)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_unmDkO8yG0_UT4V5OEYtg.png" /></figure><p><strong>We got back results :</strong></p><p><em>/blog</em></p><p><em>/javascript</em></p><p><em>/phpmyadmin</em></p><p><em>/wordpress</em></p><p>We now have to investigate eash directory manually and see if we can find any outdated or missplaced systems.</p><p>Before we can reach any directory we need to add the domaine name to our hosts file .</p><pre>sudo nano /etc/hosts</pre><p>And add :</p><p><strong>“10.10.77.2&quot; internal.thm</strong><em> &lt;&lt;Don’t forget to use your given address&gt;&gt;</em></p><p><strong>/blog :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhaV-THMT9oCAfq5SzBXAA.png" /></figure><p>Immediatly using the <a href="https://www.wappalyzer.com/">Wappalyzer</a> or with the recent finding on /wordpress we can see that it’s using WordPress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*lQZskq7K9Vt_RFbDsjxPRQ.png" /></figure><p><strong>And a an outdated version of it.</strong></p><p>We can use wpscam (a tool to scan wordpress websites for exploits)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*x7FoQ01cbgwoz1voueqUoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*s54Z4rkRJI_2oZ0e1Syipg.png" /></figure><p>Let’s no rush into rabbit holes and keep digging.</p><h3>II-FINDING THE VULNERABLE PIECE.</h3><p>/blog is a blog website with a “Hello World!” first blog and a search query.</p><p>The article contains nothing of interest but the search function can be exploited :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*K5nQG64cEkMwiGybG06eRw.png" /></figure><p>Maybe we can fuzz the <strong>s </strong>paramater and get an /etc/passwd through an LFI.</p><p>Before we dive into another rabbit hole let’s keep investigating until we run out of ressoruces.</p><p>At the bottom of the page we have a login button :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*ozzip2h-uzkFCujNzIr5wQ.png" /></figure><p>That takes us to /wp-login.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*3LtbS6IrDgAw8H_IrnAoOg.png" /></figure><p>But we need credentials for this admin portal.</p><p>Using random creds for this results in an error :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*A6C_RaHeFUUjZaZJxvqsbA.png" /></figure><p>But a very weird error : <strong>Unknown username.</strong></p><p>Let’s try admin , wpadmin , root …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*_4GBwd8-FsyZ7AdREw7WMA.png" /></figure><p>The username admin got us a new error that confirms there is an admin username , all we have to do now is find the password.</p><p>We can use the same <strong>wpscan</strong> tool to bruteforce a password since we have a valid username.</p><pre>wpscan --url <a href="http://internal.thm/blog/wp-login.php">http://internal.thm/blog/wp-login.php</a> --usernames admin --passwords /usr/share/wordlists/rockyou.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*cfww6IkAE0J6mPUvI72H3w.png" /></figure><p>The password is not sexyme but we are trying at least.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*TizVzmGHQEXu_xyPBKABkw.png" /></figure><p>And we got a match after 6 long minutes.</p><p>Now that we have the password and username we can access the WordPress admin portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aiGGeaif0OXfTGkq9oPawg.png" /></figure><p><strong>HOWDY, ADMIN</strong></p><p>At this point I have already wasted 3 hours running around WordPress 5.4.2 exploits and trying every possible piece of code against every possible parametre.</p><p>Running through google I found this :</p><p><a href="https://www.hackingarticles.in/wordpress-reverse-shell/">WordPress: Reverse Shell - Hacking Articles</a></p><p>The only working exploit I managed to get my hands on is the theme editing one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/1*h6Y_tSgsuRe8mHWEBGrWEQ.png" /></figure><p>Using the theme editor we can edit php files of the already used theme.</p><p>Let’s inject a reverse shell inside the 404 template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z9GX_PfDS2YeI55LYqpIOQ.png" /></figure><p>I used the pentestmonkey php reverse shell :</p><p><a href="https://github.com/pentestmonkey/php-reverse-shell">GitHub - pentestmonkey/php-reverse-shell</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MzRS9MTa0j_nMuQZuckTIA.png" /></figure><p>Now we set up a listener on the port of choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*Pip3D3RQRT7dR_e7vYE-bQ.png" /></figure><p>To execute our payload we need to find the 404.php</p><p><em>http://internal.thm/wordpress/wp-content/themes/twentyseventeen/404.php</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*XDoLMvT0jiXE0MuISHeAdw.png" /></figure><p>And Volià , we have a reverse shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*9pLejz5tjDf55OTcJTbGIA.png" /></figure><p>Let’s be honest here , we can’t access anything but it looks cool .</p><p>We can check /etc for folders as there is phpmyadmin folder and wordpress folder but that is a very long rabbit hole (we can find creds there but I can’t do anything with it except sign into phpmyadmin portal) .</p><p>Going to opt we can find a file <strong>wp-save.txt </strong>, inside it we can find some ssh creds for the user aubreanna.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*YnSJfXb9vVa51Oj9jteBpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*pqvsSZfvJUZf_soO9K1k9g.png" /></figure><p>We can now get the user flag.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FCGHy1hQ1WPKDCz5Xk6%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FCGHy1hQ1WPKDCz5Xk6%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FCGHy1hQ1WPKDCz5Xk6%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5ef743f7077cbd95030163fbfe8261a/href">https://medium.com/media/d5ef743f7077cbd95030163fbfe8261a/href</a></iframe><h3>III-PRIVESC.</h3><p>aaaand the jenkins.txt as our endless persuit of power never ends.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*m_VxVXhaTf_x5hura3XGPQ.png" /></figure><p>We have a jenkins service running on the machine so we have to tunnel it in a way to our machine so we can investigate it.</p><blockquote>“Jenkins is <strong>an open source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language”</strong></blockquote><p><a href="https://www.howtogeek.com/168145/how-to-use-ssh-tunneling/">How to Use SSH Tunneling to Access Restricted Servers and Browse Securely</a></p><p>Using <strong>SSH tunneling</strong> I can simply establish an SSH connection with the SSH server and tell the client to forward traffic from a specific port from my local host (localhost:5555) to the address of the service and its port.</p><pre>ssh -L 5555:172.17.0.2:8080 aubreanna@10.10.77.2</pre><p>Now we can access the jenkins servcie on our localhost:5555</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*Ccp5UTZW83jLBsBD2u8zeA.png" /></figure><p>This late at night I will just brute force it using hydra and hope for the best.</p><p>This is a POST request to /j_acegi_security_check with the parameters :</p><p><strong>j_username</strong>=azer&amp;<strong>j_password</strong>=azer</p><blockquote>curl ‘<a href="http://localhost:5555/j_acegi_security_check&#39;">http://localhost:5555/j_acegi_security_check&#39;</a> -H ‘User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36’ -H ‘Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8’ -H ‘Accept-Language: en-US,en;q=0.5’ — compressed -H ‘Content-Type: application/x-www-form-urlencoded’ -H ‘Origin: <a href="http://localhost:5555&#39;">http://localhost:5555&#39;</a> -H ‘Connection: keep-alive’ -H ‘Referer: <a href="http://localhost:5555/login?from=%2F&#39;">http://localhost:5555/login?from=%2F&#39;</a> -H ‘Cookie: JSESSIONID.1a7bf1d9=node01vyhipn3iy1ob0ztg71e1t0183.node0; screenResolution=1920x975; JSESSIONID.976b665a=node01rznbnmyvgrsn1jzo23zyp03aw0.node0’ -H ‘Upgrade-Insecure-Requests: 1’ -H ‘Sec-Fetch-Dest: document’ -H ‘Sec-Fetch-Mode: navigate’ -H ‘Sec-Fetch-Site: same-origin’ -H ‘Sec-Fetch-User: ?1’ — data-raw ‘j_username=azer&amp;j_password=azer&amp;from=%2F&amp;Submit=Sign+in’</blockquote><p>This is the full request as cURL.</p><p>Using Hydra :</p><pre>hydra 127.0.0.1 -s 5555 -V -f http-form-post “/j_acegi_security_check:j_username=^USER^&amp;j_password=^PASS^&amp;from=%2F&amp;Submit=Sign+in&amp;Login=Login:Invalid username or password” -l admin -P /usr/share/wordlists/rockyou.txt</pre><ul><li>^USER^: tells Hydra to use the username or list in the field.</li><li>^PASS^: tells Hydra to use the password list supplied.</li><li>-l: indicates a single username</li><li>-P: indicates use the following password list e.g. rockyou.txt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*nG1_Q5mi07vM1taOdwj7jQ.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FgPBKtKGk00TfD3D6mY%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FgPBKtKGk00TfD3D6mY%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FgPBKtKGk00TfD3D6mY%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/843dcd590afd6a431bc0fe0de3f1dc80/href">https://medium.com/media/843dcd590afd6a431bc0fe0de3f1dc80/href</a></iframe><p>Using the fresh creds we found we can get to the jenkins service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0HEBreb6y37Ii-KQ90J6BQ.png" /></figure><p>Googling ways to exploit Jenkings to get a reverse shell I have found this Script Console exploit under Manage Jenkings Tab.</p><p><a href="https://www.n00py.io/2017/01/compromising-jenkins-and-extracting-credentials/">https://www.n00py.io/2017/01/compromising-jenkins-and-extracting-credentials/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_p00vzmXL1wSkQgSDJ9-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JyqKBE-N6hWfVEQd3ZEHxA.png" /></figure><p>Here we can execute a groovy script.</p><blockquote>Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk.</blockquote><p>Using the dear pentestmonkey we can get a simple java payload for reverse shell :</p><p><a href="https://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet">Reverse Shell Cheat Sheet</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*eiOXQEA_m4d8WnSBQFdMyg.png" /></figure><p>And we managed to get a reverse shell from the jenkins service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YLG1FAaK2SXwIpYGwa2RfQ.png" /></figure><p>Now we look inside the container and we can find in the /opt file a note containing the <strong>root ssh creds</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lzZMXK6ybU_1RMHA0z-ogg.png" /></figure><p>Now we just SSH to the machine with the freshly obtained creds and we are <strong>ROOT.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*Ebevejoozn3z1kOv4MqQTA.png" /></figure><p>I hope you enjoyed the writeup , I spend alot of time on the box and inside rabbit holes , the box is fun and informative .</p><p>Please get back to me with feedback on the writeup and ways to enhance my writing and documentation.</p><p><a href="https://www.linkedin.com/in/azer-sebei-59876a23a/">https://www.linkedin.com/in/azer-sebei-59876a23a/</a></p><p><a href="https://www.facebook.com/azer.sebei.5">https://www.facebook.com/azer.sebei.5</a></p><p>Happy Hacking .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf27d0a4b140" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/writeup-for-tryhackme-internal-box-bf27d0a4b140">WriteUp for “Internal” box.</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building An Actual OS (Without knowing anything) PART III]]></title>
            <link>https://medium.com/@azer.sebei/building-an-actual-os-without-knowing-anything-part-iii-1a245f67262c?source=rss-88588a343b03------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a245f67262c</guid>
            <dc:creator><![CDATA[Azer Sebei]]></dc:creator>
            <pubDate>Sat, 17 Sep 2022 16:18:40 GMT</pubDate>
            <atom:updated>2022-09-17T16:18:40.967Z</atom:updated>
            <content:encoded><![CDATA[<p>the worst part so far.</p><p>This part will be about memory.</p><p><strong>Goal: Learn how the computer memory is organized.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JxAlNWbhAy9VUNK3UtnY8g.png" /></figure><p>We said earlier how the CPU fetches and executes instructions from memory, and how it was BIOS that loaded our 512-byte boot sector into memory and then, having finished its initialisations, told the CPU to jump to the start of our code, whereupon it began executing our first instruction, then the next, then the next, etc. So our boot sector code is somewhere in memory; but <strong>where</strong>? We can imagine the main memory as long sequence of bytes that can individually be accessed by an address (i.e. an index), so if we want to find out what is in the 54th byte of memory, then 54 is our address. So the start of our boot-sector code, the very first machine code byte, is at some address in memory, and it was BIOS that put us there. We might assume, unless we knew otherwise, that BIOS loaded our code at the start of memory, at address 0x0.<strong> It’s not so straightforward</strong>, though, because we know that BIOS has already being doing initialisation work on the computer long before it loaded our code, and will actually continue to service hardware interrupts for the clock, disk drives, and so on. So these BIOS routines (e.g. ISRs, services for screen printing, etc.) themselves must be stored somewhere in memory and must be preserved (i.e. not overwritten) whilst they are still of use. As it turns out, BIOS likes always to load the boot sector to the address <strong>0x7c00</strong>, where it is sure will not be occupied by important routines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*W25NbXr--5mZcNLOVUNheg.png" /></figure><p>The best way to learn about this is to actually hide something in the memory and try finding it.</p><p>I could just bluntly tell you that the BIOS places it at 0x7C00 and get it done with, but an example with wrong solutions will make things clearer.</p><p>First lets define some data with a label :</p><pre>the_secret:<br>    db &quot;X&quot;</pre><p>then we will try to print out that character on the screen. To do this we need to figure out its <strong>absolute memory address</strong>, so we can load it into al and get BIOS to print it just like last time.</p><p><strong>Attempt 1 :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*iDYGMW-WqG3IVgoS9Y2NXg.png" /><figcaption>Don’t forget to define “the_secret” and add the magical number at the end and padding.</figcaption></figure><p>The problem with the first attempt is that it tries to load the immediate offset into al as the character to print, but actually we wanted to print the character at the offset rather than the offset itself.</p><p><strong>Attempt 2 :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*fEbKCuX9NeoZ4XIyWLN1VA.png" /></figure><p>The problem is, that the CPU treats the offset as though it was from the start of memory, rather than the start address of our loaded code, which would land it around about in the interrupt vector</p><p><strong>Attempt 3 :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*905F4w7_XL0blTTZQMWH6w.png" /></figure><p>In the third attempt, we add the offset the secret to the address that we beleive BIOS to have loaded our code,<strong> 0x7c00</strong>, using the CPU add instruction. We can think of add as the higher level language statement <strong>bx=bx + 0x7c00</strong>. We have now calculated the correct memory address of our ’X’ and can store the contents of that address in al, ready for the BIOS print function, with the instruction<strong> mov al, [bx].</strong></p><p><strong>Attempt 4 :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*Ti5nPAs7MgFTxIZlj7VJ2g.png" /></figure><p>In the fourth attempt we try to be a bit clever, by pre-calculating the address of the ’X’ after the boot sector is loaded into memory by BIOS. We arrive at the address 0x7c2d based on our earlier examination of the binary code which revealed that ’X’ was 0x2d bytes from the start of our boot sector ( you can check this using <strong>xxd file.bin</strong> command).</p><p>You can see the results of the four attempts here :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*2biGnAsspZAHCAZu7VngoQ.png" /><figcaption>the bytes following 1 and 2 are just random garbage</figcaption></figure><pre>mov ah, 0x0e</pre><pre>mov al, &quot;1&quot;<br>int 0x10<br>mov al, the_secret<br>int 0x10</pre><pre>mov al, &quot;2&quot;<br>int 0x10<br>mov al, [the_secret]<br>int 0x10</pre><pre>mov al, &quot;3&quot;<br>int 0x10<br>mov bx, the_secret<br>add bx, 0x7c00<br>mov al, [bx]<br>int 0x10</pre><pre>mov al, &quot;4&quot;<br>int 0x10<br>mov al, [0x7c2d]<br>int 0x10</pre><pre>jmp $ ;</pre><pre>the_secret:</pre><pre>db &quot;X&quot;</pre><pre>times 510-($-$$) db 0<br>dw 0xaa55</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*Hxk6ul_zcbN8v554bKnUMA.png" /></figure><p>So now we have seen how BIOS does indeed load our boot sector to the address 0x7c00, and we have also seen how addressing and assembly code labels are related. It is inconvenient to always have to account for this label — memory offset in your code, so many assemblers will correct label references during assemblege if you include the following instruction at the top of your code, telling it exactly where you expect the code to loaded in memory:</p><pre>[org 0x7c00]</pre><h3><strong>THE STACK :</strong></h3><p>When on the topic of low-level computing, we often hear people talking about the stack like it is some special thing. The stack is really just a simple solution to the following inconvenience:The CPU has a limited number of registers for the temporary storage of our routine’s local variables, but we often need more temporary storage than will fit into these registers; now, we can obviously make use of main memory, but specifying specific memory addresses when reading and writing is inconvenient, especially since we do not care exactly where the data is to be stored, only that we can retrieve it easily enough. And, as we shall see later, the stack is also useful for argument passing to realise function calls. So, the CPU offers two instructions <strong>push</strong> and <strong>pop</strong> that allow us, respectively, to store a value and retrieve a value from the top of the stack, and so without worrying exactly where they are stored. Note, however, that we cannot push and pop single bytes onto and off the stack. The stack is implemented by two special CPU registers, <strong>bp</strong> and <strong>sp</strong>, which maintain the addresses of the stack base (i.e. the stack bottom) and the stack top respectively. Since the stack expands as we push data onto it, we usually set the stack’s base far away from important regions of memory (e.g. such as BIOS code or our code) so their is no danger of overwriting if the stack grows too large. One confusing thing about the stack is that it actually grows downwards from the base pointer, so when we issue a push, the value actually gets stored below — — and not above — — the address of <strong>bp</strong>, and <strong>sp</strong> is decremented by the value’s size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*pm-yZEAhhsFUY5XQtt_9lg.png" /></figure><h4>Remember that the bp register stores the base address (i.e. bottom) of the stack, and sp stores the top, and that the stack grows downwards from bp (i.e. sp gets decremented).</h4><p>A simple example of Stack usage :</p><pre>mov ah, 0x0e ; tty mode </pre><pre>mov bp, 0x8000 ; this is an address far away from 0x7c00 so that we don&#39;t get overwritten</pre><pre>mov sp, bp ; if the stack is empty then sp points to bp </pre><pre>push &#39;A&#39;<br>push &#39;B&#39;<br>push &#39;C&#39;</pre><pre>jmp $times 510-($-$$) db 0<br>dw 0xaa55</pre><p>This will puch ‘A’ ,’B’,’C’ to the stack.</p><p>To prove that the stack grown downwards we can print the top of the stack using:</p><pre>mov al, [0x7ffe] ; 0x8000 - 2<br>int 0x10</pre><p>This will get back with an “A”</p><pre>mov al, [0x7ffc] ; 0x8000 - 4<br>int 0x10</pre><p>This will print “B”</p><p>We can also recover our characters using the standard procedure: ‘<strong>pop</strong>’</p><p>We can only pop full words so we need an auxiliary register to manipulate the lower byte</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*_NjFENJIIT76WbaPqtMNtQ.png" /></figure><p>Using <strong>POP will start printing from the bottom of the stack all the way to the beginning.</strong></p><p>C →B →A</p><p>Using all this useless information we will be creating our first <strong>EVOLVED “Hello World” </strong>program<strong>.</strong></p><p>We can simply create a printing function that we can call whenever we need or even better include it from a file , we won’t be forever printing things , we need to move to more important stuff.</p><p>At the CPU level a function is nothing more than a jump to the address of a useful routine then a jump back again to the instruction immediately following the first jump. We can kind of simulate a function call like this:</p><pre>mov al , ’H ’ ; Store ’H’ in al so our function will print it. <br>call <strong>my_print_function </strong><br>.<br>.<br>.<br><strong>my_print_function</strong> :<br>mov ah , 0 x0e ; int =10/ ah =0 x0e -&gt; BIOS tele - type output <br>int 0 x10 ; print the character in al <br>ret</pre><p>Our functions are almost self-contained now, but there is a still an ugly problem that we will thank ourselves later for if we now take the trouble to consider it. When we call a function, such as a print function, within our assembly program, internally that function may alter the values of several registers to perform its job (indeed, with registers being a scarce resource, it will almost certainly do this), so when our program returns from the function call it may not be safe to assume, say, the value we stored in <strong>dx</strong> will still be there. It is often sensible (and polite), therefore, for a function immediately to push any registers it plans to alter onto the stack and then pop them off again (i.e. restore the registers’ original values) immediately before it returns. Since a function may use many of the general purpose registers, the CPU implements two convenient instructions, <strong>pusha</strong> and <strong>popa</strong>, that conveniently push and pop all registers to and from the stack respectively.</p><p>nasm allows you to include external files literally as follows:</p><pre>%include “ my_print_function.asm “ ; this will simply get replaced by ; the contents of the file …</pre><pre>mov al , ’H ’ ; Store ’H’ in al so our function will print it.</pre><pre>call my_print_function</pre><p>We now have enough knowledge about the CPU and assembly to write a more sophisticated “Hello, World” boot sector program.</p><p>The boot_main.asm</p><pre>[org 0x7c00] ; tell the assembler that our offset is bootsector code</pre><pre>; The main routine makes sure the parameters are ready and then calls the function</pre><pre>mov bx, HELLO</pre><pre>call print</pre><pre>call print_nl</pre><pre>mov bx, GOODBYE<br>call print</pre><pre>call print_nl</pre><pre>; that&#39;s it! we can hang now<br>jmp $</pre><pre>; remember to include subroutines below the hang<br>%include &quot;boot_print.asm&quot;</pre><pre>; data<br>HELLO:<br>    db &#39;Hello, World&#39;, 0</pre><pre>GOODBYE:<br>    db &#39;Goodbye&#39;, 0</pre><pre>; padding and magic number<br>times 510-($-$$) db 0<br>dw 0xaa55</pre><p>The boot_print.asm</p><pre>print:<br>    pusha</pre><pre>; keep this in mind:<br>; while (string[i] != 0) { print string[i]; i++ }</pre><pre>; the comparison for string end (null byte)<br>start:<br>    mov al, [bx] ; &#39;bx&#39; is the base address for the string<br>    cmp al, 0 <br>    je done</pre><pre>; the part where we print with the BIOS help<br>    mov ah, 0x0e<br>    int 0x10 ; &#39;al&#39; already contains the char</pre><pre>; increment pointer and do next loop<br>    add bx, 1<br>    jmp start</pre><pre>done:<br>    popa<br>    ret</pre><pre>print_nl: ;for new lines<br>    pusha<br>    <br>    mov ah, 0x0e<br>    mov al, 0x0a ; newline char<br>    int 0x10<br>    mov al, 0x0d ; carriage return<br>    int 0x10<br>    <br>    popa<br>    ret</pre><p>Now the print function can be re-used somewhere else along the line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*WSxSamibDc5T-_L-T8cjpQ.png" /></figure><p>Still, it feels that we have not come very far. That’s okay, and that’s quite normal, given the primitive environment that we have been working in. If you have understood all up until here, then we are well on our way.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl3q2Z5667uYOJ2U6I%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl3q2Z5667uYOJ2U6I%2Fgiphy-downsized.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl3q2Z5667uYOJ2U6I%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="313" frameborder="0" scrolling="no"><a href="https://medium.com/media/f49d272b86f5b5c159f3b056e8a10e5b/href">https://medium.com/media/f49d272b86f5b5c159f3b056e8a10e5b/href</a></iframe><p>REF:</p><p>“<a href="https://github.com/topics/operating-systems-project">https://github.com/topics/operating-systems-project</a>”</p><p>“<a href="https://www.youtube.com/c/AndreasKling/playlists">https://www.youtube.com/c/AndreasKling/playlists</a>”</p><p><a href="https://github.com/cfenollosa">“https://github.com/cfenollosa</a>”</p><p>“<a href="https://computersciencewiki.org/index.php/Architecture_of_the_central_processing_unit_(CPU)">https://computersciencewiki.org/index.php/Architecture_of_the_central_processing_unit_(CPU)</a>”</p><p>“<a href="https://www.geeksforgeeks.org/guide-to-build-an-operating-system-from-scratch/">https://www.geeksforgeeks.org/guide-to-build-an-operating-system-from-scratch/</a>”</p><p><a href="https://www.sciencedirect.com/topics/engineering/stack-memory">“https://www.sciencedirect.com/topics/engineering/stack-memory</a>”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a245f67262c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building An Actual OS (Without knowing anything) Part II]]></title>
            <link>https://medium.com/@azer.sebei/building-an-actual-os-without-knowing-anything-part-ii-f199fb6f4571?source=rss-88588a343b03------2</link>
            <guid isPermaLink="false">https://medium.com/p/f199fb6f4571</guid>
            <category><![CDATA[operating-systems]]></category>
            <dc:creator><![CDATA[Azer Sebei]]></dc:creator>
            <pubDate>Thu, 08 Sep 2022 15:19:43 GMT</pubDate>
            <atom:updated>2022-09-08T15:42:14.954Z</atom:updated>
            <content:encoded><![CDATA[<p>The part where I pretend to know things that I don’t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*14DYCSGrWq24GaSr2Wc93Q.jpeg" /></figure><p>Since you all requested I go through the agony of working on this , in this part we will be attempting to write some words on the screen and pretend everything is going as planned.</p><p><strong>Goal: Make our previously silent boot sector print some text</strong></p><p>After the great accomplishment of creating our first boot sector and trying it first hand , some say we got lucky but I’d say its pure skills.</p><p>The files is working perfectly and the BIOS is recongnizing it as an actual OS.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FS6Hyy3F1bd90uMYDXj%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FS6Hyy3F1bd90uMYDXj%2Fgiphy-downsized.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FS6Hyy3F1bd90uMYDXj%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0dc3e4235f145f65732405a33f7c1e9/href">https://medium.com/media/e0dc3e4235f145f65732405a33f7c1e9/href</a></iframe><p>We now need to start making some things with this file , we need to start getting our CPU to work.</p><p>What a better classic way to do this than printing the famous “Hello World” on our screen.</p><p>If this was a coding tutorial this will be easy and fun , you write some code and there you have it.</p><p>But <strong>NO , this is not a happy place , this the lowest scum level of coding .</strong></p><h4>WELCOME TO THE CPU BOIS , THE GREATEST INVETION OF MANKIND.</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F2U1WOzgmZVw2Y%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F2U1WOzgmZVw2Y%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F2U1WOzgmZVw2Y%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="290" frameborder="0" scrolling="no"><a href="https://medium.com/media/a14d3aaae43ad8f428ee3bb499938626/href">https://medium.com/media/a14d3aaae43ad8f428ee3bb499938626/href</a></iframe><p>Firstly, let’s think about what we are trying to do here. We’d like to print a character on the screen but we do not know exactly how to communicate with the screen device, since there may be many different kinds of screen devices and they may have different interfaces. This is why we need to use BIOS, since BIOS has already done some auto detection of the hardware and, evidently by the fact that BIOS earlier printed information on the screen about self-testing and so on, so can offer us a hand. So, next, we’d like to ask BIOS to print a character for us, but how do we ask BIOS to do that? Here we can make use of a fundamental mechanism of the computer: <strong>Interrupts</strong>.</p><p>Interrupts are a mechanism that allow the CPU temporarily to halt what it is doing and run some other, higher-priority instructions before returning to the original task. An interrupt could be raised either by a software instruction (e.g.<strong> int 0x10</strong>) or by some hardware device that requires high-priority action (e.g. to read some incoming data from a network device). Each interrupt is represented by a unique number that is an index to the interrupt vector, a table initially set up by BIOS at the start of memory (i.e. at physical address 0x0) that contains address pointers to interrupt service routines (<strong>ISRs</strong>). An <strong>ISR</strong> is simply a sequence of machine instructions, much like our boot sector code, that deals with a specific interrupt (e.g. perhaps to read new data from a disk drive or from a network card). So, in a nutshell, BIOS adds some of its own ISRs to the interrupt vector that specialise in certain aspects of the computer, for example: interrupt <strong>0x10</strong> causes the screen-related ISR to be invoked; and interrupt <strong>0x13</strong>, the disk-related I/O ISR. However, it would be wasteful to allocate an interrupt per BIOS routine, so BIOS multiplexes the ISRs by what we could imagine as a big<strong> switch</strong> statement, based usually on the value set in one of the CPUs general purpose registers, <strong>ax</strong>, prior to raising the interrupt.</p><p>You can find a list of all possible interrupts in this weird old file : <a href="https://ostad.nit.ac.ir/payaidea/ospic/file1615.pdf">https://ostad.nit.ac.ir/payaidea/ospic/file1615.pdf</a></p><p>Just as we use variables in a higher level languages, it is useful if we can store data temporarily during a particular routine. All x86 CPUs have four general purpose registers, ax, bx, cx, and dx, for exactly that purpose. Also, these registers, which can each hold a word (two bytes, 16 bits) of data, can be read and written by the CPU with negligible delay as compared with accessing main memory.</p><p>Please disregard all that nonsense and lets break it down simply .</p><p>To write letters on our screen we need the BIOS to do that for us.</p><p>To do that we need to invoke a specific BIOS routine by setting <strong>ax (CPU register ) </strong>to some BIOS-defined value and then triggering a specific interrupt .</p><p>The specific routine we want is the BIOS scrolling <strong>teletype routine</strong>, which will print a single character on the screen and advance the cursor, ready for the next character. <strong>TTY</strong></p><p>There is a whole list of BIOS routines published that show you which interrupt to use and how to set the registers prior to the interrupt. Here, we need interrupt <strong>0x10</strong> and to set <strong>ah</strong> to <strong>0x0e</strong> (to indicate tele-type mode) and <strong>al</strong> to the ASCII code of the character we wish to print.</p><p><a href="https://en.wikipedia.org/wiki/BIOS_interrupt_call#:~:text=BIOS%20interrupt%20calls%20can%20be,requested%20action%20to%20the%20caller">https://en.wikipedia.org/wiki/BIOS_interrupt_call#:~:text=BIOS%20interrupt%20calls%20can%20be,requested%20action%20to%20the%20caller</a>.</p><p><strong>ah</strong> and <strong>al</strong> are the lower and higher parts of <strong>ax.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oS-JIeQJYqyUkONYA2AGuQ.png" /></figure><p>1-So we need to first write the bytes <strong>0x0e</strong> to<strong> ah (to set the TTY mode in the BIOS)</strong></p><p>2-Write the first letter of our word in the<strong> al</strong></p><p>3-Raise the interrput <strong>0x10</strong> that will print the letter in the al and advance the cursor for the next.</p><p>4-Next letter and repeat the interruption.</p><p>5-A padding until we get to the magic boot sector number 0xaa55</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*b8r_suZYdbzcZJWi1SIEPw.png" /></figure><p>You know the drill after that :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-h5o5oBQm2yrjOHFoLfZSw.png" /></figure><p><strong>nasm -fbin boot.asm -o boot.bin</strong> to create the bin</p><p>and <strong>qemu boot.bin</strong> or <strong>qemu-system-x86–64 boot.bin </strong>to start the emulation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/243/1*Sx4R_pEc7oVaUO5GrYByDg.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FiKGFSJa420aUklze0O%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FiKGFSJa420aUklze0O%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FiKGFSJa420aUklze0O%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="346" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f2d8f6aeb4f84a2e210c6bdcadd4ee2/href">https://medium.com/media/3f2d8f6aeb4f84a2e210c6bdcadd4ee2/href</a></iframe><p><strong>If you are surprised by the amount of effort and understanding that is involved in writing such a barely useful program, then remember that these instructions map very closely to the CPU’s circuitry, so necessarily they are very simple, but also very fast. You are getting to know your computer now, as it really is.</strong></p><p>This took so long already for a simple Hello but we are getting there , slwoly but surely.</p><p>Until next time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5BvrVsSW7gOkj52Tmy9pA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f199fb6f4571" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building An Actual OS (Without knowing anything)]]></title>
            <link>https://medium.com/@azer.sebei/building-an-actual-os-without-knowing-anything-5a95ab2462cb?source=rss-88588a343b03------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a95ab2462cb</guid>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Azer Sebei]]></dc:creator>
            <pubDate>Sun, 04 Sep 2022 15:06:21 GMT</pubDate>
            <atom:updated>2022-09-04T15:18:18.709Z</atom:updated>
            <content:encoded><![CDATA[<p>This is my journey of building an OS , from the lowest level to actual usage without any knowledge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2BKbKQlERyBVgRNtFqxZVw.jpeg" /></figure><p><strong>Who Am I :</strong></p><p>NVM.</p><p><strong>Why Am I building an OS ? (Just use one of the available ones already )</strong></p><p>I’m not on the quest to build an OS for actual usage or to compete with Linux and Windows.</p><p>I’m trying to build an OS for the simple reason of learning how every line of code works on the lowest level of the machine.</p><p>Low level programming is a fun and exciting task, because you have to do everything. This may seem more difficult (it is, don’t worry) but by the same reasons more fun. You know how everything works, how it all fits, and the inner-most workings of your program.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FCz6TlrRVVyv9S%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FCz6TlrRVVyv9S%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FCz6TlrRVVyv9S%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="318" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0acc847bda26cfee61ed5a10dfaacd7/href">https://medium.com/media/e0acc847bda26cfee61ed5a10dfaacd7/href</a></iframe><p><strong>How long will this take ?</strong></p><p>Spoiler alert !</p><p>This will take an eternity to build and learn,</p><p>I’ll try to post on weekly basis depending on the availabilty and how much progress I made.</p><p><strong>Why are you writing an article about it ?</strong></p><p>This article will be documenting my learning curve , this is not a How-To guide or a Tutorial.</p><p>This is a documentation of my weekly progress as I learn new notions and walkthrough this project step by step.</p><p>There will be mistakes , there will be trials and errors , it will be fun trust me.</p><p><strong>Will this be an in-depth guide ?</strong></p><p>Using this article or the set of articles (depending on how long am I interested in this before I give up and start doing something else) I will try to explain everything I’m learning in a simple fun language for everyone to understand.</p><p>This doesn’t mean that this is a definitive guide or a correct one as my interpretation of some informations might be wrong as I learn.</p><p>I will try to list every guide/article/readme/paper I used along the way as they are the “correct” way to do this.</p><p>My approach for this is to tinker my way through until I have a grasp of the methodology behind it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FllKJGxQ1ESmac%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FllKJGxQ1ESmac%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FllKJGxQ1ESmac%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="327" frameborder="0" scrolling="no"><a href="https://medium.com/media/f83d44203814a207602eac783bf2712d/href">https://medium.com/media/f83d44203814a207602eac783bf2712d/href</a></iframe><p><strong>Can I join ?</strong></p><p>Everyone is welcome to join this all you need to do is contact me about this and we will get to work.</p><p>I will also creat a git repo for this that anyone can fork any progress I make and build on it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F61tYloUgq1eOk%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F61tYloUgq1eOk%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F61tYloUgq1eOk%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="284" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f813e316a6686fbd419017e69f30b50/href">https://medium.com/media/1f813e316a6686fbd419017e69f30b50/href</a></iframe><h3>FIRST THINGS FIRST , WTF is an OS 😮.</h3><p>We’ve all used an operating system (OS) before (e.g. Windows XP, Linux, etc.), and perhaps we have even written some programs to run on one; but what is an OS actually there for? how much of what I see when I use a computer is done by hardware and how much is done by software? and <strong>how does the computer actually work?</strong></p><p><strong>The moment we start the computer our journey begins.</strong></p><ul><li><strong><em>Hour Zero.</em></strong></li></ul><p>Initially without any notion of an operating system. Somehow, it must load the operating system from any permanent storage device that is currently attached to the computer (e.g. a floppy disk, a hard disk, a USB dongle, etc.). As we will shortly discover, the<em> </em><strong><em>pre-OS environment</em></strong> of the computer offers nothing but choas,Luckily, what we do have is <strong>the Basic Input/Output Software (BIOS)</strong>,</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FiVuViWKkkyElq%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FiVuViWKkkyElq%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FiVuViWKkkyElq%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="725" frameborder="0" scrolling="no"><a href="https://medium.com/media/b62c4aeb042098aee4893cf07d50cdc4/href">https://medium.com/media/b62c4aeb042098aee4893cf07d50cdc4/href</a></iframe><p>BIOS comes included with computers, on a chip on the motherboard. In contrast, an OS like Windows or iOS can either be pre-installed by the manufacturer or vendor or installed by the user. BIOS is a program that is made accessible to the microprocessor on an erasable programmable read-only memory (EPROM) chip. When users turn on their computer, the microprocessor passes control to the BIOS program, which is always located at the same place on EPROM.</p><p>When BIOS boots up a computer, it first determines whether all of the necessary attachments are in place and operational. Any piece of hardware containing files the computer needs to start is called a <em>boot device</em>. After testing and ensuring boot devices are functioning, BIOS <strong>loads the OS.</strong></p><p>These tasks are each carried out by BIOS’ four main functions:</p><ol><li><strong>Power-on self-test (</strong><a href="https://www.techtarget.com/whatis/definition/POST-Power-On-Self-Test"><strong>POST</strong></a><strong>).</strong> This tests the hardware of the computer before loading the OS.</li><li><strong>Bootstrap loader.</strong> This locates the OS.</li><li><strong>Software/drivers.</strong> This locates the software and drivers that interface with the OS once running.</li><li><strong>Complementary metal-oxide semiconductor (</strong><a href="https://www.techtarget.com/whatis/definition/CMOS-complementary-metal-oxide-semiconductor"><strong>CMOS</strong></a><strong>) setup.</strong> This is a configuration program that enable users to alter hardware and system settings. CMOS is the name of BIOS’ non-volatile memory.</li></ol><p>We don’t have to get in depth with the BIOS as our journey starts right after it decides that everything is running fine and now needs to <strong>load the OS.</strong></p><p>BIOS cannot simply load a file that represents your operating system from a disk, since BIOS has no notion of a filesystem. BIOS must read specific sectors of data (usually 512 bytes in size) from specific physical locations of the disk devices. So, the easiest place for BIOS to find our OS is in the first sector of one of the disks (i.e. Cylinder 0, Head 0, Sector 0), known as the boot sector. Since some of our disks may not contain an operating systems (they may simply be connected for additional storage), then it is important that BIOS can determine whether the boot sector of a particular disk is boot code that is intended for execution or simply data. Note that the CPU does not differentiate between code and data: both can be interpreted as CPU instructions.</p><p><strong>How does the dumb BIOS knows that it found an OS not your weird p*** files.</strong></p><p>The last two bytes of an intended boot sector must be set to the magic number <strong>0xaa55</strong>. So, BIOS loops through each storage device , reads the boot sector into memory, and instructs the CPU to begin executing the first boot sector it finds that ends with the magic number.</p><h4>This is where we seize control of the computer.</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3orieOART1XalQ7XzO%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3orieOART1XalQ7XzO%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3orieOART1XalQ7XzO%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="328" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5d7048ce65ebc63e3b0a310797403b1/href">https://medium.com/media/a5d7048ce65ebc63e3b0a310797403b1/href</a></iframe><p><strong>How does a boot sector looks like ?</strong></p><p>We can craft ourselves a simple yet valid boot sector using TextPad or Ghex</p><p>All we need is a beginning , a 510 byte long of Zero and the last two bytes has to be the magical boot bytes <strong>0xAA55.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*1skAaQI_sBugdzUTt9AsCQ.png" /></figure><p>Once the BIOS finds the last two bytes it can confirm thats this is indeed a boot block and not just raw hex p*** files that happens to be on a drive’s boot sector.</p><p>Note :</p><ul><li>The initial three bytes, in hexadecimal as 0xe9, 0xfd and 0xff, are actually machine code instructions, as defined by the CPU manufacturer, to perform an endless jump.(we’ll get to that in a second).</li><li>The file is padded with zeros basically to position the magic BIOS number at the end of the 512 byte disk sector.</li><li>beware of endianness, x86 is little-endian — as the last two bytes are 55 aa but written as 0xAA55 (less significant bytes proceed more significant bytes).</li></ul><p>You can also write the same code in assembly :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*J-JxxozwDMJbHSZlBmMDKg.png" /></figure><p>and will get to how to actually compile this and create a binary file form it.</p><blockquote><strong>Remember, it is us that program the computer, and the computer follows our instructions blindly, fetching and executing them, until it is switched off; so we need to make sure that it executes our crafted code rather than random bytes of data held somewhere in memory. At this low level, we have a lot of power and responsibility over our computer, so we need to learn how to control it.</strong></blockquote><p><strong>How are we testing this ?</strong></p><p>There are a few ways to do this.</p><p>We can use virtual machine software, such as VMWare or VirtualBox, and set the boot block code as a disk image of a virtual machine, then start-up the virtual machine. You can be sure this code has been loaded and executed if your computer simply hangs after booting, without a message such as “No operating system found”. This is the infinite loop at work, that we put at the start of the code.</p><p>Or we a CPU Emulator: Bochs or QEmu.</p><p>You can use this to install QEmu as I will be using it <a href="https://www.makeuseof.com/how-to-install-qemu-ubuntu-set-up-virtual-machine/">https://www.makeuseof.com/how-to-install-qemu-ubuntu-set-up-virtual-machine/</a></p><p>This can be a personal prefereance as I have no idea what are they built for but we will be trying them soon.</p><p>We will also need NASM in case you don’t have it already on linux.</p><p><a href="https://www.tutorialspoint.com/assembly_programming/assembly_environment_setup.htm">Assembly - Environment Setup</a></p><p>It is an assembler and disassembler for the Intel x86 architecture. It can be used to write 16-bit, 32-bit and 64-bit programs , this will convert our literal code of loops and jumps into a bin that we can test on our machine.</p><p>Remember this code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*J-JxxozwDMJbHSZlBmMDKg.png" /></figure><p>This is just a loop and it does nothing , we just need it for testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*a3j8Hju8lF18aj-ZFOxanQ.png" /></figure><p>After compiling the assembly file , use : qemu boot_sect_simple.bin to start the instance to try the code on the machine emulator.</p><p><strong>Please try this one if the last command doesn’t work</strong> : qemu-system-x86_64 boot_sect_simple.bin</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F0BorfbLqQKOWvijK0x%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F0BorfbLqQKOWvijK0x%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F0BorfbLqQKOWvijK0x%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/17d2faaeaae6ea08b7e3a20d215dfd3d/href">https://medium.com/media/17d2faaeaae6ea08b7e3a20d215dfd3d/href</a></iframe><p>Here you have it , our first glimpse of the OS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9XqFphDPE2iVMTLFCo3FUQ.png" /></figure><p>We are the operating system now, albeit at this stage with nothing more to offer than an endless loop — — but we will soon build up from this.</p><p>As we will see, all operating systems must start this way and then pull themselves up into higher level abstractions</p><p>Thank you all for reading , If you have any questions please contact me as I will be happy to explain anything , if you have anything to add or anything I may have missed also feel free to comment or contact me.</p><p>This will be the first of many articles documenting this journey.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fntl8yJ3ctzYHdJPm02%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fntl8yJ3ctzYHdJPm02%2Fgiphy-downsized.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fntl8yJ3ctzYHdJPm02%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc2682677052d8d7bcc24f32008ae5d2/href">https://medium.com/media/bc2682677052d8d7bcc24f32008ae5d2/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a95ab2462cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>