0

i perl script that reads the network traffic and prints out payloads of packets of specific length back onto the terminal. and for this to happen, the script should be initiated by root or else the packets will not be read.

i am using pcap in perl for that purpose.

now i have a webpage on my webserver. can i execute that perl script from my webpage and get the output that is being printed on the terminal into my webpage?

i am trying to use javascript to serve this purpose but i dont know how its done. i tried googling it and all i got was ssh user@remote "perl pathto/perlfile.pl"

can someone help me out with this please?

Kiran Vemuri
  • 2,762
  • 2
  • 24
  • 40
  • What's wrong with what Google gave you? Fill in user, host and name of script and you should have a starting point. Of course, the complete idea is not quite sane, but that doesn't seem to be your question. – innaM Jun 28 '13 at 16:38
  • @innaM i tried that but that approach wasn't working. i tried to run a sample ping script that doesn't require root privileges but that didn't work – Kiran Vemuri Jun 28 '13 at 16:55
  • Your edit makes it clear that you are willing to server the problem with a javascript-only solution. You can forget about that right now. Having some sort of webpage trigger a job run by root is a very, very bad idea and if you really, really have to do it, you should have lots and lots of experience. – innaM Jun 28 '13 at 17:21

1 Answers1

0
  • To initiate a command from a web page, issue an AJAX call to another CGI script running on your webserver.

    AJAX call can return the results of running your command (typically in JSON or XML format) and then call up some JavaScript handler to render that data in your page's DOM.

  • To run something as root on the web server's unix machine locally, you will need an suid script to be called from your CGI script mentioned in the first bullet (since web server and all the scripts it runs are typically run as non-root for security reasons).

  • To run something as root on ANOTHER machine, you have correctly found that you need to use ssh (from that same CGI script): ssh root@your_remotehost "perl pathto/perlfile.pl"

    You will need to set up the ssh keys correctly between 2 systems so ssh doesn't ask for a password.

    It is possible that you will NOT be able to ssh as root without a password when running as a non-root user; in which case you would need to:

    • ssh as the same user as your CGI script runs as

    • Have the command executed on remote server run the suid script, as described above for local case.

If you need further guidance, you will need to post specific code snippets and error messages or troubleshooting details so we can assess what the problems are.

DVK
  • 126,886
  • 32
  • 213
  • 327