Run a bat file as Domain Admin using PsExec.exe? but encrypt/hide password

Carl Billington
Carl Billington used Ask the Experts™
on
Below is how I would run the command normally, but I don't want to display the password in written text. Is there a way of hiding it?
 
PsExec.exe /accepteula -u DOMAIN\UserName -p PASSWORD \\SERVER\Script.bat

Open in new window


Thanks for your help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NVITEnd-user support

Commented:
You could use something like CPAU. There may be other tools like it. Still, it may not be highly secure.
http://www.joeware.net/freetools/tools/cpau/index.htm

Another is Bat2Exe.

A much better solution is Powerbroker by beyondtrust. But it isn't free.

Although I assume NOT using the -P password option is not what you want.
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
What exactly is it you're trying to do? if you want to install something that requires administrative permissions, you can use a GPO with a computer startup(! -- not a logon) script.

Then there are tons of batch to exe converters; just google for "bat to exe compiler" (minus the quotes); I can't recommend one in particular, sorry. For a simple script like this, they might work, but in general, I don't trust them.
Then there's AutoIt, an easy to learn script language that can create stand-alone exe files, as console application or GUI, and in 32bit or 64bit: https://www.autoitscript.com/site/autoit/downloads/

If the users running the script aren't tech savvy, you can "hide" the password in an alternate data stream. The script must be stored on NTFS (so if copied to a FAT32 volume, the ADS will be lost).
You can add the password to the script by calling it with Whatever.cmd /ads "TopSecret".
Whatever.cmd /ads will tell you whether the script contains the password.
Any other call will extract the password from the script and currently echo out the psexec command.
@echo off
setlocal
set ADS=
(for /f "usebackq delims=" %%a in ("%~f0:ADS") do set ADS=%%a) 2>NUL
if /i "%~1"=="/ads" (
	if "%~2"=="" (
		if defined ADS (
			echo ADS valid.
			exit /b 0
		) else (
			echo No ADS found.
			exit /b 1
		)
	) else (
		>"%~f0:ADS" echo "%~2"
		exit /b 0
	)
)
if not defined ADS exit /b 1
ECHO PsExec.exe -accepteula -u DOMAIN\UserName -p %ADS% \\SERVER\Script.bat

Open in new window

Author

Commented:
Hi oBdA

Where do you define the password in the script?

It would be perfect if I can get that working.

Thank you
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
You don't define in the script itself, that's the point, after all.
Just save the script as it is as Whatever.cmd.
Then run (from an open command prompt in the script's folder):
Whatever.cmd /ads "TopSecret"
This will add an Alternate Data Stream called "ADS" with the password to the script file; enclose the password in double quotes.
Note that depending on the program you use to edit the script after the ADS has been added, saving the file may or may not remove the ADS from the file. Windows Notepad for example keeps the ADS when saving, Notepad++ removes it. You can just call the script with "/ads" to verify that the ADS is still present:
Whatever.cmd /ads
which should return "ADS valid."
If it doesn't, you can just add it again.
Now run
Whatever.cmd
and you should see the psexec command line generated:
PsExec.exe -accepteula -u DOMAIN\UserName -p "TopSecret" \\SERVER\Script.bat

Author

Commented:
Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial