Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: XSaMuXPH *-* Traigo uno encima! =D! en 18 Septiembre 2009, 01:23 am



Título: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: XSaMuXPH *-* Traigo uno encima! =D! en 18 Septiembre 2009, 01:23 am
En VB:

Código
  1. Private Const PAGE_READWRITE As Long = &H4
  2. Private Const MEM_RELEASE As Long = &H8000
  3. Private Const MEM_COMMIT As Long = &H1000
  4. Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
  5. Private Const SYNCHRONIZE As Long = &H100000
  6. Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
  7. Private Const INFINITE As Long = &HFFFFFF
  8.  
  9. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  10. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
  11. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
  12. Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
  13. Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
  14. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  15. Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, lpThreadAttributes As Long, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
  16. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  17.  
  18.  
  19. Public Function Inyecta(RutaDll As String, Pid As Long) As Integer
  20. Dim proc As Long
  21. Dim nload As Long
  22. Dim rems As Long
  23. Dim longi As Long
  24. Dim RemThread As Long
  25. Dim Tid As Long
  26.  
  27. On Error GoTo Error
  28. proc = OpenProcess(PROCESS_ALL_ACCESS, False, Pid)
  29. nload = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA")
  30. rems = VirtualAllocEx(proc, 0, Len(RutaDll), MEM_COMMIT, PAGE_READWRITE)
  31. WriteProcessMemory proc, ByVal rems, ByVal RutaDll, Len(RutaDll), longi
  32. CreateRemoteThread proc, ByVal 0, 0, ByVal nload, ByVal rems, 0, Tid
  33. WaitForSingleObject rems, INFINITE
  34. CloseHandle proc
  35. CloseHandle rems
  36. Inyecta = 0
  37. Exit Function
  38. Error:
  39. Inyecta = 1
  40. End Function
  41.  
  42. '----------------------------------------------------------------------------------'
  43.  
  44. Private Sub Form_Load()
  45. Dim ruta As Long
  46. Dim resultado As Integer
  47.  
  48. ruta = Shell("notepad.exe")
  49. resultado = Inyecta("C:\ladll.dll", ruta)
  50.  
  51. If resultado = 0 Then
  52. MsgBox "Dll Inyectada con éxito!!!", , "Información"
  53. Else
  54. MsgBox "A ocurrido un error", vbCritical, "Información"
  55. End If
  56. End
  57. End Sub

 :o

En Delphi:

