Advertisement
liamglitches

How to make YOUR own DLL injector with Visual Basic

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