1
0

pcdu.bat 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. @echo off
  2. setlocal EnableExtensions EnableDelayedExpansion
  3. REM =====================================================
  4. REM ____ _ ____ ____ _ _
  5. REM | _ \ __ _ _ ____ _( )___ / ___| _ \| | | |
  6. REM | |_) / _` | '__\ \ / /|// __|| | | | | | | | |
  7. REM | __/ (_| | | \ V / \__ \| |___| |_| | |_| |
  8. REM |_| \__,_|_| \_/ |___(_)____|____/ \___/
  9. REM
  10. REM Parv's Case Download Utility (PCDU) v1.3
  11. REM Downloads case files from analysis server
  12. REM =====================================================
  13. set "PCDU_VERSION=1.3"
  14. set "PCDU_NAME=pcdu"
  15. set "PCDU_INSTALL_DIR=%USERPROFILE%\PCDU"
  16. set "SCRIPT_PATH=%~f0"
  17. set "SCRIPT_NAME=%~nx0"
  18. REM Icon URLs
  19. set "ICON_URL_SJLNT=https://git.4parv.in/parv.ashwani/PCDU/raw/ASSETS/Icons/ServerIcon.ico"
  20. set "ICON_URL_CASE=https://git.4parv.in/parv.ashwani/PCDU/raw/ASSETS/Icons/Casefolders.ico"
  21. set "ICON_NAME_SJLNT=.SJLNT_Icon.ico"
  22. set "ICON_NAME_CASE=.CaseFolder_Icon.ico"
  23. REM =====================================================
  24. REM Command Line Argument Handling
  25. REM =====================================================
  26. if /i "%~1"=="/install" goto :INSTALL_TO_PATH
  27. if /i "%~1"=="/uninstall" goto :UNINSTALL_FROM_PATH
  28. if /i "%~1"=="/help" goto :SHOW_HELP
  29. if /i "%~1"=="-h" goto :SHOW_HELP
  30. if /i "%~1"=="--help" goto :SHOW_HELP
  31. if /i "%~1"=="/?" goto :SHOW_HELP
  32. if /i "%~1"=="/update-icons" goto :UPDATE_ALL_ICONS
  33. REM =====================================================
  34. REM Check if first run (not installed to PATH)
  35. REM =====================================================
  36. call :CHECK_IF_INSTALLED
  37. if !PCDU_INSTALLED! EQU 0 (
  38. call :PROMPT_INSTALL
  39. )
  40. goto :MAIN_SCRIPT
  41. REM =====================================================
  42. REM SET FOLDER ICON FUNCTION
  43. REM Parameters: %1 = Folder Path, %2 = Icon URL, %3 = Icon Filename
  44. REM =====================================================
  45. :SET_FOLDER_ICON
  46. setlocal EnableDelayedExpansion
  47. set "FOLDER_PATH=%~1"
  48. set "ICON_URL=%~2"
  49. set "ICON_NAME=%~3"
  50. set "ICON_PATH=%FOLDER_PATH%\%ICON_NAME%"
  51. set "DESKTOP_INI=%FOLDER_PATH%\desktop.ini"
  52. REM Check if folder exists
  53. if not exist "%FOLDER_PATH%" (
  54. echo [!!] Folder does not exist: %FOLDER_PATH%
  55. endlocal
  56. goto :EOF
  57. )
  58. REM Download icon if not present or force update
  59. if not exist "%ICON_PATH%" (
  60. echo Downloading icon...
  61. REM Try PowerShell first (more reliable)
  62. powershell -Command "try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%ICON_URL%' -OutFile '%ICON_PATH%' -UseBasicParsing } catch { exit 1 }" >nul 2>&1
  63. if !ERRORLEVEL! NEQ 0 (
  64. REM Fallback to curl
  65. curl -sL -o "%ICON_PATH%" "%ICON_URL%" >nul 2>&1
  66. )
  67. if not exist "%ICON_PATH%" (
  68. echo [!!] Failed to download icon
  69. endlocal
  70. goto :EOF
  71. )
  72. REM Hide the icon file
  73. attrib +h +s "%ICON_PATH%" >nul 2>&1
  74. echo [OK] Icon downloaded
  75. ) else (
  76. echo [OK] Icon already exists
  77. )
  78. REM Create or update desktop.ini
  79. echo [.ShellClassInfo] > "%DESKTOP_INI%"
  80. echo IconResource=%ICON_NAME%,0 >> "%DESKTOP_INI%"
  81. echo IconFile=%ICON_NAME% >> "%DESKTOP_INI%"
  82. echo IconIndex=0 >> "%DESKTOP_INI%"
  83. echo InfoTip=PCDU Managed Folder >> "%DESKTOP_INI%"
  84. REM Set desktop.ini attributes (hidden + system)
  85. attrib +h +s "%DESKTOP_INI%" >nul 2>&1
  86. REM Set folder as system folder (required for custom icon)
  87. attrib +r "%FOLDER_PATH%" >nul 2>&1
  88. echo [OK] Folder icon configured
  89. endlocal
  90. goto :EOF
  91. REM =====================================================
  92. REM UPDATE ALL ICONS FUNCTION (for existing folders)
  93. REM =====================================================
  94. :UPDATE_ALL_ICONS
  95. echo.
  96. echo ============================================================
  97. echo ^|^> PCDU Icon Update Utility
  98. echo ============================================================
  99. echo.
  100. echo This will update icons for all existing PCDU folders.
  101. echo.
  102. REM Find all SJLNT folders
  103. echo Searching for SJLNT folders...
  104. echo.
  105. set "UPDATED_COUNT=0"
  106. REM Check common locations
  107. for %%D in (C D E F G H) do (
  108. if exist "%%D:\SJLNT" (
  109. echo Found: %%D:\SJLNT
  110. echo Updating SJLNT folder icon...
  111. call :SET_FOLDER_ICON "%%D:\SJLNT" "%ICON_URL_SJLNT%" "%ICON_NAME_SJLNT%"
  112. REM Update all case folders inside
  113. echo Scanning for case folders...
  114. for /d %%C in ("%%D:\SJLNT\*") do (
  115. echo Updating: %%~nxC
  116. call :SET_FOLDER_ICON "%%C" "%ICON_URL_CASE%" "%ICON_NAME_CASE%"
  117. set /a UPDATED_COUNT+=1
  118. )
  119. )
  120. )
  121. REM Also check C:\Temp\SJLNT
  122. if exist "C:\Temp\SJLNT" (
  123. echo Found: C:\Temp\SJLNT
  124. echo Updating SJLNT folder icon...
  125. call :SET_FOLDER_ICON "C:\Temp\SJLNT" "%ICON_URL_SJLNT%" "%ICON_NAME_SJLNT%"
  126. for /d %%C in ("C:\Temp\SJLNT\*") do (
  127. echo Updating: %%~nxC
  128. call :SET_FOLDER_ICON "%%C" "%ICON_URL_CASE%" "%ICON_NAME_CASE%"
  129. set /a UPDATED_COUNT+=1
  130. )
  131. )
  132. echo.
  133. echo ============================================================
  134. echo Icon update complete!
  135. echo Case folders updated: %UPDATED_COUNT%
  136. echo.
  137. echo NOTE: You may need to refresh Explorer (F5) or restart
  138. echo Explorer for icons to appear.
  139. echo ============================================================
  140. echo.
  141. REM Refresh icon cache
  142. echo Refreshing icon cache...
  143. ie4uinit.exe -show >nul 2>&1
  144. ie4uinit.exe -ClearIconCache >nul 2>&1
  145. pause
  146. goto :EOF
  147. REM =====================================================
  148. REM INSTALL TO PATH FUNCTION
  149. REM =====================================================
  150. :INSTALL_TO_PATH
  151. echo.
  152. echo ============================================================
  153. echo ^|^> PCDU Installation
  154. echo ============================================================
  155. echo.
  156. REM Check if already installed
  157. call :CHECK_IF_INSTALLED
  158. if !PCDU_INSTALLED! EQU 1 (
  159. echo [OK] PCDU is already installed and accessible from PATH.
  160. echo Location: !PCDU_FOUND_PATH!
  161. echo.
  162. choice /C YN /M "Reinstall/Update PCDU?"
  163. if !ERRORLEVEL! EQU 2 (
  164. echo.
  165. echo Installation cancelled.
  166. goto :EOF
  167. )
  168. )
  169. REM Create install directory
  170. echo [1/5] Creating installation directory...
  171. if not exist "%PCDU_INSTALL_DIR%" (
  172. mkdir "%PCDU_INSTALL_DIR%" 2>nul
  173. if !ERRORLEVEL! NEQ 0 (
  174. echo [ERROR] Failed to create directory: %PCDU_INSTALL_DIR%
  175. goto :EOF
  176. )
  177. echo Created: %PCDU_INSTALL_DIR%
  178. ) else (
  179. echo Exists: %PCDU_INSTALL_DIR%
  180. )
  181. REM Copy script to install directory
  182. echo.
  183. echo [2/5] Copying PCDU script...
  184. copy /Y "%SCRIPT_PATH%" "%PCDU_INSTALL_DIR%\%PCDU_NAME%.bat" >nul 2>&1
  185. if !ERRORLEVEL! NEQ 0 (
  186. echo [ERROR] Failed to copy script to installation directory.
  187. goto :EOF
  188. )
  189. echo Copied to: %PCDU_INSTALL_DIR%\%PCDU_NAME%.bat
  190. REM Create a simple launcher without .bat extension (optional convenience)
  191. echo [2b/5] Creating launcher...
  192. echo @echo off > "%PCDU_INSTALL_DIR%\%PCDU_NAME%.cmd"
  193. echo call "%PCDU_INSTALL_DIR%\%PCDU_NAME%.bat" %%* >> "%PCDU_INSTALL_DIR%\%PCDU_NAME%.cmd"
  194. echo Created: %PCDU_INSTALL_DIR%\%PCDU_NAME%.cmd
  195. REM Download icons to install directory for future use
  196. echo.
  197. echo [3/5] Downloading icons...
  198. if not exist "%PCDU_INSTALL_DIR%\Icons" mkdir "%PCDU_INSTALL_DIR%\Icons"
  199. powershell -Command "try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%ICON_URL_SJLNT%' -OutFile '%PCDU_INSTALL_DIR%\Icons\ServerIcon.ico' -UseBasicParsing } catch { exit 1 }" >nul 2>&1
  200. if exist "%PCDU_INSTALL_DIR%\Icons\ServerIcon.ico" (
  201. echo [OK] ServerIcon.ico downloaded
  202. ) else (
  203. echo [!!] Failed to download ServerIcon.ico
  204. )
  205. powershell -Command "try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%ICON_URL_CASE%' -OutFile '%PCDU_INSTALL_DIR%\Icons\Casefolders.ico' -UseBasicParsing } catch { exit 1 }" >nul 2>&1
  206. if exist "%PCDU_INSTALL_DIR%\Icons\Casefolders.ico" (
  207. echo [OK] Casefolders.ico downloaded
  208. ) else (
  209. echo [!!] Failed to download Casefolders.ico
  210. )
  211. REM Check if directory is already in PATH
  212. echo.
  213. echo [4/5] Checking PATH environment variable...
  214. set "PATH_CONTAINS_PCDU=0"
  215. echo !PATH! | findstr /I /C:"%PCDU_INSTALL_DIR%" >nul 2>&1
  216. if !ERRORLEVEL! EQU 0 (
  217. set "PATH_CONTAINS_PCDU=1"
  218. echo PCDU directory already in PATH.
  219. )
  220. REM Add to PATH if not present
  221. if !PATH_CONTAINS_PCDU! EQU 0 (
  222. echo Adding PCDU to User PATH...
  223. REM Get current user PATH
  224. for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH 2^>nul') do set "USER_PATH=%%B"
  225. REM Check if USER_PATH is empty or not set
  226. if "!USER_PATH!"=="" (
  227. set "NEW_PATH=%PCDU_INSTALL_DIR%"
  228. ) else (
  229. set "NEW_PATH=!USER_PATH!;%PCDU_INSTALL_DIR%"
  230. )
  231. REM Use setx to permanently add to user PATH
  232. setx PATH "!NEW_PATH!" >nul 2>&1
  233. if !ERRORLEVEL! EQU 0 (
  234. echo [OK] Added to User PATH successfully.
  235. ) else (
  236. echo [WARNING] Could not add to PATH automatically.
  237. echo Please manually add this to your PATH:
  238. echo %PCDU_INSTALL_DIR%
  239. )
  240. )
  241. REM Verify installation
  242. echo.
  243. echo [5/5] Verifying installation...
  244. REM Update current session PATH
  245. set "PATH=%PATH%;%PCDU_INSTALL_DIR%"
  246. if exist "%PCDU_INSTALL_DIR%\%PCDU_NAME%.bat" (
  247. echo [OK] Script installed successfully.
  248. ) else (
  249. echo [ERROR] Script not found at expected location.
  250. goto :EOF
  251. )
  252. echo.
  253. echo ============================================================
  254. echo ^|^> Installation Complete!
  255. echo ============================================================
  256. echo.
  257. echo PCDU has been installed to: %PCDU_INSTALL_DIR%
  258. echo.
  259. echo You can now run PCDU from anywhere using:
  260. echo.
  261. echo pcdu - Run interactively
  262. echo pcdu [CaseNumber] - Download specific case
  263. echo pcdu [CaseNo] [User] - With username
  264. echo pcdu [CaseNo] [User] [Pw] - Fully automated
  265. echo.
  266. echo pcdu /help - Show help
  267. echo pcdu /install - Reinstall PCDU
  268. echo pcdu /uninstall - Remove PCDU from system
  269. echo pcdu /update-icons - Update all folder icons
  270. echo.
  271. echo NOTE: You may need to restart your terminal/CMD for
  272. echo PATH changes to take effect.
  273. echo.
  274. echo ============================================================
  275. echo.
  276. REM Refresh environment for current process
  277. call :REFRESH_ENV
  278. pause
  279. goto :EOF
  280. REM =====================================================
  281. REM UNINSTALL FROM PATH FUNCTION
  282. REM =====================================================
  283. :UNINSTALL_FROM_PATH
  284. echo.
  285. echo ============================================================
  286. echo ^|^> PCDU Uninstallation
  287. echo ============================================================
  288. echo.
  289. choice /C YN /M "Are you sure you want to uninstall PCDU?"
  290. if !ERRORLEVEL! EQU 2 (
  291. echo.
  292. echo Uninstallation cancelled.
  293. goto :EOF
  294. )
  295. echo.
  296. echo [1/3] Removing PCDU from PATH...
  297. REM Get current user PATH
  298. for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH 2^>nul') do set "USER_PATH=%%B"
  299. REM Remove PCDU_INSTALL_DIR from PATH
  300. set "NEW_PATH=!USER_PATH:%PCDU_INSTALL_DIR%;=!"
  301. set "NEW_PATH=!NEW_PATH:;%PCDU_INSTALL_DIR%=!"
  302. set "NEW_PATH=!NEW_PATH:%PCDU_INSTALL_DIR%=!"
  303. REM Update PATH
  304. if not "!NEW_PATH!"=="!USER_PATH!" (
  305. setx PATH "!NEW_PATH!" >nul 2>&1
  306. echo [OK] Removed from PATH.
  307. ) else (
  308. echo [--] PCDU was not in PATH.
  309. )
  310. echo.
  311. echo [2/3] Removing installation directory...
  312. if exist "%PCDU_INSTALL_DIR%" (
  313. rmdir /S /Q "%PCDU_INSTALL_DIR%" 2>nul
  314. if !ERRORLEVEL! EQU 0 (
  315. echo [OK] Removed: %PCDU_INSTALL_DIR%
  316. ) else (
  317. echo [WARNING] Could not remove directory. Please delete manually:
  318. echo %PCDU_INSTALL_DIR%
  319. )
  320. ) else (
  321. echo [--] Installation directory not found.
  322. )
  323. echo.
  324. echo [3/3] Cleanup complete.
  325. echo.
  326. echo NOTE: Folder icons on SJLNT and case folders will remain.
  327. echo To remove them, delete desktop.ini and .ico files
  328. echo from those folders.
  329. echo.
  330. echo ============================================================
  331. echo ^|^> PCDU has been uninstalled.
  332. echo ============================================================
  333. echo.
  334. echo NOTE: Restart your terminal for PATH changes to take effect.
  335. echo.
  336. pause
  337. goto :EOF
  338. REM =====================================================
  339. REM SHOW HELP FUNCTION
  340. REM =====================================================
  341. :SHOW_HELP
  342. echo.
  343. echo ============================================================
  344. echo ^|^> Parv's Case Download Utility ^(PCDU^) v%PCDU_VERSION%
  345. echo ============================================================
  346. echo.
  347. echo DESCRIPTION:
  348. echo Downloads case files from the analysis server including
  349. echo configurations, packet captures, and media files.
  350. echo.
  351. echo USAGE:
  352. echo %PCDU_NAME% [options]
  353. echo %PCDU_NAME% [CaseNumber] [Username] [Password]
  354. echo.
  355. echo OPTIONS:
  356. echo /install Install PCDU to system PATH
  357. echo /uninstall Remove PCDU from system
  358. echo /update-icons Update folder icons for all SJLNT folders
  359. echo /help, -h Show this help message
  360. echo.
  361. echo EXAMPLES:
  362. echo %PCDU_NAME% Interactive mode
  363. echo %PCDU_NAME% 12345678 Download case 12345678
  364. echo %PCDU_NAME% 12345678 myuser With username
  365. echo %PCDU_NAME% /install Install to PATH
  366. echo %PCDU_NAME% /update-icons Refresh all folder icons
  367. echo.
  368. echo STORAGE LOCATIONS (in priority order):
  369. echo 1. D:\SJLNT\[CaseNumber]
  370. echo 2. [Temporary Storage Drive]:\SJLNT\[CaseNumber]
  371. echo 3. C:\Temp\SJLNT\[CaseNumber] (fallback)
  372. echo.
  373. echo FOLDER ICONS:
  374. echo - SJLNT folders get a Server icon
  375. echo - Case folders get a Case folder icon
  376. echo - Icons are downloaded from git.4parv.in
  377. echo.
  378. echo DOWNLOADED FILES:
  379. echo - Saved configs (ns.conf) from collector bundles
  380. echo - Running configs (ns_running_config.conf)
  381. echo - Packet captures (.pcap, .cap, .har, etc.)
  382. echo - SSL keys (.sslkeys, .keys)
  383. echo - Media files (images)
  384. echo - Log and text files
  385. echo.
  386. echo REQUIREMENTS:
  387. echo - PuTTY (pscp.exe, plink.exe) OR OpenSSH (scp.exe)
  388. echo - Network access to sjanalysis.citrite.net
  389. echo.
  390. echo ============================================================
  391. echo.
  392. pause
  393. goto :EOF
  394. REM =====================================================
  395. REM CHECK IF INSTALLED FUNCTION
  396. REM =====================================================
  397. :CHECK_IF_INSTALLED
  398. set "PCDU_INSTALLED=0"
  399. set "PCDU_FOUND_PATH="
  400. REM Check if pcdu command is available
  401. where pcdu.bat >nul 2>&1
  402. if !ERRORLEVEL! EQU 0 (
  403. for /f "delims=" %%P in ('where pcdu.bat 2^>nul') do (
  404. set "PCDU_FOUND_PATH=%%P"
  405. )
  406. set "PCDU_INSTALLED=1"
  407. goto :EOF
  408. )
  409. where pcdu.cmd >nul 2>&1
  410. if !ERRORLEVEL! EQU 0 (
  411. for /f "delims=" %%P in ('where pcdu.cmd 2^>nul') do (
  412. set "PCDU_FOUND_PATH=%%P"
  413. )
  414. set "PCDU_INSTALLED=1"
  415. goto :EOF
  416. )
  417. REM Check if running from install directory
  418. if /i "%~dp0"=="%PCDU_INSTALL_DIR%\" (
  419. set "PCDU_INSTALLED=1"
  420. set "PCDU_FOUND_PATH=%PCDU_INSTALL_DIR%\%PCDU_NAME%.bat"
  421. )
  422. goto :EOF
  423. REM =====================================================
  424. REM PROMPT INSTALL FUNCTION
  425. REM =====================================================
  426. :PROMPT_INSTALL
  427. echo.
  428. echo ============================================================
  429. echo ^|^> PCDU First Run Setup
  430. echo ============================================================
  431. echo.
  432. echo PCDU is not installed to your system PATH.
  433. echo Installing allows you to run 'pcdu' from any directory.
  434. echo.
  435. echo Installation will:
  436. echo - Create folder: %PCDU_INSTALL_DIR%
  437. echo - Copy PCDU script to that folder
  438. echo - Download folder icons
  439. echo - Add folder to your User PATH
  440. echo.
  441. choice /C YNC /M "Install PCDU to PATH? (Y=Yes, N=No, C=Cancel script)"
  442. if !ERRORLEVEL! EQU 3 (
  443. echo.
  444. echo Script cancelled.
  445. exit /b 0
  446. )
  447. if !ERRORLEVEL! EQU 1 (
  448. call :INSTALL_TO_PATH
  449. echo.
  450. echo Continuing with case download...
  451. echo.
  452. )
  453. goto :EOF
  454. REM =====================================================
  455. REM REFRESH ENVIRONMENT FUNCTION
  456. REM =====================================================
  457. :REFRESH_ENV
  458. REM This refreshes the PATH for the current cmd session
  459. for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH 2^>nul') do set "PATH=%%B;%PATH%"
  460. goto :EOF
  461. REM =====================================================
  462. REM SETUP SJLNT FOLDER ICON
  463. REM =====================================================
  464. :SETUP_SJLNT_ICON
  465. echo.
  466. echo [ICON SETUP] Configuring SJLNT folder icon...
  467. call :SET_FOLDER_ICON "%STORAGE_BASE%" "%ICON_URL_SJLNT%" "%ICON_NAME_SJLNT%"
  468. goto :EOF
  469. REM =====================================================
  470. REM SETUP CASE FOLDER ICON
  471. REM =====================================================
  472. :SETUP_CASE_ICON
  473. echo.
  474. echo [ICON SETUP] Configuring case folder icon...
  475. call :SET_FOLDER_ICON "%DEST%" "%ICON_URL_CASE%" "%ICON_NAME_CASE%"
  476. goto :EOF
  477. REM =====================================================
  478. REM MAIN SCRIPT
  479. REM =====================================================
  480. :MAIN_SCRIPT
  481. REM =====================================================
  482. REM Storage Drive Configuration
  483. REM Priority: D: -> "Temporary Storage" -> C:\Temp
  484. REM =====================================================
  485. set "STORAGE_DRIVE="
  486. set "STORAGE_BASE="
  487. set "DRIVE_STATUS="
  488. echo.
  489. echo [STORAGE CHECK] Checking available storage drives...
  490. echo.
  491. REM Check for D: drive first
  492. if exist "D:\" (
  493. set "STORAGE_DRIVE=D:"
  494. set "STORAGE_BASE=D:\SJLNT"
  495. set "DRIVE_STATUS=D: Drive found and accessible"
  496. echo [OK] D: Drive found and accessible
  497. goto :DRIVE_FOUND
  498. )
  499. echo [--] D: Drive not found, checking for 'Temporary Storage' drive...
  500. REM Check for drive with label "Temporary Storage"
  501. for /f "tokens=1,2*" %%A in ('wmic logicaldisk get caption^,volumename 2^>nul ^| findstr /I "Temporary Storage"') do (
  502. set "TEMP_DRIVE=%%A"
  503. if exist "!TEMP_DRIVE!\" (
  504. set "STORAGE_DRIVE=!TEMP_DRIVE!"
  505. set "STORAGE_BASE=!TEMP_DRIVE!\SJLNT"
  506. set "DRIVE_STATUS=Temporary Storage drive found at !TEMP_DRIVE!"
  507. echo [OK] 'Temporary Storage' drive found at !TEMP_DRIVE!
  508. goto :DRIVE_FOUND
  509. )
  510. )
  511. REM Alternative method: Check all drives for "Temporary Storage" label
  512. for %%D in (E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  513. if exist "%%D:\" (
  514. for /f "tokens=*" %%L in ('vol %%D: 2^>nul ^| findstr /I "Temporary Storage"') do (
  515. set "STORAGE_DRIVE=%%D:"
  516. set "STORAGE_BASE=%%D:\SJLNT"
  517. set "DRIVE_STATUS=Temporary Storage drive found at %%D:"
  518. echo [OK] 'Temporary Storage' drive found at %%D:
  519. goto :DRIVE_FOUND
  520. )
  521. )
  522. )
  523. echo [--] 'Temporary Storage' drive not found
  524. echo.
  525. REM Fallback to C:\Temp if no preferred drive found
  526. echo [!!] WARNING: Neither D: nor 'Temporary Storage' drive found!
  527. echo.
  528. echo Available options:
  529. echo 1. Use C:\Temp\SJLNT (fallback location)
  530. echo 2. Cancel and check your drives
  531. echo.
  532. choice /C 12 /M "Select option"
  533. if !ERRORLEVEL! EQU 2 (
  534. echo.
  535. echo Operation cancelled by user.
  536. echo Please ensure D: drive or a drive labeled 'Temporary Storage' is available.
  537. pause
  538. exit /b 1
  539. )
  540. set "STORAGE_DRIVE=C:"
  541. set "STORAGE_BASE=C:\Temp\SJLNT"
  542. set "DRIVE_STATUS=Using fallback location C:\Temp\SJLNT"
  543. echo.
  544. echo [!!] Using fallback: C:\Temp\SJLNT
  545. :DRIVE_FOUND
  546. REM Check for pscp.exe (PuTTY SCP) or scp.exe
  547. set "SCP_TOOL="
  548. where pscp.exe >nul 2>&1
  549. if !ERRORLEVEL! EQU 0 (
  550. set "SCP_TOOL=pscp.exe"
  551. set "SCP_TYPE=PSCP"
  552. ) else (
  553. where scp.exe >nul 2>&1
  554. if !ERRORLEVEL! EQU 0 (
  555. set "SCP_TOOL=scp.exe"
  556. set "SCP_TYPE=SCP"
  557. )
  558. )
  559. if "%SCP_TOOL%"=="" (
  560. echo.
  561. echo ============================================================
  562. echo [ERROR] SCP Tool Not Found
  563. echo ============================================================
  564. echo.
  565. echo Neither pscp.exe nor scp.exe found in PATH.
  566. echo.
  567. echo Please install one of the following:
  568. echo - PuTTY ^(includes pscp.exe^) - https://www.putty.org/
  569. echo - OpenSSH Client ^(includes scp.exe^) - Built into Windows 10/11
  570. echo.
  571. echo To enable OpenSSH on Windows:
  572. echo Settings ^> Apps ^> Optional Features ^> Add OpenSSH Client
  573. echo.
  574. pause
  575. exit /b 1
  576. )
  577. REM =====================================================
  578. REM Configuration
  579. REM =====================================================
  580. set "REMOTE_SERVER=sjanalysis.citrite.net"
  581. set "REMOTE_BASE_PATH=/upload/ftp"
  582. REM Prompt for case number if not provided
  583. if "%~1"=="" (
  584. set /p CASENO=Enter Case Number:
  585. ) else (
  586. REM Skip if argument is an option
  587. echo %~1 | findstr /B /C:"/" /C:"-" >nul
  588. if !ERRORLEVEL! EQU 0 (
  589. set /p CASENO=Enter Case Number:
  590. ) else (
  591. set "CASENO=%~1"
  592. )
  593. )
  594. if "%CASENO%"=="" (
  595. echo ERROR: Case number cannot be empty.
  596. exit /b 1
  597. )
  598. REM Prompt for credentials if not provided
  599. if "%~2"=="" (
  600. set /p USERNAME=Enter SSH Username:
  601. ) else (
  602. set "USERNAME=%~2"
  603. )
  604. if "%USERNAME%"=="" (
  605. echo ERROR: Username cannot be empty.
  606. exit /b 1
  607. )
  608. if "%~3"=="" (
  609. echo Enter SSH Password for %USERNAME%@%REMOTE_SERVER%:
  610. REM Use PowerShell for hidden password input
  611. for /f "delims=" %%P in ('powershell -Command "$p = Read-Host -AsSecureString; [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($p))"') do set "PASSWORD=%%P"
  612. ) else (
  613. set "PASSWORD=%~3"
  614. )
  615. if "%PASSWORD%"=="" (
  616. echo ERROR: Password cannot be empty.
  617. exit /b 1
  618. )
  619. REM =====================================================
  620. REM Paths - Now using configured storage drive
  621. REM =====================================================
  622. set "REMOTE_CASE_PATH=%REMOTE_BASE_PATH%/%CASENO%"
  623. set "DEST=%STORAGE_BASE%\%CASENO%"
  624. set "LOGFILE=%DEST%\download_%CASENO%.log"
  625. set "TEMP_LIST=%TEMP%\caselist_%CASENO%.txt"
  626. set "TEMP_FILTERED=%TEMP%\filtered_%CASENO%.txt"
  627. set "COLLECTOR_LIST=%TEMP%\collectors_%CASENO%.txt"
  628. set "ALL_FILES_LIST=%TEMP%\allfiles_%CASENO%.txt"
  629. echo.
  630. echo ============================================================
  631. echo ^|^> Parv's Case Download Utility ^(PCDU^) v%PCDU_VERSION%
  632. echo ============================================================
  633. echo Case Number : %CASENO%
  634. echo Remote Server : %REMOTE_SERVER%
  635. echo Remote Path : %REMOTE_CASE_PATH%
  636. echo Storage Drive : %STORAGE_DRIVE%
  637. echo Local Dest : %DEST%
  638. echo SCP Tool : %SCP_TYPE%
  639. echo User : %USERNAME%
  640. echo Drive Status : %DRIVE_STATUS%
  641. echo ============================================================
  642. echo.
  643. REM =====================================================
  644. REM Create destination directory structure
  645. REM =====================================================
  646. echo [PATH CHECK] Verifying destination paths...
  647. echo.
  648. REM Track if SJLNT folder was just created (for icon setup)
  649. set "SJLNT_CREATED=0"
  650. set "CASE_CREATED=0"
  651. REM Check if base storage path exists
  652. if exist "%STORAGE_BASE%" (
  653. echo [OK] Base path exists: %STORAGE_BASE%
  654. ) else (
  655. echo [!!] Base path does not exist: %STORAGE_BASE%
  656. echo Creating base directory...
  657. mkdir "%STORAGE_BASE%" 2>nul
  658. if !ERRORLEVEL! EQU 0 (
  659. echo [OK] Created: %STORAGE_BASE%
  660. set "SJLNT_CREATED=1"
  661. ) else (
  662. echo [ERROR] Failed to create base directory: %STORAGE_BASE%
  663. echo.
  664. echo Possible reasons:
  665. echo - Drive not writable
  666. echo - Insufficient permissions
  667. echo - Drive full
  668. echo.
  669. pause
  670. exit /b 1
  671. )
  672. )
  673. REM Setup SJLNT folder icon (always ensure it's set)
  674. call :SETUP_SJLNT_ICON
  675. REM Check if case destination exists
  676. if exist "%DEST%" (
  677. echo [OK] Case path exists: %DEST%
  678. echo.
  679. echo [!!] WARNING: Case folder already exists!
  680. echo Files may be overwritten.
  681. echo.
  682. choice /C YN /M "Continue and potentially overwrite existing files?"
  683. if !ERRORLEVEL! EQU 2 (
  684. echo.
  685. echo Operation cancelled by user.
  686. pause
  687. exit /b 0
  688. )
  689. ) else (
  690. echo [!!] Case path does not exist: %DEST%
  691. echo Creating case directory...
  692. mkdir "%DEST%" 2>nul
  693. if !ERRORLEVEL! EQU 0 (
  694. echo [OK] Created: %DEST%
  695. set "CASE_CREATED=1"
  696. ) else (
  697. echo [ERROR] Failed to create case directory: %DEST%
  698. pause
  699. exit /b 1
  700. )
  701. )
  702. REM Setup case folder icon
  703. call :SETUP_CASE_ICON
  704. REM Create subdirectories for organization
  705. echo.
  706. echo [PATH CHECK] Creating subdirectories...
  707. for %%S in (configs captures media) do (
  708. if exist "%DEST%\%%S" (
  709. echo [OK] Exists: %DEST%\%%S
  710. ) else (
  711. mkdir "%DEST%\%%S" 2>nul
  712. if !ERRORLEVEL! EQU 0 (
  713. echo [OK] Created: %DEST%\%%S
  714. ) else (
  715. echo [!!] Failed to create: %DEST%\%%S
  716. )
  717. )
  718. )
  719. echo.
  720. REM Initialize log file
  721. echo ============================================================ > "%LOGFILE%"
  722. echo Parv's Case Download Utility ^(PCDU^) v%PCDU_VERSION% - Download Log >> "%LOGFILE%"
  723. echo ============================================================ >> "%LOGFILE%"
  724. echo Case Number : %CASENO% >> "%LOGFILE%"
  725. echo Date/Time : %DATE% %TIME% >> "%LOGFILE%"
  726. echo Remote Server : %REMOTE_SERVER% >> "%LOGFILE%"
  727. echo User : %USERNAME% >> "%LOGFILE%"
  728. echo Storage Drive : %STORAGE_DRIVE% >> "%LOGFILE%"
  729. echo Destination : %DEST% >> "%LOGFILE%"
  730. echo Drive Status : %DRIVE_STATUS% >> "%LOGFILE%"
  731. echo ============================================================ >> "%LOGFILE%"
  732. echo. >> "%LOGFILE%"
  733. REM =====================================================
  734. REM Test SSH connection and verify case directory
  735. REM =====================================================
  736. echo [1/5] Testing SSH connection...
  737. echo [1/5] Testing SSH connection... >> "%LOGFILE%"
  738. if "%SCP_TYPE%"=="PSCP" (
  739. echo y | plink.exe -batch -pw "%PASSWORD%" %USERNAME%@%REMOTE_SERVER% "test -d %REMOTE_CASE_PATH% && echo OK || echo NOTFOUND" 2>nul | findstr /V /C:"Keyboard" /C:"prompts from server" > "%TEMP_LIST%"
  740. ) else (
  741. sshpass -p "%PASSWORD%" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL %USERNAME%@%REMOTE_SERVER% "test -d %REMOTE_CASE_PATH% && echo OK || echo NOTFOUND" > "%TEMP_LIST%" 2>&1
  742. )
  743. if !ERRORLEVEL! NEQ 0 (
  744. echo ERROR: SSH connection failed. >> "%LOGFILE%"
  745. type "%TEMP_LIST%" >> "%LOGFILE%"
  746. echo ERROR: SSH connection failed.
  747. echo Check credentials and network connectivity.
  748. echo See log: %LOGFILE%
  749. del "%TEMP_LIST%" 2>nul
  750. pause
  751. exit /b 1
  752. )
  753. findstr /C:"OK" "%TEMP_LIST%" >nul
  754. if !ERRORLEVEL! NEQ 0 (
  755. echo ERROR: Case directory not found on server: %REMOTE_CASE_PATH% >> "%LOGFILE%"
  756. echo ERROR: Case directory not found on server.
  757. echo Path: %REMOTE_CASE_PATH%
  758. echo Please verify the case number.
  759. del "%TEMP_LIST%" 2>nul
  760. pause
  761. exit /b 1
  762. )
  763. echo Connection successful.
  764. echo Connection successful. >> "%LOGFILE%"
  765. REM =====================================================
  766. REM Single SSH call to get all required info
  767. REM Collectors + All files in case root
  768. REM =====================================================
  769. echo.
  770. echo [2/5] Scanning case directory...
  771. echo [2/5] Scanning case directory... >> "%LOGFILE%"
  772. if "%SCP_TYPE%"=="PSCP" (
  773. plink.exe -batch -pw "%PASSWORD%" %USERNAME%@%REMOTE_SERVER% "echo '===COLLECTORS==='; find %REMOTE_CASE_PATH% -maxdepth 1 -type d -name 'collector_*' 2>/dev/null; echo '===FILES==='; find %REMOTE_CASE_PATH% -maxdepth 1 -type f \( -name '*.cap' -o -name '*.pcap' -o -name '*.pcapng' -o -name '*.sslkeys' -o -name '*.keys' -o -name '*.har' -o -name '*.xml' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.gif' -o -name '*.bmp' -o -name '*.webp' -o -name '*.tiff' -o -name '*.svg' -o -name '*.txt' -o -name '*.log' -o -name '*.csv' -o -name '*.json' \) 2>/dev/null" 2>nul | findstr /V /C:"Keyboard" /C:"prompts from server" > "%ALL_FILES_LIST%"
  774. ) else (
  775. sshpass -p "%PASSWORD%" ssh -o StrictHostKeyChecking=no %USERNAME%@%REMOTE_SERVER% "echo '===COLLECTORS==='; find %REMOTE_CASE_PATH% -maxdepth 1 -type d -name 'collector_*' 2>/dev/null; echo '===FILES==='; find %REMOTE_CASE_PATH% -maxdepth 1 -type f \( -name '*.cap' -o -name '*.pcap' -o -name '*.pcapng' -o -name '*.sslkeys' -o -name '*.keys' -o -name '*.har' -o -name '*.xml' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.gif' -o -name '*.bmp' -o -name '*.webp' -o -name '*.tiff' -o -name '*.svg' -o -name '*.txt' -o -name '*.log' -o -name '*.csv' -o -name '*.json' \) 2>/dev/null" > "%ALL_FILES_LIST%"
  776. )
  777. REM Parse collectors from combined output
  778. set "IN_COLLECTORS=0"
  779. set "IN_FILES=0"
  780. echo. > "%COLLECTOR_LIST%"
  781. echo. > "%TEMP_LIST%"
  782. for /f "usebackq delims=" %%A in ("%ALL_FILES_LIST%") do (
  783. set "LINE=%%A"
  784. REM Check for section markers
  785. echo !LINE! | findstr /C:"===COLLECTORS===" >nul
  786. if !ERRORLEVEL! EQU 0 (
  787. set "IN_COLLECTORS=1"
  788. set "IN_FILES=0"
  789. ) else (
  790. echo !LINE! | findstr /C:"===FILES===" >nul
  791. if !ERRORLEVEL! EQU 0 (
  792. set "IN_COLLECTORS=0"
  793. set "IN_FILES=1"
  794. ) else (
  795. REM Skip empty lines and filter noise
  796. if not "!LINE!"=="" (
  797. echo !LINE! | findstr /C:"Keyboard" /C:"prompts" /C:"authentication" >nul
  798. if !ERRORLEVEL! NEQ 0 (
  799. if !IN_COLLECTORS! EQU 1 (
  800. echo !LINE!>> "%COLLECTOR_LIST%"
  801. )
  802. if !IN_FILES! EQU 1 (
  803. echo !LINE!>> "%TEMP_LIST%"
  804. )
  805. )
  806. )
  807. )
  808. )
  809. )
  810. REM Count collectors
  811. set "COLLECTOR_COUNT=0"
  812. for /f "usebackq delims=" %%A in ("%COLLECTOR_LIST%") do (
  813. set "LINE=%%A"
  814. if not "!LINE!"=="" (
  815. echo !LINE! | findstr /C:"collector_" >nul
  816. if !ERRORLEVEL! EQU 0 (
  817. set /a COLLECTOR_COUNT+=1
  818. for %%B in ("!LINE!") do echo Found: %%~nxB
  819. echo Found collector: !LINE! >> "%LOGFILE%"
  820. )
  821. )
  822. )
  823. if %COLLECTOR_COUNT% EQU 0 (
  824. echo No collector bundles found.
  825. echo No collector bundles found. >> "%LOGFILE%"
  826. ) else (
  827. echo Total collectors found: %COLLECTOR_COUNT%
  828. )
  829. REM =====================================================
  830. REM Download Saved Config (ns.conf from nsconfig folder)
  831. REM Inside collector bundles only
  832. REM =====================================================
  833. echo.
  834. echo [3/5] Downloading saved configurations ^(ns.conf^)...
  835. echo [3/5] Downloading saved configurations... >> "%LOGFILE%"
  836. set "CONFIG_COUNT=0"
  837. for /f "usebackq delims=" %%C in ("%COLLECTOR_LIST%") do (
  838. set "COLLECTOR_PATH=%%C"
  839. REM Skip empty lines and filter noise
  840. if not "!COLLECTOR_PATH!"=="" (
  841. echo !COLLECTOR_PATH! | findstr /C:"collector_" >nul
  842. if !ERRORLEVEL! EQU 0 (
  843. for %%D in ("!COLLECTOR_PATH!") do set "COLLECTOR_NAME=%%~nxD"
  844. echo Checking !COLLECTOR_NAME!...
  845. set "DEST_FILENAME=ns.conf_!COLLECTOR_NAME!"
  846. if "%SCP_TYPE%"=="PSCP" (
  847. pscp.exe -batch -pw "%PASSWORD%" -q "%USERNAME%@%REMOTE_SERVER%:!COLLECTOR_PATH!/nsconfig/ns.conf" "%DEST%\configs\!DEST_FILENAME!" >nul 2>&1
  848. ) else (
  849. scp -o StrictHostKeyChecking=no -q "%USERNAME%@%REMOTE_SERVER%:!COLLECTOR_PATH!/nsconfig/ns.conf" "%DEST%\configs\!DEST_FILENAME!" 2>nul
  850. )
  851. if exist "%DEST%\configs\!DEST_FILENAME!" (
  852. echo [OK] !DEST_FILENAME!
  853. echo [OK] Downloaded: !DEST_FILENAME! >> "%LOGFILE%"
  854. set /a CONFIG_COUNT+=1
  855. ) else (
  856. echo [--] ns.conf not found
  857. )
  858. )
  859. )
  860. )
  861. echo Saved configs downloaded: %CONFIG_COUNT%
  862. REM =====================================================
  863. REM Download Running Config (ns_running_config.conf)
  864. REM Inside collector bundles only
  865. REM =====================================================
  866. echo.
  867. echo [4/5] Downloading running configurations...
  868. echo [4/5] Downloading running configurations... >> "%LOGFILE%"
  869. set "RUNNING_COUNT=0"
  870. for /f "usebackq delims=" %%C in ("%COLLECTOR_LIST%") do (
  871. set "COLLECTOR_PATH=%%C"
  872. REM Skip empty lines and filter noise
  873. if not "!COLLECTOR_PATH!"=="" (
  874. echo !COLLECTOR_PATH! | findstr /C:"collector_" >nul
  875. if !ERRORLEVEL! EQU 0 (
  876. for %%D in ("!COLLECTOR_PATH!") do set "COLLECTOR_NAME=%%~nxD"
  877. echo Checking !COLLECTOR_NAME!...
  878. set "DEST_FILENAME=ns_running_config.conf_!COLLECTOR_NAME!"
  879. if "%SCP_TYPE%"=="PSCP" (
  880. pscp.exe -batch -pw "%PASSWORD%" -q "%USERNAME%@%REMOTE_SERVER%:!COLLECTOR_PATH!/shell/ns_running_config.conf" "%DEST%\configs\!DEST_FILENAME!" >nul 2>&1
  881. ) else (
  882. scp -o StrictHostKeyChecking=no -q "%USERNAME%@%REMOTE_SERVER%:!COLLECTOR_PATH!/shell/ns_running_config.conf" "%DEST%\configs\!DEST_FILENAME!" 2>nul
  883. )
  884. if exist "%DEST%\configs\!DEST_FILENAME!" (
  885. echo [OK] !DEST_FILENAME!
  886. echo [OK] Downloaded: !DEST_FILENAME! >> "%LOGFILE%"
  887. set /a RUNNING_COUNT+=1
  888. ) else (
  889. echo [--] Running config not found
  890. )
  891. )
  892. )
  893. )
  894. echo Running configs downloaded: %RUNNING_COUNT%
  895. REM =====================================================
  896. REM Download Capture and Media Files
  897. REM OUTSIDE collector bundles only (case root level)
  898. REM Using pre-fetched file list
  899. REM =====================================================
  900. echo.
  901. echo [5/5] Downloading files from case directory...
  902. echo [5/5] Downloading files from case root... >> "%LOGFILE%"
  903. set "CAPTURE_COUNT=0"
  904. set "MEDIA_COUNT=0"
  905. set "OTHER_COUNT=0"
  906. for /f "usebackq delims=" %%F in ("%TEMP_LIST%") do (
  907. set "REMOTE_FILE=%%F"
  908. REM Skip empty lines and filter noise
  909. if not "!REMOTE_FILE!"=="" (
  910. echo !REMOTE_FILE! | findstr /C:"Keyboard" /C:"prompts" /C:"authentication" >nul
  911. if !ERRORLEVEL! NEQ 0 (
  912. for %%G in ("!REMOTE_FILE!") do (
  913. set "FILENAME=%%~nxG"
  914. set "FILEEXT=%%~xG"
  915. )
  916. if not "!FILENAME!"=="" (
  917. REM Determine file type and destination
  918. set "FILE_DEST="
  919. set "FILE_TYPE="
  920. REM Check if capture file
  921. echo !FILEEXT! | findstr /I /C:".cap" /C:".pcap" /C:".pcapng" /C:".sslkeys" /C:".keys" /C:".har" >nul
  922. if !ERRORLEVEL! EQU 0 (
  923. set "FILE_DEST=%DEST%\captures\!FILENAME!"
  924. set "FILE_TYPE=capture"
  925. )
  926. REM Check if image file
  927. echo !FILEEXT! | findstr /I /C:".jpg" /C:".jpeg" /C:".png" /C:".gif" /C:".bmp" /C:".webp" /C:".tiff" /C:".svg" >nul
  928. if !ERRORLEVEL! EQU 0 (
  929. set "FILE_DEST=%DEST%\media\!FILENAME!"
  930. set "FILE_TYPE=media"
  931. )
  932. REM Check if other file (txt, log, xml, json, csv)
  933. echo !FILEEXT! | findstr /I /C:".txt" /C:".log" /C:".xml" /C:".json" /C:".csv" >nul
  934. if !ERRORLEVEL! EQU 0 (
  935. set "FILE_DEST=%DEST%\!FILENAME!"
  936. set "FILE_TYPE=other"
  937. )
  938. REM Download the file
  939. if defined FILE_DEST (
  940. echo Downloading: !FILENAME!
  941. if "%SCP_TYPE%"=="PSCP" (
  942. pscp.exe -batch -pw "%PASSWORD%" -q "%USERNAME%@%REMOTE_SERVER%:!REMOTE_FILE!" "!FILE_DEST!" >nul 2>&1
  943. ) else (
  944. scp -o StrictHostKeyChecking=no -q "%USERNAME%@%REMOTE_SERVER%:!REMOTE_FILE!" "!FILE_DEST!" 2>nul
  945. )
  946. if exist "!FILE_DEST!" (
  947. echo [OK] !FILENAME!
  948. echo [OK] Downloaded !FILE_TYPE!: !FILENAME! >> "%LOGFILE%"
  949. if "!FILE_TYPE!"=="capture" set /a CAPTURE_COUNT+=1
  950. if "!FILE_TYPE!"=="media" set /a MEDIA_COUNT+=1
  951. if "!FILE_TYPE!"=="other" set /a OTHER_COUNT+=1
  952. )
  953. )
  954. )
  955. )
  956. )
  957. )
  958. echo.
  959. echo Capture files downloaded: %CAPTURE_COUNT%
  960. echo Media files downloaded : %MEDIA_COUNT%
  961. echo Other files downloaded : %OTHER_COUNT%
  962. REM =====================================================
  963. REM Cleanup and Summary
  964. REM =====================================================
  965. del "%TEMP_LIST%" 2>nul
  966. del "%TEMP_FILTERED%" 2>nul
  967. del "%COLLECTOR_LIST%" 2>nul
  968. del "%ALL_FILES_LIST%" 2>nul
  969. REM Remove empty directories
  970. for %%D in (configs captures media) do (
  971. dir /b "%DEST%\%%D" 2>nul | findstr "." >nul || rmdir "%DEST%\%%D" 2>nul
  972. )
  973. REM Refresh icon cache to show new icons
  974. echo.
  975. echo [ICONS] Refreshing icon cache...
  976. ie4uinit.exe -show >nul 2>&1
  977. echo.
  978. echo ============================================================
  979. echo ^|^> Download Complete - Summary
  980. echo ============================================================
  981. echo.
  982. echo STORAGE INFORMATION:
  983. echo Storage Drive : %STORAGE_DRIVE%
  984. echo Drive Status : %DRIVE_STATUS%
  985. echo Base Path : %STORAGE_BASE%
  986. echo.
  987. echo FROM COLLECTOR BUNDLES:
  988. echo Collector bundles found : %COLLECTOR_COUNT%
  989. echo Saved configs ^(ns.conf^) : %CONFIG_COUNT%
  990. echo Running configs : %RUNNING_COUNT%
  991. echo.
  992. echo FROM CASE ROOT DIRECTORY:
  993. echo Capture files ^(pcap,har^) : %CAPTURE_COUNT%
  994. echo Media files ^(images^) : %MEDIA_COUNT%
  995. echo Other files ^(xml,txt^) : %OTHER_COUNT%
  996. echo.
  997. echo Destination : %DEST%
  998. echo Log file : %LOGFILE%
  999. echo.
  1000. echo FOLDER ICONS:
  1001. echo SJLNT folder and case folder have custom icons.
  1002. echo If icons don't appear, press F5 to refresh Explorer.
  1003. echo.
  1004. REM Write summary to log
  1005. echo. >> "%LOGFILE%"
  1006. echo ============================================================ >> "%LOGFILE%"
  1007. echo SUMMARY >> "%LOGFILE%"
  1008. echo ============================================================ >> "%LOGFILE%"
  1009. echo STORAGE INFORMATION: >> "%LOGFILE%"
  1010. echo Storage Drive : %STORAGE_DRIVE% >> "%LOGFILE%"
  1011. echo Drive Status : %DRIVE_STATUS% >> "%LOGFILE%"
  1012. echo. >> "%LOGFILE%"
  1013. echo FROM COLLECTOR BUNDLES: >> "%LOGFILE%"
  1014. echo Collector bundles found : %COLLECTOR_COUNT% >> "%LOGFILE%"
  1015. echo Saved configs : %CONFIG_COUNT% >> "%LOGFILE%"
  1016. echo Running configs : %RUNNING_COUNT% >> "%LOGFILE%"
  1017. echo. >> "%LOGFILE%"
  1018. echo FROM CASE ROOT DIRECTORY: >> "%LOGFILE%"
  1019. echo Capture files : %CAPTURE_COUNT% >> "%LOGFILE%"
  1020. echo Media files : %MEDIA_COUNT% >> "%LOGFILE%"
  1021. echo Other files : %OTHER_COUNT% >> "%LOGFILE%"
  1022. echo ============================================================ >> "%LOGFILE%"
  1023. echo ============================================================
  1024. echo.
  1025. REM Open destination folder
  1026. choice /C YN /M "Open destination folder now?"
  1027. if !ERRORLEVEL! EQU 1 explorer "%DEST%"
  1028. endlocal
  1029. exit /b 0