SECURE INSTALLING STUFF USING RUNAS WITHOUT CONSOLE


The following shows an imho secure way of installing stuff on W2k and up using the RUNAS command, without the console prompting for a password.


PROCEDURE

1. Copy/Paste the codes and make the four files
2. Make sure the requirements are met (place all files in one folder)
3. Start the MAKEEXE_SANUR.cmd command file
4. Run the KASAI_SANUR_STARTER.kix script to see a messagebox displaying the admin-user and it's privileges


REQUIREMENTS

- Wkix32.exe ( http://www.kixtart.org/downloads/ )
- Wkixcrpt.exe ( http://www.sgbit.demon.co.uk/kix/files/ )
- Sanur.exe ( http://www.commandline.co.uk/sanur )
- User 'Deployer' with local admin rights and password '1234567890'
(change code if other user/password is desired)
- KASAI_SANUR.kix
- MAKEEXE_SANUR.cmd
- KASAI_SANUR_STARTER.kix
- KASAI_SANUR_SCR2RUN.kix


KASAI_SANUR.kix



SetL 'SPWD='+$SANUR_password

If Exist('%WINDIR%\system32\runas.exe')
    Sleep 1
    Shell '%COMSPEC% /c runas.exe /env /user:%%SUSER%% "%%SCMD%%" | '+@SCRIPTDIR+'\sanur.exe %%SPWD%%'
     If @ERROR
        $rc=WriteProfileString(@SCRIPTDIR+'\KASAI_SANUR.log',@DATE+' '+@TIME,'Cmd-result','-E- (EC=@ERROR) While executing --> %SCMD%.')
    EndIf
    Sleep 1
EndIf
Exit 0




MAKEEXE_SANUR.cmd



wkixcrpt -f ".\WKIX32.EXE" -f ".\SANUR.EXE" -m "" -e """"%%KIXCRYPTDIR%%\wkix32.exe""" """%%KIXCRYPTFILE%%""" $SANUR_PASSWORD=1234567890" ".\KASAI_SANUR.kix"




KASAI_SANUR_STARTER.kix



Break on
$cmd=@scriptdir+'\wkix32.exe '+@scriptdir+'\kasai_sanur_scr2run.kix'
SetL 'SUSER=Deployer'
SetL 'SCMD='+$cmd
Shell @scriptdir+"\KASAI_SANUR"
Exit 0




KASAI_SANUR_SCR2RUN.kix



$rc=MessageBox("@userid (@priv)","")
Exit 0






Example for rolling out the MSO03-039 patch:


;****************************************************************************
;SCRIPT/FUNCTION : HotFix.kix
;
;ACTION          : Installs hotfixes
;
;AUTHOR          : Patrick Rutten (MightyR1@hotmail.com)
;
;CONTRIBUTORS    : 
;                 
;
;SCRIPT VERSION  :
;                  1.0.0.0 - 2003-09-12
;                    Initial Release
;
;SYNTAX          : -
;
;PARAMETERS      : -
;
;RETURNS         : -
;
;REMARKS         : -
;
;DEPENDENCIES    : KASAI_SANUR.exe
;
;EXAMPLE(S)      : -
;
;KNOWN ISSUES    : -
;
;KIXTART VERSION : -

;KIXTART BBS     : -
;
;****************************************************************************
;
;

;Enable Break to allow killing the script without logoff
Break on

;Set some global options
$rc=SetOption('NoVarsInStrings','ON')
$rc=SetOption('Explicit','ON')

;Declare variables
Dim $SecSrc,$Hotfix,$HotfixExe,$HotfixChk,$Parms

;Assign Variables
$SecSrc='\\HOTFIXSERVER\Security$'

;MS03-039: A Buffer Overrun in RPCSS May Allow Code Execution
;http://support.microsoft.com/?kbid=824146
$Hotfix='Q824146'

$HotfixExe=HfExe($Hotfix)
$HotfixExe=$SecSrc+'\'+$Hotfix+'\'+$HotfixExe
$Parms=' /q /u /z'

$HotfixChk=GetFileVersion('%windir%\system32\Rpcrt4.dll','Productversion')

Select
    ;W2k
    Case InStr(@PRODUCTTYPE,'Windows 2000') AND $HotfixChk<>'5.0.2195.6802'
        $rc=ApplyHotfix($HotfixExe,$Parms)
    ;Wxp
    Case InStr(@PRODUCTTYPE,'Windows XP') AND ($HotfixChk<>'5.1.2600.109' OR $HotfixChk<>'5.1.2600.1254')
        $rc=ApplyHotfix($HotfixExe,$Parms)
EndSelect

;Exit the script
Exit 0

;****************************************************************************
;
;ADDITIONAL FUNCTIONS
;
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function HfExe($Hf)
    Select
        Case InStr(@PRODUCTTYPE,'Windows 2000')
            $HfExe=$Hf+'-W2K-'
        Case InStr(@PRODUCTTYPE,'Windows XP')
            $HfExe=$Hf+'-WXP-'
        Case 1
            $HfExe=0
    EndSelect
    Select
        Case @SYSLANG = '0413DUTCH'
            $HfExe=$HfExe+'NLD.exe'
        Case @SYSLANG = '0409ENGLISH'
            $HfExe=$HfExe+'ENU.exe'
        Case 1
            $HfExe=0
    EndSelect
EndFunction

Function ApplyHotfix($Exe,$Par)
    Dim $KASAI_SANUR
   
    $KASAI_SANUR='\\HOTFIXSERVER\Security$\KASAI_SANUR\KASAI_SANUR.exe'
   
    If Exist($Exe)
        SetL 'SUSER=Deployer'
        SetL 'SCMD='+$Exe+$Par
        Shell $KASAI_SANUR
    EndIf
EndFunction



[ 29. September 2003, 21:04: Message edited by: MightyR1 ]
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...