[VB.NET] ★ HWID license file auth system ★ [TUT] - Mr. Fink - Aug 25, 2011
★ HWID license file auth system ★
This tutorial will teach you how to use a combination of HWID to protect your application from leaker
First, you create new class , and add these HWID function to it in order to call it later. Don't forget to add a reference to System.Management
Code Imports System.Management
Public Class clsComputerInfo
Public Shared Function GetProcessorId() As String
Dim strProcessorId As String = String.Empty
Dim query As New SelectQuery("Win32_processor")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strProcessorId = info("processorId").ToString()
Next
Return strProcessorId
End Function
Public Shared Function GetMACAddress() As String
Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim MACAddress As String = String.Empty
For Each mo As ManagementObject In moc
If (MACAddress.Equals(String.Empty)) Then
If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()
mo.Dispose()
End If
MACAddress = MACAddress.Replace(":", String.Empty)
Next
Return MACAddress
End Function
Public Shared Function GetVolumeSerial(Optional ByVal strDriveLetter As String = "C") As String
Dim disk As ManagementObject = New ManagementObject(String.Format("win32_logicaldisk.deviceid=""{0}:""", strDriveLetter))
disk.Get()
Return disk("VolumeSerialNumber").ToString()
End Function
End Class
So my class will look like this.
[img]http://upic.me/i/qg/4hl42.png[/img]
Then we declare 3 variables to store 3 HWID by
Code Dim MyMacAddress As String = clsComputerInfo.GetMACAddress()
Dim MyProcessAddress As String = clsComputerInfo.GetProcessorId()
Dim MyVolumeAddress As String = clsComputerInfo.GetVolumeSerial()
So MacAddress,ProcessorID,HDVolume will be stored.
Then we declare another variable to store the formatted HWID.
Code Dim TFC_MID As String = "TFCZ-" & MyMacAddress.Substring(MyMacAddress.Length() - 4, 4) _
& "-" & MyProcessAddress.Substring(MyProcessAddress.Length() - 4, 4) & "-" & MyVolumeAddress.Substring(MyVolumeAddress.Length() - 4, 4)
The above code will declare TFC_MID to be a string with TFCZ as salt followed by last 4 string of MACAddress , ProcessID , Volume.
The format will look like this
*Note that you can change how to order those three above or change salt TFCZ into another name.
After that, we add RC4 encryption algorithm below the sub form1_load
Code Public Shared Function rc4(ByVal message As String, ByVal password As String) As String
Dim i As Integer = 0
Dim j As Integer = 0
Dim cipher As New StringBuilder
Dim returnCipher As String = String.Empty
Dim sbox As Integer() = New Integer(256) {}
Dim key As Integer() = New Integer(256) {}
Dim intLength As Integer = password.Length
Dim a As Integer = 0
While a <= 255
Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))
key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
sbox(a) = a
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
End While
Dim x As Integer = 0
Dim b As Integer = 0
While b <= 255
x = (x + sbox(b) + key(b)) Mod 256
Dim tempSwap As Integer = sbox(b)
sbox(b) = sbox(x)
sbox(x) = tempSwap
System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
End While
a = 1
While a <= message.Length
Dim itmp As Integer = 0
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
itmp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = itmp
Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)
Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)
itmp = Asc(ctmp)
Dim cipherby As Integer = itmp Xor k
cipher.Append(Chr(cipherby))
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
End While
returnCipher = cipher.ToString
cipher.Length = 0
Return returnCipher
End Function
And don't forget to add
Code Imports System.IO
Imports System.Text
on the top as imports
Then we add
Code If (File.Exists(Application.StartupPath & "\TFC.lic")) Then
To check that the file "TFC.lic" is existed or not, and add this to make a stream reader to read for our license key
Code Dim stream_reader As New StreamReader(Application.StartupPath & "\TFC.LIC")
then we decrypted the lic file to compare with our HWID with TFC as password
Code Dim myMIDReader = rc4(stream_reader.ReadToEnd, "TFC")
stream_reader.close()
After that we put
Code If (myMIDReader = TFC_MID) Then
Else
MsgBox("The license key is incorrect, please contact [email protected] for more information", MsgBoxStyle.Critical)
End
End If
Else
MsgBox("Your machine ID is : " & TFC_MID & vbCrLf & "Your machine ID is copied to clipboard, press ctrl+v to paste it!", MsgBoxStyle.Critical)
Clipboard.SetText(TFC_MID)
End
End If to check that the decrypted lic file is same as TFC_MID or not. If yes, the program run normal.
And if it's not the same , it show the msgbox that the license key is incorrect and end the application.
The next else show the machine ID and copy it to clipboard in case the license key is not found.
This is the final code in form1_load()
[img]http://upic.me/i/fl/0rj63.png[/img]
[color=#FFD700]The keygen part
[img]http://upic.me/i/zd/ykh94.png[/img]
Create new project and add 1 textbox and 1 button as above.
then add
Code Imports System.IO
Imports System.Text
as import of the application
and add this RC4 encryption to the application
Code Public Shared Function rc4(ByVal message As String, ByVal password As String) As String
Dim i As Integer = 0
Dim j As Integer = 0
Dim cipher As New StringBuilder
Dim returnCipher As String = String.Empty
Dim sbox As Integer() = New Integer(256) {}
Dim key As Integer() = New Integer(256) {}
Dim intLength As Integer = password.Length
Dim a As Integer = 0
While a <= 255
Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))
key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
sbox(a) = a
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
End While
Dim x As Integer = 0
Dim b As Integer = 0
While b <= 255
x = (x + sbox(b) + key(b)) Mod 256
Dim tempSwap As Integer = sbox(b)
sbox(b) = sbox(x)
sbox(x) = tempSwap
System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
End While
a = 1
While a <= message.Length
Dim itmp As Integer = 0
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
itmp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = itmp
Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)
Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)
itmp = Asc(ctmp)
Dim cipherby As Integer = itmp Xor k
cipher.Append(Chr(cipherby))
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
End While
returnCipher = cipher.ToString
cipher.Length = 0
Return returnCipher
End Function
then double click at the button and add this code
Code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim write_file As New StreamWriter(Application.StartupPath & "\TFC.lic", False)
write_file.Write(rc4(TextBox1.Text, "TFC"))
write_file.Close()
End Sub
*Note that the password "TFC" must the same as your application and keep it private or else anyone can gen your lic file :D . You can freely change the order or salt . Don't forget to obfuscate your application to prevent viewing through reflector and keep your keygen private.
That's it! Have fun :D
* - Ap - Aug 25, 2011
Great HQ tutorial, I recommend for you to keep this up, Amazing work!
* - Mr. Fink - Aug 25, 2011
(Aug 25, 2011 08:57 PM)Ap. Wrote: Great HQ tutorial, I recommend for you to keep this up, Amazing work!
Thanks mate, enjoy. Hope I helped. 🤩
* - Coleak - Aug 25, 2011
Awesome tutorial, but i suggest you remove the code, and keep the pictures, a small anti-copypaste measure.
* - mrstean - Dec 28, 2011
Amazing tutorial !
Right now im typing everything in my project Love u :D
* - зяяоя - Dec 28, 2011
Very good tutorial, nice job.
Of course you would have to build on this but yea. =)
* - fillobotto - Jan 15, 2012
i will implement my system with MAC address function ;)
thank you
* - King of Hearts - Mar 19, 2012
Hey,
Nice tutorial. However, I am new to vb and have a question. What's the difference between the first part and the second set of code? So what's the difference between the keygen and the first part. Do I implement the first part in my application? Thanks for helping me.
* - Padawan of VB - Mar 19, 2012
Really nice Tutorial - my advice, just use pictures so there's no chance for c&p :) !
keep working
* - Vamprrr - Mar 19, 2012
this looks really cool, is it easy to crack into?
* - Deceptive - Mar 19, 2012
(Mar 19, 2012 07:24 PM)IlyGreenz Wrote: this looks really cool, is it easy to crack into?
Yes, it's just a simple patch. It's only one check.
|