6 ms·
No one expects command execution
- orf 11y agoI don't get it, it's not really unexpected if you pass the name of the executable (which just happens to be a script) via a flag... used explicitly for passing an executable to run. I mean, is it unexpected if `./my_command --execute-this-right-now=somescript.sh` executes somescript.sh?
- ushi 11y agoI agree. Every single example in this article makes perfect sense to me.
- strictfp 11y agoI think he wants to bring to peoples attention that if you give someone sudo rights for a specific program chances are that they will be able to elevate their privilegies.
- reubenmorais 11y agoI guess the author's point is don't ever, ever, ever mix shells and unsanitized user inputs, even if you think it can't possibly be harmful. In other words, even if it's not obvious, doing this creates a security vulnerability: tar bla bla ${user input}
- krylon 11y agoPerl has a special "taint" mode (Ruby does, too, I think, but I don't know about the differences or similarties), where any data coming from outside the program - environment variables, network connections, files, etc. - is considered "tainted", i.e. treated as bad, until you validate it using regular expressions (or something along those lines). I have to admit I never tried it, but it sounds like a good idea, assuming it works as advertised, when dealing with potentially malicious input or paranoia.
- JonnieCache 11y agoRails has ActiveSupport::SafeBuffer for doing XSS protection, but ruby doesn't track external strings as dirty like that.
- flgr 11y ago> but ruby doesn't track external strings as dirty like that. It does: irb(main):001:0> gets.tainted? foo => true You can even set $SAFE to 1 or higher to disallow the use of tainted strings in potentially dangerous commands: freya:~ flgr$ ruby -e '$SAFE = 1; system "tar bla bla #{gets}"' foo -e:1:in `system': Insecure operation: -r (SecurityError) from -e:1:in `<main>' See http://phrogz.net/programmingruby/taint.html http://phrogz.net/programmingruby/taint.html for more information.
- vidarh 11y ago> but ruby doesn't track external strings as dirty like that. Yes, it does. E.g: x = STDIN.gets puts x.tainted? y = "hello "+x puts y.tainted? z = "foo" puts z.tainted? The two first will return "true", and the last will print "false". If you set the safe-level appropriately some methods will be disallowed for x and y above (e.g. eval()), though I would not trust that as comprehensive, but it's a lot better than nothing.
- andrey-p 11y agoBut if you're plugging in input like that, couldn't the malicious user just pass in something like && sudo rm -rf / anyway? Which would render the whole point of the article moot.
- andrewaylett 11y agoNot every command gets run through the shell, and not using the shell was one of the prerequisites in the article.
- ninkendo 11y agoThere's simple ways to "escape" user input (as in, ensure the whole input string is interpreted as a single argument to this program) in ways that ensure you can't do simple &&'s or ;'s and execute a totally different command. But the point of the article is even if it's properly escaped, users can still do malicious things when input is passed to lots of standard UNIX utilities.
- Gibbon1 11y agoWhat I wish, I wish there was a flag in unicode to declare characters as 'unsafe user input' so that system utilizes and databases can recognize unsafe user input and barf on it.
- enno 11y agoThis is a point that should have been made in the author's article. As it is, it presents a poorly defined problem without offering solutions (other than "be afraid").
- Retr0spectrum 11y agoIt isn't much different from something like echo `somescript.sh`
- marcosdumay 11y agoYes, it's unexpected and less commands should do that. Did you read the manpage of every utility on your computers to know that they won't execute a user supplied program? If you didn't you are up to nasty surprises. That $HOME trick alone would give privilege escalation to anybody that gets a user-level access to a server of mine. Gota change it.
- tokenizerrr 11y agoHow so? I might be missing something but as far as I can tell it's just executing the runme.sh as the user who ran the bash command. It would be virtually identical to ./runme.sh
- subway 11y agoI've seen a lot of novice sysadmins do silly things like rely on sudo's command restrictions, expecting this to actually contain a user. For those sysadmins, yeah, it's unexpected.
- digi_owl 11y agoAll security is a matter of degree, be it computing or physical. the most determined of attackers will always find a way in.
- 0x0 11y agoThere's been a bit of attention recently on these things. The big issue is people using " * " on the command line without prefixing with an "--" argument or simply "./*". If someone has managed to sneak in particularly evil filenames (that look like -options), then the unsuspecting user may be in for a surprise, for example tar'ing up a public upload directory.
- yk 11y agoThis way around is perfectly obvious. But assume that you are writing a website that prints a man page, for example by piping the output of man $URLPARAMETER to the user. In that case it is only obvious to check if man can execute arbitrary commands if you already know that man is not just a cat for man pages.
- Retr0spectrum 11y agoAre there any real examples of how this could be used to do something malicious?
- schoen 11y agoProbably strictfp's example above of allowing someone to run specific commands with sudo. In the past there were also various implementations of a "restricted shell"; it's conceivable that some of these could bypass a restricted shell's restrictions, depending on how they were implemented.
- tptacek 11y agoSure: any attempt to build a "sandboxed" command line interface with a shell, or any web app that shells out to one of these commands and passes user input as an argument.
- jlgaddis 11y agoIn one case, I could have used tcpdump to elevate privileges on a customer's router. They had an x86 box running RHEL as their firewall/router and I was hired to resolve an (IPSec) issue they were having. I asked for a capture of some specific traffic but their I.T. guys (small company w/ only two technical staff) weren't "fluent" with bpf filters, so they created a user account for me, provided me with access via SSH, and granted me the ability to run tcpdump via sudo. From the example given, I could have used the "-z" flag to run arbitrary commands and escalate to root (although, in this case, I likely could have gained root simply by asking nicely).
- joeyh 11y agoCommand execution is overrated. How about having tar download an arbitrary tar file over the network, from a server you control? http://bugs.debian.org/290435 http://bugs.debian.org/290435
- 0x0 11y agoThat's a bit of a surprise!
- juhanima 11y agoThis might be related to another article about OLE execution, to cast a shadow of doubt that it is not an isolated habit. Having outside stuff executed when not meaning to is always bad. I for one would be badly disappointed, if tar xvf unexpectedly run some code. Luckily, that is not the case. UNIX got battle-hardened during its college years, the cases of unexpected execution are few and far between. One of them is post-install, never run dpkg -i unless you trust the packager.
- cbd1984 11y ago> UNIX got battle-hardened during its college years Is that when it finally gave up making shar archives? For the unitiated: A shar is a "shell archive", or a shell script which (typically) makes heavy use of 'here documents' to do what tarballs do, only they're shell scripts so you have to execute them and then they can potentially execute arbitrary code unless you read through them very closely and actually understand them. Yes, people actually made these. Yes, people actually ran these. Yes, they still exist on some old archive FTP servers and so on. It's amazing how clever you can be when you don't think you'll ever have to care about security or The Sufficiently Stupid User (because sufficiently advanced stupidity is indistinguishable from malice).
- huherto 11y agoI loved shars. It was a carefree time. Nothing to worry about.
- schoen 11y agoAlso there used to be services based on telnet somehost someport | sh (I remember an IRC client installer script hosted on sci.dixie.edu like that.) Unfortunately we still have curl http://somehost/somepath http://somehost/somepath | bash which is not very safe even if somehost is not malicious. But it was kind of awesome when the Internet was friendly!
- Blackthorn 11y agoI don't really understand how a shar is more dangerous than the still-incredibly-common "./configure; make".
- tome 11y agoOh for explicity typed IO. (Sadly command-line programs have yet to pass the threshold of even having a types system at all.)
- vezzy-fnord 11y agoOr, you know, a proper capability-based security model.
- alanctgardner3 11y agoPowershell! Seriously, MS doesn't do everything great, but Powershell has typed pipes (typed everything, actually, it's not just stringly like *sh) which are seriously awesome.
- bediger4000 11y agoI've used a "shell" that had a type system. Just before Control Data Corporation (CDC) dried up and blew away, they put out a mainframe OS called "NOS/VE". Yes, "VE", not "BE" - "NOS/BE" was a somewhat unrelated OS for CDC mainframes. The NOS/VE shell had string types and integer types at least. The experience was absolutely horrible. It's hard for me to remember much other than the difficulty of getting anything practical to work, and that may be a consequence of CDC's incredibly poor design choices for the "shell" rather than the types. But I personally have never said "Oh, for a type system in this darn shell!" since then.
- WalterBright 11y agoWhat I find interesting is the thread title being a pun from a 40 year old movie. Back in the 70s, there wasn't any interest in movies, music, etc. from the 30s. And there still isn't interest in 30s culture, but plenty in the 70s. I wonder why.
- krylon 11y agoMy guess: Because it's Monty Python. They weren't around in the 1930s, but they are still funny today.
- deleted 11y ago[deleted]
- dsjoerg 11y agoGreat question. Hypotheses: a) 70s culture was a brief moment where geek culture was also pop culture, e.g. Monty Python. So geeks will forever adore that moment b) mass culture underwent a big shift when TV emerged, so that people after TV cannot easily understand culture before TV c) the disillusionment and paranoia of the 70s is especially relevant today
- cbd1984 11y ago> Back in the 70s, there wasn't any interest in movies, music, etc. from the 30s. I don't know, Hawkeye Pierce did a pretty good impression of Groucho Marx. I think it's down to numbers: There are a Hell of a lot more people born who know about the 1970s alive now compared to people who knew about the 1930s alive in the 1970s. It was a Baby Boom, after all.
- supertruth 11y agoI think you're in a bubble. Lots of people have interest in the 30s given it was the golden age of Hollywood: Gone with the Wind references have entered the cultural lexicon, so have The Wizard of Oz references.
- WalterBright 11y agoA movie from the 70s that compares with TWoO and GWTW in stature would be Star Wars, certainly not MPatHG. I find it unremarkable that people today quote SW.
- brynet 11y agoAnd yet another interesting GNU tar "feature", also noteworthy is remote tar: https://www.gnu.org/software/tar/manual/html_section/tar_46.html#remote_002ddev https://www.gnu.org/software/tar/manual/html_section/tar_46.... > "If the archive file name includes a colon (`:'), then it is assumed to be a file on another machine. If the archive file is `user@host:file', then file is used on the host host. The remote host is accessed using [rsh]." and > "If you need to use a file whose name includes a colon, then the remote tape drive behavior can be inhibited by using the `--force-local' option." On many systems, rsh is aliased to ssh, so if you don't properly sanitize your archive names, GNU tar will make network connections.
- im3w1l 11y agoWow... I'm starting to get really scared of the shell, and how much hidden complexity there is waiting to trap the unwary. Feels like best practice for shellscripts is to only ever use them for one-offs. And that tar and friends should never be used as "helpers" by other programs.
- digi_owl 11y agoWelcome to life.
- im3w1l 11y agoWhat you are, rudely, implying is that what I am saying is already well known. I'd argue that isn't so. Until recently shell-scripts was the way you inited a system. I still have almost 2000 shell scripts on my machine that I didn't write myself. People got owned during shellshock, which means they did run helper programs, in web-facing applications even.
- digi_owl 11y agoNo, life is stuffed full of hidden complexities. Complexities that are ready to bite the hand of the unwary at the slightest of chances. Honesty i think the biggest lie in modern times is the MS/Apple lie that computing can be made so simple that even the proverbial aunt Tillie can do it without reading any sort of manual.
- elchief 11y agoThere must be a bug in my OpenBSD, because none of these work...
- jcape 11y agoIf your ~/.bashrc is a SYMLINK to a bash or sh script, bash will AUTOMATICALLY EXECUTE that script on login. If you give rsync command a source or destination with an unescaped colon, it will read an ENVIRONMENT VARIABLE to figure out a command to run to AUTOMATICALLY CONNECT TO ARBITRARY NETWORK RESOURCES. If you have keys, it will even SKIP PASSWORD ENTRY, and with default Kerberos, it will not only skip password, but make a network connections to a login server:port specified by a DNS ENTRY. Seriously, who is this guy, and why is this trainwreck #1 on HN?
- deleted 11y ago[deleted]
- ajkjk 11y agoDid this article make you angry? Why do you call it a trainwreck?
- rylee 11y agoThe article is literally "If you tell these utilities to execute this script, they'll execute this script". NONE of these should be "unexpected".
- jjoonathan 11y agoNot the point. Of course it's not surprising that these utilities will execute scripts if you tell them to. The unexpected fact is that you can tell them to -- and that this is documented behavior which probably isn't going away. If your argument was that no programmer should be surprised that you can tell an archive utility to execute an arbitrary script, then you and the author of the post are in complete agreement. The remaining difference is that the article actually does something to fix the problem while you merely hurl an implicit insult at anyone who hasn't seen this type of privilege escalation yet. One of these actions is more constructive than the other.
- d23 11y ago
- dlsym 11y agoHey guys! Did you know you can actually execute a script with date by running date && ./myscript.sh WOW! I better get on going writing my blog post "executing abitrary code with 'date'".
- AceJohnny2 11y agoWell geez, it's almost like the tools were designed with flexibility and pluggability in mind before the advent of the internet and the fear of remote shell exploits... /s
- evilDagmar 11y agoOh my god! Who would have ever expected that command line utilities might be able to execute external programs?! Quick! Everyone! Run in circles!
- tcannon 11y agoYou didn't expect command execution.