Código
  1. Procedure InjectDll(Dll:string);
  2. var
  3.   Thread,HandleWindow: THandle;
  4.   DMod,Lib: Pointer;
  5.   ThreadID,Written: Cardinal;
  6.   WindowName,ProcessId: DWORD;
  7. begin
  8.   WindowName := FindWindow(nil, 'Tester');
  9.   ThreadId := GetWindowThreadProcessId(WindowName, @ProcessId);
  10.   HandleWindow := OpenProcess(PROCESS_ALL_ACCESS, False, ProcessId);
  11.   Lib := GetProcAddress(GetModuleHandle(PChar('kernel32.dll')), PChar('LoadLibraryA'));
  12.   DMod := VirtualAllocEx(HandleWindow, nil, Length(Dll) + 1, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  13.   if WriteProcessMemory(HandleWindow, DMod, @Dll[1>, Length(Dll), Written) then
  14.   Thread := CreateRemoteThread(HandleWindow, nil, 0, Lib, DMod, 0, ThreadID);
  15.   WaitForSingleObject(Thread, INFINITE);
  16.   CloseHandle(HandleWindow);
  17.   CloseHandle(Thread);
  18. end;

 :o

En Masm:

Código
  1. .386
  2. .model flat,stdcall
  3. option casemap:none
  4. include \masm32\include\windows.inc
  5. include \masm32\include\kernel32.inc
  6. includelib \masm32\lib\kernel32.lib
  7.  
  8. .const
  9. ID_proceso EQU 2964   ;La ID del proceso q sea
  10.  
  11. .data
  12. Kernel32 db "kernel32.dll", 0
  13. LoadLibrary_nombre db "LoadLibraryA", 0
  14. DLL db "C:\DLL.dll", 0
  15.  
  16. .data?
  17. Proceso_ID DWORD ?
  18. Proceso_handle DWORD ?
  19. Kernel32_offset DWORD ?
  20. LoadLibrary_offset DWORD ?
  21. String DWORD ?
  22. Proceso PROCESSENTRY32 <?>
  23.  
  24. .code
  25. Start:
  26. invoke GetModuleHandle, addr Kernel32
  27. mov Kernel32_offset, eax
  28. invoke GetProcAddress, Kernel32_offset, addr LoadLibrary_nombre
  29. mov LoadLibrary_offset, eax
  30.  
  31. mov Proceso.dwSize, 296
  32. invoke OpenProcess, PROCESS_ALL_ACCESS, FALSE, ID_proceso
  33. mov Proceso_handle, eax
  34. invoke VirtualAllocEx, Proceso_handle, NULL, 64, MEM_COMMIT + MEM_RESERVE, PAGE_READWRITE
  35. mov String, eax
  36. invoke WriteProcessMemory, Proceso_handle, String, addr DLL, 64, NULL
  37. invoke CreateRemoteThread, Proceso_handle, NULL, NULL, LoadLibrary_offset, String, NULL, NULL
  38. invoke CloseHandle, Proceso_handle
  39. invoke ExitProcess, 0
  40. End Start

En C++ [Sin Dll :-X]:

Código
  1. #include <windows.h>
  2. #include <tlhelp32.h>
  3. #include <stdio.h>
  4.  
  5. typedef int (WINAPI *datMessageBoxA) (HWND, LPCTSTR, LPCTSTR, UINT);
  6.  
  7. struct datos
  8. {
  9. datMessageBoxA apiMessageBoxA;
  10. char titulo [20];
  11. char mensaje [20];
  12. };
  13.  
  14.  
  15. DWORD GetAdres(char *module, char *function);
  16.  
  17. DWORD inyectada (datos *data)
  18. {
  19. data -> apiMessageBoxA (0, data->mensaje, data->titulo, 0);
  20. return 0;
  21. }
  22.  
  23. void inyectora()
  24. {
  25. int pid;
  26. HANDLE proc;
  27. datos dat;
  28. DWORD TamFun;
  29. void* esp;
  30.  
  31. HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  32. PROCESSENTRY32 procinfo = { sizeof(PROCESSENTRY32) };
  33. while(Process32Next(handle, &procinfo))
  34. {
  35. if(!strcmp(procinfo.szExeFile, "notepad.exe"))
  36. {
  37. CloseHandle(handle);
  38. pid = procinfo.th32ProcessID;
  39. }
  40. }
  41. CloseHandle(handle);
  42.  
  43. proc = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_WRITE, false, pid);
  44.  
  45. dat.apiMessageBoxA = (datMessageBoxA) GetAdres ("USER32.DLL", "MessageBoxA");
  46.  
  47. sprintf(dat.mensaje,"holaaaaaa!!!");
  48. sprintf(dat.titulo,"titulo!!!");
  49.  
  50.  
  51. datos *dat_ = (datos*) VirtualAllocEx(proc, 0, sizeof(datos), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  52. WriteProcessMemory(proc, dat_, &dat, sizeof(datos), NULL);
  53.  
  54. TamFun = (long unsigned int) inyectora - (long unsigned int)inyectada;
  55.  
  56. esp = VirtualAllocEx(proc, 0, TamFun, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  57. WriteProcessMemory(proc, esp, (void*)inyectada, TamFun, NULL);
  58. CreateRemoteThread(proc, NULL, 0, (LPTHREAD_START_ROUTINE) esp, dat_, 0, NULL);
  59. }
  60.  
  61. void main()
  62. {
  63. inyectora();
  64. }
  65.  
  66. DWORD GetAdres(char *module, char *function)
  67. {
  68. HMODULE dh = LoadLibrary(module);
  69. DWORD pf = (DWORD)GetProcAddress(dh,function);
  70. FreeLibrary(dh);
  71. return pf;
  72. }

Wowww! en todos los lenguajes que se pueden no :P?

Pero y en C#  :-\?

Alguien tiene alguno  :xD?

Hasta luego :P.


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: raul338 en 18 Septiembre 2009, 01:44 am
En VB:

Código
  1. Private Const PAGE_READWRITE As Long = &H4
  2. Private Const MEM_RELEASE As Long = &H8000
  3. Private Const MEM_COMMIT As Long = &H1000
  4. Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
  5. Private Const SYNCHRONIZE As Long = &H100000
  6. Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
  7. Private Const INFINITE As Long = &HFFFFFF
  8.  
  9. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  10. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
  11. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
  12. Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
  13. Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
  14. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  15. Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, lpThreadAttributes As Long, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
  16. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  17.  
  18.  
  19. Public Function Inyecta(RutaDll As String, Pid As Long) As Integer
  20. Dim proc As Long
  21. Dim nload As Long
  22. Dim rems As Long
  23. Dim longi As Long
  24. Dim RemThread As Long
  25. Dim Tid As Long
  26.  
  27. On Error GoTo Error
  28. proc = OpenProcess(PROCESS_ALL_ACCESS, False, Pid)
  29. nload = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA")
  30. rems = VirtualAllocEx(proc, 0, Len(RutaDll), MEM_COMMIT, PAGE_READWRITE)
  31. WriteProcessMemory proc, ByVal rems, ByVal RutaDll, Len(RutaDll), longi
  32. CreateRemoteThread proc, ByVal 0, 0, ByVal nload, ByVal rems, 0, Tid
  33. WaitForSingleObject rems, INFINITE
  34. CloseHandle proc
  35. CloseHandle rems
  36. Inyecta = 0
  37. Exit Function
  38. Error:
  39. Inyecta = 1
  40. End Function
  41.  
  42. '----------------------------------------------------------------------------------'
  43.  
  44. Private Sub Form_Load()
  45. Dim ruta As Long
  46. Dim resultado As Integer
  47.  
  48. ruta = Shell("notepad.exe")
  49. resultado = Inyecta("C:\ladll.dll", ruta)
  50.  
  51. If resultado = 0 Then
  52. MsgBox "Dll Inyectada con éxito!!!", , "Información"
  53. Else
  54. MsgBox "A ocurrido un error", vbCritical, "Información"
  55. End If
  56. End
  57. End Sub

Wowww! en todos los lenguajes que se pueden no :P?

Pero y en C#  :-\?

Alguien tiene alguno  :xD?

Hasta luego :P.

ejem. Si lo tienes en vb, es facilmente convertible a .net (sea vb.net o C#), si sabes y usas un poquito de logica, lo sacas en seguida. Total, en vb.net un 90% del codigo seguira intacto ^^

EDIT: Para usar las APIs, busca la declaracion en www.pInvoke.net


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: XSaMuXPH *-* Traigo uno encima! =D! en 18 Septiembre 2009, 07:31 am
Ops! error, pInvoke.net VS 2003-2005, yo uso 2008  :huh:


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: raul338 en 18 Septiembre 2009, 19:07 pm
jeje...dije busca la declaracion, no es necesario el plugin. Igual funciona en el 2008 (no te fijaste bien, tiene una version para el 2008 o capaz es la misma) pero junto con el plugin te viene otra de sus utilidades pero en version de prueba. yo no lo tengo instalado, solo usa el buscador: pones el nombre de la api o la dll y te sale una lista de las declaraciones en C#, vb.net (no todas, pero son convertibles) y la clasica vb6


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: MANULOMM en 19 Septiembre 2009, 00:40 am
En VB:

Código
  1. Private Const PAGE_READWRITE As Long = &H4
  2. Private Const MEM_RELEASE As Long = &H8000
  3. Private Const MEM_COMMIT As Long = &H1000
  4. Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
  5. Private Const SYNCHRONIZE As Long = &H100000
  6. Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
  7. Private Const INFINITE As Long = &HFFFFFF
  8.  
  9. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  10. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
  11. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
  12. Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
  13. Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
  14. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  15. Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, lpThreadAttributes As Long, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
  16. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  17.  
  18.  
  19. Public Function Inyecta(RutaDll As String, Pid As Long) As Integer
  20. Dim proc As Long
  21. Dim nload As Long
  22. Dim rems As Long
  23. Dim longi As Long
  24. Dim RemThread As Long
  25. Dim Tid As Long
  26.  
  27. On Error GoTo Error
  28. proc = OpenProcess(PROCESS_ALL_ACCESS, False, Pid)
  29. nload = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA")
  30. rems = VirtualAllocEx(proc, 0, Len(RutaDll), MEM_COMMIT, PAGE_READWRITE)
  31. WriteProcessMemory proc, ByVal rems, ByVal RutaDll, Len(RutaDll), longi
  32. CreateRemoteThread proc, ByVal 0, 0, ByVal nload, ByVal rems, 0, Tid
  33. WaitForSingleObject rems, INFINITE
  34. CloseHandle proc
  35. CloseHandle rems
  36. Inyecta = 0
  37. Exit Function
  38. Error:
  39. Inyecta = 1
  40. End Function
  41.  
  42. '----------------------------------------------------------------------------------'
  43.  
  44. Private Sub Form_Load()
  45. Dim ruta As Long
  46. Dim resultado As Integer
  47.  
  48. ruta = Shell("notepad.exe")
  49. resultado = Inyecta("C:\ladll.dll", ruta)
  50.  
  51. If resultado = 0 Then
  52. MsgBox "Dll Inyectada con éxito!!!", , "Información"
  53. Else
  54. MsgBox "A ocurrido un error", vbCritical, "Información"
  55. End If
  56. End
  57. End Sub

Wowww! en todos los lenguajes que se pueden no :P?

Pero y en C#  :-\?

Alguien tiene alguno  :xD?

Hasta luego :P.

ejem. Si lo tienes en vb, es facilmente convertible a .net (sea vb.net o C#), si sabes y usas un poquito de logica, lo sacas en seguida. Total, en vb.net un 90% del codigo seguira intacto ^^

EDIT: Para usar las APIs, busca la declaracion en www.pInvoke.net

como te atreves a decir eso.....


El framework te cambia radiclamente todo, que puedas hacer lo mismo de antes de forma parecida es algo muy diferente, pero hasta la administracion de memoria es toalemente diferente en .net, lo que debes hacer es  er que clases son las que te sirven para las tareas en vez de usar la APIS, ese es el objetivo del framewrok.


Atentamente,


Juan Manuel Lombana
Medellín - Colombia


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: raul338 en 19 Septiembre 2009, 01:03 am

como te atreves a decir eso.....


El framework te cambia radiclamente todo, que puedas hacer lo mismo de antes de forma parecida es algo muy diferente, pero hasta la administracion de memoria es toalemente diferente en .net, lo que debes hacer es  er que clases son las que te sirven para las tareas en vez de usar la APIS, ese es el objetivo del framewrok.


Atentamente,


Juan Manuel Lombana
Medellín - Colombia

Ejem, me referi a que el codigo quedaria intacto, ovbiamente cambia radicalmente todo, pero el codigo se mantiene practicamente parecido (ni hablar de MSIL  :laugh: ahi si te creo que cambia todo)
Que yo sepa, .net no tiene clases para manejar la memoria con "libre albedrio"  :-\


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: XSaMuXPH *-* Traigo uno encima! =D! en 3 Octubre 2009, 01:57 am
Listo!, lo logre :P, en mi siguiente post posteare el code tal vez sea de utilidad para muchos  :P.


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: ‭‭‭‭jackl007 en 11 Octubre 2009, 14:06 pm
como funciona?
lo compile en C++, y todo normal, lo ejecuto por consola y no muestra nada ni hace nada...
abro el notepad y todo normal...

entonces que hace? no inyecta nada ni codigo


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: XSaMuXPH *-* Traigo uno encima! =D! en 14 Octubre 2009, 04:57 am
como funciona?
lo compile en C++, y todo normal, lo ejecuto por consola y no muestra nada ni hace nada...
abro el notepad y todo normal...

entonces que hace? no inyecta nada ni codigo

Compilialo en consola de C++, antes abre el block de notas y luego veras que aparecera un mensaje, esto no es inyeccion dll esto es inyeccion dll sin dll osea inyecta un messagebox como si fuese el la dll, a mi me funciona.


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: elrasta17 en 7 Noviembre 2009, 21:40 pm

En VB:

Código
  1. Private Const PAGE_READWRITE As Long = &H4
  2. Private Const MEM_RELEASE As Long = &H8000
  3. Private Const MEM_COMMIT As Long = &H1000
  4. Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
  5. Private Const SYNCHRONIZE As Long = &H100000
  6. Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
  7. Private Const INFINITE As Long = &HFFFFFF
  8.  
  9. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  10. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
  11. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
  12. Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
  13. Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
  14. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  15. Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, lpThreadAttributes As Long, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
  16. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  17.  
  18.  
  19. Public Function Inyecta(RutaDll As String, Pid As Long) As Integer
  20. Dim proc As Long
  21. Dim nload As Long
  22. Dim rems As Long
  23. Dim longi As Long
  24. Dim RemThread As Long
  25. Dim Tid As Long
  26.  
  27. On Error GoTo Error
  28. proc = OpenProcess(PROCESS_ALL_ACCESS, False, Pid)
  29. nload = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA")
  30. rems = VirtualAllocEx(proc, 0, Len(RutaDll), MEM_COMMIT, PAGE_READWRITE)
  31. WriteProcessMemory proc, ByVal rems, ByVal RutaDll, Len(RutaDll), longi
  32. CreateRemoteThread proc, ByVal 0, 0, ByVal nload, ByVal rems, 0, Tid
  33. WaitForSingleObject rems, INFINITE
  34. CloseHandle proc
  35. CloseHandle rems
  36. Inyecta = 0
  37. Exit Function
  38. Error:
  39. Inyecta = 1
  40. End Function
  41.  
  42. '----------------------------------------------------------------------------------'
  43.  
  44. Private Sub Form_Load()
  45. Dim ruta As Long
  46. Dim resultado As Integer
  47.  
  48. ruta = Shell("notepad.exe")
  49. resultado = Inyecta("C:\ladll.dll", ruta)
  50.  
  51. If resultado = 0 Then
  52. MsgBox "Dll Inyectada con éxito!!!", , "Información"
  53. Else
  54. MsgBox "A ocurrido un error", vbCritical, "Información"
  55. End If
  56. End
  57. End Sub

salu2 a todoz bueno tengo una pequeña duda con respecto a este scritp... yo recien estoy aprendiendo a utilizar el VB 0.6 me he propuesto la meta de aprenderlo solo estudiando de los foros nada de profes -.-" pero al verme topado con esta pregunta.. quisiera pedir ayuda a uds que dominan mas del tema.. estoy usando el scritp de arriba llego a crear mi proyecto.. denominado [inyector xD].. llega a inyectar la *.dll que quiero al programa*.exe que quiero .. pero aqui viene mi duda... al scanear mi [inyector xD].exe en virustotal.com me detecta un virus o algo asi T_T quisiera saber xq ocurre eso o como hago para quitarle ese troyano o virus al programa que he creado y en que momento le meti ese virus o.O" ? ploop!!! aver si alguien me da alguna respuesta T_T grax de antemando
chaito ...!!
 


Título: Re: Inyeccion dll: [ Delphi ] - [ C++ ] - [ VB ] - [ Masm32 ] - [ C# ??? ]
Publicado por: luigymax en 10 Noviembre 2010, 18:41 pm
Muchas Gracias Amigo por la información, me sirvió de mucho...
Pero Podrías Traducir el código en C++ a DELPHI si es posible....
Ahora es que estoy aprendiendo sobre el tema, y solo se un poco en DELPHI,
Ya logre inyectar una DLL, pero quiero inyectar código directamente.
Gracias de antemano...