Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Depends. You didn't gave much information about the environment your script is used in (exposition to threats) and what it is supposed to do (extend of damage in case of successful attack). The measures you have to take might be simple (e.g. when operating in a somewhat closed environment: intranet, VPN) or more complex (Internet).

E.g., your current implementation is accessible for everybody who can connect to port 12000 of the webhost. If your're not talking about an intranet webhost, the script is in principle globally accessible! There is no password protection. If you had one, it could be snooped since there is no encryption in place. I guess, you will replace the interact() sub with something more powerful. It could be something innocent as

# simple time service sub interact { ... print $sock "It's: " . localtime . "\n"; ... }
or something like
# poor man's telnet sub interact { ... while ( <$sock> ) { chomp; print $sock `$_ 2>&1`; } ... }

Read perlsec as an introduction. Minimum security measures to take:

  • use taint-mode / sanitize all input
  • execute with minimum privileges
  • chroot if possible
  • provide password protection
  • restrict access to given IPs (ideally localhost, maybe you can use an SSH-tunnel?)
  • restrict local resource usage (e.g. kill script if interact() runs too long) / ulimit
  • use a daemon package
  • don't forget logging
  • keep your environment patched
  • update: add - SIGPIPE handler (see what I mean with next item?)
  • etc. ... it's the game to forget something that can be used to compromise your site.
It is not impossible to create a reasonable safe socket based server, but it is hard work and little mistakes have potential for great harm (or I am just too paranoid ;-).


In reply to Re^3: Why socket not responding in webserver by Perlbotics
in thread Why socket not responding in webserver by romy_mathew

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
  • Outside of code tags, you may need to use entities for some characters:
            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 romping around the Monastery: (4)
    As of 2014-07-31 22:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (255 votes), past polls