As a general rule of thumb, I would not let users choose the filename of files they upload.
my $file = param("file"); my @file_name = split(/\\/,$file); my $file_name = pop(@file_name);
What happens if the filename is .htaccess? I'm not really up on my un*x type environments, but I imagine that this could cause you heartaches.

Also, since your shebang line (#!/usr/bin/perl -w) suggests that you are on a un*x type system, shouldn't your slashes be the other way? Consider the following:

my $file ='../../bin/ls|'; my @file_name = split(/\\/,$file); my $file_name = pop(@file_name); print $file_name;
That prints "../../bin/ls|" as the filename. With the reverse directory traversal, this should allow them to back up to the /bin directory and with the trailing pipe, run commands on the server. Again, I'm am not as familiar with non-Windows environments, but this doesn't look terribly secure to me.

Of course, you also want taint checking. Read perlsec for details. Plus, my online CGI course has a bit of information about security that you may find useful.

If I have my CPU up my exhaust port, please let me know.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid - insecure upload) Re: Help make upload from web secure by Ovid
in thread Help make upload from web secure by dchau

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.