PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [C++] HardwareID Protection



Beaving
26.04.2009, 13:40
Hier ist eine HardwareID Protection die ich vor nen paar Wochen geschrieben hab, funktioniert gut, vielleicht ein bisschen Tuning für euch nötig.

Kommentierte lines mit */ müssen/können entfernt werden, und mit // kommentiert müssen/können geändert werden.



/*#include <vcl.h>
*/

#include <Windows.h>
//#include <hashlibpp.h>

char hwid[MAX_PATH] = ""; //this hwid will be generated

BOOL HWCheck();
BOOL HWInfos();


int main()
{
if(HWCheck() != 0)
{
return -1; //error, dont continue
}

return 0; //all is ok
}

BOOL HWCheck()
{
//const std::string hwhashcheck = "13a27d9e33b4a0d0e0fdd32d7f2775f3"; //customer hwid to check with hwid (current one)

if(HWInfos() != 0)
{
//couldnt get system-infos to generate hwinfo
MessageBox(NULL, "Couldn't get System-infos, exiting", "ERROR:", MB_OK | MB_ICONSTOP);
return -1;
}

/*
//MD5 the hwid
hashwrapper *md5 = new md5wrapper();

std::string hwhashid = md5->getHashFromString(hwid);

delete md5;
*/


//MessageBox(NULL, hwhashid.c_str(), "HardwareID:", MB_OK | MB_ICONINFORMATION);


//if(strcmp(hwhashid.c_str(),hwhashcheck.c_str()) != 0)
{
//hwinfo doesnt match
MessageBox(NULL, "Your current HW profile doesn't match with the owners", "ERROR:", MB_OK | MB_ICONSTOP);
return -1;
}


//hwinfo matches
MessageBox(NULL, "Authorized to continue program", "SUCCESS:", MB_OK | MB_ICONINFORMATION);


return 0; //all is ok
}


BOOL HWInfos()
{

//PRODUCT ID
char proid[MAX_PATH];

HKEY hKey;
DWORD nSize = sizeof(proid);

if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
{
//couldnt open regkey
return -1;
}

if(RegQueryValueEx(hKey, "ProductId", NULL, NULL, (LPBYTE)proid,&nSize) != ERROR_SUCCESS)
{
//couldnt query regvalue
return -1;
}

strcat(hwid,proid); //add productid to hwid

RegCloseKey(hKey);




//BUILD LAB
char buildlab[MAX_PATH];

HKEY hKey2;
DWORD nSize2 = sizeof(proid);

if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey2) != ERROR_SUCCESS)
{
//couldnt open regkey
return -1;
}

if(RegQueryValueEx(hKey2, "BuildLab", NULL, NULL, (LPBYTE)buildlab,&nSize2) != ERROR_SUCCESS)
{
//couldnt query regkey
return -1;
}

strcat(hwid,buildlab); //add build lab to hwid

RegCloseKey(hKey2);




//CPU INFO
int sum;
char cpuinfo[MAX_PATH];

SYSTEM_INFO temp;
GetSystemInfo(&temp );

sum = temp.dwProcessorType + temp.wProcessorLevel + temp.wProcessorRevision;

itoa(sum, cpuinfo, 10); //converts the ints to strings

strcat(hwid,cpuinfo); //add cpu info to hwid




//VOLUME SN
char rootdrive[MAX_PATH], vsnc[MAX_PATH];
DWORD vsn;


GetEnvironmentVariable("HOMEDRIVE",rootdrive,sizeof(rootdrive));
strcat(rootdrive,"\\");


if(GetVolumeInformation(rootdrive, 0, 0, &vsn, 0, 0, 0, 0) == 0)
{
//couldnt get volume serial number
return -1;
}

itoa(vsn, vsnc, 10); //converts the ints to strings

strcat(hwid,vsnc); //add volume serial number to hwid




//HW PROFILE
HINSTANCE DLL = LoadLibraryA("ADVAPI32.DLL");

if(!DLL)
{
//coudlnt load .dll
return -1;
}

