-
Notifications
You must be signed in to change notification settings - Fork 357
/
smb.bat
132 lines (117 loc) · 5.67 KB
/
smb.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@echo off
echo 504msf_exercise.bat
echo.
echo This script will start the lanmanserver service if it is not already running, and change the value of the following registry keys:
echo hklm\software\microsoft\windows\currentversion\policies\system\LocalAccountTokenFilterPolicy = 1
echo hklm\system\currentcontrolset\control\lsa\ForceGuest = 0
echo hklm\system\currentcontrolset\control\lsa\LmCompatibilityLevel = 0
echo.
echo This script will also create a script on your Desktop called 504msf_restore.bat that will restore each setting to its original value.
echo.
echo Is it okay to proceed?
pause
echo.
REM Create beginning of restore script (if "." is passed, script will be created in current directory instead of Desktop)
if [%1]==[.] (
set RESTOREFILE=.\504msf_restore.bat
) else (
set RESTOREFILE=%USERPROFILE%\Desktop\504msf_restore.bat
)
if exist "%RESTOREFILE%" (
echo.
echo The 504msf_restore.bat file already exists. Please run it and then delete it before running this script again so that you don't lose your original settings!
pause
exit /B 1
)
echo @echo off > "%RESTOREFILE%"
echo at ^> nul >> "%RESTOREFILE%"
echo if %%ERRORLEVEL%% NEQ 0 ( >> "%RESTOREFILE%"
echo echo Please run this script with elevated privileges! >> "%RESTOREFILE%"
echo pause >> "%RESTOREFILE%"
echo exit /B 1 >> "%RESTOREFILE%"
echo ) >> "%RESTOREFILE%"
echo echo 504msf_restore.bat >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
echo echo This script will revert the system settings changed by 504msf_exercise.bat back to their original settings on this system. >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
echo echo Is it okay to proceed? >> "%RESTOREFILE%"
echo pause >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
REM Start the lanmanserver service if it isn't working
sc query lanmanserver | findstr RUNNING >nul
if %ERRORLEVEL% EQU 1 (
echo Running: sc start lanmanserver
sc start lanmanserver
echo.
echo echo Running: sc stop lanmanserver >> "%RESTOREFILE%"
echo sc stop lanmanserver >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
)
REM Global findstr command (used in all subsequent reg queries)
set fnd=findstr /I /L /C:"REG_DWORD"
REM TokenFilter check
set qry=reg query "hklm\software\microsoft\windows\currentversion\policies\system" /v LocalAccountTokenFilterPolicy
%qry% >nul 2>nul
if %ERRORLEVEL% EQU 1 (set TOKENFILTER=DELME) else (
for /f "Tokens=2*" %%a in ('%qry%^|%fnd%') do (
@set TOKENFILTER=%%b
)
)
echo Running: reg add hklm\software\microsoft\windows\currentversion\policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
reg add hklm\software\microsoft\windows\currentversion\policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
echo.
if %TOKENFILTER%==DELME (
echo echo Running: reg delete hklm\software\microsoft\windows\currentversion\policies\system /v LocalAccountTokenFilterPolicy /f >> "%RESTOREFILE%"
echo reg delete hklm\software\microsoft\windows\currentversion\policies\system /v LocalAccountTokenFilterPolicy /f >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
) else (
echo echo Running: reg add hklm\software\microsoft\windows\currentversion\policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d %TOKENFILTER% /f >> "%RESTOREFILE%"
echo reg add hklm\software\microsoft\windows\currentversion\policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d %TOKENFILTER% /f >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
)
REM ForceGuest check
set qry=reg query "HKLM\System\CurrentControlSet\Control\Lsa" /v ForceGuest
%qry% >nul 2>nul
if %ERRORLEVEL% EQU 1 (set FORCEGUEST=DELME) else (
for /f "Tokens=2*" %%a in ('%qry%^|%fnd%') do (
@set FORCEGUEST=%%b
)
)
echo Running: reg add hklm\system\currentcontrolset\control\lsa /v ForceGuest /t REG_DWORD /d 0 /f
reg add hklm\system\currentcontrolset\control\lsa /v ForceGuest /t REG_DWORD /d 0 /f
echo.
if %FORCEGUEST%==DELME (
echo echo Running: reg delete hklm\system\currentcontrolset\control\lsa /v ForceGuest /f >> "%RESTOREFILE%"
echo reg delete hklm\system\currentcontrolset\control\lsa /v ForceGuest /f >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
) else (
echo echo Running: reg add hklm\system\currentcontrolset\control\lsa /v ForceGuest /t REG_DWORD /d %FORCEGUEST% /f >> "%RESTOREFILE%"
echo reg add hklm\system\currentcontrolset\control\lsa /v ForceGuest /t REG_DWORD /d %FORCEGUEST% /f >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
)
REM LmCompatibilityLevel check
set qry=reg query "HKLM\System\CurrentControlSet\Control\Lsa" /v LmCompatibilityLevel
%qry% >nul 2>nul
if %ERRORLEVEL% EQU 1 (set LMCOMPAT=DELME) else (
for /f "Tokens=2*" %%a in ('%qry%^|%fnd%') do (
@set LMCOMPAT=%%b
)
)
echo Running: reg add hklm\system\currentcontrolset\control\lsa /v LmCompatibilityLevel /t REG_DWORD /d 0 /f
reg add hklm\system\currentcontrolset\control\lsa /v LmCompatibilityLevel /t REG_DWORD /d 0 /f
echo.
if %LMCOMPAT%==DELME (
echo echo Running: reg delete hklm\system\currentcontrolset\control\lsa /v LmCompatibilityLevel /f >> "%RESTOREFILE%"
echo reg delete hklm\system\currentcontrolset\control\lsa /v LmCompatibilityLevel /f >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
) else (
echo echo Running: reg add hklm\system\currentcontrolset\control\lsa /v LmCompatibilityLevel /t REG_DWORD /d %LMCOMPAT% /f >> "%RESTOREFILE%"
echo reg add hklm\system\currentcontrolset\control\lsa /v LmCompatibilityLevel /t REG_DWORD /d %LMCOMPAT% /f >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
)
echo Finished!
echo.
pause
echo echo Finished! >> "%RESTOREFILE%"
echo echo. >> "%RESTOREFILE%"
echo pause >> "%RESTOREFILE%"