Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Borito30 en 20 Marzo 2017, 02:03 am



Título: mi dll hace lo contrario de lo que debería hacer
Publicado por: Borito30 en 20 Marzo 2017, 02:03 am
Este es el injector:
Código
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5. #include <Tlhelp32.h>
  6. #include <wchar.h>
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. void error(char *err);
  11.  
  12. HANDLE myProc = NULL;
  13.  
  14. void error(char *err)
  15. {
  16. if (myProc != NULL) CloseHandle(myProc);
  17. printf("%s", err);
  18. exit(0);
  19. }
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23. HANDLE processList = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  24. PROCESSENTRY32 pInfo;
  25. BOOL st = TRUE;
  26. pInfo.dwSize = sizeof(PROCESSENTRY32);
  27. Process32First(processList, &pInfo);
  28. int myPid = 0;
  29. do
  30. {
  31. std::wstring name(L"taskmgr.exe");
  32. const wchar_t* szName = name.c_str();
  33. if (wcscmp(pInfo.szExeFile, szName) == 0)
  34. {
  35. myPid = pInfo.th32ProcessID;
  36. cout << myPid << endl;
  37. break;
  38. }
  39. Process32Next(processList, &pInfo);
  40. } while (st != FALSE);
  41.  
  42. // Abrir el proceso
  43. printf("[+] Opening process %i\n", myPid);
  44. myProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, myPid);
  45. if (myProc == NULL) error("[-] Error abriendo proceso.\n");
  46. else printf("[+] Proceso abierto.\n");
  47.  
  48. // Reservar memoria para el argumento (ruta de la DLL)
  49. char thData[] = "dllmain.dll";
  50. LPVOID dirToArg = VirtualAllocEx(myProc, NULL, strlen(thData), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  51. if (dirToArg == NULL)
  52. error("[-] Error reservando memoria para argumento.\n");
  53. else
  54. printf("[+] Memoria reservada para argumento (%i bytes).\n", strlen(thData));
  55.  
  56.  
  57. // Escribir la ruta de la DLL en la memoria reservada
  58. SIZE_T written = 0;
  59. if (WriteProcessMemory(myProc, dirToArg, (LPVOID)&thData, strlen(thData), &written) == 0)
  60. error("[-] Error escribiendo memoria.\n");
  61. else
  62. printf("[+] Memoria escrita (arg %i bytes).\n", written);
  63. //Lanzar un hilo con LoadLibrary
  64. //Load the DLL
  65. //Load the DLL
  66. HANDLE rThread = CreateRemoteThread(myProc, NULL, NULL, (LPTHREAD_START_ROUTINE)GetProcAddress(LoadLibrary(L"Kernel32.dll"), "LoadLibraryA"), dirToArg, NULL, NULL);
  67. if (rThread == NULL)
  68. error("[-] Error creando el hilo.\n");
  69. else
  70. printf("[+] Hilo creado.\n");
  71. CloseHandle(rThread);
  72.  
  73. }

Este es la .dll:
Código
  1. // dllmain.cpp : Defines the entry point for the DLL application.
  2. #include "stdafx.h"
  3. #include "C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h"//MHook header
  4. #include <iostream>
  5. #include <windows.h>
  6. #include <Commctrl.h>
  7. #include <conio.h>
  8.  
  9. using namespace std;
  10.  
  11. typedef void (*SENDMESSAGEW)();//Typedef for the hooked function
  12. static SENDMESSAGEW Basewritefoobar;//Backup of the originak fonction
  13.  
  14. static const wchar_t *pwned=L"PWNED";//PWNED
  15. LRESULT WINAPI BSSSendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
  16. {
  17.    if ( msg == LVM_INSERTITEMW || msg == LVM_SETITEMW)//Intercepts LVM_INSERTITEM and LVM_SETITEM messages
  18.    {
  19.        ((LVITEMW*)lparam)->pszText=pwned;//Replace the item text with our text.
  20.    }
  21.    return baseSendMessage(hwnd, msg, wparam, lparam);//Calls the real SendMessage function.
  22. }
  23. static bool Hook();
  24.  
  25. template <typename T>
  26. inline MH_STATUS MH_CreateHookEx(void* target, void* const base, T** original)
  27. {
  28.    return MH_CreateHook(target, base, reinterpret_cast<void**>(original));
  29. }
  30.  
  31.  
  32. extern "C" __declspec (dllexport) void __cdecl SendWrite()
  33. {
  34.  
  35. }
  36.  
  37. BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
  38. {
  39. //Different behaviors depending on the reason why DllMain is called
  40. switch (ul_reason_for_call) {
  41. case DLL_PROCESS_ATTACH:
  42. if (!Hook())//Hook "Writefoobar"
  43. {
  44. cout << "Hook failed" << endl;
  45. return 1;
  46. }
  47. break;
  48. case DLL_PROCESS_DETACH:
  49. break;
  50. case DLL_THREAD_ATTACH:
  51. break;
  52. case DLL_THREAD_DETACH:
  53. break;
  54. }
  55.  
  56. return TRUE;
  57. }
  58.  
  59. bool Hook()
  60. {
  61.    if (MH_Initialize() != MH_OK)
  62.    {
  63.        return false;
  64.    }
  65.  
  66.    if (MH_CreateHookEx((void*)&SendMessageW, (void*)&BSSSendMessageW, &Basewritefoobar) != MH_OK)
  67.    {
  68.        return FALSE;
  69.    }
  70.    return MH_EnableHook((void*)&SendMessageW) == MH_OK;
  71. }

Cuando lo hago me muestra un hola mundo el cual ni lo incluí en mi codigo:
(https://i.imgsafe.org/f297d24e55.png)

Que no deberia..


Título: Re: mi dll hace lo contrario de lo que debería hacer
Publicado por: Borito30 en 20 Marzo 2017, 11:45 am
Solucionao


Título: Re: mi dll hace lo contrario de lo que debería hacer
Publicado por: z3nth10n en 20 Marzo 2017, 12:59 pm
Solucionao

:rolleyes: :rolleyes: :rolleyes:

Por lo menos podrías poner un titulo más descriptivo y una solución a tu problema.


Título: Re: mi dll hace lo contrario de lo que debería hacer
Publicado por: Borito30 en 20 Marzo 2017, 13:06 pm
:rolleyes: :rolleyes: :rolleyes:

Por lo menos podrías poner un titulo más descriptivo y una solución a tu problema.
Si tienes razón aparte que era el inyector que cuando no ponía la dll me mostraba el hola mundo por arte de magia.. por eso puse el código de ambos.