Menú

Mostrar Mensajes

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ú

Mensajes - Borito30

#132
Cita de: ivancea96 en 19 Marzo 2017, 17:30 PM
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.
Código (cpp) [Seleccionar]
*hthread = pi.hThread;
Pues 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.
El código es el siguiente:
Código (cpp) [Seleccionar]
// 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);

}


El error que me devuelve a la mejor creo por hacer conversion al handle..
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


Debugeando podría ver pero aún así se cual es la razón al incluir la función para que arranque mi proceso de manera pausada algo estaré haciendo mal, si me sugieres debuguear podría tambien chekearlo.
#133
Este es el injector:
Código (cpp) [Seleccionar]
#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);

}


Este es la .dll:
Código (cpp) [Seleccionar]
// 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;
}


Cuando lo hago me muestra un hola mundo el cual ni lo incluí en mi codigo:


Que no deberia..
#134
Hola hay alguna manera de grabar la sesion de un meeting en teamviewer sin necesidad de tener que grabarlo ocupando la pantalla es decir una vez que abra la sesion se graba y . y al mismo tiempo uno puede estar haciendo otras cosas?
#135
que diferencia hay entre un handle y un phandle son lo mismo? Esque encuentro informacion sobre handle pero no phandle.. disculpa las molestias..
#136
Hola estoy haciendo un pequeño programa que me iniciara mi proceso de forma pausada el siguiente código obtengo el pid y se lo paso a mi funcion:
Código (cpp) [Seleccionar]
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);
}

La funcion:
Código (cpp) [Seleccionar]
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;
}


Sigo teniendo problemas al resolver errores de argumentos. Los errores son los siguientes:
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)

:P No me hace la conversión char * correctamente alguna idea como convertir mi entero a char *? Y luego PHandle que diferencia tiene con Handle?
#137
Tienes razon tengo primero que aprender lo basico ejemplo: a crear una ventana con la API de Windows, mis preguntas son muy poco maduras me lanzo a cosas que a lo mejor antes de preguntar deberia plantearme  si se lo básico y luego ir entrando a cosas complejas porque la mayoría son asuntos facilmente deducibles y por mi parte no lo estoy resolviendo asi que disculpa.
Y tampoco me di cuenta que al final es una funcion luego simplemente hay que pasarle los valores.. luego.. un grave error por mi parte..
#138
Hola como podría llamar a la siguiente funcion desde el int main usando windows api.
Funcion:
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:
int main()
{
//calling api function
}


Como podría a la función de windows api desde el main.
#139
Puedes usar detour o api hooking centrado a video juegos. Con eso podrás interceptar las funciones de estos juegos y hacer determinadas cosas(como dispara rcuando la distancia sea X, entre otras muchas cosas).

Aqui te paso un video que intercepta las llamadas del buscaminas para ganar la partida:
[youtube=640,360]https://www.youtube.com/watch?v=yZPEIceQ0eM[/youtube]
#140
Programación C/C++ / Re: Nose si se puede
15 Marzo 2017, 16:56 PM
Todos son buenos python tambien es muy valioso en general cualquier te vale a no ser que sea un lenguaje de scripting que puede variar un poco.