TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Terminal size matters, hackers get root in unusual way

5 pointsby Iwillgetbyover 5 years ago
The command usr&#x2F;bin&#x2F;sudo &#x2F;usr&#x2F;bin&#x2F;journalctl -n5 -u whatever.service prints out the log and exits. But we can&#x27;t exploit it because journalctl exits right after printing. Our aim is to launch a shell from within the journalctl command. Journalctl uses less command by default to view the log. So we have to find a way to prevent the command from exiting. The trick can be found in the journalctl man page.<p>man journalctl | grep width -B 1 -A 2<p><pre><code> The output is paged through less by default, and long lines are &quot;truncated&quot; to screen width. The hidden part can be viewed by using the left-arrow and right-arrow keys. Paging can be disabled; see the --no-pager option and the &quot;Environment&quot; section below. </code></pre> So if we run this command in a small resized window, it won&#x27;t exit after printing the log and then we can spawn a shell as root user.

4 comments

Iwillgetbyover 5 years ago
Original source can be found easily online. Link not included because this comes from an online CTF that discourages spoilers.
lfdominguezover 5 years ago
hummm, that&#x27;s a less &quot;problem&quot;, less is a software that allow execute programs with ! command, but not is a systemd problem, with man you can get the same behavior. The problem is the sysadmin that allow to execute that program with sudo.
Someoneover 5 years ago
I don’t understand. If you can run<p><pre><code> usr&#x2F;bin&#x2F;sudo &#x2F;usr&#x2F;bin&#x2F;journalctl </code></pre> , what stops you from running<p><pre><code> usr&#x2F;bin&#x2F;sudo &#x2F;usr&#x2F;bin&#x2F;bash </code></pre> instead?
评论 #22079128 未加载
zzo38computerover 5 years ago
The pager should not automatically be executed. If the user use a pipe then you can use that way instead, rather than putting everything in one program; it work better due to this reason explained.