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.

Ancient “su – hostile” vulnerability in Debian 8 and 9

145 pointsby l2dyalmost 7 years ago

15 comments

tedunangstalmost 7 years ago
For those unaware, ioctl(TIOCSTI) allows injecting characters back into the tty, where they will be read by the next process to read from the terminal. In this case, that process is the root shell that execed su.
评论 #17312100 未加载
_wmdalmost 7 years ago
Another variant of using TIOCSTI with poor permissions. FWIW this exact same bug impacted Docker and LXC at various points. In the case of lxc-attach, when stdio is connected to a TTY, it creates a new pty within the container and multiplexes between them to avoid the issue. I don&#x27;t think there is a single legitimate use for that ioctl.. it should just die already<p>tl;dr passing a TTY with stopped privileged jobs reading from it (like an interactive root shell) into an unprivileged location is deadly, as the unprivileged location can use TIOCSTI to load up the TTY&#x27;s input buffer and then exit, causing the stopped jobs to read that input when they&#x27;re resumed
评论 #17312137 未加载
评论 #17312256 未加载
bcaa7f3a8bbcalmost 7 years ago
PaX&#x2F;grsecurity has mitigation to this issue, at least for 10 years.<p>From grsecurity&#x27;s config for GRKERNSEC_HARDEN_TTY.<p><pre><code> | There are very few legitimate uses for this functionality and it | has made vulnerabilities in several &#x27;su&#x27;-like programs possible in | the past. Even without these vulnerabilities, it provides an | attacker with an easy mechanism to move laterally among other | processes within the same user&#x27;s compromised session. </code></pre> Has one run a grsecurity kernel, the system would not be affected.<p>Some independent developers and KSPP people are also trying to submit this mitigation to the mainline kernel for many years, but so far none of the patch went into the kernel. Since grsecurity is now a private product, you may want to check them out and apply this mitigation to the mainline kernel.<p><pre><code> [PATCH] drivers&#x2F;tty: add protected_ttys sysctl</code></pre> * <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;thejh&#x2F;e163071dfe4c96a9f9b589b7a2c24fc6" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;thejh&#x2F;e163071dfe4c96a9f9b589b7a2c24f...</a><p><pre><code> tiocsti-restrict : make TIOCSTI ioctl require CAP_SYS_ADMIN</code></pre> * <a href="https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;720740&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;720740&#x2F;</a>
im3w1lalmost 7 years ago
I&#x27;m increasingly feeling that terminals and bash are just too complex and have too many edge cases and footguns and that we&#x27;d be better of just starting over with something were security was a focus from day zero.
评论 #17314717 未加载
评论 #17314626 未加载
peterwwillisalmost 7 years ago
This explains the problem a little clearer I think: <a href="https:&#x2F;&#x2F;bugzilla.redhat.com&#x2F;show_bug.cgi?id=173008" rel="nofollow">https:&#x2F;&#x2F;bugzilla.redhat.com&#x2F;show_bug.cgi?id=173008</a>
评论 #17312200 未加载
codedokodealmost 7 years ago
As I remember, `login` program (that asks for your login and password on terminal) does a &quot;virtual hangup&quot; to prevent such things.
评论 #17312330 未加载
评论 #17312850 未加载
erlkonigalmost 7 years ago
Ah, this looks like the old ungetc() exploit, where (back in the 1980s at utexas.edu) we&#x27;d leave a process connected to a terminal, wait for another user to log in, then push characters to their shell from our program using ungetc(). Essentially, each character pushed ends up looking like a fresh input character to the other program. The basic issue is whether all open file handles that shouldn&#x27;t be there (our hack program, for example) got closed out by the new login session. For something like login, the question is easy, <i>ONLY</i> itself should be connected early on. For su, it&#x27;s much weirder, since the user may have created background jobs before running su, and su and sudo can&#x27;t reasonably close all other handles on the original tty device.<p>Further su and sudo can&#x27;t close all file descriptors of the &quot;sub-session&quot; as it exits, because that the &quot;sub-session&quot; is created by forking, so su&#x2F;sudo aren&#x27;t around at the end.<p>Creating a separate pseudo-terminal device to allow for draconian cleanup, and prevent even having both user IDs connected to the same tty device, seems like the best place to start.<p>Hmm, now I want to go update the user-group-setter program I use (which also can set auth user IDs on Solaris, etc) and try having it do ptty allocation for the subjob.<p>In the meantime, try this to get a session and run through the same demo steps:<p><pre><code> setsid -w su - &lt;user&gt; </code></pre> Won&#x27;t for <i>everything</i> (no &#x2F;dev&#x2F;tty), but it does block the example. You can add a tty if you have one handy, too, by using redirection in the spawned process in this general form, but I don&#x27;t currently have the cluon for how to create a &#x2F;dev&#x2F;pts&#x2F;&lt;num&gt; from the shell level - if someone can construct the full command, I&#x27;d like to see it :-)<p><pre><code> setsid sh -c &#x27;exec command &lt;&gt; &#x2F;dev&#x2F;tty2 &gt;&amp;0 2&gt;&amp;1&#x27;</code></pre>
评论 #17318211 未加载
评论 #17316101 未加载
carroccioalmost 7 years ago
TIOCSTI ioctl <a href="https:&#x2F;&#x2F;events.ccc.de&#x2F;congress&#x2F;2008&#x2F;Fahrplan&#x2F;events&#x2F;2992.en.html" rel="nofollow">https:&#x2F;&#x2F;events.ccc.de&#x2F;congress&#x2F;2008&#x2F;Fahrplan&#x2F;events&#x2F;2992.en....</a>
wilunalmost 7 years ago
Posix TTY and more precisely stdin&#x2F;stdout&#x2F;stderr inheritance and internals of FD have a completely insane design. There is the famous divide between file descriptors and file descriptions. Hilarity can and will ensue in tons of domains. I nearly shipped some code with bugs because of that mess (and could only avoid those bugs by using threads; you can NOT switch your std fd to non-blocking without absolutely unpredictable consequences), and obviously some bugs of a given class can create security issues. Especially, and in a way, obviously, when objects are shared across security boundaries.<p>Far is the time when Unix people were making fun of the lack of security in consumer Windows. Today, there is no comprehensive model on the most used &quot;Unix&quot; side, while modern Windows certainly have problems in the default way they are configured, but at least the security model exist with well defined boundaries (even if we can be sad that some seemingly security related features are not considered officially as security boundaries, at least we are not deluding ourselves into thinking that a spaghetti of objects without security descriptors can be shared and the result can be a secure system...)
评论 #17316654 未加载
exikyutalmost 7 years ago
Nobody else has pointed this out (!): whatever platform is running at this URL doesn&#x27;t sanitize input.<p>Notice how the C #includes seem to be including emptiness. Well, &lt;stdio.h&gt; et al weren&#x27;t stripped; they&#x27;re still in the source code, un-converted &lt; &gt; (ie NOT converted to &amp;lt; &amp;gt;) and all.
pjkundertalmost 7 years ago
We used TIOCSTI to attack Unix terminal sessions left open to “write” — in 1985. I was wondering when&#x2F;if this would show up again!
JdeBPalmost 7 years ago
This is old news, that keeps being reported over and over. Part of the problem, I suspect, is that people keep pointing to the wrong locus of the problem. Even here, this is being characterized as a <i>Debian</i> problem.<p>This is a <i>kernel</i> mechanism.<p>* <a href="https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2013-6409" rel="nofollow">https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2013-6409</a><p>* <a href="https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2015-6565" rel="nofollow">https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2015-6565</a><p>* <a href="https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2016-2779" rel="nofollow">https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2016-2779</a><p>* <a href="https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2016-7545" rel="nofollow">https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2016-7545</a><p>* <a href="https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2017-5226" rel="nofollow">https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2017-5226</a><p>Some kernel people take the view that TIOCSTI is of no Earthly use, and there are other ways to implement line editing, and just make using it an error.<p>* <a href="http:&#x2F;&#x2F;undeadly.org&#x2F;cgi?action=article&amp;sid=20170701132619" rel="nofollow">http:&#x2F;&#x2F;undeadly.org&#x2F;cgi?action=article&amp;sid=20170701132619</a><p>* <a href="https:&#x2F;&#x2F;github.com&#x2F;openbsd&#x2F;src&#x2F;commit&#x2F;baecf150995d4609cd147948779361c3152f355d" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;openbsd&#x2F;src&#x2F;commit&#x2F;baecf150995d4609cd1479...</a><p>Others take a different view.<p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;oss-security&#x2F;2017&#x2F;06&#x2F;03&#x2F;9" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;oss-security&#x2F;2017&#x2F;06&#x2F;03&#x2F;9</a><p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;15&#x2F;8" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;15&#x2F;8</a><p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;17&#x2F;1" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;17&#x2F;1</a><p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;29&#x2F;16" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;29&#x2F;16</a><p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;30&#x2F;9" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;30&#x2F;9</a><p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;30&#x2F;26" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;30&#x2F;26</a><p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;30&#x2F;27" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;30&#x2F;27</a><p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;30&#x2F;32" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;30&#x2F;32</a><p>* <a href="http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;31&#x2F;16" rel="nofollow">http:&#x2F;&#x2F;www.openwall.com&#x2F;lists&#x2F;kernel-hardening&#x2F;2017&#x2F;05&#x2F;31&#x2F;16</a>
评论 #17313219 未加载
bjt2n3904almost 7 years ago
Just tested this out, can confirm it works on Debian 7 as well. Genius little trick! Not sure about practical exploitation, though.
blauditorealmost 7 years ago
I&#x27;m not a shell pro; what is happening on the sleep line?
评论 #17312042 未加载
评论 #17312003 未加载
评论 #17312061 未加载
评论 #17312017 未加载
sandworm101almost 7 years ago
Lol. Thanks. Work machine. Must have ctrl-tabbed without realizing.
评论 #17312398 未加载