News for hackers. Stuff that matters.
Re:A web server in a shell script by cstross on Tuesday November 02, 2010 @06:06PM (#1862592)
cat "$filename"

...

Oh dear. Ohdearohdearohdear.

Now all we need to do is make sure that the first character in $filename is "&" followed by some privilege escalation exploit and ...

(Am I missing something?)

Re:A web server in a shell script by msbarnett on Tuesday November 02, 2010 @07:05PM (#1862813)
Nothing about this is intended to be the least bit secure. It's a fun hack, nothing more.
Re:A web server in a shell script by sjs on Tuesday November 02, 2010 @08:34PM (#1863065)
Not saying there isn't an exploit here, but that's not it.

    % foo="& do_evil"
    % cat "$foo"
    cat: & do_evil: No such file or directory
Now if the request was for the path /../../../../../../etc/passwd ... that's a different story.

edit: and with the CGI stuff it might be possible to execute rm or something else dangerous/destructive.

Re:A web server in a shell script by rix0r on Tuesday November 02, 2010 @06:34PM (#1862708)
Well the variable expansion is quoted, so afaik it could only be interpreted as a single argument to cat.
Re:A web server in a shell script by Erwin on Tuesday November 02, 2010 @07:55PM (#1862953)
The double quote quoting, while allowing you to do e.g. rm "file with spaces" still expands $ and `. Compare:

echo none:`date`

echo double: "`date`"

echo single: '`date`'

Re:A web server in a shell script by js2 on Tuesday November 02, 2010 @09:47PM (#1863255)
But it doesn't expand recursively, so "$var" is safe to protect against special characters in var. That said, one should really read one's shell's documentation, because there be dragons.