echo rm * echo chown -R nobody:nobody *.php echo chmod 000 * echo tar cvvf archive.tar * echo tar cf archive.tar * echo rsync -t *.c foo:src This article starts with the premise that the person executing the command has no idea what files are in the current working directory. That is itself a more serious problem than the behaviour of wildcards. Later in the article we learn that it also assumes GNU utilities. That i…
> GNU userland and unneeded complexity (e.g. more features than any user will ever use) are practically synonymous. Ahhhh, the memories. These accusations bring me back to the early 1990's. Remember? Remember how it was? Oh, boy, how did we all get so old? To be young and running System V again... And still today, whenever I'm faced on a system without GNU utilities, I find myself installing them to get what seems to…
Unix Wildcards Gone Wild
31–40 of 54 posts
Re: Unix Wildcards Gone Wild
#32echo rm * echo chown -R nobody:nobody *.php echo chmod 000 * echo tar cvvf archive.tar * echo tar cf archive.tar * echo rsync -t *.c foo:src This article starts with the premise that the person executing the command has no idea what files are in the current working directory. That is itself a more serious problem than the behaviour of wildcards. Later in the article we learn that it also assumes GNU utilities. That i…
Substitute `person executing the command' with `simple script', and you've got a better justification. I don't want my simple scripts to break down in the face of silly filenames.
Re: Unix Wildcards Gone Wild
#33Earlier quoted context omitted.
Yes, because no user-uploaded filename will ever be parsed by a maintenance script in a server.
Not by any sane person, no. Why are you letting people upload and name their own files on your server? Should we be posting articles about the vulnerabilities in the finger daemon or Solaris 8's NIS implementation, while we're at it? It seems like this article is aiming towards shared servers where you actually allow shell login to "untrusted" users, which IMO is a relic of days long past, that only really persists a…
Re: Unix Wildcards Gone Wild
#34That said, I going to have to check a few scripts for that chmod attack (or similar) - I think I've seen that type of attack before, but I must have forgotten about it... sigh
Re: Unix Wildcards Gone Wild
#35David A. Wheeler, FOSS (and occasionally security) luminary, who also happens to be creator of the popular sloccount tool, has an excellent page that covers this topic and how to use paths safely and portably in shell scripts (spoiler: it's hard ) : http://www.dwheeler.com/essays/filenames-in-shell.html I strongly recommend his many other essays to HN readers: http://www.dwheeler.com/ Edit: a simple way to avoid thes…
At what point do you give up and, if you must have portability, bootstrap a saner environment?
Are there many options in this area? Assume perl is available? Use autoconf-like shell script compiler? Starting with Lua (which I hope/assume can build anywhere, though I know it's missing lots of functionality out of the box)?
Re: Unix Wildcards Gone Wild
#36^-- SC2035: Use ./* so names with dashes won't become options.
Re: Unix Wildcards Gone Wild
#37echo rm * echo chown -R nobody:nobody *.php echo chmod 000 * echo tar cvvf archive.tar * echo tar cf archive.tar * echo rsync -t *.c foo:src This article starts with the premise that the person executing the command has no idea what files are in the current working directory. That is itself a more serious problem than the behaviour of wildcards. Later in the article we learn that it also assumes GNU utilities. That i…
Anyway, I didn't think about what happens if you create one file called "-e" and then do
echo *
Anyway, as someone else pointed out, using ./* instead of * will defeat the "exploits" in the article.Re: Unix Wildcards Gone Wild
#38- homepage http://homes.cs.washington.edu/~weise/unix-haters.html
- working download link http://richard.esplins.org/static/downloads/unix-haters-hand...
A lot of it is outdated, and yet many things are still incredibly relevant
Re: Unix Wildcards Gone Wild
#39Re: Unix Wildcards Gone Wild
#40Many people are recommending the '--' option-terminating option. Note David Wheeler's caution (in the essay already linked by AceJohnny2 at https://news.ycombinator.com/item?id=8190208 ) about why this is not an all-purpose solution: http://www.dwheeler.com/essays/filenames-in-shell.html#dashd... .
1. For “--” to work, all maintainers would have to faithfully use “--” in
practically every command invocation. That just doesn’t happen in real
life, even after decades of people trying. People forget it all the
time; no one is that consistent, especially since code seems to work
without it. Very few commands require it, after all.
So because other people may or may not forget it, I shouldn’t use it in my scripts/day-to-day usage? That’s about as silly as saying that, because other people will write unreadable code anyway I shouldn’t bother with comments, short functions or sensible variable names. 2. You can’t do it anyway, even if you were perfectly consistent; many
programs and commands do not support “--”. POSIX even explicitly for-
bids echo from supporting “--”, and echo must support “-n” (and GNU
coreutils echo supports other options too).
This is a problem, but iff you have to use echo for some reason. printf works nearly equally well and supports -- just fine. I may have read somewhere that using printf is actually advocated nowadays, but I’m not sure where and why.