Results 1 to 2 of 2
  1. #1
    Ragehax's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Posts
    357
    Reputation
    12
    Thanks
    87
    My Mood
    Inspired

    Help with DLL Injector!

    Down Below is my code for the dll injector... but it always fails at WriteProcessMemory...

    can anyone tell me why?



    Code:
    Imports System.IO
    Imports System.Diagnostics
    Public Class Form1
        Private Declare Function CreateRemoteThread Lib "kernel32.dll" (ByVal hProcess As Int32, ByRef lpThreadAttributes As Security_Attributes, ByVal dwStackSize As Int32, ByRef lpStartAddress As Int32, ByVal lpParameter As Int32, ByVal dwCreationFlags As Int32, ByRef lpThreadId As Int32) As Int32
        Private Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As Int32, ByVal lpAddress As Int32, ByRef dwSize As Int32, ByVal flAllocationType As Int32, ByVal flProtect As Int32) As Int32
        Private Declare Function WriteProcessMemory Lib "kernel32.dll" (ByVal hProcess As Int32, ByVal lpBaseAddress As Int32, ByRef lpBuffer As Byte(), ByVal nSize As Int32, ByRef lpNumberOfBytesWritten As Int32) As Int32
        Private Declare Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Int32, ByVal lpAddress As Int32, ByRef dwSize As Int32, ByVal dwFreeType As Int32) As Int32
        Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" (ByVal idHook As Int32, ByVal lpfn As Int32, ByVal hmod As Int32, ByVal dwThreadId As Int32) As Int32
        Private Declare Function GetExitCodeThread Lib "kernel32.dll" (ByVal hThread As Int32, ByRef lpExitCode As Int32) As Int32
        Private Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Int32
        Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Int32
        Private Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Int32, ByVal lpProcName As String) As Int32
        Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Int32, ByVal bInheritHandle As Int32, ByVal dwProcessId As Int32) As Int32
        Private Declare Function CreateRemoteThreadex Lib "kernal32.dll" (ByVal HProcess As IntPtr, ByVal dwstacksize As Int32, ByVal LpStartAddress As Int32, ByVal LpParameter As Int32, ByVal DwCreationFlags As UInt32, ByVal lpAttributeList As Integer, ByRef lpThreadid As Int32) As Int32
        Private Process_All_Access As Integer = &H1F0FFF
    
        Public Structure Security_Attributes
            Dim nLength As UInteger
            Dim LpSecurityDescriptor As IntPtr
            Dim bInheritHandle As Boolean
        End Structure
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim ofd As New OpenFileDialog
            With ofd
                .Filter = "Dll's (*.dll)|*.dll"
                .Title = "Select a dll to inject.."
                .CheckPathExists = True
                .CheckFileExists = True
            End With
            If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim lvi As New ListViewItem(ofd.SafeFileName)
                lvi.SubItems.Add(ofd.FileName)
                ListView1.Items.Add(lvi)
            End If
        End Sub
    
    
        Public Function DllInjection(ByVal DllBfile() As Byte, ByVal ProcessHandle As Int32)
            Try
                Dim DllVirtLoc As Int32
                Dim DllLength As Int32
                Dim Inject As Int32
                Dim LibAddress As Int32
                Dim CreateThread As Int32
                Dim ThreadID As Int32
                DllLength = UBound(DllBfile)
                DllVirtLoc = VirtualAllocEx(ProcessHandle, 0, DllLength, &H1000, &H4)
                If DllVirtLoc = 0 Then
                    MessageBox.Show("Call to VirtualAllocEx Failed", "Error", MessageBoxButtons.OK)
                    Exit Function
                Else
                    Inject = WriteProcessMemory(ProcessHandle, DllVirtLoc, DllBfile, DllLength, Nothing)
                    If Inject = 0 Then
                        MessageBox.Show("Call To WriteProcessMemory", "Error", MessageBoxButtons.OK)
                        Exit Function
                    Else
                        Dim mHandle As Int32
                        mHandle = GetModuleHandle("Kernal32.dll")
                        If mHandle = 0 Then
                            MessageBox.Show("Call to GetModuleHandle failed.", "Error", MessageBoxButtons.OK)
                            Exit Function
                        Else
                            LibAddress = GetProcAddress(mHandle, "LoadLibraryA")
                            If LibAddress = 0 Then
                                MessageBox.Show("Error Getting Address of LoadLibrary", "Error", MessageBoxButtons.OK)
                                Exit Function
                            Else
                                CreateThread = CreateRemoteThread(ProcessHandle, Nothing, 0, LibAddress, DllVirtLoc, 0, ThreadID)
                                If CreateThread = 0 Then
                                    MessageBox.Show("Call to CreateRemoteThread Failed", "Error", MessageBoxButtons.OK)
                                    Exit Function
                                Else
                                    StatusStrip1.Text = "Injected!"
                                    StatusStrip1.ForeColor = Color.Green
                                End If
                            End If
                        End If
                    End If
                End If
            Catch ex As Exception
            End Try
        End Function
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim splits() As String
            Dim myprocess As Process() = Process.GetProcessesByName(TextBox1.Text)
            Dim Hhandle As Int32
            Dim i As Integer
    
            splits = Split(TextBox1.Text, ".")
            If TextBox1.Text = "" Then
                Exit Sub
            ElseIf UBound(splits) <> 0 Then
                MessageBox.Show("Dont include the '.exe' at the end of the Process Name", "Error", MessageBoxButtons.OK)
                Exit Sub
            End If
            Try
                Hhandle = OpenProcess(Process_All_Access, 0, myprocess(0).Id)
            Catch ex As Exception
            End Try
            For i = 0 To ListView1.Items.Count - 1
                Dim items As String
                items = ListView1.Items(i).SubItems(1).Text
                Dim bfile() As Byte
                Dim Fileinfo1 As New FileInfo(ListView1.Items(i).SubItems(1).Text)
                Dim Fs As FileStream
                Fs = Fileinfo1.OpenRead()
                bfile = New Byte((Fs.Length - 1)) {}
                Fs.Read(bfile, 0, Fileinfo1.Length)
                DllInjection(bfile, Hhandle)
            Next i
        End Sub
    End Class

  2. #2
    wtfiwantthatname's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Posts
    260
    Reputation
    10
    Thanks
    39
    My Mood
    Bored
    Ill tell you. Your writing the whole dll as a byte array to the process not as its path(string). All attach my new source. I was wondering where you got my old source at? Also if your on vista or 64 bit OS set debugPrivileges.

    P.S: It also is not your code.
    Last edited by wtfiwantthatname; 11-22-2009 at 05:33 PM.
    "I don't believe in an afterlife, so I don't have to spend my whole life fearing hell, or fearing heaven even more. For whatever the tortures of hell, I think the boredom of heaven would be even worse." - Isaac Asimov

Similar Threads

  1. Help with the injectors and and the dlls
    By pergel in forum CrossFire Spammers, Injectors and Multi Tools
    Replies: 0
    Last Post: 07-01-2011, 08:24 PM
  2. please help with dll injector, there's video
    By /b/oss in forum Programming Tutorials
    Replies: 2
    Last Post: 03-08-2010, 12:09 AM
  3. hey ! Help about Dll injector
    By wschiam in forum Blackshot Hacks & Cheats
    Replies: 0
    Last Post: 07-19-2009, 02:54 AM
  4. Need help with my injector
    By grrgto in forum Combat Arms Hacks & Cheats
    Replies: 1
    Last Post: 06-11-2009, 08:16 PM
  5. help with dll in hack!
    By bldymarien in forum C++/C Programming
    Replies: 0
    Last Post: 08-05-2008, 06:54 PM

Tags for this Thread