• STATISTIQUES
  • Il y a eu un total de 1 membres et 7669 visiteurs sur le site dans les dernières 24h pour un total de 7 670 personnes!


    Membres: 2 609
    Discussions: 3 580
    Messages: 32 820
    Tutoriels: 78
    Téléchargements: 38
    Sites dans l'annuaire: 58


  • ANNUAIRE
  • [FR] InfoMirmo
    Apprentissage de l'informatique par l'intermédiaire de challenges de sécurité. Venez app...
    Hacking
    [EN] Exploit-db
    Une base de données d'exploits triés par genre (GHDB, Remote, Local, Web, DOS, ShellCode) à ...
    Vulnérabilités
    [EN] PHPFreaks
    PHPFreaks est un site dédié à l'apprentissage et l'enseignement du PHP. Ici vous trouver...
    Programmation
    [EN] Defcon
    Lancé en 1992 par Dark Tangent, DEFCON est la plus ancienne et la plus grande conférence underground de...
    Hacking
    [EN] Reddit
    Subreddit dédié à la sécurité informatique.
    Hacking
    [EN] Security Traps
    Site de challenge qui prétend être construit non pas dans le but de parfaire vos connaissances, mais plutôt dan...
    Challenges
    [EN] Net Force
    Javascript: 9, Java Applets: 6, Cryptography: 16, Exploits: 7, Cracking: 14, Programming: 13, Internet: 15, Steganograph...
    Challenges

  • DONATION
  • Si vous avez trouvé ce site internet utile, nous vous invitons à nous faire un don du montant de votre choix via Paypal. Ce don servira à financer notre hébergement.

    MERCI!




Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5
[C++] Executable protector (stub)
01-10-2011, 21h42 (Modification du message : 19-11-2012, 19h29 par ark.)
Message : #1
Fr3ak Hors ligne
Banni



Messages : 25
Sujets : 4
Points: 1
Inscription : Sep 2011
[C++] Executable protector (stub)
Yop les chtis baznets,
Voici le stub d'un protecteur d'exécutable qui demande une clé et utilise un simple ou exclusif.

Directory.cpp

Code PHP :
#include <string>
#include <windows.h>
#include "Directory.h"

using namespace std;

