how to make a MD5 batch virus scanner? [closed]

2020-07-27 03:09发布

问题:

So I have done my research on md5 and found this which PieSub quoted MD5 generation code;

@echo off  
for /r %%f in (*) do md5.exe %%f >> output.txt

which when I try to generate md5 code for the files in a certain directory this batch (md5.bat) was placed in the result looks like this;

8232D53AB6DF337DC341A589EF1FA687  C:\Users\User\Downloads\md5\index.html
695D352F6D8974463855443E83B6F000  C:\Users\User\Downloads\md5\main.c
6C35472B8D3FDC82BF6AEDD2E6AC855E  C:\Users\User\Downloads\md5\Makefile
F3A54C9B5AC78F44CF22095D448E7712  C:\Users\User\Downloads\md5\md5.bat
AB5E72E19362E8E60E41F05B9D192A58  C:\Users\User\Downloads\md5\md5.c
8D443F2E93A3F0B67F442E4F1D5A4D6D  C:\Users\User\Downloads\md5\md5.exe
4CFADCA7BC0717091EDDCBF19D2E065F  C:\Users\User\Downloads\md5\md5.h
036D9462A58BEE6F0F404BC4A569108B  C:\Users\User\Downloads\md5\md5.png
A1F984ABE556555208BA3036496ED74B  C:\Users\User\Downloads\md5\md5.sln
83FFA789C81056966980ED58D9E0726A  C:\Users\User\Downloads\md5\md5.vcproj
16596D5330EF48A9E53944749BED44DE  C:\Users\User\Downloads\md5\md5s.png
69390C0E13ECFE8818BB29B108ACA751  C:\Users\User\Downloads\md5\rfc1321.html
754B9DB19F79DBC4992F7166EB0F37CE  C:\Users\User\Downloads\md5\rfc1321.txt

So basically, I want a script that compares the md5 hash with this md5 database and deletes any malicious file.

回答1:

When the virus database is downloaded :

@echo off
set "$base=HashBase.txt"

for /r %%f in (*) do md5.exe %%f >> output.txt

for /f "tokens=1* delims= " %%a in (output.txt) do find /i "%%a" "%$base%" >nul && echo del "%%b"

I putted an echo before the del. So you can make a non-destructiv test. If the output is OK remove it.