Skip to content

Instantly share code, notes, and snippets.

@olliencc
Last active March 6, 2021 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olliencc/4225cedcc49db5c70b4c1c7a9be88bbb to your computer and use it in GitHub Desktop.
Save olliencc/4225cedcc49db5c70b4c1c7a9be88bbb to your computer and use it in GitHub Desktop.
Calculate MD5s for each file in a directory structure and then check if that MD5 is present in a file - if it isn't it will print out the list of files not found
@echo off
REM °²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²°
REM °² Calc file hashes and check they are present ²°
REM °² in a file ²°
REM °² ²°
REM °² twitter: @ollieatnccgroup ²°
REM °²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²°
REM example usage
REM md5check.bat "C:\Users\Ollie Whitehouse\Downloads\Exchange2013-x64-cu23\setup\MD5"
REM Paramater checking
set "param1=%~1"
if "!param1!"=="" (
echo [i] Get hash set from https://github.com/nccgroup/Cyber-Defence/tree/master/Intelligence/Exchange
echo [i] then supply as paramater e.g. check.bat "C:\Path\to\MD5"
exit /b
)
if not exist "%param1%" (
echo "[i] %param1% does not exist"
exit /b
)
REM features++
SETLOCAL ENABLEDELAYEDEXPANSION
call :treeProcess
goto :eof
:treeProcess
rem Do whatever you want here over the files of this subdir, for example:
for %%f in (*.*) do (
REM certutil -hashfile %%f MD5 | findstr /V ":"
for /f "delims=" %%A in ('certutil -hashfile %%f MD5 ^| findstr /V ":"') do (
set "var=%%A"
REM echo %%f %%A
findstr /I %%A %1
if not %errorlevel% neq 0 echo [*] %%f with MD5 of %%A not found
)
)
for /D %%d in (*) do (
cd %%d
call :treeProcess
cd ..
)
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment