Professional Documents
Culture Documents
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#.
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
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:
%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.
%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.
Open Visual Studio and create a new Console App in C# called Forkbomb. Write the
following code into your 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:
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.
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:
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 😊
Open a new project in Visual studio and call it Factorial_Recursion. After that, write the
following code:
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.
In Windows, open a new text file using Notepad and insert the following code:
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?”
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:
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?
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.
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:
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
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.