Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
    0: #!/usr/bin/perl -w
    1: 
    2: use strict;
    3: 
    4: # This is a RIDUCULOUSLY simple script which I often use
    5: # with ISP's that prohibit telnet access.  It simply runs
    6: # an arbitrary UNIX command and captures its output to a
    7: # web page.
    8: 
    9: # I won't debate whether or not it belongs here; that's for
    10: # exalted others to decide; I merely present something I
    11: # have found to be useful.
    12: 
    13: # Be Warned: this appends sh redirection (of stderr to
    14: # stdout: '2>&1') to the command entered, so arbitrary
    15: # redirection entered as part of any command may not
    16: # work as expected!
    17: 
    18: # DISCLAIMER: Do NOT leave this script in an accessible
    19: # location on any active web server!! It is VERY insecure!
    20: # At least chmod the 'x' bit off when not in use!
    21: 
    22: use CGI qw( :standard *table *Tr *pre );
    23: use CGI::Carp qw( fatalsToBrowser );
    24: use File::Basename;
    25: 
    26: my $title = 'UNIX Command';
    27: 
    28: my $command = param('command'); # get command entered
    29: # append command name, if any, to title
    30: $title .= ': '. basename( (split /\s/, $command)[0] ) if $command;
    31: 
    32: # display control panel
    33: print join( "\n", header,
    34: 		  start_html($title),
    35: 		  strong(h1($title)),
    36: 		  start_form({ -method=>'get' }),
    37: 		  start_table({-width=>'100%',-borders=>0}),
    38: 		  start_Tr,
    39: 		  td( 'Command:' ),
    40: 		  td( textfield({-size=>100,-name=>'command'}) ),
    41: 		  td( submit('run')),
    42: 		  end_Tr,
    43: 		  end_table,
    44: 		  end_form ), "\n";
    45: 
    46: # if command was entered, run it in a pipe and display its output
    47: if ($command) {
    48:   open( CMD, "$command 2>&1|" ) or die "$!: running command: '$command'";
    49:   print start_pre, "\n";
    50:   print while (<CMD>);
    51:   print end_pre, "\n";
    52:   close CMD;
    53: }
    54: 
    55: print join( "\n",
    56:             end_html ),"\n";
    

In reply to Run arbitrary UNIX commands on webserver without telnet by dmmiller2k

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (8)
    As of 2015-07-04 05:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (57 votes), past polls