typedef BOOL (WINAPI *GetHwProfileFn)(LPHW_PROFILE_INFOA);

if (GetHwProfileFn fn = (GetHwProfileFn)::GetProcAddress(DLL, "GetCurrentHwProfileA"))
{

HW_PROFILE_INFOA profile;

if ((fn)(&profile))
{
char dockinfo[MAX_PATH];


itoa(profile.dwDockInfo, dockinfo, 10); //converts the ints to strings

strcat(hwid,dockinfo);
strcat(hwid,profile.szHwProfileGuid);
strcat(hwid,profile.szHwProfileName);

FreeLibrary(DLL);

}

else
{
//error
FreeLibrary(DLL);
return -1;

}

}

else
{
//error while getting proc adress
FreeLibrary(DLL);
return -1;

}


return 0;

}

bl0b
26.04.2009, 14:03
Sehr schönes Code Snippet :D
Jetzt muss ich nur noch eine Methode erarbeiten, die auch das Cracken/Ändern des Hashes unmöglich macht.

l0dsb
26.04.2009, 14:51
Um den Schutz zu umgehen, in Olly einen Breakpoint auf strcmp setzen (beim retn) und eax auf Null setzen. Um bl0b's Aussage mal anders darzustellen: Jetzt muss ich daraus nur noch eine richtige Protection machen.

HaCk & CrAcK
26.04.2009, 16:29
Hi Leute

sry für die dumme frage, aber was genau macht das?
Protecion = sicherheit bzw. sichern, gesichert !

Also was genau macht das..? ;)

ghosty
26.04.2009, 16:32
Ich würd sagen das das Tool dann nur auf einem Rechner läuft :D

v0id
26.04.2009, 16:52
Hi Leute

sry für die dumme frage, aber was genau macht das?
Protecion = sicherheit bzw. sichern, gesichert !

Also was genau macht das..? ;)

Das überprüft ob die Hardware ID deines Computers mit der im Code angegebenen übereinstimmt. Da die Hardware ID einzigartig ist kann man so dafür sorgen, dass dein Programm wirklich nur auf einem Computer läuft! Macht man bei Private-Versions, damit nicht einfach einer das Teil kauft und dann shared...

HaCk & CrAcK
27.04.2009, 14:43
Asoooo...ok..thx !
Werde ihn mal compilen und testen :D

G36KV
29.04.2009, 18:18
Vielleicht sollte ein Mod mal den Topic Titel ändern, weil das hier ist keine Hardware ID. Richtiger wäre: Software ID.

Warum Soft und nicht Hard?
Sobald ein neues Betriebssystem installiert wird, ändert sich die ID.
Das als "Hardware ID" zu bezeichnen ist Kunden-Verarsche :rolleyes:

bl0b
29.04.2009, 21:09
Ist das nicht bei jeder Hardware-ID der Falls, dass sich der Hash auch bei einer Formatierung ändert?

Andybritten
29.04.2009, 21:57
Ne wenn man nen Hash aus der CPUID und der Seriennummer der Festplatte erstellt dann nicht!
Aber ich mach bei meinen auch noch den username als faktor dabei!
Wenn der trottel dann seinen name ändert bei der formatierung...
Selber schuld.

St3r3oboy
29.04.2009, 22:59
Wie lerne ich alle diese begriffe und funktionen und header etc ... Kann die basics aber wenn ich dann sowas sehe bin ich komplett verwirrt .......

l0dsb
30.04.2009, 13:48
Wenn der trottel dann seinen name ändert bei der formatierung...
Grundsatz moderner Softwaretechnik: Der Kunde ist König. So eine Einstellung bringt dich nicht weiter, da entwickelt man lieber einen Schutz, der zuverlässigere Quellen verwendet als irgendeinen Benutzernamen. ;)

Schließlich soll die Anwendung an den PC gebunden sein, _nicht_ auch gleichzeitig an den Nutzer. Und wenn doch, bedient man sich doch lieber an der SSID oder Ähnlichem, wenn überhaupt.