<?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 Szwochm on Medium]]></title>
        <description><![CDATA[Stories by Szwochm on Medium]]></description>
        <link>https://medium.com/@szwochm?source=rss-8d0ed343ccf8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*bJYldfGbjTcUxN9N</url>
            <title>Stories by Szwochm on Medium</title>
            <link>https://medium.com/@szwochm?source=rss-8d0ed343ccf8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:10:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@szwochm/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[Journey to Becoming a Certificate Wizard Part 4: Creating a PKI — The CA]]></title>
            <link>https://szwochm.medium.com/journey-to-becoming-a-certificate-wizard-part-4-creating-a-pki-the-ca-ad66fb9fbf7b?source=rss-8d0ed343ccf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad66fb9fbf7b</guid>
            <category><![CDATA[small-steps]]></category>
            <category><![CDATA[x509]]></category>
            <category><![CDATA[certificate-authority]]></category>
            <category><![CDATA[pki]]></category>
            <category><![CDATA[infrastructure]]></category>
            <dc:creator><![CDATA[Szwochm]]></dc:creator>
            <pubDate>Thu, 21 Aug 2025 23:54:08 GMT</pubDate>
            <atom:updated>2025-08-22T00:10:56.299Z</atom:updated>
            <content:encoded><![CDATA[<h3>Journey to Becoming a Certificate Wizard Part 4: Creating a PKI — The CA</h3><p>Okay, so it seems like <em>making</em> a Certificate Authority (CA) is easy. On the other hand… maintaining a CA — managing certificate lifecycles, revocation lists, and integrating with group policy — is a whole different beast.</p><p>For starters, Root CAs are generally kept offline and only powered on to perform critical tasks like signing intermediate certificates or updating CRLs. They’re typically isolated and air-gapped to minimize exposure and protect the private key.</p><p>Here’s an image of how the network topology would look if I extended the virtual network I set up. The Secure Transfer Laptop would connect to the air-gapped network, retrieve the necessary files, and then disconnect from the server once the transfer is complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q1cpcrnH__9LusX6_9mSDg.png" /><figcaption>Logical map of my virtual network(s). Packet Tracer</figcaption></figure><p>Once the files are on the secure transfer laptop, the laptop disconnects from the air-gapped network. From there, the media is distributed to the rest of the network.</p><p>Now, there are a few clunky ways to emulate this setup in VirtualBox. I could spin up a host and toggle its network interface so that it’s only part of one network at a time. Alternatively, I could use shared folders and treat my host machine as the “secure” file transfer device. I didn’t want to do either of those options, so instead, here is the network topology I decided to use:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*QTbVO16kLEsgCI9zVIo3LA.png" /><figcaption>Probably shouldn’t do this in production</figcaption></figure><p>In this virtual network, only the intermediate CA servers would have an interface to the root CA’s virtual network.</p><p>It’s important to note that<strong> this topology is a risky practice in production</strong>. If the intermediate CA servers were ever compromised, they could be used as a pivot to attack the root CA — effectively invalidating the entire trust model. But since this setup is purely for learning, I’ve opted for convenience over strict security.</p><p>Okay, lets get started.</p><p><strong>Step 1: Create the Root CA</strong></p><p>There’s a couple of solutions out there that you can use to manage your PKI, I opted for Smallstep.</p><p>I spun up a new instance of Ubuntu Server, added SmallStep to my repo, and installed <strong>step-ca</strong> as well as <strong>step-cli</strong></p><pre>curl -fsSL https://packages.smallstep.com/keys/apt/repo-signing-key.gpg -o /etc/apt/trusted.gpg.d/smallstep.asc<br>echo &#39;deb [signed-by=/etc/apt/trusted.gpg.d/smallstep.asc] https://packages.smallstep.com/stable/debian debs main&#39; | sudo tee /etc/apt/sources.list.d/smallstep.list<br>sudo apt update<br>sudo apt install step-ca step-cli</pre><p>Then I ran step ca init to set up my server as a CA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*li8aL1xgz2PKnLjrhWUmLg.png" /><figcaption>don’t steal my finger print please</figcaption></figure><p>Just like that, my Root Certificate Authority is set up and ready to go!</p><p>The initialization process does a few key things: it generates two key pairs — one for the root CA and one for the intermediate keys. At this point, the <strong>root private key</strong> is taken offline and stored securely, because it represents the <strong>trust anchor</strong> of the entire PKI. If that key were ever compromised, the integrity of the entire certificate hierarchy would be invalidated, and no issued certificates could be trusted.</p><p><strong>Step 2: Add an intermediate CA</strong></p><p>Now we will expand the PKI and add an intermediate CA. The intermediate CA doesn’t trust my root CA out of the box. So I run the following command on the intermediate server:</p><pre>step ca bootstrap - ca-url 192.168.200.1 - fingerprint [CA fingerprint]</pre><p>Forgot the fingerprint? Just extract it from the root cert and run step ca init to prep the server.</p><pre>step certificate fingerprint $(step path)/certs/root_ca.crt</pre><p>I also ran the step ca init command to generate the boilerplate and get this server ready. It sets up the basic directory structure, configuration files, and keys needed for the CA to function. Think of it as laying the foundation before you start issuing certs. All of the certs generated from this command will be replaced shortly after.</p><p>As before, this generates two key pairs. Per Smallstep’s instructions, I shredded the newly generated root_ca_key, since it won’t be used on the intermediate CA:</p><pre>shred -u $(step path)/secrets/root_ca_key</pre><p>I also replaced the root_ca_crt with the root CA’s public key.</p><pre><br>mv rootcapublickey.crt $(step path)/certs/root_ca.crt</pre><p>Now let’s get this intermediate CA server its certificate!</p><p>First, I generate the intermediate key pair and the signing request:</p><pre>step certificate create &quot;intca01&quot; intermediate.csr intermediate_ca_key -csr</pre><p>Then, on my root CA box, I fire up the certificate authority service:</p><pre>step-ca $(step path)/config/ca.json</pre><p>Back on the intermediate server, I send the signing request to the root CA:</p><pre>step ca sign intermediate.csr intermediate.crt --ca-url 192.168.200.1:443 --root $(step path)/certs/root_ca.crt</pre><p>This signs the intermediate certificate using the root, completing the trust chain. Now the intermediate CA is officially blessed and ready to start issuing certs.</p><p>Finally, I replace the placeholder files generated by step ca init with the newly signed ones:</p><pre>mv intermediate.crt $(step path)/certs/intermediate_ca.crt<br>mv intermediate_ca_key $(step path)/secrets/intermediate_ca_key</pre><p>Now this may seem a little confusing so I made a flow chart of how I think it works. I wasn’t too sure about how the Root Ca’s Intermediate public key is used but otherwise I believe it works as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*ZjAoQ84biDiya5NFlNwBQA.png" /><figcaption>more or less — give me a break its my first one!</figcaption></figure><p>And just like that, in <em>just “</em>two” easy steps, our PKI is set up!</p><p>So what&#39;s next? All we need to do is install the root public key in endpoint trust stores and distribute leaf certificates to the servers. After that we can play with certificate life cycles, revocation, etc…</p><p>Until next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad66fb9fbf7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Journey to becoming a certificate wizard Part 3: The sniff test — What’s that smell?]]></title>
            <link>https://szwochm.medium.com/journey-to-becoming-a-certificate-wizard-part-3-the-sniff-test-whats-that-smell-5dca84f1e566?source=rss-8d0ed343ccf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dca84f1e566</guid>
            <category><![CDATA[openssl]]></category>
            <category><![CDATA[packet-sniffing]]></category>
            <category><![CDATA[web-server]]></category>
            <category><![CDATA[wireshark]]></category>
            <category><![CDATA[lighttpd]]></category>
            <dc:creator><![CDATA[Szwochm]]></dc:creator>
            <pubDate>Fri, 15 Aug 2025 00:29:03 GMT</pubDate>
            <atom:updated>2025-08-15T00:29:42.842Z</atom:updated>
            <content:encoded><![CDATA[<h3>Journey to becoming a certificate wizard Part 3: The sniff test — What’s that smell?</h3><p>A few days ago, I <a href="https://szwochm.medium.com/journey-to-becoming-a-certificate-wizard-part-2-setting-up-a-test-network-2a30c0778efb">set up a VirtualBox internal network</a> with a host machine and a server. The server is running a DHCP service and will soon be hosting a web server.</p><p>Just for fun, let’s see how the server appears from an outside perspective</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*FarFdEh5UDcm4KOBKmMKYg.png" /><figcaption>nmap stealth scan — TCP, all ports</figcaption></figure><p>As expected, only SSH (and DHCP on the UDP side) responded to the scan.</p><p>Let’s start by limiting SSH access to the internal network, and then we’ll move on to adding some functionality.</p><p>To do this, I edit the /etc/ssh/sshd_config file and set the ListenAddress to the IP address of my virtual network adapter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*Mk3ytUFfIlpANoAObiPxdg.png" /><figcaption>ssh config on webserver</figcaption></figure><p>And just to play around with the firewall a bit, let’s limit SSH traffic to only the virtual network interface using persistent iptables.</p><pre>sudo apt install iptables-persistent<br><br>sudo iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT<br>sudo iptables -A INPUT -p tcp --dport 22 -j DROP<br><br>sudo netfilter-persistent save</pre><p>For this next part, I SSH into the server from my virtual network’s host machine. Ubuntu Server, by default, is a headless operating system, and VirtualBox’s copy/paste functionality is implemented via Guest Additions — which typically requires a GUI to work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*_ldF4jEXPfor6BkyS4Um6Q.png" /><figcaption>Hackerman: I’m in</figcaption></figure><p>I don’t plan on running anything too fancy on the server — just a couple of static web pages. But we do need a way to serve them up, so let’s install Lighttpd:</p><pre>sudo apt update<br>sudo apt install lighttpd</pre><p>After that, I configure /etc/lighttpd/conf-available/10-ssl.conf by adding the following:</p><pre>$SERVER[&quot;socket&quot;] == &quot;:443&quot; {<br>    ssl.engine = &quot;enable&quot;<br>    ssl.pemfile = &quot;/etc/ssl/certs/lighttpd.pem&quot;<br>}</pre><p>Then I create a certificate using OpenSSL:</p><pre>sudo openssl req -new -x509 -days 365 -nodes \<br>-config /etc/lighttpd/openssl.cnf \<br>-extensions req_ext \<br>-out /etc/lighttpd/server.pem \<br>-keyout /etc/lighttpd/server.pem</pre><p>Finally, I enable Lighttpd’s SSL module, restart the service, and secure the certificate file’s permissions:</p><pre>sudo lighttpd-enable-mod ssl<br><br>sudo systemctl restart lighttpd<br><br>secured the cert<br>sudo chmod 600 /etc/lighttpd/server.pem<br>sudo chown root:root /etc/lighttpd/server.pem</pre><p>Great! Let’s test out the web server and see if it works.</p><p>The first host I spun up for this network is actually the machine that will try to sniff and intercept traffic, so this time I spin up an Ubuntu Desktop VM to act as a tester. I do a quick ping to verify that this new VM can communicate with the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*cb0zGfM7cS9VxIm8UYGM_Q.png" /><figcaption>New Ubuntu host can see server</figcaption></figure><p>I open up the browser, type in the server’s IP, and hit Enter… Boom — the default Lighttpd page loads. Success!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ryV40Gi6pkjJ2g3TkbF8WQ.png" /><figcaption>Host connects to a default web-page</figcaption></figure><p>Next, I switch over to the sniffer box to check if it’s picking up any traffic from the test VM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*LaYnubFfMdhZCD5VVHbNqw.png" /><figcaption>One router solicitation please</figcaption></figure><p>Anddddd… there’s no HTTP traffic to be seen.</p><p>Then I remembered: while setting things up, I noticed that under the VirtualBox network adapter options, there’s an “Advanced” tab with a setting for <em>Promiscuous Mode</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*GgYMkGI-XucTRjO3VCZ59A.png" /><figcaption>Promiscuous Mode, where-ever you are</figcaption></figure><p>I enable Promiscuous Mode and send another packet from the host to the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*HnvuPQny12Gig3g7TxvyWA.png" /><figcaption>Sniffer box can see host-server traffic</figcaption></figure><p>Success!</p><p>Now I can finally explore the question that’s been on my mind for the past three days: <strong>What happens if an attacker gets a copy of the private certificate? Can they decrypt the traffic?</strong></p><p>To test this, I make a copy of the certificate file — which contains both the public and private keys — and drop it into an easily accessible location: /var/www/html. This simulates an unsecured credential that an attacker might stumble upon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*v5eEO9EUVXYmQy6sb_GUmw.png" /><figcaption>Don’t ever do this</figcaption></figure><p>I also change the permissions on the certificate file so that anyone can access it, then download it onto the sniffer box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HU96C4BSuqXHyEeMSXMMMw.png" /><figcaption>Certificate acquired</figcaption></figure><p>In the same Wireshark session from earlier, I simply add the certificate under <em>Preferences</em> as a TLS key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKFYfcWuSnXMj3jzB3adyA.png" /><figcaption>Wireshark Preferences</figcaption></figure><p>So now, we finally get to answer the million-dollar question I’ve been sitting on for days: <strong>Can I decrypt this traffic?!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*m6OfcKbzlmnUoemPZtGN4g.png" /><figcaption>Data is still encrypted?</figcaption></figure><p>The answer to that question is a big fat <strong>“No.”</strong></p><p>After digging deeper, I found out that only RSA key exchanges are decryptable using the private key in Wireshark. If the server is using ECDH (Elliptic Curve Diffie-Hellman), the private key alone isn’t enough to decrypt the traffic.</p><p>To check which key exchange method the server is using, I run the following OpenSSL command:</p><pre>openssl s_client -connect 192.168.100.1:443 | grep &quot;Server Temp Key&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*YryIXwkt-U1l5QcY3N8GJg.png" /><figcaption>No decryption for you!</figcaption></figure><p>The output showing X25519 confirms that the server is using ECDH for key exchange. That means it’s not susceptible to this kind of decryption attack — unless you also have access to the SSL session keys. These keys are only obtainable by dumping the memory of the host machine initiating the connection, or if the client happens to log them.</p><p>So what’s next?</p><p>My test may have failed, but that doesn’t make improper certificate storage any less dangerous. A stolen certificate can still lead to <strong>man-in-the-middle (MITM) attacks</strong>, <strong>impersonation</strong>, and even <strong>forging other certificates</strong>, which undermines the entire trust model of secure communication.</p><p>I think it’s about time we set up a Certificate Authority (CA) to properly manage and issue certificates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dca84f1e566" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Journey to becoming a certificate wizard Part 2: Setting up a simple virtual network]]></title>
            <link>https://szwochm.medium.com/journey-to-becoming-a-certificate-wizard-part-2-setting-up-a-test-network-2a30c0778efb?source=rss-8d0ed343ccf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a30c0778efb</guid>
            <category><![CDATA[dhcp]]></category>
            <category><![CDATA[dnsmasq]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[ubuntu-server]]></category>
            <dc:creator><![CDATA[Szwochm]]></dc:creator>
            <pubDate>Tue, 12 Aug 2025 04:37:46 GMT</pubDate>
            <atom:updated>2025-08-12T23:56:08.701Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://szwochm.medium.com/journey-to-secure-my-home-network-part-1-89a2736d6271">Yesterday, I created a certificate for my printer</a> so I could log in without broadcasting my credentials in plain text over Wi-Fi. While cleaning up my project files, I found some older certificates from previous failed attempts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*eYi3SF1Ck76dwKqKHZPb3A.png" /><figcaption>failed certificate attempts</figcaption></figure><p>While these certificates and keys are no longer in use, it got me thinking… What if they were real? If an attacker stumbled across them and they were actually deployed, they could sniff traffic, execute MITM attacks, forge certificates — maybe even pull off an evil twin attack.</p><p>Could I try these attacks on my own devices? And how hard would it be? Well, I still use my printer and I don’t want to accidentally brick it during my research — so I figured now’s a good time to spin up a virtual network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*DSoiXTAfB9TlDzDJ-mxi9w.png" /></figure><p>I‘m fairly familiar with Ubuntu — it has tons of community support, and the server edition is headless, which should keep resource requirements to a minimum for my tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYI_s7Njf1XlBQm6Hs1mBQ.png" /><figcaption>Ubuntu Server 24.04 booting up</figcaption></figure><p>I load it up with OpenSSH, PostgreSQL, and Docker — just to give myself some flexibility depending on what I want it to do. Now let’s spin up a lightweight HTTPS server on it! At this point, I just want to run a simple POC before diving into more complex tests. I also spin up a Kali VM since I already had that set up.</p><p>I test connectivity between the machines and realize both are missing IP info for their internal VirtualBox network adapters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ojq_U4PR53hzVDSUhcDCQ.png" /><figcaption>Wheres the IP Lebowski?</figcaption></figure><p>Okay… turns out VirtualBox doesn’t provide DHCP services to internal networks by default.</p><p>At first, I tried setting static IPs for both boxes and manually configuring routes. It worked — until I restarted them and everything vanished. I could set permanent static IPs for each host using Network Manager… or I could just configure one for the DHCP server and let it handle the rest.</p><p>I run:</p><pre>sudo apt update<br>sudo apt install dnsmasq</pre><p>Then I configure my web server — now also acting as the DHCP server — to have a static IP. I edit the netplan config:</p><pre>sudo nano /etc/netplan/50-cloud-init.yaml</pre><pre>network:<br>  version: 2<br>  ethernets:<br>    enp0s3:<br>      dhcp4: true<br>    enp0s10:<br>      dhcp4: no<br>      addresses: [192.168.100.1/24]</pre><p>Then I apply the changes:</p><pre>sudo netplan apply</pre><p>After that, I set up a simple dnsmasq config and start the service.</p><pre>interface=enp0s8<br>dhcp-range=192.168.100.10,192.168.100.50,12h<br>port=0</pre><p>Finally, I force a DHCP request on my Kali box</p><pre>sudo dhclient enp0s10</pre><p>Boom. We have communication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ze66DvvQBf8GFomPyIvYVQ.png" /><figcaption>I ping you!</figcaption></figure><p>Well, I didn’t get to play with certificates today. But with this simple virtual network and DHCP server in place, future lab environments should be easy to spin up.</p><p><a href="https://szwochm.medium.com/journey-to-secure-my-home-network-part-1-89a2736d6271">Part 1</a> | Current | Next</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a30c0778efb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Journey to becoming a certificate wizard Part 1: Securing my printer]]></title>
            <link>https://szwochm.medium.com/journey-to-secure-my-home-network-part-1-89a2736d6271?source=rss-8d0ed343ccf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/89a2736d6271</guid>
            <category><![CDATA[openssl]]></category>
            <category><![CDATA[certificate]]></category>
            <category><![CDATA[network-security]]></category>
            <category><![CDATA[pki]]></category>
            <category><![CDATA[printers]]></category>
            <dc:creator><![CDATA[Szwochm]]></dc:creator>
            <pubDate>Mon, 11 Aug 2025 04:21:11 GMT</pubDate>
            <atom:updated>2025-08-12T23:52:47.950Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, for no particular reason, I decided to fire up Wireshark and see what was going on in my network. I didn’t have a specific goal — just a hunch. I’ve got a couple of iOS devices, a Chromecast, and a printer lurking around, so odds were good that at least one of them was up to something weird.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*oNh_dznuxEkgrPEdxGom3w.png" /><figcaption>Plain text? On my network?!</figcaption></figure><p>I noticed some plain-text HTTP traffic from my machine to another device on the network. That struck me as odd, so I decided to investigate — I popped the IP into my browser to see what was going on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*lM18CNfsLmitY5R0n79k7Q.png" /><figcaption>I should probably get some toner</figcaption></figure><p>Sure enough, it’s just my printer. Okay — this seems like as good a place as any to start. I wonder if there’s any SSL/TLS set up on it at all, or if it’s just using HTTP for compatibility reasons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p7UG6S1wT6P35nenfSUx2A.png" /><figcaption>Is any connection truely private?</figcaption></figure><p>Okay, looks like we’ve got some work to do.</p><p>I log in through the admin portal and start poking around for anything I can do to secure this printer. First bit of low-hanging fruit: a firmware update. Let’s push that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*csrAo-ujW_sjslekJ60sMg.png" /><figcaption>Low-hanging fruit</figcaption></figure><p>I check out the network settings and see options for various services — including login. Now I’m wondering: can I generate a certificate and force encrypted traffic without locking myself out of the printer? I’ve installed certificates before, but I’ve never really generated them outside of VPN setups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*rNULMdQ0VvBuY7GMPxszaQ.png" /><figcaption>Printer protocol options</figcaption></figure><p>There printer doesn’t have any certificates, but there are options to create them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*xMLzjvOfD3I0g2zLlVZsrQ.png" /><figcaption>More printer protocol options</figcaption></figure><p>But what happens if I lose the certificate and disable HTTP? Logically, I’d be locked out of my own system.</p><p>Sure, I could generate a certificate and stash it somewhere safe… but that got me thinking.</p><p>Big networks have certificate authorities — so where can I store and manage certificates on a home network?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*boGtn33EPsVAcE7n9z8txQ.png" /><figcaption>I ask the oracle for guidance</figcaption></figure><p>Looks like we’re creating a CA, boys and gals.</p><p>OpenSSL is a tool I’ve heard of before, so let’s roll with that.</p><p>I take a look at my printer and see three options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*oN0b_xXuIf3ERhUnxB66fw.png" /><figcaption>Certificate options</figcaption></figure><p>So it looks like I can either generate a certificate using the printer itself or import one. I decide to dig into OpenSSL a bit more. Copilot pointed me to this <a href="https://olegignat.com/openssl-certification-authority/">WordPress blog</a>, which breaks down the process nicely.</p><p>After some reading, I realized that setting up a dedicated CA just for a home printer would probably cause more headaches than it solves — though it’d make for a great future project.</p><p>After a bit of risk analysis, I landed on this security stance: I want security to be an option, but if something goes wrong, I need a way back in. At the very least, I want to log into my printer without my admin password being sniffed over Wi-Fi.</p><p>So, I create a self-signed certificate using the printer’s web interface…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*mywcduTd090U2SeH67w-WA.png" /><figcaption>Self-signed printer cert</figcaption></figure><p>I also install the printer’s public certificate on my machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Ng_mJxOngD06LrfxXhTnDw.png" /><figcaption>I authenticate myself to you that I am me</figcaption></figure><p>I verify that traffic is now using HTTPS instead of HTTP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*hJuLea0JY6I8kN3F3YlN-A.png" /><figcaption>TLS handshake</figcaption></figure><p>However, I don’t love that Edge still says the certificate isn’t valid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*gfjGzcAqOBhkVBukQlNkYA.png" /><figcaption>Certificate flagged as unsafe</figcaption></figure><p>I did some research and found that modern browsers require the SAN (Subject Alternative Name) field to be set. Okay, guess I’ll have to use OpenSSL to create my own certificate after all.</p><p>First, I create a config file for the cert.</p><pre>[req]<br>default_bits = 2048<br>prompt = no<br>default_md = sha256<br>req_extensions = req_ext<br>distinguished_name = dn<br><br>[dn]<br>CN = 10.0.0.39<br><br>[req_ext]<br>subjectAltName = @alt_names<br><br>[alt_names]<br>IP.1 = 10.0.0.39</pre><p>Next, I generate the private and public key using OpenSSL.</p><pre>openssl req -x509 -nodes -days 365 \<br> -newkey rsa:2048 \<br> -keyout printer.key \<br> -out printer.crt \<br> -config printer_cert.cnf \<br> -extensions req_ext</pre><p>Then I package the .key and .crt files into a .pfx file — since that’s what my printer requires.</p><pre>openssl pkcs12 -export \<br> -out printer.pfx \<br> -inkey printer.key \<br> -in printer.crt</pre><p>Finally, I upload the .pfx file to my printer and import the .crt into my Windows certificate store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*hzxaP0o_dWdeH0gYoCFMhw.png" /></figure><p>This time, Edge is happy!</p><p><strong>Things Learned</strong></p><ol><li><strong>Browsers require both CN and SAN fields</strong> — or they’ll complain that the certificate isn’t legit.</li></ol><p>2. <strong>Different certificate types indicate what keys they contain</strong>:</p><ul><li>.cer files only have the <strong>public key</strong></li><li>.key files only have the <strong>private key</strong></li><li>.pfx or .p12 files contain <strong>both</strong></li></ul><p>3. <strong>Chrome and Firefox have their own CA stores</strong> — they don’t rely on the Windows certificate store.</p><p>4. <strong>Facebook and my printer use one-way TLS communication</strong> — only the client verifies the server, not the other way around.</p><p>5. <strong>Root CAs are self-signed</strong> — because there’s nothing higher to sign them.</p><p>6. <strong>Public Certificate Authorities can’t issue certs for internal domains</strong> — regulatory bodies prohibit it. So no, you can’t request a cert from a public CA for your home network.</p><p><strong>Things that can be done better next time</strong></p><ol><li><strong>Use a hostname instead of an IP for CN and SAN</strong> Right now, the certificate is tied to an IP address — which can change or be spoofed. Next time, I’d give the printer a proper hostname and use that instead.</li><li><strong>Set up a CA to manage certificates</strong> It might be a little overkill for a home network, but it’d be a fun project — and way more scalable if I start securing more devices.</li></ol><p>Continue the journey <a href="https://szwochm.medium.com/journey-to-becoming-a-certificate-wizard-part-2-setting-up-a-test-network-2a30c0778efb">here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89a2736d6271" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TCM’s Ethical Hacking in 15 Hours — 2023 Edition — Learn to Hack! (Part 1) — Review]]></title>
            <link>https://szwochm.medium.com/tcms-ethical-hacking-in-15-hours-2023-edition-learn-to-hack-part-1-review-ddd2bc327a2b?source=rss-8d0ed343ccf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddd2bc327a2b</guid>
            <category><![CDATA[tcm]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[review]]></category>
            <dc:creator><![CDATA[Szwochm]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 21:51:57 GMT</pubDate>
            <atom:updated>2023-06-25T21:51:57.603Z</atom:updated>
            <content:encoded><![CDATA[<h3>TCM’s Ethical Hacking in 15 Hours — 2023 Edition — Learn to Hack! (Part 1) — Review</h3><p><strong><em>Content link: </em></strong><a href="https://www.youtube.com/watch?v=3FNYvj2U0HM"><strong><em>https://www.youtube.com/watch?v=3FNYvj2U0HM</em></strong></a></p><h3><strong>Background</strong></h3><p>Before I delve into the review, I would like to talk a little bit about my background so that the reader has an idea of the perspective this review is coming from</p><p>I am <em>SzwochM</em>, an up and coming Cybersecurity professional. I am <a href="https://elearnsecurity.com/product/ejpt-certification/">eJPT</a>, and Security+ certified. I have also recently graduated with a B.A in Computer Science, so I have a decent amount of knowledge when it comes to programming in general. The last thing I would like to mention is that I did about 80% of the <a href="https://ine.com/learning/certifications/internal/elearnsecurity-certified-professional-penetration-tester">eCPPT’s</a> content before my subscription expired. I decided not to renew my subscription with <a href="https://ine.com/learning/certifications/internal/elearnsecurity-certified-professional-penetration-tester">INE</a>, and instead went with <a href="https://www.offsec.com/learn/">Offsec’s<em> Learn One</em></a> as the OSCP has better employment opportunities at the time of writing this article. (See below)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*UT9X3QUzk5tQcsMhxz-fcw.png" /><figcaption>6/14/2023 — LinkedIn Job Results — No other filters</figcaption></figure><p>God Dang INE! I love your content but you guys gotta’ step up your HR game. You’re getting beat by the new guy on the block!</p><h3><strong>Goal</strong></h3><p>When approaching this content my goal was to reinforce concepts, fill in knowledge gaps, and learn new tricks. In other words I wanted to approach the material from a different angle rather than learning something new from scratch. I also wanted something convenient that I could watch while on lunch, or otherwise away from my computer. This means that I watched the video content in a relatively small timeframe (5–7 hours a day), and would not recommend this approach for someone learning these topics for the first time.</p><p>With that being said lets begin.</p><p><a href="https://www.youtube.com/watch?v=3FNYvj2U0HM">TCM’s Ethical Hacking in 15 Hours — 2023 Edition — Learn to Hack! (Part 1)</a> covers the first half of the PEH course released by The Cyber Mentor A.K.A Heath Adam. As the CEO of <a href="https://academy.tcm-sec.com/">TCM</a>, a company that produces Cybersecurity content. TCM released this content so that anyone in the world with an internet connection has access to quality content.</p><h3><strong>The Layout</strong></h3><p>The course consists of ~50 short videos all aggregated into one video. Part one acts as a foundation, with a little Cybersecurity at the end. Here is the simplified organization:</p><ol><li>Introduction &amp; Day in the Life of an Ethical Hacker <br>Time range (<a href="https://www.youtube.com/watch?v=3FNYvj2U0HM&amp;t=0s">0:00</a> -&gt; 27:43)</li><li>Preliminary Skills: Notetaking, Networking, Protocols, Subnetting<br>Time range (<a href="https://www.youtube.com/watch?v=3FNYvj2U0HM&amp;t=1664s">27:44</a> -&gt; 1:46:00)</li><li>Preliminary Skills: Using VMs, Kali and Linux in general<br>Time range (<a href="https://www.youtube.com/watch?v=3FNYvj2U0HM&amp;t=6361s">1:46:01</a> -&gt; 3:18:35)</li><li>Preliminary Skills: Scripting, Programing in Python<br>Time range (<a href="https://www.youtube.com/watch?v=3FNYvj2U0HM&amp;t=11915s">3:18:35</a> -&gt; 6:22:31)</li><li>Ethical Hacking: Beginning of Information Gathering<br>Time range (<a href="https://www.youtube.com/watch?v=3FNYvj2U0HM&amp;t=22952s">6:22:32</a> -&gt; 7:14:29)</li></ol><h3><strong>Introduction &amp; Day in the Life of an Ethical Hacker</strong></h3><p>Right off the bat, I loved the <em>Day in the Life of an Ethical Hacker</em> section. No other course I had taken at this point had broken down exactly how long each type of assessment should take. For example consider the following slide…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*la8lyBK7IVtMHvpHMl73gg.png" /><figcaption>Wireless Assessment Timeframe — TCM (15:39)</figcaption></figure><p>Prior to viewing this slide I had no idea about what would be an appropriate amount of time to spend on a Wireless Pentest. Three bullets later, and now I feel confident with giving clients estimates for this service. Small details such as this are exactly why I love TCM’s content.</p><h3><strong>Preliminary Skills: Notetaking, Networking, Protocols, Subnetting</strong></h3><p>There were a couple of things I liked about this section. I ended up preferring TCM’s suggestion of Greenshot and KeepNote over the tools I had been using (Windows Snipping Tool &amp; CherryTree). The networking, and protocol videos were short and sweet. Just enough to get an aspiring analyst going, but I would recommend more research to anyone learning these topics for the first time. By comparison INE’s protocol content was much more granular. For example TCM mentions the TCP 3-way handshake, while INE dives into the nitty gritty such as TCP sequence number generation, TCP Headers, and constantly referring to <a href="https://datatracker.ietf.org/doc/html/rfc9293#:~:text=RFC%209293%20%2D%20Transmission%20Control%20Protocol%20(TCP)">RFCs.</a> Finally I thought that the subnetting section was sufficient, but again would recommend practice.</p><h3><strong>Preliminary Skills: Using VMs, Kali and Linux in general</strong></h3><p>This section is where TCM blows the competition out of the water again by making the content more friendly for new students. TCM walks the student through on installing the software necessary to create a lab. He goes step by step from installing VMware, to updating Kali. He also points out the dangers associated with said updates (Tools breaking) which competitors forget. Although this seems simple, I’m sure new students will appreciate the warning. TCM then shows the student general Linux usage, mentioning things that I had previously missed. In particular I enjoyed how Sudo, and Linux privileges were explained. Finally, I fully intend to make use of his recommendation of <a href="https://github.com/Dewalt-arch/pimpmykali/blob/master/pimpmykali.sh">PimpMyKali.sh </a>to fix the various broken tools I have on my distro.</p><h3><strong>Preliminary Skills: Scripting (Bash), Programing (Python)</strong></h3><p>As I am a Computer Science graduate, I already had tons of experience programming projects in Python, thus I skipped through alot of this content. I did enjoy how TCM broke down on how to create a ping scanner using Bash. It was very easy to follow along, while also creating a useful tool. Yes there are dozens of better ping scan options out there (Fping, Amass, Nmap), but this simple example encourages students to try their hand at creating tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*W1ioIEITM4z6TGw_KyaixA.png" /><figcaption>Scripting a PingSweeper using Bash — TCM (<a href="https://youtu.be/3FNYvj2U0HM?t=11915">3:35:37</a>)</figcaption></figure><h3><strong>Ethical Hacking: Beginning of Information Gathering</strong></h3><p>The final section covers some basics of information gathering. TCM’s approach of using Bug Crowd to find a target for OSINT was very clever, and miles ahead of INE’s elsfoo.com (Which no longer works anyways). TCM’s recommendations for credential hunting also greatly exceed the typical suggestion of <em>rockyou.txt</em>.</p><h3>Grading / Summary</h3><p><em>Pricing: 10/10</em><br>0$ The best things in life are free. If you decide that you want to get the PNPT certificate there’s a few things to note. The exam voucher is $<a href="https://certifications.tcm-sec.com/product/practical-network-penetration-tester-standalone/">299,</a> however it also covers concepts from the <a href="https://academy.tcm-sec.com/p/windows-privilege-escalation-for-beginners">Windows Priv Escalation</a>, <a href="https://academy.tcm-sec.com/p/linux-privilege-escalation">Linux Priv Escalation</a> courses. I would suggest just getting the <a href="https://certifications.tcm-sec.com/product/practical-network-penetration-tester-with-training/">$399</a> package which also includes courses on <a href="https://academy.tcm-sec.com/p/osint-fundamentals">OSINT</a>, and a <a href="https://academy.tcm-sec.com/p/external-pentest-playbook">playbook for external pentesting</a>. Finally, TCM is moving to a subscription model in July 2023, so courses will be available for $30 monthly instead of a flat $30 per course. (Similar to OSCP’s Learn One, and INE’s Annual plans)</p><p><em>Student Friendliness: 9/10</em><br>Concepts were introduced, explained, and reinforced in a way that any student can understand.</p><p><em>Hands On: 8/10</em><br>INE and OffSec provide a greater variety of labs allowing for a more accurate simulation. However, these labs are generally only available with annual subscriptions and may be outside of the price point of aspiring hackers. Also some of INE’s and OffSec’s labs can be buggy/slow and prone to crashes.</p><p><em>Quality of information: 8/10</em><br>It is apparent that this course is aimed at people new to the Cybersecurity field. This course balances detail while still maintaining a relatively low learning curve.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddd2bc327a2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fingerprinting pfSense using GitHub analysis]]></title>
            <link>https://szwochm.medium.com/fingerprinting-pfsense-using-github-analysis-72051829194b?source=rss-8d0ed343ccf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/72051829194b</guid>
            <category><![CDATA[enumeration]]></category>
            <category><![CDATA[version]]></category>
            <category><![CDATA[pfsense]]></category>
            <category><![CDATA[fingerprinting-services]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Szwochm]]></dc:creator>
            <pubDate>Wed, 31 May 2023 04:19:01 GMT</pubDate>
            <atom:updated>2023-05-31T04:19:01.026Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B_FrurQ6JMxam5lS" /></figure><p>Penetration testers employ various techniques to uncover vulnerabilities in open source applications. One commonly utilized tactic involves scrutinizing the GitHub repository associated with the target application. By accessing the repository, analysts can closely examine individual files to identify potential weaknesses or chance upon known vulnerabilities (CVEs) or proof-of-concept (PoC) exploits tailored to specific application versions. This article delves into a step-by-step process for determining the version of a target application, such as pfSense, by leveraging its GitHub repository.</p><p>During a recent target engagement, I encountered a host running pfSense. Despite conducting initial scans and analyzing web traffic, determining the precise version proved to be a challenge. However, I knew that user-accessible web application files are commonly stored in the /www/ or /inetpub/ directories. With this in mind, I decided to explore pfSense’s /www/ folder located at “/src/usr/local/www”.</p><p>To begin, I conducted tests on various files, starting with /help.php, and received a successful 200 status code. Initially, I considered the possibility that the website had simply ignored my request. To further investigate, I intentionally introduced a typo with /helpz.php, resulting in a 404 not found error. This discovery led me to realize that I could use requests to verify the existence of files. Thus, I believed that the pfSense version could potentially be narrowed down by analyzing the presence or absence of certain files. <em>Please note that all the referenced scripts can be found at </em><a href="https://github.com/Szwochm/wwwEnum"><em>https://github.com/Szwochm/wwwEnum</em></a><em>.</em></p><p>Attempting to identify the discrepancies in files across different versions, I initially turned to the change log and commits. However, due to the significant number of branches (20 at the time of writing), I recognized the necessity for a more efficient approach. To streamline the process, I utilized Python’s request library in conjunction with GitHub’s API to develop a script that retrieves the names of all branches.</p><pre>#getversions.py<br><br>import requests<br><br># Set the repository information<br>owner = &#39;pfsense&#39;<br>repo = &#39;pfsense&#39;<br><br># Make the API request to get the branches<br>url = f&#39;https://api.github.com/repos/{owner}/{repo}/branches&#39;<br>response = requests.get(url)<br><br># Check if the request was successful<br>if response.status_code == 200:<br>    branches = response.json()<br><br>    # Extract the branch names<br>    branch_names = [branch[&#39;name&#39;] for branch in branches]<br><br>    # Save branch names to versions.txt<br>    with open(&#39;versions.txt&#39;, &#39;w&#39;) as file:<br>        file.write(&#39;\n&#39;.join(branch_names))<br><br>    print(&quot;Branch names saved to versions.txt file.&quot;)<br>else:<br>    print(f&quot;Failed to retrieve branch names. Status Code: {response.status_code}&quot;)</pre><p>Running this script returned a text file that contained the following data…</p><pre>CE_Plus_Upgrade<br>RELENG_1_2<br>RELENG_2_0<br>...<br>...<br>master</pre><p>Next, I developed a script that performs the following tasks:</p><p>1. Utilizes the GitHub API to retrieve a comprehensive list of items in the “www” directory for each version mentioned in the versions file.</p><p>2. Saves the collected data to a CSV file for further analysis and reference.</p><p>As recursive exploration of directories was unnecessary due to the 403 status code (forbidden) returned by each directory, I focused solely on the top-level files. I also added a 1 second delay to avoid hitting GitHub’s API request limits.</p><pre>#initWithVersions.py<br>import csv<br>import requests<br>import time<br>import os<br><br>def get_directory_contents(owner, repo, branch, path):<br>    url = f&quot;https://api.github.com/repos/{owner}/{repo}/contents/{path}?ref={branch}&quot;<br>    response = requests.get(url)<br>    <br>    if response.status_code == 200:<br>        contents = response.json()<br>        file_names = [item[&#39;name&#39;] for item in contents if item[&#39;type&#39;] == &#39;file&#39;]<br>        directory_names = [item[&#39;name&#39;] for item in contents if item[&#39;type&#39;] == &#39;dir&#39;]<br>        return file_names, directory_names<br>    else:<br>        return None, None<br><br>owner = &quot;pfsense&quot;<br>repo = &quot;pfsense&quot;<br><br># Read branches from versions.txt<br>with open(&#39;versions.txt&#39;, &#39;r&#39;) as file:<br>    branches = file.read().splitlines()<br><br>delay = 1  # Delay in seconds between requests<br><br>for branch in branches:<br>    version = branch.replace(&#39;/&#39;, &#39;_&#39;)<br>    csv_file = f&quot;{version}.csv&quot;<br>    <br>    if os.path.exists(csv_file):<br>        print(f&quot;CSV file {csv_file} already exists. Skipping.&quot;)<br>        continue<br>    <br>    path = &quot;src/usr/local/www&quot;<br>    <br>    file_names, directory_names = get_directory_contents(owner, repo, branch, path)<br><br>    if file_names is None or directory_names is None:<br>        print(f&quot;Failed to fetch directory contents for branch {branch}.&quot;)<br>        continue<br><br>    with open(csv_file, &#39;w&#39;, newline=&#39;&#39;) as file:<br>        writer = csv.writer(file)<br>        writer.writerow([&quot;File Names&quot;])<br>        for file in file_names:<br>            writer.writerow([file])<br>        <br>        writer.writerow([])  # Empty row separator<br>        <br>        writer.writerow([&quot;Directory Names&quot;])<br>        for directory in directory_names:<br>            writer.writerow([directory])<br><br>    print(f&quot;Directory contents for branch {branch} stored in {csv_file}.&quot;)<br>    time.sleep(delay)</pre><p>However when I ran the script, an error had occurred. This was because versions prior to “RELENG_2_3_0” had a slightly different path to the www folder. Thus I created two scripts, one for each path.</p><pre># init.py<br>import csv<br>import requests<br>import time<br>import os<br><br>def get_directory_contents(owner, repo, branch, path):<br>    url = f&quot;https://api.github.com/repos/{owner}/{repo}/contents/{path}?ref={branch}&quot;<br>    response = requests.get(url)<br>    <br>    if response.status_code == 200:<br>        contents = response.json()<br>        file_names = [item[&#39;name&#39;] for item in contents if item[&#39;type&#39;] == &#39;file&#39;]<br>        directory_names = [item[&#39;name&#39;] for item in contents if item[&#39;type&#39;] == &#39;dir&#39;]<br>        return file_names, directory_names<br>    else:<br>        return None, None<br><br>owner = &quot;pfsense&quot;<br>repo = &quot;pfsense&quot;<br>branches = [<br>    &quot;RELENG_1_2&quot;,<br>    &quot;RELENG_2_0&quot;,<br>    &quot;RELENG_2_1&quot;,<br>    &quot;RELENG_2_2&quot;<br>]<br>delay = 1  # Delay in seconds between requests<br><br>for branch in branches:<br>    version = branch.replace(&#39;/&#39;, &#39;_&#39;)<br>    csv_file = f&quot;{version}.csv&quot;<br>    <br>    if os.path.exists(csv_file):<br>        print(f&quot;CSV file {csv_file} already exists. Skipping.&quot;)<br>        continue<br>    <br>    path = f&quot;usr/local/www&quot;<br>    <br>    file_names, directory_names = get_directory_contents(owner, repo, branch, path)<br><br>    if file_names is None or directory_names is None:<br>        print(f&quot;Failed to fetch directory contents for branch {branch}.&quot;)<br>        continue<br><br>    with open(csv_file, &#39;w&#39;, newline=&#39;&#39;) as file:<br>        writer = csv.writer(file)<br>        writer.writerow([&quot;File Names&quot;])<br>        for file in file_names:<br>            writer.writerow([file])<br>        <br>        writer.writerow([])  # Empty row separator<br>        <br>        writer.writerow([&quot;Directory Names&quot;])<br>        for directory in directory_names:<br>            writer.writerow([directory])<br><br>    print(f&quot;Directory contents for branch {branch} stored in {csv_file}.&quot;)<br>    time.sleep(delay)</pre><pre># init2.py<br>import csv<br>import requests<br>import time<br>import os<br><br>def get_directory_contents(owner, repo, branch, path):<br>    url = f&quot;https://api.github.com/repos/{owner}/{repo}/contents/{path}?ref={branch}&quot;<br>    response = requests.get(url)<br>    <br>    if response.status_code == 200:<br>        contents = response.json()<br>        file_names = [item[&#39;name&#39;] for item in contents if item[&#39;type&#39;] == &#39;file&#39;]<br>        directory_names = [item[&#39;name&#39;] for item in contents if item[&#39;type&#39;] == &#39;dir&#39;]<br>        return file_names, directory_names<br>    else:<br>        return None, None<br><br>owner = &quot;pfsense&quot;<br>repo = &quot;pfsense&quot;<br>branches = [<br>    &quot;RELENG_2_3_0&quot;,<br>    &quot;RELENG_2_3_1&quot;,<br>    &quot;RELENG_2_3_2&quot;,<br>    &quot;RELENG_2_3_3&quot;,<br>    &quot;RELENG_2_4_0&quot;,<br>    &quot;RELENG_2_4_1&quot;,<br>    &quot;RELENG_2_4_2&quot;,<br>    &quot;RELENG_2_3_4&quot;,<br>    &quot;RELENG_2_3&quot;,<br>    &quot;RELENG_2_4_3&quot;,<br>    &quot;RELENG_2_3_5&quot;,<br>    &quot;RELENG_2_4_4&quot;,<br>    &quot;RELENG_2_5_0&quot;,<br>    &quot;RELENG_2_4_5&quot;,<br>    &quot;RELENG_2_5_1&quot;,<br>    &quot;RELENG_2_5_2&quot;,<br>    &quot;RELENG_2_6_0&quot;,<br>    &quot;CE_Plus_Upgrade&quot;,<br>    &quot;master&quot;<br>]<br>delay = 1  # Delay in seconds between requests<br><br>for branch in branches:<br>    version = branch.replace(&#39;/&#39;, &#39;_&#39;)<br>    csv_file = f&quot;{version}.csv&quot;<br>    <br>    if os.path.exists(csv_file):<br>        print(f&quot;CSV file {csv_file} already exists. Skipping.&quot;)<br>        continue<br>    <br>    path = f&quot;src/usr/local/www&quot;<br>    <br>    file_names, directory_names = get_directory_contents(owner, repo, branch, path)<br><br>    if file_names is None or directory_names is None:<br>        print(f&quot;Failed to fetch directory contents for branch {branch}.&quot;)<br>        continue<br><br>    with open(csv_file, &#39;w&#39;, newline=&#39;&#39;) as file:<br>        writer = csv.writer(file)<br>        writer.writerow([&quot;File Names&quot;])<br>        for file in file_names:<br>            writer.writerow([file])<br>        <br>        writer.writerow([])  # Empty row separator<br>        <br>        writer.writerow([&quot;Directory Names&quot;])<br>        for directory in directory_names:<br>            writer.writerow([directory])<br><br>    print(f&quot;Directory contents for branch {branch} stored in {csv_file}.&quot;)<br>    time.sleep(delay)</pre><p>The only difference between the two scripts is the declaration of the branches list. The reason I did not combine them into one script, is because I believe that this way will make it easier to repurpose the script for other repositories. If a different repository had 5 different paths across it’s branches, I could just brainlessly create 5 separate scripts, without worrying about updating the logic.</p><p>Now that I had all of the data, I could begin analyzing the data. First I created another script to quickly create a wordlist of every possible file. My initial plan was to pass this wordlist to a tool such as <em>dirbuster</em> or <em>wfuzz</em>. As I had the csv files in a separate directory, I simply scanned every .csv file in the working directory. Afterwards, I aggregated all of the items into a single text document.</p><pre>#wordlistgenerator.py <br><br>import glob<br>import csv<br><br># Find all CSV files in the current directory<br>csv_files = glob.glob(&#39;*.csv&#39;)<br><br># Set to store all filenames and directory names<br>names_set = set()<br><br># Process each CSV file<br>for csv_file in csv_files:<br>    with open(csv_file, &#39;r&#39;) as file:<br>        reader = csv.reader(file)<br>        for row in reader:<br>            for item in row:<br>                names_set.add(item)<br><br># Create a text file and write the names<br>with open(&#39;wordlist.txt&#39;, &#39;w&#39;) as file:<br>    for name in sorted(names_set):<br>        file.write(name + &#39;\n&#39;)</pre><p>Which returned a text file of 382 potential files resembling the block below…</p><pre>android-chrome-192x192.png<br>android-chrome-512x512.png<br>apple-touch<br>apple-touch-icon.png<br>auto_complete_helper.js<br>bandwidth_by_ip.php<br>...<br>...<br>...<br>vpn_wg_edit.php<br>widgets<br>wizard.php<br>wizards<br>wlan_strong_key_generator<br>xmlrpc.php</pre><p>Not wanting to potentially crash my target with excessive requests (and also to be stealthy), I decided that I needed another approach. Thus I created one final script. This script would read every versions csv file, and do the following:</p><p>1. Generate comparisons between every version. Example how does master compare to 1_2, 2_0, 2_1…. and so on.</p><p>2. Make a distinction between added and removed files. What files does the master branch have that 1_2 does not? What files does 1_2 have that master does not?</p><p>3. Save all of the data to a JSON file for easy readability. There is a JSON file generated for every version. There is some redundancy here but I felt that this was the most straight forward approach. It also provides the data necessary for any future projects containing algorithms</p><p>The resulting script is as follows:</p><pre>#differencesgenerator.py<br><br>import json<br>import csv<br><br><br># Function to read file names from a CSV file<br>def read_file_names(csv_file):<br>    file_names = set()<br>    with open(csv_file, &#39;r&#39;) as file:<br>        reader = csv.reader(file)<br>        next(reader)  # Skip header row<br>        for row in reader:<br>            if row:<br>                file_names.add(row[0])<br>    return file_names<br><br># Function to compare versions<br>def compare_versions(version_csv1, version_csv2):<br>    file_names1 = read_file_names(version_csv1)<br>    file_names2 = read_file_names(version_csv2)<br><br>    file_names_missing_from_1 = file_names2 - file_names1<br>    file_names_missing_from_2 = file_names1 - file_names2<br><br>    differences = {<br>        &quot;added_files&quot;: list(file_names_missing_from_2),<br>        &quot;missing_files&quot;: list(file_names_missing_from_1)<br>    }<br><br>    return differences<br><br><br># Read versions from versions.txt<br>with open(&#39;versions.txt&#39;, &#39;r&#39;) as file:<br>    versions = file.read().splitlines()<br><br># Process each version<br>for version_csv in versions:<br>    output_dict = {}<br><br>    # Process current version<br>    current_files = read_file_names(version_csv)<br>    current_only_files = current_files.copy()<br><br>    # Compare with other versions<br>    for other_version_csv in versions:<br>        if other_version_csv != version_csv:<br>            differences = compare_versions(version_csv, other_version_csv)<br>            output_dict[other_version_csv] = differences<br>            current_only_files -= set(differences[&#39;added_files&#39;])<br><br>    # Store results for current version<br>    current_results = {<br>        &quot;added_files&quot;: [],<br>        &quot;missing_files&quot;: list(current_only_files)<br>    }<br>    output_dict[version_csv] = current_results<br><br>    # Write differences to JSON file<br>    output_file = f&quot;{version_csv.replace(&#39;.csv&#39;, &#39;&#39;)}.json&quot;<br>    with open(output_file, &#39;w&#39;) as file:<br>        json.dump(output_dict, file, indent=4)<br><br>    print(f&quot;Differences for {version_csv} saved in {output_file}.&quot;)</pre><p>The output of this script was 20 different JSON files; one for each branch. This seems intimidating however much of the information is redundant. By using a simple system of trial and error I was able to narrow down the version with 4 requests. For example lets look at master’s JSON file…</p><pre>{<br>    &quot;RELENG_2_6_0.csv&quot;: {<br>        &quot;added_files&quot;: [],<br>        &quot;missing_files&quot;: []<br>    },<br>    &quot;RELENG_2_5_2.csv&quot;: {<br>        &quot;added_files&quot;: [<br>            &quot;system_register.php&quot;<br>        ],<br>        &quot;missing_files&quot;: []<br>    },<br>    &quot;RELENG_2_5_1.csv&quot;: {<br>        &quot;added_files&quot;: [<br>            &quot;system_register.php&quot;<br>        ],<br>        &quot;missing_files&quot;: []<br>    },<br>    &quot;RELENG_2_4_5.csv&quot;: {<br>        &quot;added_files&quot;: [<br>            &quot;status_logs_packages.php&quot;,<br>            &quot;system_certmanager_renew.php&quot;,<br>            &quot;services_captiveportal_hasync.php&quot;,<br>            &quot;apple-touch&quot;,<br>            &quot;system_register.php&quot;<br>        ],</pre><p>From here we can see that there is no way to differentiate 2_6_0 from the master branch. That’s a pity, however, observe the data for 2_5_2. Here we can see that master has “system_register.php” while 2_5_2 does not, as it is in the “added_files”. Because the “missing_files” section is empty, we know that there were no files that were deleted between versions 2_5_2 and 2_6_0.</p><p>Using this information I was able to identify that my target system was using version 2_6_0 or master. When requesting “system_register.php”, I received a 200 status code indicating that the file existed. This made it very likely that the version was either 2_6_0 or master. I then eliminated every other version by using their respective differences which I explained here. <a href="https://github.com/Szwochm/wwwEnum/tree/main#readme"><em>https://github.com/Szwochm/wwwEnum/tree/main#readme</em></a></p><p>With this information, the next plan of action is to further investigate the finger printed version of pfSense…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72051829194b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>