1

I am trying to run some command on the client system through server. I know server has lots of security issues while executing server commands, is there any way to run command form browser.

I have following commands in nodejs but, i need this to run form the browser in clients system.

same as in this question but form html page. node.js shell command execution

function run_cmd(cmd, args, callBack ) {
   var spawn = require('child_process').spawn;
   var child = spawn(cmd, args);
   var resp = "";      
   child.stdout.on('data', function (buffer) { resp += buffer.toString() });
   child.stdout.on('end', function() { callBack (resp) });
} 

Usage:

run_cmd( "ls", ["-l"], function(text) { console.log (text) });
Community
  • 1
  • 1
rughimire
  • 374
  • 1
  • 5
  • 16

1 Answers1

2

No, you may not execute arbitrary shell/console commands through a browser.

The security implications for this would be gigantic. You wouldn't want someone to execute:

run_cmd( "rm", ["-rf *"], function(text) { console.log ("lol") });

Through your browser. Not even if you could explicitly trust it.

CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
  • Isn't there any way to accomplish such task? – rughimire Mar 12 '14 at 09:13
  • Is there any way to open a program that is installed on client machine from HTML page through javascript. This will also sove my problem. – rughimire Mar 12 '14 at 10:28
  • 1
    Not through Javascript, no. If you have control of that client machine, you could write a piece of software and use [protocol handler](https://developer.mozilla.org/en/docs/Web-based_protocol_handlers) to launch that software. It can then redirect the request to the console on behalf of the user. – CodingIntrigue Mar 12 '14 at 11:49