How To Make A Simple Batch Anti-virus
The following is a tutorial on how to make a batch anti-virus. What this program does actually isn't classified as an "anti-virus" because of the limitations of batch. However, it is sufficient enough to locate any batch files that could harm your computer.
What will You Learn ->>
-The use of "findstr"
- It is used to find strings of text in files
Lets Begin
@echo off
findstr /s /m "del" C:\*.bat >> results.txt
if %errorlevel%==0 (
echo Found! "del" in bat files. Logged files into results
echo. >> results.txt
)
findstr /s /m "taskkill" C:\*.bat >> results.txt
if %errorlevel%==0 (
echo Found! "taskkill" in bat files. Logged files into results
echo. >> results.txt
)
findstr /s /m "del" C:\*.bat >> results.txt
if %errorlevel%==0 (
echo Found! "del" in bat files. Logged files into results
echo. >> results.txt
)
findstr /s /m "taskkill" C:\*.bat >> results.txt
if %errorlevel%==0 (
echo Found! "taskkill" in bat files. Logged files into results
echo. >> results.txt
)
What's Happening?
The above code is telling cmd to search the entire C:\ drive and all sub-directories for any batch files that contain the text "del" or "taskkill".
Anyone who's coded batch for a while will know that those two words can really screw your computer up.
After it's scanned your computer, the results are outputted to a text file called "results". This allows you to see all the files that contain those words and review them if they are indeed harmful.
Now, Let's go over what those keywords in the code are.
Anyone who's coded batch for a while will know that those two words can really screw your computer up.
After it's scanned your computer, the results are outputted to a text file called "results". This allows you to see all the files that contain those words and review them if they are indeed harmful.
Now, Let's go over what those keywords in the code are.
findstr - This basically means "find all files that contain the string that is given"
/s - This tells it to search all the sub-directories that are contained in the given file. In this example, it searches the sub-directories in C:\
/m - Prints only the file name if a file contains a match with the string.
*.bat - Looks for all files that have the extension of ".bat". You could also use this to search all txt, exe, ini, etc files.
>> results.txt - This prints the results to a text file on a new line. If you used a single '>' then it would delete the text in the file and replace it with the result of the search.
if %errorlevel%==0 - This is a conditional statement. If the 'findstr' finds a match, then the errorlevel will be placed as 0 and it will do whatever is in the brackets. However, if there is no match for the string of text, then the errorlevel is not 0 and will not do what is in the brackets.
Done...!!
Run batch file as Antivirus...:)
Comments
Post a Comment