In the following few tutorials, we’ll be learning about batch file viruses. We’ll look at various techniques to bring down a computer using small and simple scripts. Even if you have no background in programming, you’ll find it very easy to follow along.
I recommend you use a virtual machine running a Windows OS if you want to follow along yourself. This is as much for safety as it is for convenience. This tutorial is pretty safe but from the next one we’ll start building viruses. The first virus we’ll look at will overload the computer’s memory. That is, the computer will run out of RAM and likely freeze up and shut down. While this is unlikely to cause any lasting damage, using a virtual machine will still be more convenient simply because you won’t have to keep restarting your computer because it crashed. Soon after this we will get to viruses that can do some very real and permanent damage to your system. You don’t want to hack yourself, right? So you might as well learn how to setup a virtual machine for hacking practice before continuing.
Now let us begin.
What are batch files?
A batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter. Batch files have the extension
.cmd). They can be easily created using any text editor such as notepad.
Now let’s see some of these commands.
echo Hello World
echo command is used to print out a message, in this case “Hello World”. Type up the above in a text editor and save it as
something.bat. Now open it and a command window pops up. But you’ll notice that it closes before we get a chance to see what it outputs. Let’s fix that.
echo Hello World pause
pause command pauses the execution of the batch file until a user presses a key. You should now see the following output:
C:\Users\Xeus\Desktop>echo Hello World Hello World C:\Users\Xeus\Desktop>pause Press any key to continue . . .
C:\Users\Xeus\Desktop> is where the execution is happening. In my case, I’ve saved the batch file on the desktop. The batch file seems to be printing the commands before executing them. It first prints
echo Hello World then actually executes it to output
Hello World. Let’s see if we can clean this up a bit.
@echo off echo Hello World pause
And this outputs…
Hello World Press any key to continue . . .
@echo off is used to stop the commands from being printed and leaves only the output of those commands. Now let’s add a little dynamic behavior.
@echo off set a=Xeus echo Hello %a% pause
set command is used to define variables that can hold different values, in this case the string “Xeus”. The variable name enclosed within
%% is how we access the value stored in the variable. Run the above and you should see
Hello Xeus Press any key to continue . . .
Be careful here, the set command is pretty sensitive about the use of spaces:
ahas the value ‘Xeus’
set a= Xeus(with a space after the
=) means ‘a’ has the value ‘ Xeus’ (with a space before it) and
set a =Xeus(with a space before
=) means that the variable is not defined as
a(‘a’ followed by a space).
Some commands come with modifiers that slightly alter their behavior:
@echo off set /a a=5 set /a b=10 set /a c=%a% + %b% echo %c% pause
set /a, the
/a part is telling
set that it should treat the value of the variable as a number, allowing us to perform mathematical operations on it.
@echo off set /p a=Enter your name: echo Hello %a% pause
/p modifier tells the
set command that it should take in some input from the user and store that in the variable
a. When you run the batch file, you will be prompted to enter something. The output looks like:
Enter your name: Emily Hello Emily Press any key to continue . . .
Examples of Batch Files
That was pretty easy, now let’s take a look at a couple more batch files that might actually be useful and then we’ll go and make some viruses.
@echo off title Pinger set /p target=Enter IP address or URL: ping %target% -t pause
Enter IP address or URL: google.com Pinging google.com [18.104.22.168] with 32 bytes of data: Reply from 22.214.171.124: bytes=32 time=26ms TTL=57 Reply from 126.96.36.199: bytes=32 time=25ms TTL=57 Reply from 188.8.131.52: bytes=32 time=27ms TTL=57 Reply from 184.108.40.206: bytes=32 time=25ms TTL=57 Reply from 220.127.116.11: bytes=32 time=26ms TTL=57
Pretty handy if you want to quickly ping an IP address/URL or check your internet connection.
P.S: Pressing CTRL+C forcefully stops any running command (like
ping -t which likes to run forever).
The batch file schedules a shutdown after X minutes.
@echo off title Shutdown Input set /p mins=Enter number of minutes to wait until shutdown: set /a mins=%mins%*60 shutdown -s -t %mins%
This was but a glimpse of what batch files can do. Almost anything your operating system does for you can be done through batch files. You can even use them to automate repetitive and boring tasks. The limit is only your imagination.
One of these imaginative uses is creating batch file viruses and that is just what we’re going to learn now. Let’s start with the famous fork bomb.
Want to be a real hacker? Sign Up!