|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+@echo off
|
|
|
2
|
+setlocal enabledelayedexpansion
|
|
|
3
|
+
|
|
|
4
|
+:: Configuration
|
|
|
5
|
+set "csv_file=allowed_pcs.csv"
|
|
|
6
|
+
|
|
|
7
|
+:: Check if the policy file exists
|
|
|
8
|
+if not exist "%csv_file%" (
|
|
|
9
|
+ echo [ERROR] %csv_file% not found.
|
|
|
10
|
+ pause
|
|
|
11
|
+ exit /b
|
|
|
12
|
+)
|
|
|
13
|
+
|
|
|
14
|
+echo ============================================
|
|
|
15
|
+echo Secure Shadow Session Menu (CSV Based)
|
|
|
16
|
+echo ============================================
|
|
|
17
|
+echo NO. : PC NAME : USER : DESC
|
|
|
18
|
+echo --------------------------------------------
|
|
|
19
|
+
|
|
|
20
|
+:: Read CSV and display the menu
|
|
|
21
|
+set count=0
|
|
|
22
|
+for /f "usebackq tokens=1-4 delims=," %%a in ("%csv_file%") do (
|
|
|
23
|
+ set /a count+=1
|
|
|
24
|
+ set "pc_!count!=%%a"
|
|
|
25
|
+ set "user_!count!=%%b"
|
|
|
26
|
+ set "id_!count!=%%c"
|
|
|
27
|
+ echo [!count!] : %%a : %%b : %%d
|
|
|
28
|
+)
|
|
|
29
|
+
|
|
|
30
|
+echo.
|
|
|
31
|
+set /p choice="Select a number to connect (or 'q' to quit): "
|
|
|
32
|
+
|
|
|
33
|
+:: Handle exit or invalid input
|
|
|
34
|
+if /i "%choice%"=="q" exit /b
|
|
|
35
|
+if not defined pc_%choice% (
|
|
|
36
|
+ echo [ERROR] Invalid selection.
|
|
|
37
|
+ pause
|
|
|
38
|
+ exit /b
|
|
|
39
|
+)
|
|
|
40
|
+
|
|
|
41
|
+:: Map selected ID to variables
|
|
|
42
|
+set "target_pc=!pc_%choice%!"
|
|
|
43
|
+set "allowed_user=!user_%choice%!"
|
|
|
44
|
+set "allowed_id=!id_%choice%!"
|
|
|
45
|
+
|
|
|
46
|
+echo.
|
|
|
47
|
+echo [INFO] Target PC: %target_pc%
|
|
|
48
|
+echo [INFO] Policy: User must be "%allowed_user%" with ID %allowed_id%
|
|
|
49
|
+echo Verifying remote session status...
|
|
|
50
|
+
|
|
|
51
|
+:: Verify the actual session status on the remote PC
|
|
|
52
|
+set "verified=false"
|
|
|
53
|
+for /f "tokens=1-4" %%i in ('qwinsta /server:%target_pc% ^| findstr /i "Active"') do (
|
|
|
54
|
+ :: Check if the row contains both the allowed username and the specific session ID
|
|
|
55
|
+ echo %%i %%j %%k %%l | findstr /i "%allowed_user%" | findstr "%allowed_id%" >nul
|
|
|
56
|
+ if not errorlevel 1 (
|
|
|
57
|
+ set "verified=true"
|
|
|
58
|
+ )
|
|
|
59
|
+)
|
|
|
60
|
+
|
|
|
61
|
+:: Proceed if session matches the CSV policy
|
|
|
62
|
+if "%verified%"=="true" (
|
|
|
63
|
+ echo [SUCCESS] Verification passed. Requesting connection...
|
|
|
64
|
+ :: Note: /noConsentPrompt is omitted here. The user on the target PC must accept the request.
|
|
|
65
|
+ mstsc /v:%target_pc% /shadow:%allowed_id% /control
|
|
|
66
|
+) else (
|
|
|
67
|
+ echo [SECURITY ALERT] Session verification failed.
|
|
|
68
|
+ echo The current active user on %target_pc% does not match the CSV policy.
|
|
|
69
|
+)
|
|
|
70
|
+
|
|
|
71
|
+pause
|