Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. Public Class Form1
  2. Private TargetProcessHandle As Integer
  3. Private pfnStartAddr As Integer
  4. Private pszLibFileRemote As String
  5. Private TargetBufferSize As Integer
  6.  
  7. Public Const PROCESS_VM_READ = &H10
  8. Public Const TH32CS_SNAPPROCESS = &H2
  9. Public Const MEM_COMMIT = 4096
  10. Public Const PAGE_READWRITE = 4
  11. Public Const PROCESS_CREATE_THREAD = (&H2)
  12. Public Const PROCESS_VM_OPERATION = (&H8)
  13. Public Const PROCESS_VM_WRITE = (&H20)
  14. Dim DLLFileName As String
  15. Public Declare Function ReadProcessMemory Lib "kernel32" (
  16. ByVal hProcess As Integer,
  17. ByVal lpBaseAddress As Integer,
  18. ByVal lpBuffer As String,
  19. ByVal nSize As Integer,
  20. ByRef lpNumberOfBytesWritten As Integer) As Integer
  21.  
  22. Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (
  23. ByVal lpLibFileName As String) As Integer
  24.  
  25. Public Declare Function VirtualAllocEx Lib "kernel32" (
  26. ByVal hProcess As Integer,
  27. ByVal lpAddress As Integer,
  28. ByVal dwSize As Integer,
  29. ByVal flAllocationType As Integer,
  30. ByVal flProtect As Integer) As Integer
  31.  
  32. Public Declare Function WriteProcessMemory Lib "kernel32" (
  33. ByVal hProcess As Integer,
  34. ByVal lpBaseAddress As Integer,
  35. ByVal lpBuffer As String,
  36. ByVal nSize As Integer,
  37. ByRef lpNumberOfBytesWritten As Integer) As Integer
  38.  
  39. Public Declare Function GetProcAddress Lib "kernel32" (
  40. ByVal hModule As Integer, ByVal lpProcName As String) As Integer
  41.  
  42. Private Declare Function GetModuleHandle Lib "Kernel32" Alias "GetModuleHandleA" (
  43. ByVal lpModuleName As String) As Integer
  44.  
  45. Public Declare Function CreateRemoteThread Lib "kernel32" (
  46. ByVal hProcess As Integer,
  47. ByVal lpThreadAttributes As Integer,
  48. ByVal dwStackSize As Integer,
  49. ByVal lpStartAddress As Integer,
  50. ByVal lpParameter As Integer,
  51. ByVal dwCreationFlags As Integer,
  52. ByRef lpThreadId As Integer) As Integer
  53.  
  54. Public Declare Function OpenProcess Lib "kernel32" (
  55. ByVal dwDesiredAccess As Integer,
  56. ByVal bInheritHandle As Integer,
  57. ByVal dwProcessId As Integer) As Integer
  58.  
  59. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (
  60. ByVal lpClassName As String,
  61. ByVal lpWindowName As String) As Integer
  62.  
  63. Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandleA" (
  64. ByVal hObject As Integer) As Integer
  65.  
  66.  
  67. Dim ExeName As String = IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath)
  68. Private Sub Inject()
  69. On Error GoTo 1 ' If error occurs, app will close without any error messages
  70. Timer1.Stop()
  71. Dim TargetProcess As Process() = Process.GetProcessesByName(ViTextBox1.Text)
  72. TargetProcessHandle = OpenProcess(PROCESS_CREATE_THREAD Or PROCESS_VM_OPERATION Or PROCESS_VM_WRITE, False, TargetProcess(0).Id)
  73. pszLibFileRemote = OpenFileDialog1.FileName
  74. pfnStartAddr = GetProcAddress(GetModuleHandle("Kernel32"), "LoadLibraryA")
  75. TargetBufferSize = 1 + Len(pszLibFileRemote)
  76. Dim Rtn As Integer
  77. Dim LoadLibParamAdr As Integer
  78. LoadLibParamAdr = VirtualAllocEx(TargetProcessHandle, 0, TargetBufferSize, MEM_COMMIT, PAGE_READWRITE)
  79. Rtn = WriteProcessMemory(TargetProcessHandle, LoadLibParamAdr, pszLibFileRemote, TargetBufferSize, 0)
  80. CreateRemoteThread(TargetProcessHandle, 0, 0, pfnStartAddr, LoadLibParamAdr, 0, 0)
  81. CloseHandle(TargetProcessHandle)
  82. 1: Me.Show()
  83. End Sub
  84.  
  85. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  86. DLLs.Name = "DLLs"
  87. ViButton1.Text = "Browse"
  88. Label1.Text = "Waiting for Program to Start.."
  89. Timer1.Interval = 50
  90. Timer1.Start()
  91. End Sub
  92.  
  93. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViButton1.Click
  94. OpenFileDialog1.Filter = "DLL (*.dll) |*.dll"
  95. OpenFileDialog1.ShowDialog()
  96. End Sub
  97.  
  98. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViButton2.Click
  99. For i As Integer = (DLLs.SelectedItems.Count - 1) To 0 Step -1
  100. DLLs.Items.Remove(DLLs.SelectedItems(i))
  101. Next
  102. End Sub
  103.  
  104. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViButton3.Click
  105. DLLs.Items.Clear()
  106. End Sub
  107.  
  108. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViButton4.Click
  109. If IO.File.Exists(OpenFileDialog1.FileName) Then
  110. Dim TargetProcess As Process() = Process.GetProcessesByName(ViTextBox1.Text)
  111. If TargetProcess.Length = 0 Then
  112.  
  113. Me.Label1.Text = ("Waiting for " + ViTextBox1.Text + ".exe")
  114. Else
  115. Timer1.Stop()
  116. Me.Label1.Text = "Successfully Injected!"
  117. Call Inject()
  118. If CheckBox1.Checked = True Then
  119. End
  120. Else
  121. End If
  122. End If
  123. Else
  124. End If
  125. End Sub
  126.  
  127. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  128. If IO.File.Exists(OpenFileDialog1.FileName) Then
  129. Dim TargetProcess As Process() = Process.GetProcessesByName(ViTextBox1.Text)
  130. If TargetProcess.Length = 0 Then
  131.  
  132. Me.Label1.Text = ("Waiting for " + ViTextBox1.Text + ".exe")
  133. Else
  134. Timer1.Stop()
  135. Me.Label1.Text = "Successfully Injected!"
  136. Call Inject()
  137. If CheckBox1.Checked = True Then
  138. End
  139. Else
  140. End If
  141. End If
  142. Else
  143. End If
  144. End Sub
  145.  
  146. Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
  147. Dim FileName As String
  148. FileName = OpenFileDialog1.FileName.Substring(OpenFileDialog1.FileName.LastIndexOf("\"))
  149. Dim DllFileName As String = FileName.Replace("\", "")
  150. Me.DLLs.Items.Add(DllFileName)
  151. End Sub
  152.  
  153. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViButton5.Click
  154. Me.Close()
  155. End Sub
  156.  
  157. Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
  158. ViButton4.Enabled = True
  159. Timer1.Enabled = False
  160. End Sub
  161.  
  162. Private Sub ViTheme1_Click(sender As Object, e As EventArgs) Handles ViTheme1.Click
  163.  
  164. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement