Solucionao
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúCita de: ivancea96 en 19 Marzo 2017, 17:30 PMPues al final lo corregi haciendo la conversión pasando el * intente pero no iba. Pero aún así mi inyector falla cuando hago esto de iniciar un proceso pausado y llamo a la función obviamente si descarto esto funciona. Pero el objetivo es iniciar un proceso de manera pausada, sacar el pid nuevo para ese proceso y luego inyectar una dll en el proceso. Supongo que no debería poner *ph = (PHANDLE)GetCurrentProcess(); ya que estoy llamando a otro proceso diferente que sería el taskmgr.. claro que estaría cerrado yo lo iniciaria.
Los tipos de Windows que empiezan con P o con LP suelen sen punteros.
En cualquier caso: https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
De todos modos, si no te gusta PHANDLE, puedes poner HANDLE*. La razón de que hayan puesto un HANDLE* en esa función es para poder devolver el HANDLE.*hthread = pi.hThread;
// injector.cpp: define el punto de entrada de la aplicación de consola.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <Tlhelp32.h>
#include <wchar.h>
#include <iostream>
using namespace std;
void error(char *err);
HANDLE myProc = NULL;
void error(char *err)
{
if (myProc != NULL) CloseHandle(myProc);
printf("%s", err);
exit(0);
}
HANDLE Startpausedprocess(char *cmd, PHANDLE hthread)//Not const char* because CreateProcess may write on it
{
PROCESS_INFORMATION pi;
STARTUPINFOA si;//STARTUPINFOA is the ANSI version of STARTUPINFO.
ZeroMemory(&si, sizeof(STARTUPINFOA));
si.cb = sizeof(STARTUPINFOA);
if (!CreateProcessA(NULL, cmd, NULL, NULL, false, CREATE_SUSPENDED, NULL, NULL, &si, &pi))//The flag "CREATE_SUSPENDED" will create the process and pause the main thread.
{
cout << "CreateProcess failed, " << GetLastError() << endl;
return NULL;
}
*hthread = pi.hThread;
return pi.hProcess;
}
int main(int argc, char *argv[])
{
PHANDLE *ph=NULL;
*ph = (PHANDLE)GetCurrentProcess();
Startpausedprocess("taskmgr.exe",*ph);
HANDLE processList = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pInfo;
BOOL st = TRUE;
pInfo.dwSize = sizeof(PROCESSENTRY32);
Process32First(processList, &pInfo);
int myPid = 0;
do
{
std::wstring name(L"taskmgr.exe");
const wchar_t* szName = name.c_str();
if (wcscmp(pInfo.szExeFile, szName) == 0)
{
myPid = pInfo.th32ProcessID;
cout << myPid << endl;
break;
}
Process32Next(processList, &pInfo);
} while (st != FALSE);
// Abrir el proceso
printf("[+] Opening process %i\n", myPid);
myProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, myPid);
if (myProc == NULL) error("[-] Error abriendo proceso.\n");
else printf("[+] Proceso abierto.\n");
// Reservar memoria para el argumento (ruta de la DLL)
char thData[] = "dllmain.dll";
LPVOID dirToArg = VirtualAllocEx(myProc, NULL, strlen(thData), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (dirToArg == NULL)
error("[-] Error reservando memoria para argumento.\n");
else
printf("[+] Memoria reservada para argumento (%i bytes).\n", strlen(thData));
// Escribir la ruta de la DLL en la memoria reservada
SIZE_T written = 0;
if (WriteProcessMemory(myProc, dirToArg, (LPVOID)&thData, strlen(thData), &written) == 0)
error("[-] Error escribiendo memoria.\n");
else
printf("[+] Memoria escrita (arg %i bytes).\n", written);
//Lanzar un hilo con LoadLibrary
//Load the DLL
//Load the DLL
HANDLE rThread = CreateRemoteThread(myProc, NULL, NULL, (LPTHREAD_START_ROUTINE)GetProcAddress(LoadLibrary(L"Kernel32.dll"), "LoadLibraryA"), dirToArg, NULL, NULL);
if (rThread == NULL)
error("[-] Error creando el hilo.\n");
else
printf("[+] Hilo creado.\n");
CloseHandle(rThread);
}
Problem signature:
Problem Event Name: APPCRASH
Application Name: injector.exe
Application Version: 0.0.0.0
Application Timestamp: 58cf59ba
Fault Module Name: injector.exe
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 58cf59ba
Exception Code: c0000005
Exception Offset: 000179a9
OS Version: 6.1.7601.2.1.0.256.1
Locale ID: 1043
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <Tlhelp32.h>
#include <wchar.h>
#include <iostream>
using namespace std;
void error(char *err);
HANDLE myProc = NULL;
void error(char *err)
{
if (myProc != NULL) CloseHandle(myProc);
printf("%s", err);
exit(0);
}
int main(int argc, char *argv[])
{
HANDLE processList = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pInfo;
BOOL st = TRUE;
pInfo.dwSize = sizeof(PROCESSENTRY32);
Process32First(processList, &pInfo);
int myPid = 0;
do
{
std::wstring name(L"taskmgr.exe");
const wchar_t* szName = name.c_str();
if (wcscmp(pInfo.szExeFile, szName) == 0)
{
myPid = pInfo.th32ProcessID;
cout << myPid << endl;
break;
}
Process32Next(processList, &pInfo);
} while (st != FALSE);
// Abrir el proceso
printf("[+] Opening process %i\n", myPid);
myProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, myPid);
if (myProc == NULL) error("[-] Error abriendo proceso.\n");
else printf("[+] Proceso abierto.\n");
// Reservar memoria para el argumento (ruta de la DLL)
char thData[] = "dllmain.dll";
LPVOID dirToArg = VirtualAllocEx(myProc, NULL, strlen(thData), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (dirToArg == NULL)
error("[-] Error reservando memoria para argumento.\n");
else
printf("[+] Memoria reservada para argumento (%i bytes).\n", strlen(thData));
// Escribir la ruta de la DLL en la memoria reservada
SIZE_T written = 0;
if (WriteProcessMemory(myProc, dirToArg, (LPVOID)&thData, strlen(thData), &written) == 0)
error("[-] Error escribiendo memoria.\n");
else
printf("[+] Memoria escrita (arg %i bytes).\n", written);
//Lanzar un hilo con LoadLibrary
//Load the DLL
//Load the DLL
HANDLE rThread = CreateRemoteThread(myProc, NULL, NULL, (LPTHREAD_START_ROUTINE)GetProcAddress(LoadLibrary(L"Kernel32.dll"), "LoadLibraryA"), dirToArg, NULL, NULL);
if (rThread == NULL)
error("[-] Error creando el hilo.\n");
else
printf("[+] Hilo creado.\n");
CloseHandle(rThread);
}
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h"//MHook header
#include <iostream>
#include <windows.h>
#include <Commctrl.h>
#include <conio.h>
using namespace std;
typedef void (*SENDMESSAGEW)();//Typedef for the hooked function
static SENDMESSAGEW Basewritefoobar;//Backup of the originak fonction
static const wchar_t *pwned=L"PWNED";//PWNED
LRESULT WINAPI BSSSendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if ( msg == LVM_INSERTITEMW || msg == LVM_SETITEMW)//Intercepts LVM_INSERTITEM and LVM_SETITEM messages
{
((LVITEMW*)lparam)->pszText=pwned;//Replace the item text with our text.
}
return baseSendMessage(hwnd, msg, wparam, lparam);//Calls the real SendMessage function.
}
static bool Hook();
template <typename T>
inline MH_STATUS MH_CreateHookEx(void* target, void* const base, T** original)
{
return MH_CreateHook(target, base, reinterpret_cast<void**>(original));
}
extern "C" __declspec (dllexport) void __cdecl SendWrite()
{
}
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
//Different behaviors depending on the reason why DllMain is called
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
if (!Hook())//Hook "Writefoobar"
{
cout << "Hook failed" << endl;
return 1;
}
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
bool Hook()
{
if (MH_Initialize() != MH_OK)
{
return false;
}
if (MH_CreateHookEx((void*)&SendMessageW, (void*)&BSSSendMessageW, &Basewritefoobar) != MH_OK)
{
return FALSE;
}
return MH_EnableHook((void*)&SendMessageW) == MH_OK;
}
int main(int argc, char *argv[])
{
HANDLE processList = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pInfo;
BOOL st = TRUE;
pInfo.dwSize = sizeof(PROCESSENTRY32);
Process32First(processList, &pInfo);
int myPid = 0;
do
{
std::wstring name(L"miproceso.exe");
const wchar_t* szName = name.c_str();
if (wcscmp(pInfo.szExeFile, szName) == 0)
{
myPid = pInfo.th32ProcessID;
cout << myPid << endl;
break;
}
Process32Next(processList, &pInfo);
} while (st != FALSE);
char chaine[10];
sprintf(chaine,"%d",myPid);
Startpausedprocess(chaine,processList);
}
HANDLE Startpausedprocess(char *cmd, PHANDLE hthread)//Not const char* because CreateProcess may write on it
{
PROCESS_INFORMATION pi;
STARTUPINFOA si;//STARTUPINFOA is the ANSI version of STARTUPINFO.
ZeroMemory(&si, sizeof(STARTUPINFOA));
si.cb = sizeof(STARTUPINFOA);
if (!CreateProcessA(NULL, cmd, NULL, NULL, false, CREATE_SUSPENDED, NULL, NULL, &si, &pi))//The flag "CREATE_SUSPENDED" will create the process and pause the main thread.
{
cout << "CreateProcess failed, " << GetLastError() << endl;
return NULL;
}
*hthread = pi.hThread;
return pi.hProcess;
}
Citar
Build FAILED.
"C:\Users\Androide\Desktop\colo\injector\injector\injector.vcxproj" (default ta
rget) (1) ->
(ClCompile target) ->
c:\users\androide\desktop\colo\injector\injector\injector.cpp(64): error C266
4: 'HANDLE Startpausedprocess(char *,PHANDLE)': cannot convert argument 2 from
'HANDLE' to 'PHANDLE' [C:\Users\Androide\Desktop\colo\injector\injector\injecto
r.vcxproj]
c:\users\androide\desktop\colo\injector\injector\injector.cpp(63): error C499
6: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help
for details. [C:\Users\Androide\Desktop\colo\injector\injector\injector.vcxproj
]
0 Warning(s)
2 Error(s)
static const wchar_t *lol=L"";
LRESULT WINAPI BSSSendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if ( msg == LVM_INSERTITEMW || msg == LVM_SETITEMW)//Intercepts LVM_INSERTITEM and LVM_SETITEM messages
{
if (!lstrcmpW(((LVITEMW*)lparam)->pszText, lol))//The lparam is a LVITEM* struct.
{
return 0;//we simply return 0 (and we do not call the real SendMessage function.
}
return 0;
}
return base.SendMessage(hwnd, msg, wparam, lparam);//Calls the real SendMessage function.
}
int main()
{
//calling api function
}