Introduction to Batch File Viruses

You are here: Home » Blog » Computer Programming Languages » Coding Computer Viruses » MSDOS Batch Script » Introduction to Batch File Viruses

Introduction to Batch File Viruses

Introduction to Batch File Viruses: We’ll be learning about batch file viruses. We’ll look at various techniques used in small and simple batch file scripts. Even if you have no background in programming, you’ll find it very easy to follow along and learn.

 What are batch files?

batch file is a 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 .bat(or .cmd). They can be easily created using any text editor such as notepad. See here for more details about batch script file.

Now let’s see some of these commands.

echo Hello World

The 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

The pause command pauses the execution of the batch file until a user presses a key. You should now see the following output:

C:\>echo Hello World
Hello World
Press any key to continue . . .

It first prints

C:\>echo Hello World

then actually executes it to output  Hello World. Let’s see if we can clean this up a little for better GUI (graphical user interface) purposes.

@echo off
echo Hello World

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 behaviour.

@echo off
set a=Bernie
echo Hello %a%
pause

The set command is used to define variables that can hold different values, in this case the string “Bernie”. The variable name enclosed within %% is how we access the value stored in the variable.

Run the above and you should see:

Hello Bernie 
Press any key to continue . . .

Be careful here, the set command is pretty sensitive to the use of spaces:

set a=Bernie

means a has the value ‘Bernie’.

set a= Bernie

(with a space after the =) means ‘a’ has the value ‘ Bernie’ (with a space before it).

set a =Bernie

and (with a space before =) means that the variable is not defined as a but as a (‘a ’ followed by a space).

Some commands come with modifiers that slightly alter their behaviour:

@echo off
set /a a=5 
set /a b=10
set /a c=%a% + %b% 
echo %c%
pause

In 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

The /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: Eve 
Hello Eve 
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.


Pinger Batch Script 1.0

@echo off 
title Pinger Batch Script 1.0
set /p target=Enter IP address or URL: 
ping %target% -t 
pause

This outputs the following:

Notice how the second code line ‘title Pinger Batch Script 1.0’ puts the caption “Pinger Batch Script 1.0” in the batch file window Title when it runs.


Used by itself or in conjunction with other batch script commands it’s pretty handy if you want to quickly ping an IP address/URL or check your internet connection.

NOTE: Pressing CTRL+C forcefully stops any running command (like ping -t which likes to run forever).


Shutdown Timer

This 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%

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. Remember batch files are scripts.

 


Related Videos:

MiltonMarketing.com Related Videos.

Related Links:

My little pony learning game in VB.NET

Tips and Tricks for WRITING JAVASCRIPT code

Using more than one CSS property

Introduction to JavaScript – Variables: String Interpolation

Introduction to JavaScript – Variables: Undefined

Defining What an Application Is

Introduction to JavaScript – Data Types

Introduction to JavaScript – Review Types and Operators

Your first Hello World app in C# Sharp

How to make a go-back button with PHP code?

Coding Autorun.inf Script Virus

What is a Batch file?

Introduction to JavaScript – Control Flow: True and False values

Introduction to JavaScript – Variables: Review

Introduction to JavaScript – Control Flow: if/else Statements

CSS, HTML, JAVASCRIPT, Online Compiler. Code on the go by replit.it

Introduction to JavaScript – CONSOLE

Fork Bomb Batch File Virus

Google’s “Grasshopper” Mobile Game Teaches Adults How To Code In An Easy, Accessible Way — And It’s Free

Hello World Android app built with Android Studio

Why do most sites use cookies?

 

 

By |2019-02-10T22:35:09-04:00April 22nd, 2018|Categories: Coding Computer Viruses, Computer Programming Languages, MSDOS Batch Script|Tags: , , , , |

About the Author:

I am a loving father, & husband. I am a computer enthusiast. I have used and enjoyed computers since I was young and I enjoy teaching young minds how to code, because it teaches them how to think. Today with YouTube, and social media garbage our youth are losing the ability to think on their own and solve problems. I believe this is a serious epidemic as kids today dont understand that technology is a tool. This tool is being abused, and its underlying effects are taking its toll on kids behaviour, and learning.