1

I'm trying to write a program that runs a series of commands as my other user account, which is an administrator, however I'm running into an issue where the "Please enter the password" part of this is completely skipped, filled in with random blank spaces for no reason.

How do I go about responding to prompts in Node.JS child procsses?

Here's my code:

var {spawn} = require("child_process");
var cmd = spawn("cmd.exe");

var sleep = t => new Promise(r => setTimeout(r, t * 1000));

cmd.on('close', code => interact({message: "Command executed."}));
// "interact" is a pop-up function, it'll be removed when testing is done, it functions as expected no issues.
cmd.stdout.on('data', text => console.log(Buffer.from(text).toString()));
cmd.stderr.on('data', text => console.log('Err:', Buffer.from(text).toString()));

cmd.stdin.write("runas /profile /user:Manxy \"cmd.exe\"\n");
await sleep(.2);
cmd.stdin.write("ThisIsThePassword\n");
await sleep(.2);
cmd.stdin.write("exit\n");

Here's the response: Image of the response

MistakingManx
  • 31
  • 1
  • 7
  • It's also important to know that /savecred cannot be used in this situation as the password is changed over time and synced with the server this will be running on, I have to get around the password prompt. – MistakingManx Jul 30 '22 at 22:59
  • 1
    I suspect this won't be possible with `runas` (based on Google search results for [`runas password stdin`](https://www.google.com/search?q=runas+password+stdin)). I haven't seen an explanation, but perhaps it does something like spawn a subprocess (which would have a different `stdin`) for the purposes of accepting the password. See [this answer](https://stackoverflow.com/a/56633699/438273) for an alternative. – jsejcksn Jul 31 '22 at 00:12

1 Answers1

0

RUNAS directly prevents people from using it insecurely, however I can include this file with my package and use it instead: https://learn.microsoft.com/en-us/sysinternals/downloads/psexec

Example; psexec.exe -u Manxy -p "ThisIsThePassword" cmd.exe

This greatly simplifies it for me.

Thank you, jsejcksn for the link

MistakingManx
  • 31
  • 1
  • 7