Eseguire il “run as Administrator” senza fornire la password su Windows
Una necessità che si presenta in alcune circostanze è quella di dare la possibilità ad utenti con permessi limitati di eseguire determinati comandi che richiedano diritti amministrativi senza fornirgli le credenziali.
Ad esempio poter eseguire il classico “run as Administrator” senza che l’utente sia a conoscenza dei dati di accesso e senza richiedere la presenza dell’amministratore.
Un programma che viene in soccorso si chiama CPAU, che ha la possibilità di preparare un file di lavoro ove verranno salvate le credenziali di accesso in maniera cifrata in maniera poi che l’utente con diritti limitati possa eseguire ugualmente il comando.
Un esempio di utilizzo è il seguente:
CPAU.exe -u <nomedominio\nomeutente> -p <password> -ex <comando> -enc -file <nomefile>
Una volta generato il file è possibile farlo eseguire in questa maniera:
CPAU.exe -dec -file <nomefile> -lwp
Per avere la lista completa delle opzioni è possibile richiamarle mediante il comando “CPAU.exe /?”, per completezza le riporto qui di seguito:
CPAU V01.11.00cpp Joe Richards (joe@joeware.net) November 2005
Usage:
CPAU -u user [-p password] -ex "WhatToRun" [switches]
user User to log on as. Ex: user or domain\user
password User's password
WhatToRun What to execute
Switches: (designated by - or /)
-profile Do local logon with profile instead of net logon
-localwithprofile Alias for -profile
-lwp Alias for -profile
-localwithoutprofile Local logon but do not load profile.
-lwop Alias for -localwithoutprofile
-k Prefix command with cmd /k to leave window open
-c Prefix command with cmd /c to close window after exec.
-pipepwd Special method allows you to pipe password in
-enc Encrypt a job file for later user
-dec Use an ecrypted job file
-file Specify job file to execute or create
-wait Wait for process completion before returning.
-outprocexit Used with -wait, the errorlevel variable has the
exit code of the spawned process instead of cpau.
-cwd x Start at working directory x.
-hide Start the new process in a hidden state.
-title x Allow you specify title of command prompt windows.
-crc file[,file,file] This option allows you to encode
CRC info for files in the job file. When decoded
the CRC have to match or the program bombs. Note that
it will not chase paths looking for the file, you must
specify the exact path.
-nowarn Don't output warning about network logon.
Ex1:
cpau -u joehome\joe -p logon -ex "perl cleanup.pl" -lwp
Runs perl script cleanup.pl as joehomejoe
Ex2:
cpau -u joehome\joe -p logon -ex "perl cleanup.pl" -enc -file cleanup.job
Creates job file called cleanup.job to run perl script cleanup.pl as joehomejoe
Ex3:
cpau -dec -file cleanup.job -lwp
Execute job file cleanup.job
Ex4:
cpau -u joehome\joe -p logon -ex "perl cleanup.pl" -wait -lwp
Runs perl script cleanup.pl as joehomejoe and waits for process to end
Ex5:
cpau -u joe -p logon -ex notepad.exe -lwp
Runs notepad as user joe
Ex6:
cpau -u joehome\joe -p logon -ex logonscript.cmd -lwp
Runs logon script in current directory as user joe (see note below)
Ex7:
cpau -u joehome\joe -p logon -ex logonscript.cmd -lwp -cwd c:\temp
Runs logon script in/from c:\temp as user joe (see note below)
Ex8:
cpau -u joe -p logon -ex logonscript.cmd -enc -file logon.job -crc logonscript.cmd
Encodes logon.job file and CRC protects the batch file