:: Writed by: Sergey.Golovanov at kaspersky.com for habrahabr.ru (enchanted by Alexey Girin - vk.com/alexey.girin)
@ echo on
If you want to get access to this file from the Internet files.
Pause
:: Setup new user ::
set safeusername = saferun_user_% random%
set safepassword =% random% Ai% random%
echo Login:% safeusername%
echo Password:% safepassword%
net user% safeusername% / delete
del Browserlist4saferun.txt
net user% safeusername%% safepassword% / add
:: init new user profile ::
echo Option explicit> init_new_user_profile.vbs
echo Dim oShell >> init_new_user_profile.vbs
echo set oShell = Wscript.CreateObject ("WScript.Shell") >> init_new_user_profile.vbs
echo oShell.Run "RunAs / profile / user:% safeusername% ping" >> init_new_user_profile.vbs
echo WScript.Sleep 1000 >> init_new_user_profile.vbs
echo oShell.Sendkeys "% safepassword%" >> init_new_user_profile.vbs
echo oShell.Sendkeys "{ENTER}" >> init_new_user_profile.vbs
echo Wscript.Quit >> init_new_user_profile.vbs
call cscript init_new_user_profile.vbs
ping -n 10 localhost >> nul
del init_new_user_profile.vbs
:: Setup privileges for new user ::
net localgroup users% safeusername% / delete
cscript "% Programfiles% \ Windows Resource Kits \ Tools \ XCACLS.vbs" "% USERPROFILE% \ .. \% safeusername% \" / D% safeusername% :( OI) (IO) (WDAC, WO, X)
:: Setup browsers ::
: FindOpera
if exist "% APPDATA% \ Opera \" xcopy / E / I / C / Y / Q / H / R "% APPDATA% \ Opera \ *" "% USERPROFILE% \ .. \% safeusername% \ AppData \ Roaming \ Opera \ "
if exist "% Programfiles% \ Opera \ Opera.exe" goto run4opera
if exist "% Programfiles (x86)% \ Opera \ Opera.exe" goto run4operax86
Goto FindFireFox
: run4opera
echo Opera ^ |% Programfiles% \ Opera >> Browserlist4saferun.txt
Goto FindFireFox
: run4operax86
Set Browsername = Opera
echo Opera ^ |% Programfiles (x86)% \ Opera >> Browserlist4saferun.txt
Goto FindFireFox
: FindFireFox
if exist "% APPDATA% \ Mozilla \" xcopy / E / I / C / Y / Q / H / R "% APPDATA% \ Mozilla \ *" "% USERPROFILE% \ .. \% safeusername% \ AppData \ Roaming \ Mozilla \ "
if exist "% Programfiles% \ Mozilla Firefox \ Firefox.exe" goto run4Firefox
if exist "% Programfiles (x86)% \ Mozilla Firefox \ Firefox.exe" goto run4Firefoxx86
Goto FindChrome
: run4Firefox
echo Firefox ^ |% Programfiles% \ Mozilla Firefox >> Browserlist4saferun.txt
Goto FindChrome
: run4Firefoxx86
echo Firefox ^ |% Programfiles (x86)% \ Mozilla Firefox >> Browserlist4saferun.txt
Goto FindChrome
: FindChrome
If exist "% LOCALAPPDATA% \ Google \ Chrome \ Application \ chrome.exe" goto run4chrome
Goto findie
: run4chrome
:: // Chrome by not stable. Dissabled for performance.
:: xcopy / E / I / C / Y / Q / H / R "% LOCALAPPDATA% \ Google \ Chrome \ *" "% USERPROFILE% \ .. \% safeusername% \ AppData \ Local \ Google \ Chrome \"
:: for / r "% USERPROFILE% \ .. \% safeusername% \ AppData \ Local \ Google \ Chrome \" %% C in (* .exe) do icacls %% C / grant% safeusername% :( X)
:: for / r "% USERPROFILE% \ .. \% safeusername% \ AppData \ Local \ Google \ Chrome \" %% C in (* .dll) do icacls %% C / grant% safeusername% :( X)
:: echo Chrome ^ | "% USERPROFILE% \ .. \% safeusername% \ AppData \ Local \ Google \ Chrome \ Application \" >> Browserlist4saferun.txt
Goto findie
: FindIE
:: // TODO A lot of XCOPYs
if exist "% LOCALAPPDATA% \ Microsoft \ Internet Explorer" (
xcopy / E / I / C / Y / Q / H / R "% USERPROFILE% \ Favorites \ *" "% USERPROFILE% \ .. \% safeusername% \ Favorites \"
xcopy / E / I / C / Y / Q / H / R "% LOCALAPPDATA% \ Microsoft \ Internet Explorer \ *" "% USERPROFILE% \ .. \% safeusername% \ AppData \ Local \ Microsoft \ Internet Explorer \"
xcopy / E / I / C / Y / Q / H / R "% LOCALAPPDATA% \ Microsoft \ Windows \ History \ *" "% USERPROFILE% \ .. \% safeusername% \ AppData \ Local \ Windows \ History"
xcopy / E / I / C / Y / Q / H / R "% APPDATA% \ Roaming \ Microsoft \ Windows \ Cookies \ *" "% USERPROFILE% \ .. \% safeusername% \ AppData \ Roaming \ Microsoft \ Windows \ Cookies \ "
)
if exist "% Programfiles (x86)% \ Internet Explorer \ iexplore.exe" goto run4iex86
if exist "% Programfiles% \ Internet Explorer \ iexplore.exe" goto run4ie
: run4iex86
echo IExplore ^ |% Programfiles (x86)% \ Internet Explorer >> Browserlist4saferun.txt
goto MakeLinks
: run4ie
echo IExplore ^ |% Programfiles% \ Internet Explorer >> Browserlist4saferun.txt
:: Make links ::
: MakeLinks
rd / s / q "% USERPROFILE% \ Downloads \ Browser"
rd / s / q "% USERPROFILE% \ ђ Ў bv" \ SafeLinks "
"% Programfiles% \ Windows Resource Kits \ Tools \ linkd.exe" / d "% USERPROFILE% \ Downloads \ Browser" "% USERPROFILE% \ .. \% safeusername% \ Downloads"
mkdir "% USERPROFILE% \ ђ Ў bv" \ SafeLinks "
echo on
For / f "tokens = 1,2 delims = |" %% A in (Browserlist4saferun.txt) do (
echo Option explicit> "%% B \ %% A.vbs"
echo Dim oShell >> "%% B \ %% A.vbs"
echo set oShell = Wscript.CreateObject ^ ("WScript.Shell" ^) >> "%% B \ %% A.vbs"
echo oShell.Run "RunAs / user:% safeusername% %% A.exe" >> "%% B \ %% A.vbs"
echo WScript.Sleep 1000 >> "%% B \ %% A.vbs"
echo oShell.Sendkeys "% safepassword%" >> "%% B \ %% A.vbs"
echo oShell.Sendkeys "{ENTER}" >> "%% B \ %% A.vbs"
echo Wscript.Quit >> "%% B \ %% A.vbs"
echo Set oWS = WScript.CreateObject ^ ("WScript.Shell" ^)> "% USERPROFILE% \ ђ WYE bv" \ SafeLinks \ %% A.lnk.vbs "
echo sLinkFile = "% USERPROFILE% \ Desktop \ SafeLinks \ %% A_saferun.LNK" >> "% USERPROFILE% \ ђ Ў bv" \ SafeLinks \ %% A.lnk.vbs "
echo Set oLink = oWS.CreateShortcut ^ (sLinkFile ^) >> "% USERPROFILE% \ ђ WYE bv" \ SafeLinks \ %% A.lnk.vbs "
echo oLink.
echo oLink.IconLocation = "%% B \ %% A.exe, 0" >> "% USERPROFILE% \ ђ Ў bv" \ SafeLinks \ %% A.lnk.vbs "
echo oLink.WorkingDirectory = "%% B \" >> "% USERPROFILE% \ ђ Ў bv" \ SafeLinks \ %% A.lnk.vbs "
echo oLink.Save >> "% USERPROFILE% \ ђ Ў bv" \ SafeLinks \ %% A.lnk.vbs "
)
for / r "% USERPROFILE% \ ђ Ў bv" \ SafeLinks \ "%% p in (* .vbs) do cscript %% p
for / r "% USERPROFILE% \ ђ Ў bv" \ SafeLinks \ "%% v in (* .vbs) do del %% v
:: Open Explorer with links ::
explorer "% USERPROFILE% \ ђ Ў bv" \ SafeLinks \ "
:: Create Uninstall ::
echo @ echo off> uninstall_% ~ n0.bat
echo net user% safeusername% / del >> uninstall_% ~ n0.bat
echo rd / s / q "% USERPROFILE% \ Downloads \ Browser" >> uninstall_% ~ n0.bat
echo rd / s / q "% USERPROFILE% \ ђ Ў bv" \ SafeLinks ">> uninstall_% ~ n0.bat
echo rd / s / q "% USERPROFILE% \ .. \% safeusername% \" >> uninstall_% ~ n0.bat
echo For / f "tokens = 1,2 delims = |" %%%% A in (Browserlist4saferun.txt) del "%%%% B \ %%%% A.vbs" >> uninstall_% ~ n0.bat
echo del Browserlist4saferun.txt >> uninstall_% ~ n0.bat
echo del %% 0 >> uninstall_% ~ n0.bat
: Exit
Source: https://habr.com/ru/post/241081/
All Articles