12 ms·
On Linux, 'less' can probably get you owned
- fleitz 12y agoAm I missing something? Is lesspipe run as root? What could you execute via lesspipe that you couldn't from the command line?
- Moral_ 12y ago>Is lesspipe run as root? Not normally >What could you execute via lesspipe that you couldn't from the command line? Nothing, but running lesspipe on some file shouldn't lead to remote shell being opened to some guy in Russia.
- gear54rus 12y ago> Ultimately, I think that there's an expectation that running less on a downloaded file won't lead to RCE When you use less, you do not expect any code to be executed, and this article shows how this might be the case (through unexpected invocations of other utilities which may have bugs in them). There are many ways to go from normal shell to root shell after that.
- andreasvc 12y agoAnd there is no need to get root to do serious damage, rm -r ~/* comes to mind.
- orblivion 12y agoSo what's the point of root? To keep me out but let malicious people in?
- danielweber 12y agoThere's not a firm list, but certain commands should always be safe to run against hostile input. If I type "make" on a project I downloaded, arbitrary stuff gets run. I accept that as part of make. If I sha256sum a hostile file, that should never lead to RCE.
- tedunangst 12y agoIf you open a PDF, that should never lead to RCE, but that's not the world we live in. Better for tools not to open PDFs when you don't expect that to happen.
- danielweber 12y agoIt depends what's hiding in the word "open." If I open a PDF in a full-featured reader, I'm slightly ill at ease. If I sha256sum it or wc it, I should be (read: ought to be, in any sane world) perfectly at ease. No matter how complicated the data structures in it, they shouldn't affect those programs.
- tedunangst 12y agoAs per the link, I'm talking about less "opening" a PDF by shelling out to pdftotext. "Hiding" is a good word for the behavior. :)
- jlgaddis 12y agoImagine the case where someone sends you a malicious file and you open it with less.
- vezzy-fnord 12y agoThis was also mentioned in one of the pages of The Fuzzing Project, linked on HN just a short while ago as of this comment: https://fuzzing-project.org/background.html https://fuzzing-project.org/background.html
- danielweber 12y agoI was idly wondering about "less" a month ago. https://news.ycombinator.com/item?id=8506813 https://news.ycombinator.com/item?id=8506813 It looks like my answer is "yeah, people are looking at that."
- userbinator 12y agoI'm also not sure if the automation actually scratches any real itch - I doubt that people try to run 'less' on CD images or 'ar' archives when knowingly working with files of that sort. This is a trend not uncommon in GNU software -- features added by someone who at some point thought it was a good idea, but probably didn't even bother using them much beyond an initial test to see that they are somewhat working. Most users likely think of 'less' as nothing more than a bidirectional version of 'more', and not as the "file viewer that attempts to do everything" that it seems to actually be. It's also a little reminiscent of ShellShock.
- alayne 12y agoThis sounds more like a problem with gluing a bunch of "stuff" together with shell scripts that are not well thought out than a problem with less or GNU in general having untested features.
- jschwartzi 12y agoTo be fair, the usefulness of a tool is often proportional to your power to also do really dumb things with it.
- fafner 12y agolesspipe is not a GNU project...
- 12y ago
- mrmondo 12y agoThat is bad default behaviour on Ubuntu's (and centos'?) behalf. I have confirmed this is not the case in Debian.
- steakejjs 12y agoThis research lcamtuf has been doing with AFL is really important. One thing that it is proving (exactly as a lot of people expected) is, we don't have any idea where security bugs (think the next heartbleed or shellshock) are going to show up, we have no idea how good the software out there is (meaning it is bad), and most of the time we don't even know what's running on our own boxes. If these basic things we use hundreds of times a day (less, strings) have huge flaws, we have a lot of work ahead of us.
- pjmlp 12y agoThey will never go away while people insist in using C and its derivatives to write userspace code.
- rquirk 12y agoThis is covered in the fuzzing project's FAQ https://fuzzing-project.org/faq.html https://fuzzing-project.org/faq.html "if you start a new software project it is a good idea to avoid C right from the start. however ... most major software components we use today [are] written in C. Rewriting things from scratch is hard, compared to that finding bugs with fuzzing is the low hanging fruit." While something like Go has good performance, writing low-level tools in interpreted languages (Python, Ruby, etc) means you would always have the performance overhead of firing up the interpreter for everything. A hypothetical non-C system would feel sluggish compared to what we have now.
- pjmlp 12y agoWho said anything about interpreted languages? Modula-2, Modula-3, Go, D, Haskell, OCaml, Oberon, Ada, Extended Pascal, Object Pascal, C#, Java, ... The list of languages with native code compilers is quite big, no need for interpreters. The problem with fuzzing is that, like the use of safer languages, it just won't get adopted unless forced down the throat of developers. This is why, Google, Microsoft and now Apple are adopting a "our way or the high way" in memory safe languages for their platforms. After all, proprietary APIs would already be enough for platform lockin. I do agree no one is going to re-write the huge amount of code out there. However it is already good enough if new code get written into something else.
- reubenbond 12y agoLess really is more
- jlgaddis 12y agoIndeed. $ sha256 /usr/bin/less /usr/bin/more SHA256 (/usr/bin/less) = 9d517bcdf5bb22e756337ee450657de4d4edba779f7c17acfcaf7ba71f76bf59 SHA256 (/usr/bin/more) = 9d517bcdf5bb22e756337ee450657de4d4edba779f7c17acfcaf7ba71f76bf59
- fidz 12y agoUsing Ubuntu 12.04 md5sum /bin/less /bin/more 4be69e915a4b4514d3d06ee07dd56a68 /bin/less 11fc84952b1f31a91b5b6ec29740e497 /bin/more Or it just my system?
- ars 12y ago/bin/more is in the util-linux package. Less can pretend to be more if run that way, but debian also does ship the real more command.
- Anthony-G 12y agoThe `more` command is often provided by `util-linux` package. Ubuntu 12.04: dpkg -S /bin/more /bin/less util-linux: /bin/more less: /bin/less CentOS 5.10: rpm -qf /bin/more /usr/bin/less util-linux-2.13-0.59.el5_8 less-436-9.el5
- Glyptodon 12y agoShould this show when I run env or not?
- jlgaddis 12y ago$ env | grep ^LESS LESSOPEN=||/usr/bin/lesspipe.sh %s $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.6 (Santiago)
- viraptor 12y agoThis is probably a good reminder of something else: using selinux/apparmor/tomoyo/... can save you from many situations where you'd be exploited otherwise. For example as a response to this you can set a policy on lesspipe and all its children so that they cannot access the internet or write outside of temp directories. Whatever library is used by lesspipe - you're safe as long as the output terminal and your kernel are safe.
- jschwartzi 12y agoThis should honestly be part of every modern Linux system. It would go a long way toward creating the kind of reasonably secure system people are looking for. I would envision this to be useful if there were a pre-installed local database of common use cases for each utility, and the user invoking the utility could interactively decide whether to allow specific exceptions, with a big fat warning. Then, it doesn't matter whether someone exploits your tool, they're only ever allowed to utilize the tool for its intended use cases.
- reirob 12y agoAbsolutely agree! It's even more true for closed source software like Skype - to be able to prevent it from accessing to data it doesn't have to. I know there are many alternatives to Skype, but there are people that have to use it from time to time for professional reasons. I started doing this for Skype on Ubuntu 14.04 - but have to admit that I quickly ran out of steam. Need to pick up where I ended.
- pflanze 12y agoIsn't it impossible to secure Skype because of it's use of X11? I've found it to be impossible to run Skype in untrusted X11 (so that it doesn't get full control over your X display), and running it in a nested X server is probably too slow for video. (And running it in a VM didn't work either for me because of audio and video performance. I really decided I couldn't use Skype except when running it on a real machine dedicated to running Skype.)
- username223 12y agoThe first time I accidentally ran "less" on a directory and it piped some version of "ls" into itself, I was mildly annoyed. The thing's supposed to page a text file on a terminal. Since then, I've had to think twice before invoking it to avoid this "helpful" behavior, and I'm not surprised that it came back to bite people.
- userbinator 12y agoI suppose this would be the more straightforward and expected behaviour: less: somedir: is a directory
- cbd1984 12y ago> The first time I accidentally ran "less" on a directory and it piped some version of "ls" into itself, I was mildly annoyed. % less . . is a directory % less imadir imadir is a directory My point is, that behavior is a configuration issue on your end, not inherent to the less codebase.
- naner 12y agoI believe that is the point of the linked email. Some distributions have less symlinked to something else (e.g. the lesspipe script) for convenience. Plain 'ol less isn't that much of a problem.
- username223 12y ago> My point is, that behavior is a configuration issue on your end, ... On my end, and on every "end" where I ever log in. "less" works as a simple pager on my own system, but now I need to remember to possibly fix it everywhere else. "You can fix it in the config file" is not an excuse for broken-by-design software. > ... not inherent to the less codebase. Well yes, it kind of is. "less" used to be a better replacement for "more." Now it's something else, which should have a different name. Should "cat" be changed to automatically uncompress files and concatenate archives?
- lmm 12y ago
- Animats 12y agoLast month, it was "file", which turned out to have a parser for executables which can be exploited via a buffer overflow. Probably the best exploit in this line is crafting JPEG files which cause buffer overflows in forensic tools and take over the machine being used for forensics. We need an effort to convert Linux userspace tools likely to be invoked as root or during installs from C/C++ to something with subscript checking.
- twinge 12y ago"strings" is also vulnerable: http://lcamtuf.blogspot.com/2014/10/psa-dont-run-strings-on-untrusted-files.html http://lcamtuf.blogspot.com/2014/10/psa-dont-run-strings-on-... Inspecting files is apparently hazardous.
- MichaelGG 12y agoNo, writing general handling code in C is hazardous.. And after that, mixing domains, especially for human convenience, is dangerous as parsing gets complicated and leads to the unexpected. Rust can solve the first problem. A sense of elegance or just good taste can solve the second.
- pjmlp 12y agoAny language with native code compilers can be used for 90% of the stuff C is still used, not only Rust. I think due to the rise in VM based runtimes and lost of investment in alternative languages (e.g. Modula-2....) many developers created the myth that C and C++ are the only languages with native code compilers.
- xorcist 12y agoThis problem with LESSOPEN would exist even if less was written in Rust. The same goes for the strings command.
- Scramblejams 12y agoAll the more reason to use memory safe languages as far up the stack as you can go.
- jacquesm 12y agorm /bin/less Problem solved. Any binary utility that I haven't used in a 6 month period can get lost. The problem is that there are probably a hundred or so more issues like this hiding in /bin/* and /usr/bin/* and wherever else executables are hiding. Is there a way to retrofit 'can shell out' as a capability flag not unlike the regular access permission bits?
- MichaelGG 12y agoOr just unset LESSOPEN ?
- edwintorok 12y agoYou probably did use less in the past 6 months if you used Linux in the past 6 months. less is usually the default pager for things like 'man', 'git log', etc. But as pointed out in another comment the problem is not with 'less', but with some distros configuring it to use 'lesspipe' as preprocessor.
- deleted 12y ago[deleted]
- fsniper 12y agoI think this is one side effect of development. We are trying to implement any feature that would be nice to have into every software. LESSOPEN or LESSPIPE is a feature that is already achievable via manual means. But automation is the king so it's a nice feature to have it in the software implemented. If we could just stop and move on whenever software is capable of doing what they are intended for as smooth as possible, many of these issues would diminish to exist.
- pmontra 12y agoI checked what I have on my Ubuntu 12.04. $ env|grep LESS LESS= -R LESSOPEN=| /usr/share/source-highlight/src-hilite-lesspipe.sh %s Safe, as long as source-highlight isn't buggy. I also checked my .bashrc and found this # make less more friendly for non-text input files, see lesspipe(1) # NO! I don't want this! # [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" So yes, lesspipe was the default and for some reason I commented it out. I vaguely remember at being annoyed about less showing me something different from the actual binary content of the files.
- zobzu 12y agobut also vim. and irssi. and gpg. and a bunch of other day to day linux programs nobody bothered to review very thoroughly. Just any case anybody still believe its just java, flash, openssl and bash that suffers bad vulns (oh oh oh).
- guard-of-terra 12y agoThat's why alias less=/usr/share/vim/macros/less.sh
- Aissen 12y agoI used to do that with vimpager (a better implementation of this shell script). Unfortunately this cannot work as it doesn't process data as it arrives, you need to wait for input to end. So it's only good for fast & short commands.
- guard-of-terra 12y agoSure, but I have a separate alias for streams. alias -g even, zsh-style.
- deleted 12y ago[deleted]
- upofadown 12y agoI checked on Debian Jessie and the /usr/bin/lesspipe script runs entirely off the file extension. So there is no issue with less itself. If someone sends me, say, a malicious doc file I would have to type "less blort.doc" to get owned by catdoc. The only time i would ever type that is if I knew that less would invoke catdoc, that I actually had catdoc installed on the machine and for some reason I wanted to use catdoc to look at a doc file. Less only installs a mailcap entry for "text/*". A mail reader that could not handle plain text itself would not be much of a mail reader. That also means that it is kind of stupid to have less display non-text things. Still not a real security issue.
- gwern 12y agoUser continence works great until someone figures out how to get lesspipe called automatically... 'I would never run bash manually on unsanitized input from HTTP requests!' [years pass] /shellshocked!
- michaelcampbell 12y ago> Many Linux distributions ship with the 'less' command automagically interfaced to 'lesspipe'-type scripts, usually invoked via LESSOPEN. This is certainly the case for CentOS and Ubuntu. I just ran less on a dir in Ubuntu Trusty (latest LTS) and got the expected "<dir> is a directory" message.
- Sami_Lehtinen 12y agoUsing cat in terminal can get you owned.