You are on page 1of 9

Page 1 of 9

CO1508 Computer Systems & Security – Week 09 – Fork


Bomb, Windows Pranks and Keyloggers!

Summary
You are going to learn different methods to write a fork bomb for Windows operating
system and C#. You’ll also learn how to write simple Windows pranks. Finally, you’ll research
how to write a keylogger using C#.

Disclaimer (READ ME)


The Fork Bomb, Windows Pranks and Keyloggers exercises are presented for educational
purposes within an academic environment. You MUST NOT use this knowledge outside
UCLan labs to develop and/or distribute programmes like these. If you do so, you are
personally responsible and might be prosecuted under the Computer Misuse Act 1990.
Ignorance is not an excuse. By continuing this exercise, you agree to NOT misuse any of the
information/knowledge here. If you’re not sure about this, please speak to your lab tutor.

Note
Before commencing the following activities, make sure to save all your work and close open
programmes down. Your machine might freeze and needs restarting during these activities.

Activities

1. Fork Bomb on Windows

Open Notepad and write the following lines:

Save the file as forkbomb.bat on Desktop. Make sure it’s NOT a txt file.

Now, double click on this file and let it run. What’s happening?

After you restart your machine, open the file again, remove all contents and write the
following line:

CO1508 Computer Systems and Security, UCLAN – 2019-2020


Page 2 of 9

%0 | %0
Now save the file and double click again. What’s happening now?

Discuss what happened with your lab tutor and see the code explanation below.

In the first programme,

:ForkBomb Creates a label ForkBomb


start %0 Start the programme itself
goto ForkBomb Loop back to the top and start over again

While the second programme,

%0 | %0
%0 means run the programme itself, | pipe symbol will take the output of the first command
to be the input for the next command. Hence, this line will run the same programme
recursively creating so many processes and slowing the system down.

Speaking of recursively, let’s do the following exercises in C#.

2. Fork Bomb using C#

Open Visual Studio and create a new Console App in C# called Forkbomb. Write the
following code into your programme:

Now hit Run and see what will happen.

CO1508 Computer Systems and Security, UCLAN – 2019-2020


Page 3 of 9

You’ll receive System.StackOverflowException and the execution will stop. C# is a control


environment and it’ll stop the programme.

Now, let’s try multi-threading and see what happen. Remove all contents from your
programme and write the following code:

Run and check the memory usage. It’ll stop eventually like this:

CO1508 Computer Systems and Security, UCLAN – 2019-2020


Page 4 of 9

Let’s discuss what happened above. Basically, you’ve created 1551097 threads for the same
process, each has an infinite loop. This will consume the memory space and eventually stop
the execution with OutofMemoryException. This might take a while depending on your PC
memory.

3. Factorial Calculation – Recursion in C#

Do you know what is factorial? Well, for a number n, the factorial n! is the product of all
integers less than or equal to n but greater than or equal to 1. Mathematically, it can be
written like this:

n! = n * (n - 1)*(n - 2)*(n - 3) ... (3)*(2)*(1)

if n = 0 then n! = 1

Now, do you know what is a recursion function? Basically, it’s a function that calls itself
(probably with different parameters).

If you look back at the factorial calculation, it makes a good case to write a recursion
function that calculates n! Let’s do it 😊

CO1508 Computer Systems and Security, UCLAN – 2019-2020


Page 5 of 9

Open a new project in Visual studio and call it Factorial_Recursion. After that, write the
following code:

Now hit Run and try with 5, 7, 10 and 12.

Okay, now can you modify the code so that it acts like the fork bomb we did at the
beginning? It’s only one little change 😊 … if you give up, ask you tutor.

4. Windows Pranks – Harmless One

In Windows, open a new text file using Notepad and insert the following code:

X = MsgBox(“Message Description”, 0+16, “Title”)

Save the file as Prank.vbs Note that the “vbs” file extension refers to an executable file type.
Now, find the file and double click on it. What happens? What is the “Message
Description”? What is the “Title”?

Let’s make this more interesting. Replace “Message Description” with “Error while opening
computer. Do you want to fix it?”

CO1508 Computer Systems and Security, UCLAN – 2019-2020


Page 6 of 9

Save the file and double click to execute. What happened?

Now replace “Title” with “Computer”. Save and execute again to see the change.

Next, open the file to see the code. Note that in the middle you have two numbers: 0 + 16.
You can write any number from 1, 2, 3, 4, or, 5, to replace 0. The meaning of these numbers
is the following:

• 0: OK Buttons
• 1: OK/Cancel Buttons
• 2: Abort/Retry/Ignore Buttons
• 3: Yes/No/Cancel Buttons
• 4: Yes/No Buttons
• 5: Retry/Cancel Buttons

