|
51
|
Programación / Programación C/C++ / Pasar argumentos a WinMain
|
en: 25 Marzo 2017, 00:10 am
|
Estaba intentando convertir una consola a formulario. Para ello lo hice añadiendo una configuración equivocada ya que eso era para Qt. La manera correcta de convertir una consola a un formulario y luego pasar los argumentos de linea de comandos a la aplicación es usando GetCommandLine
|
|
|
53
|
Programación / Programación General / Que es user32 y kernel32¿? que diferencias existen?
|
en: 23 Marzo 2017, 20:26 pm
|
Se que son bibliotecas de enlace dinámico que implementa la biblioteca de windows pero mi pregunta es cuando uno esta usando la librería kernel32 o user32 cuando uno es administrador usa kernel32 o cuando uno usa user32 esta en modo usuario¿? Soy un total ingnorante al respecto por lo que cualquier explicacion me vendría bastante bien. Gracias.
|
|
|
54
|
Programación / Programación C/C++ / Tutorial como poner tus procesos en PWNED
|
en: 20 Marzo 2017, 12:25 pm
|
Hola en este tutorial os enseñare a como poner tus procesos en PWNED con la siguiente apariencia: El inyector: #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 ptr_thread ) // cleaned up a bit, but no RAII { if( ptr_thread == nullptr ) return nullptr ;
PROCESS_INFORMATION pi; STARTUPINFOA si {} ; // initialize with zeroes. si.cb = sizeof(STARTUPINFOA);
if( !CreateProcessA( nullptr, cmd, nullptr, nullptr, false, CREATE_SUSPENDED, nullptr, nullptr, std::addressof(si), std::addressof(pi) ) ) { std::cerr << "CreateProcess failed, " << GetLastError() << '\n' ; *ptr_thread = nullptr ; return nullptr; }
*ptr_thread = pi.hThread; return pi.hProcess; }
int main(int argc, char *argv[]) { char cmd[] = "taskmgr.exe" ; // note: non-const (writeable array) HANDLE thread = nullptr ; auto myProc=Startpausedprocess( cmd, std::addressof(thread) ) ; if(myProc) { std::cout << "press enter to resume process... " && std::cin.get() ; ResumeThread(thread) ;
//CloseHandle(thread) ; //CloseHandle(myProc) ; }
// 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 código, simplemente compilas en gcc y inyectais. #include "stdafx.h" #include "cabecera minhook"//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 wchar_t pwned[]=L"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 SendMessage(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; }
Funcionara como filtro y cambiara la apariencia de vuestro administrador de tareas.
|
|
|
55
|
Programación / Programación C/C++ / mi dll hace lo contrario de lo que debería hacer
|
en: 20 Marzo 2017, 02:03 am
|
Este es el injector: #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: // 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..
|
|
|
57
|
Programación / Programación C/C++ / Iniciar un proceso de forma pausada c++
|
en: 19 Marzo 2017, 14:46 pm
|
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: 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: 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: 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) No me hace la conversión char * correctamente alguna idea como convertir mi entero a char *? Y luego PHandle que diferencia tiene con Handle?
|
|
|
58
|
Programación / Programación C/C++ / Como llamar a la funcion de windows api
|
en: 16 Marzo 2017, 22:46 pm
|
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.
|
|
|
59
|
Programación / Scripting / Actualizar mi ip usando dyndns en python
|
en: 14 Marzo 2017, 19:27 pm
|
Hola estoy verificando un pequeño programa para obtener la ip actualizada de mi dns lo que hago es lo siguiente: #!/usr/bin/python import requests import json user = "email" password = "pass" checkip = "http://thisisnt.com/api/getRemoteIp.php" dynupdate = "https://members.dyndns.com/nic/update" print "starting. Get current IP..." ipraw = requests.get(checkip) if ipraw.status_code is not 200: raise "Cannot get IP address" exit ip = ipraw.json()['REMOTE_ADDR'] print "Remote IP: " + ip print "updating..." # update dyndns headers = {'user-agent': 'mPythonClient/0.0.3'} dyn = requests.get(dynupdate, \ headers=headers, \ auth=(user, password), \ params={'hostname': 'mydyndns', \ 'myip': ip, \ 'wildcard': 'NOCHG', \ 'mx': 'MX', \ }) if dyn.status_code is not 200: print "Update failed. HTTP Code: " + str(dyn.status_code) if "good" in dyn.text: print "update successful.." else: print "Update unsuccessful: " + dyn.text.strip()
El resultado que obtengo siempre es Es decir dyn.text la peticion no la hace bien por lo que tenga hacer la peticion de otra manera. Alguien sabría como podría obtener mi ip con my dyndns usando python?
|
|
|
60
|
Programación / Programación C/C++ / Como resolver estos errores?
|
en: 14 Marzo 2017, 14:21 pm
|
Estoy intentando compilar ejemplos de esta libreria: https://www.codeproject.com/KB/winsdk/LibMinHook/MinHook_133_src.zip El tio compila ejemplos de todos pero cuando yo lo intento me devuelve: C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h:141: 22: note: candidate expects 5 arguments, 4 provided DynamicLinkSample.cpp:12:18: note: template<class T> MH_STATUS MH_CreateHookApiE x(LPCWSTR, LPCSTR, LPVOID, T**) inline MH_STATUS MH_CreateHookApiEx(LPCWSTR pszModule, LPCSTR pszProcName, LPVO ID pDetour, T** ppOriginal) ^ DynamicLinkSample.cpp:12:18: note: template argument deduction/substitution fa iled: DynamicLinkSample.cpp:37:88: note: cannot convert 'DetourMessageBoxW' (type 'i nt (__attribute__((__stdcall__)) *)(HWND, LPCWSTR, LPCWSTR, UINT) {aka int (__at tribute__((__stdcall__)) *)(HWND__*, const wchar_t*, const wchar_t*, unsigned in t)}') to type 'LPVOID {aka void*}' if (MH_CreateHookApiEx(L"user32", "MessageBoxW", &DetourMessageBoxW, &fpMes sageBoxW) != MH_OK)
^ DynamicLinkSample.cpp:43:35: error: invalid conversion from 'int (__attribute__( (__stdcall__)) *)(HWND, LPCWSTR, LPCWSTR, UINT) {aka int (__attribute__((__stdca ll__)) *)(HWND__*, const wchar_t*, const wchar_t*, unsigned int)}' to 'LPVOID {a ka void*}' [-fpermissive] if (MH_EnableHook(&MessageBoxW) != MH_OK) ^ In file included from DynamicLinkSample.cpp:2:0: C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h:154: 22: note: initializing argument 1 of 'MH_STATUS MH_EnableHook(LPVOID)' MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget); ^ DynamicLinkSample.cpp:52:36: error: invalid conversion from 'int (__attribute__( (__stdcall__)) *)(HWND, LPCWSTR, LPCWSTR, UINT) {aka int (__attribute__((__stdca ll__)) *)(HWND__*, const wchar_t*, const wchar_t*, unsigned int)}' to 'LPVOID {a ka void*}' [-fpermissive] if (MH_DisableHook(&MessageBoxW) != MH_OK) ^ In file included from DynamicLinkSample.cpp:2:0: C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h:161: 22: note: initializing argument 1 of 'MH_STATUS MH_DisableHook(LPVOID)' MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget); ^ Supongo algo estare haciendo mal. En este caso estoy intentando desde consola con g++, que el compilador sería mingw.
|
|
|
|
|
|
|