Hey folks,
I'm in a position now where I'd like to provide access to a binary on a web-server via a cgi script. I've been handed a cgi that does the job reasonably well, but I'm not convinced it's at all secure or robust, so I'd like some confirmation/advice on it.
The first problem is it wasn't written using CGI.pm and I'm not quite up to re-writing it the right way just now unless I absolutely have to. Here's what it does:
- Checks for the presence of the binary in an accessible location. (It used to be looking for it in /usr/local/bin! I've changed that.)
- It expects to be called as the GET action from a form, so it checks to make sure it got a single parameter from the form. (Since this parameter is a standard regular expression, I can't realistically filter out too much from the input stream.)
- Open an anonymous pipe for input like so:
unless (open(PIPE, "search \"$pattern\" |")) {
# barf out some error messages
}
# carry on processing the output from the search command
Now is it just me, or is this opening a sub-shell and thus providing a way for almost anyone to execute almost any code on my web-server with (at least) the permissions of the server's UID/GID? Is there a way I can insist that the open() command execute a restricted shell, or better yet only execute the 'search' command without a shell at all so I don't have to worry about evil escape sequences that I can't really quotemeta since they are regexps?
Thanks,
-J.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.