You can also write any number from 32, 48, or, 64, to replace 16. The meaning of these
numbers is the following:

• 16: Critical Icon


• 32: Help Icon
• 48: Warning Icon
• 64: Information Icon

Try different combinations of these numbers, to locate the differences. To execute make
sure that you double click on the file icon.

If everything works as expected, you can move onto the next step. Now that you know the
basics let’s create this harmless prank. Make sure your file has the following lines. Can you
guess what will happen?

X=MsgBox(“Error while opening computer. Do you want to fix it?”, 4+64,


“Computer”)
X=MsgBox(“Unable to fix error! Do you want to scan the computer?”, 3+48,
“Computer Scan”)
X=MsgBox(“Alert! Virus has been detected! Delete virus?”, 3+16, “Alert”)
X=MsgBox(“Unable to delete virus!”, 1+64, “Critical Error”)
X=MsgBox(“Virus is Activated!”, 2+16, “Virus Alert”)

CO1508 Computer Systems and Security, UCLAN – 2019-2020


Page 7 of 9

X=MsgBox(“Deleting System Files…”, 2+16, “File Deletion”)


X=MsgBox(“Virus is Copying your Password…”, 2+48, “Virus Alert”)
X=MsgBox(“Please wait. Uploading Files to external server. Do you want to
stop?”, 4+64, “File Transfer”)
X=MsgBox(“Cannot Stop. File Transfer Completed.”, 1+16, “Completed”)
X=MsgBox(“This was a PRANK. There is no virus.”, 1+64, “No virus”)

Save the file in your folder and create a shortcut and paste it on the Desktop. Change the
Icon to look like My Computer and rename it to “My Computer”. If you cannot change it ask
your tutor.

Double click on the final shortcut. What happened?!

5. Windows Pranks – More

Do you want to make your keyboard lights go crazy? Try this one. In Windows, open a new
text file using Notepad and insert the following code:

Save the file as lights.vbs then double click. Check your keyboard lights.

Do you want to write a message automatically? Try this one. In Windows, open a new text
file using Notepad and insert the following code:

Set wshshell = wscript.CreateObject("WScript.Shell")


Wshshell.run "Notepad"
wscript.sleep 400
wshshell.sendkeys "H"
wscript.sleep 100
wshshell.sendkeys "i"
wscript.sleep 200
wshshell.sendkeys " "
wscript.sleep 200
wshshell.sendkeys "I"

CO1508 Computer Systems and Security, UCLAN – 2019-2020


Page 8 of 9

wscript.sleep 200
wshshell.sendkeys " "
wscript.sleep 100
wshshell.sendkeys "a"
wscript.sleep 100
wshshell.sendkeys "m"
wscript.sleep 200
wshshell.sendkeys " "
wscript.sleep 100
wshshell.sendkeys "a"
wscript.sleep 100
wshshell.sendkeys " "
wscript.sleep 100
wshshell.sendkeys "P"
wscript.sleep 100
wshshell.sendkeys "r"
wscript.sleep 100
wshshell.sendkeys "a"
wscript.sleep 100
wshshell.sendkeys "n"
wscript.sleep 100
wshshell.sendkeys "k"
wscript.sleep 100
wshshell.sendkeys "!"
wscript.sleep 100
wshshell.sendkeys " "
wscript.sleep 200
wshshell.sendkeys "W"
wscript.sleep 100
wshshell.sendkeys "h"
wscript.sleep 100
wshshell.sendkeys "o"
wscript.sleep 100
wshshell.sendkeys " "
wscript.sleep 100
wshshell.sendkeys "a"
wscript.sleep 100
wshshell.sendkeys "r"
wscript.sleep 100
wshshell.sendkeys "e"
wscript.sleep 100

CO1508 Computer Systems and Security, UCLAN – 2019-2020


Page 9 of 9

wshshell.sendkeys " "


wscript.sleep 100
wshshell.sendkeys "y"
wscript.sleep 100
wshshell.sendkeys "o"
wscript.sleep 100
wshshell.sendkeys "u"
wscript.sleep 100
wshshell.sendkeys "?"
wscript.sleep 100
wshshell.sendkeys "!"
wscript.sleep 100

Save the file as automsg.vbs then double click.

6. Directed Task – Keylogger in C#

A keylogger is a simple programme that will keep track of keys pressed on the keyboard.
Why would this be useful to a hacker?

Sometimes you don’t need to write everything from scratch. Learning how to use and
integrate others’ code is an important skill. Obviously, if you do so, you’ve to provide a
reference and citation to your resources.

Using your friend Google, find out how you can write a simple keylogger in C#. This is not an
optional task. You should do it and show your tutor your work.

CO1508 Computer Systems and Security, UCLAN – 2019-2020

You might also like