-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode_sonicwall.bat
More file actions
108 lines (88 loc) · 2.57 KB
/
decode_sonicwall.bat
File metadata and controls
108 lines (88 loc) · 2.57 KB
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
@echo off
setlocal enabledelayedexpansion
:: Check if a file was dragged onto the script
if "%~1"=="" (
echo ERROR: No file specified!
echo.
echo Usage: Drag and drop a SonicWall .exp file onto this batch file.
echo.
pause
exit /b 1
)
:: Get the full path and details of the dropped file
set "INPUT_FILE=%~1"
set "FILE_DIR=%~dp1"
set "FILE_NAME=%~n1"
set "FILE_EXT=%~x1"
echo ========================================
echo SonicWall Config Decoder
echo ========================================
echo.
echo Input file: %INPUT_FILE%
echo Directory: %FILE_DIR%
echo.
:: Check if file exists
if not exist "%INPUT_FILE%" (
echo ERROR: File does not exist!
pause
exit /b 1
)
:: Step 1: Remove trailing ampersands from the .exp file
echo [Step 1/3] Removing trailing ampersands...
set "TEMP_FILE=%FILE_DIR%%FILE_NAME%_temp.exp"
:: Read the file, remove trailing &, and save to temp file
powershell -Command "(Get-Content '%INPUT_FILE%' -Raw) -replace '&+$', '' | Set-Content '%TEMP_FILE%' -NoNewline"
if errorlevel 1 (
echo ERROR: Failed to process file!
pause
exit /b 1
)
echo Done.
echo.
:: Step 2: Decode the base64 file using certutil
echo [Step 2/3] Decoding base64 content...
set "DECODED_FILE=%FILE_DIR%%FILE_NAME%_decoded.txt"
certutil -decode "%TEMP_FILE%" "%DECODED_FILE%" >nul 2>&1
if errorlevel 1 (
echo ERROR: Decode command failed!
echo Make sure the file is a valid SonicWall .exp backup file.
del "%TEMP_FILE%" 2>nul
pause
exit /b 1
)
echo Decode command completed successfully.
echo.
:: Step 3: Replace & with newlines to make it readable
echo [Step 3/3] Formatting output (replacing ^& with newlines)...
set "OUTPUT_FILE=%FILE_DIR%%FILE_NAME%_readable.txt"
:: Use PowerShell to replace & with newlines
powershell -Command "(Get-Content '%DECODED_FILE%' -Raw) -replace '&', \"`r`n\" | Set-Content '%OUTPUT_FILE%'"
if errorlevel 1 (
echo ERROR: Failed to format output!
del "%TEMP_FILE%" 2>nul
pause
exit /b 1
)
echo Done.
echo.
:: Clean up temporary files
del "%TEMP_FILE%" 2>nul
:: Summary
echo ========================================
echo SUCCESS!
echo ========================================
echo.
echo Output files created:
echo Decoded: %DECODED_FILE%
echo Readable: %OUTPUT_FILE%
echo.
echo You can now open the readable file to view the configuration.
echo Search for "interfaces" to find IP address information.
echo.
:: Ask if user wants to open the file
set /p "OPEN_FILE=Open the readable file now? (Y/N): "
if /i "%OPEN_FILE%"=="Y" (
start "" notepad "%OUTPUT_FILE%"
)
echo.
pause