string Directory::getTempPath()
{
    
// Get temporary pathname
    
char buf[MAX_PATH];
    
GetTempPath(sizeof(buf), buf);
    return 
buf;


Directory.h

Code PHP :
#ifndef DIRECTORY_H
#define DIRECTORY_H

class Directory
{
    public:
        static 
std::string getTempPath();
};

#endif 

main.cpp

Code PHP :
#include <algorithm>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <windows.h>

#include "Directory.h"
#include "Process.h"
#include "Resource.h"
#include "Xor.h"

using namespace std;

int main(int argcchar **argv)
{
    try {
        
// Check count of arguments
        
if (argc != 2)
            throw 
runtime_error("main: bad argc");
        
        
// Load and decrypt resource data
        
Resource res("");
        
string dat(res.load(MAKEINTRESOURCE(0), RT_RCDATA));
        Xor 
xorKey(argv[1]);
        
for_each(dat.begin(), dat.end(), xorKey);
        
        
// Write and run executable
        
string exe(Directory::getTempPath() + "\\a.exe");
        
ofstream f(exe);
        
<< dat;
        
Process::run(exe);
    } catch (
exception const &e) {
        
// Print exception
        
cout << e.what() << endl;
    }


Makefile.sh

Code PHP :
#!/bin/sh

i686-pc-mingw32-g++ *.cpp -pedantic -Wall -Wextra -Woverloaded-virtual \
-
Wfloat-equal -Wwrite-strings -Wpointer-arith -Wcast-qual -Wcast-align \
-
Wconversion  -Wshadow -Weffc++ -Wredundant-decls -Winit-self \
-
Wswitch-default -Wswitch-enum -Wundef -Wlogical-op -Winline -Werror \
-
Wfatal-errors -std=c++0x -O2 -s

strip 
-s a.exe && upx a.exe 

Process.cpp

Code PHP :
#include <stdexcept>
#include <windows.h>
#include "Process.h"

using namespace std;

void Process::run(string const &proc)
{
    
// Check process name
    
if (proc.empty())
        throw 
runtime_error("Process@run: bad proc");
    
    
// Zero out startup information
    
STARTUPINFO si;
    
ZeroMemory(&sisizeof(si));
    
si.cb sizeof(si);
    
    
// Create new detached process
    
PROCESS_INFORMATION pi;
    
CreateProcess(proc.c_str(), 000falseNORMAL_PRIORITY_CLASS DETACHED_PROCESS00, &si, &pi);


Process.h

Code PHP :
#ifndef PROCESS_H
#define PROCESS_H

#include <string>

class Process
{
    public:
        static 
void run(std::string const &proc);
};

#endif 

Resource.cpp

Code PHP :
#include <stdexcept>
#include <string>
#include <windows.h>
#include "Resource.h"

using namespace std;

string Resource::load(char const *namechar const *type)
{
    
// Check type
    
if (not type)
        throw 
runtime_error("Resource@load: bad type");
    
    
// Load resource and get size
    
string res("");
    
void *resInf(FindResource(GetModuleHandle(m_mod.c_str()), nametype));
    
unsigned size(SizeofResource(0static_cast<HRSRC__*>(resInf)));
    
void *resDat(LoadResource(0static_cast<HRSRC__*>(resInf)));
    
char *dat(static_cast<char*>(LockResource(resDat)));
    
    
// Copy resource data
    
for (unsigned i(0); size; ++i)
        
res.push_back(dat[i]);
    
    
// Free resource data
    // and return as a std::string
    
FreeResource(resDat);
    return 
res;
}

Resource::Resource(string const &mod) : m_mod(mod)
{
    
// Do not check mod
    // It could be 0


Resource.h

Code PHP :
#ifndef RESOURCE_H
#define RESOURCE_H

class Resource
{
    
std::string m_mod;
    
    public:
        
std::string load(char const *namechar const *type);
        
Resource(std::string const &mod);
};

#endif 

Xor.cpp

Code PHP :
#include <stdexcept>
#include "Xor.h"

using namespace std;

void Xor::operator()(char &x)
{
    
// Replace iterator at the beginning of the string
    
if (m_it == m_end) {
        
m_end m_key.end();
        
m_it m_key.begin();
    }
    
    
// Xor byte and increment key
    
^= *m_it++;
}

Xor::Xor(
string const &key) : m_end(0), m_it(0), m_key(key)
{
    
// Check key
    
if (key.empty())
        throw 
runtime_error("Xor@Xor: bad key");
    
    
// Get iterators now or it will be too late
    
m_end m_key.end();
    
m_it m_key.begin();


Xor.h

Code PHP :
#ifndef XOR_H
#define XOR_H

#include <string>

typedef std::string::iterator stringIt;

class Xor
{
    
stringIt m_end;
    
stringIt m_it;
    
std::string m_key;
    
    public:
        
void operator()(char &x);
        Xor(
std::string const &key);
};

#endif 

Todo

- Faire l'autre partie du programme
- Tester le stub (je l'ai pas testé mais c'est censé marcher)
+1 (0) -1 (0) Répondre
05-10-2011, 23h42
Message : #2
fr0g Hors ligne
NTEuNDI2MzcsLTEuNzc4NDg4
*****



Messages : 348
Sujets : 22
Points: 56
Inscription : Aug 2011
[C++] Executable protector (stub)
Yeah cool , je me remet doucement au c++ ces temps ci, merci pour le code Wink
+1 (0) -1 (0) Répondre
14-12-2011, 18h34
Message : #3
Xylitol Hors ligne
Membre
*



Messages : 34
Sujets : 3
Points: 11
Inscription : Sep 2011
[C++] Executable protector (stub)
La "protection" qu'offre cette "Executable protector" est nulle.
Il faut lancer le PE protégé en runtime, pas comme tu le fais.
+1 (0) -1 (0) Répondre


Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
N-PN
Accueil | Challenges | Tutoriels | Téléchargements | Forum | Retourner en haut