|
71
|
Programación / ASM / Heap
|
en: 1 Julio 2012, 03:07 am
|
Bueno pues en una conversacion con un amigo salio la conversacion de la pila y el heap y me surgio la siguiente duda que no pudimos solucionar entre los dos...
La pila la puedes manejar desde instrucciones en ASM y puedes gestionar esa memoria, que tiene un limite como quieras, pero el heap donde esta? no creo que eso se reserve con los datos del formato PE ya que puedes utilizar esta memoria dinamicamente con el tamaño que deses... pensando pensando me llego una ligera idea de que el heap lo maneja el SO, para gestionar bien la memoria RAM o que se yo... alguien sabe responder dicha duda?
saludos.
|
|
|
72
|
Programación / ASM / Crear gráficos
|
en: 1 Mayo 2012, 12:47 pm
|
Como se pueden crear gráficos a partir de la consola? es una duda que tengo desde hace bastante  saludos.
|
|
|
73
|
Foros Generales / Sugerencias y dudas sobre el Foro / Sección Analisis y Diseño de Malware
|
en: 15 Diciembre 2011, 13:29 pm
|
Ultimamente se esta desmadrando y solo hay preguntas de tipo "lammer", no estaria de menos que se pusieran unas reglas y que se empezaran a eliminar post mas que absurdos y que no siguen la politica del foro ni la ética, ademas creo que en algun momento estuvieron prohibidos en ese subforo.
saludos.
|
|
|
74
|
Seguridad Informática / Análisis y Diseño de Malware / Intento de agregar sección a ejecutable
|
en: 16 Septiembre 2011, 23:22 pm
|
Ya estoi aqui de nuevo, esta vez e intentado agregar una nueva sección a un ejecutable, sin exito  este es el código que tengo: #include <windows.h> #include <stdio.h> #include <stdlib.h> int main() { IMAGE_DOS_HEADER dh; IMAGE_NT_HEADERS nth; IMAGE_SECTION_HEADER * sección; IMAGE_SECTION_HEADER nSeccion; // char * stub_dos -> Datos del STUB_DOS // char * dSecciones -> Datos de las secciones FILE * archivo = fopen("c:\\windows\\system32\\calc.exe","r+b"); if (archivo == NULL) { printf("Error al leer el archivo\n"); return 1; } fread(&dh ,sizeof(dh ),1,archivo ); // Rellenamos IMAGE_DOS_HEADER char * stub_dos = (char*)malloc(dh. e_lfanew-0x40); fread(stub_dos ,1,dh. e_lfanew-0x40,archivo ); // Leemos el Stub DOS fread(&nth ,sizeof(nth ),1,archivo ); // leemos nt headers sección = (IMAGE_SECTION_HEADER *)malloc(sizeof(IMAGE_SECTION_HEADER )*nth. FileHeader. NumberOfSections); fread(sección ,sizeof(IMAGE_SECTION_HEADER ),nth. FileHeader. NumberOfSections,archivo ); char * dSecciones = (char*)malloc(nth. OptionalHeader. SizeOfImage); fread(dSecciones ,nth. OptionalHeader. SizeOfImage,1,archivo ); //leo todos los datos de las secciones. fclose(archivo ); // terminamos de leer ZeroMemory(&nSeccion,sizeof(IMAGE_SECTION_HEADER)); int A = sección[nth.FileHeader.NumberOfSections-1].VirtualAddress; int B = sección[nth.FileHeader.NumberOfSections-1].Misc.VirtualSize; int C = nth.OptionalHeader.SectionAlignment; strcpy((char*)nSeccion. Name,".fary"); // nombre de la nueva sección: .fary nSeccion.VirtualAddress = ((A+B)/C)*C+C;// direccion Virtual nSeccion.SizeOfRawData = 0x64; // tamaño de la sección: 100 nSeccion.PointerToRawData = sección[nth.FileHeader.NumberOfSections-1].PointerToRawData + 0x64; // direccion fisica nSeccion.Characteristics = 0x10000020; nSeccion.Misc.VirtualSize = 0x64; //nSeccion.VirtulSize nth.FileHeader.NumberOfSections += 1; // sumamos la nueva sección nth.OptionalHeader.SizeOfImage += 0x64; FILE * nuevo = fopen("NuevaCalc.exe","wb+"); fwrite(&dh ,sizeof(dh ),1,nuevo ); fwrite(stub_dos ,dh. e_lfanew-0x40,1,nuevo ); fwrite(&nth ,sizeof(nth ),1,nuevo ); fwrite(sección ,sizeof(IMAGE_SECTION_HEADER )*nth. FileHeader. NumberOfSections,1,nuevo ); fwrite(&nSeccion ,sizeof(IMAGE_SECTION_HEADER ),1,nuevo ); fwrite(dSecciones ,nth. OptionalHeader. SizeOfImage,1,nuevo ); char * DatosSeccion = (char*)malloc(0x64); ZeroMemory(DatosSeccion,0x64); fwrite(DatosSeccion ,0x64,1,nuevo ); return 0; }
Genera bien el nuevo archivo pero no pone bien los datos de la sección y ni que decir de ejecutarse (peta) XD. Así es como salen los datos de mi sección desde el lordPE:  haber si aguien sabe que ago mal... saludos.
|
|
|
75
|
Seguridad Informática / Análisis y Diseño de Malware / [AYUDA] formato PE obtener dirección fisica de secciones y mas cosas
|
en: 2 Septiembre 2011, 13:38 pm
|
Buenas, bueno al fin he decidido meterme de lleno a aprender el formato PE y tenia pensado agrandar la sección de código par aintroducir un pequeño opcode con un msgbox y tal una chorradilla pero para ensayar no me parece mal  . El problema viene cuando no puedo detectar el ISH bien de todas las secciones, solo lo detecta bien de la primera, el código que he creado es este: #include <stdio.h> #include <stdlib.h> #include <windows.h> int main() { IMAGE_DOS_HEADER idh; IMAGE_FILE_HEADER ifh; IMAGE_OPTIONAL_HEADER ioh; IMAGE_SECTION_HEADER ish; char ruta[] = "C:\\MS-DOC.exe"; FILE * archivo = fopen(ruta ,"r+b"); if (archivo == NULL) { // si no podemos abrri el archivo. printf("Error al abrir el archivo\n"); return 1; } fread(&idh ,0x40,1,archivo ); // rellenamos IMAGE_DOS_HEADER if (idh.e_magic != IMAGE_DOS_SIGNATURE) { // comprovamos el e_magic para saber si es un EXE printf("No es un archivo EXE\n"); return 1; } fseek(archivo ,idh. e_lfanew + 4,SEEK_SET ); fread(&ifh ,0x14,1,archivo ); // rellenamos IMAGE_FILE_HEADER fseek(archivo , idh. e_lfanew + 4 + sizeof(ifh ), SEEK_SET ); fread(&ioh ,ifh. SizeOfOptionalHeader,1,archivo ); // Leemos IMAGE_OPTIONAL_HEADER int suma = 0; for (int i=0;i<ifh.NumberOfSections;i++) { fseek(archivo , idh. e_lfanew + 4 + sizeof(ifh ) + ifh. SizeOfOptionalHeader + (sizeof(ish )*(ifh. NumberOfSections-1)) + suma ,SEEK_SET ); fread(&ish , sizeof(ish ),1,archivo ); // rellenamos IMAGE_SECTION_HEADER printf("%x\n",(&ish )[i ]. Misc. PhysicalAddress); suma += 0x28; // sumo 0x28 que es lo que ocupa ish para pasar a los datos de la siguiente sección. } return 0; }
Nose que andará mal por ahi si me peuden hechar una mano sería de gran ayuda  un saludo.
|
|
|
76
|
Seguridad Informática / Análisis y Diseño de Malware / Error intentando hookear FindNextFileA
|
en: 4 Agosto 2011, 13:03 pm
|
pues eso, estoi intentando hookear la api FindNextFileA con una dll que estoi creando en FASM pero no hay manera, el programa me explota cuando arga la dll y intento usar la api, el problema creo que esta en que no vuelve a llamar correctamente al api que modifique y por eso explota :S Este es el código: format PE GUI 4.0 DLL entry DllEntryPoint include 'd:\Fasm\INCLUDE\win32ax.inc' section '.code' code readable executable proc DllEntryPoint hinstDLL,fdwReason,lpvReserved cmp [fdwReason],1 je mensage jne salir mensage: invoke LoadLibrary,"Kernel32.dll" invoke GetProcAddress,eax,"FindNextFileA" mov ebx,eax ; Dirección de la api en ebx mov [PunteroOri],ebx lea edx,dword[ebp-4] invoke VirtualProtectEx,-1,ebx,7,PAGE_EXECUTE_READWRITE,edx mov ecx,ApiOriginal lea edx,dword[ebp-4] invoke VirtualProtectEx,-1,ecx,7,PAGE_EXECUTE_READWRITE,edx mov al,byte[ebx] ; movemos el primer byte mov byte[ecx],al mov byte[ebx],0x68 ; push inc ebx inc ecx mov eax,dword[ebx] ; movemos 4 bytes mov dword[ecx],eax mov dword[ebx],Funcion ; dreccion funcion add ebx,4 add ecx,4 mov al,byte[ebx] ; ultimo byte mov byte[ecx],al mov byte[ebx],0xC3 ;ret inc ebx salir: ret endp Funcion: ApiOriginal: nop nop nop nop nop nop mov eax,[PunteroOri] add eax,6 jmp eax ret ; VOID ShowErrorMessage(HWND hWnd,DWORD dwError); proc ShowErrorMessage hWnd,dwError local lpBuffer:DWORD lea eax,[lpBuffer] invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0 invoke MessageBoxA,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK invoke LocalFree,[lpBuffer] ret endp ; VOID ShowLastError(HWND hWnd); proc ShowLastError hWnd invoke GetLastError stdcall ShowErrorMessage,[hWnd],eax ret endp section '.data' data readable writeable PunteroOri dd ? section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ GetLastError,'GetLastError',\ SetLastError,'SetLastError',\ FormatMessage,'FormatMessageA',\ LocalFree,'LocalFree',\ LoadLibrary,'LoadLibraryA',\ GetProcAddress,'GetProcAddress',\ VirtualProtectEx,'VirtualProtectEx',\ ExitProcess,'ExitProcess' import user,\ MessageBoxA,'MessageBoxA' section '.edata' export data readable export 'ERRORMSG.DLL',\ ShowErrorMessage,'ShowErrorMessage',\ ShowLastError,'ShowLastError' section '.reloc' fixups data discardable
Tambien me gustaría que me explicasen como puedo debugear estas cosas ya que no lo tengo muy claro  saludos.
|
|
|
77
|
Programación / ASM / Funciones en FASM
|
en: 10 Julio 2011, 13:25 pm
|
Os dejo algunas funciones en FASM que e ido haciendo desde que empece con asm. Función que compara dos cadenas: proc Comparar,cadena1,cadena2 ;Si son iguales EAX = 1 ;Si son diferentes EAX = 0 mov esi,[cadena1] mov ecx,[cadena2] dec ecx bucle: inc ecx lodsb cmp byte[ecx],al jne diferentes cmp al,0 je comprovar jmp bucle comprovar: cmp byte[ecx],0 je iguales jne diferentes diferentes: mov eax,0 ret iguales: mov eax,1 ret endp
Ejemplo de su uso: include 'win32ax.inc' .data palabra db 'Drinky94',0 palabra2 db 'Drinky94',0 .code start: stdcall Comparar,palabra,palabra2 .if eax = 0 invoke MessageBoxA,0,'Son Diferentes',0,0 .else invoke MessageBoxA,0,'Son Iguales',0,0 .endif ret proc Comparar,cadena1,cadena2 ;Si son iguales EAX = 1 ;Si son diferentes EAX = 0 mov esi,[cadena1] mov ecx,[cadena2] dec ecx bucle: inc ecx lodsb cmp byte[ecx],al jne diferentes cmp al,0 je comprovar jmp bucle comprovar: cmp byte[ecx],0 je iguales jne diferentes diferentes: mov eax,0 ret iguales: mov eax,1 ret endp .end start
Función que mide la longitud de una cadena: proc Len,Cadena ;ECX = Longitud de la cadena. mov eax,[Cadena] mov ecx,-1 bucle: inc ecx cmp byte[eax+ecx],0 jne bucle ret endp
Ejemplo de su uso: include 'win32ax.inc' .data palabra db 'Drinky94',0 longitud dd ? .code start: stdcall Len,palabra mov [longitud],ecx invoke GlobalAlloc,GPTR,1024 push eax invoke wsprintfA,eax,"%d",[longitud] pop eax invoke MessageBox,0,eax,0,MB_OK leave ret proc Len,Cadena ;ECX = Longitud de la cadena mov eax,[Cadena] mov ecx,-1 bucle: inc ecx cmp byte[eax+ecx],0 jne bucle ret endp .end start
Función que puede servir de remplazo a GlobalAlloc: proc DGlobalAlloc,cantidad sub esp,[cantidad] mov eax,esp ret endp
Ejemplo de su uso: include 'win32ax.inc' .data palabra db 'Drinky94',0 longitud dd ? .code start: stdcall Len,palabra mov [longitud],ecx stdcall DGlobalAlloc,1024 push eax invoke wsprintfA,eax,"%d",[longitud] pop eax invoke MessageBox,0,eax,0,MB_OK leave ret proc Len,Cadena mov eax,[Cadena] mov ecx,-1 bucle: inc ecx cmp byte[eax+ecx],0 jne bucle ret endp proc DGlobalAlloc,cantidad sub esp,[cantidad] mov eax,esp ret endp .end start
Código para saber si nos están debuggeando (usa el PEB): format PE GUI 4.0 entry start include 'win32ax.inc' SiDbg db 'Hay Debugger',0 NoDbg db 'No hay Debugger',0 start: mov eax,dword[fs:18h] mov eax,dword[eax+30h] mov bl,byte[eax+2] ; si bl = 1 Nos estan debujeando. .if bl = 1 invoke MessageBoxA,0,SiDbg,0,0 .else invoke MessageBoxA,0,NoDbg,0,0 .endif ret data import library user32,'user32.dll' import user32,MessageBoxA,'MessageBoxA' end data
Simple cifrado Xor: proc Cifrar,Cadena xor ecx,ecx mov eax,[Cadena] .bucle: .if byte[eax+ecx] = 0 jmp .salir .endif xor byte[eax+ecx],7 inc ecx jmp .bucle .salir: ret endp
Ejemplo de su uso: include 'win32ax.inc' .data hola db 'hola',0 .code start: stdcall Cifrar,hola invoke MessageBoxA,0,eax,0,0 ret proc Cifrar,Cadena xor ecx,ecx mov eax,[Cadena] .bucle: .if byte[eax+ecx] = 0 jmp .salir .endif xor byte[eax+ecx],7 inc ecx jmp .bucle .salir: ret endp .end start
Función que pasa un número entero a cadena: proc NumToString,Numero ;Función creada por Drinky94. Agradecimientos a Jep. locals divisor dw ? ; buffer rb 20 Agregar esta variable en la sección data ; El numero 20 es la longitud que tendra la cadena ;si nuestro numero tiene 4 cifras tendremos que poner 4 ; CadenaFinal rb 20 ; lo mismo que con la variable buffer. endl mov [divisor],10 xor eax,eax xor ebx,ebx mov eax,[Numero] bucle: xor edx,edx div [divisor] add dl,0x30 mov byte[buffer+ebx],dl inc ebx cmp eax,0 jne bucle inc ebx mov byte[buffer+ebx],0x0 mov eax,buffer mov ecx,-1 buclelen: inc ecx cmp byte[eax+ecx],0 jne buclelen xor ebx,ebx dec ecx reverse: xor edx,edx mov dl,byte[eax+ecx] mov byte[CadenaFinal+ebx],dl inc ebx sub ecx,1 cmp ecx,-1 jne reverse mov eax,CadenaFinal ret endp
Ejemplo de su uso: include 'win32ax.inc' .data buffer rb 4 CadenaFinal rb 4 .code start: stdcall NumToString,1994 invoke MessageBoxA,0,eax,0,0 ret proc NumToString,Numero ;Función creada por Drinky94. Agradecimientos a Jep. locals divisor dw ? ; buffer rb 20 Agregar esta variable en la sección data ; El numero 20 es la longitud que tendra la cadena ;si nuestro numero tiene 4 cifras tendremos que poner 4 ; CadenaFinal rb 20 ; lo mismo que con la variable buffer. endl mov [divisor],10 xor eax,eax xor ebx,ebx mov eax,[Numero] bucle: xor edx,edx div [divisor] add dl,0x30 mov byte[buffer+ebx],dl inc ebx cmp eax,0 jne bucle inc ebx mov byte[buffer+ebx],0x0 mov eax,buffer mov ecx,-1 buclelen: inc ecx cmp byte[eax+ecx],0 jne buclelen xor ebx,ebx dec ecx reverse: xor edx,edx mov dl,byte[eax+ecx] mov byte[CadenaFinal+ebx],dl inc ebx sub ecx,1 cmp ecx,-1 jne reverse mov eax,CadenaFinal ret endp .end start
Cuando valla haciendo mas las voi posteando  saludos.
|
|
|
78
|
Seguridad Informática / Análisis y Diseño de Malware / Ayuda api hoking :P
|
en: 3 Mayo 2011, 20:41 pm
|
Bueno estoi intentando hookear una API desde una DLL creada en Fasm pero no lo consigo y nose que estoi haciendo mal, este es el código de la dll: format PE GUI 4.0 DLL entry DllEntryPoint include 'win32ax.inc' section '.code' code readable executable proc DllEntryPoint hinstDLL,fdwReason,lpvReserved locals proteccion dd ? endl invoke LoadLibrary,'user32.dll' invoke GetProcAddress,eax,"MessageBoxA" mov ebx,eax; ebx = direccion MessageBoxA invoke VirtualProtect,-1,ebx,5,PAGE_EXECUTE_READWRITE,edx mov ebx,0xE9 inc ebx mov dword[ebx],hook add ebx,4 ret endp proc hook,uno,dos,tres,cuatro invoke MessageBox,0,0,0,0 mov eax,0 ret endp ; VOID ShowErrorMessage(HWND hWnd,DWORD dwError); proc ShowErrorMessage hWnd,dwError local lpBuffer:DWORD lea eax,[lpBuffer] invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0 invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK invoke LocalFree,[lpBuffer] ret endp ; VOID ShowLastError(HWND hWnd); proc ShowLastError hWnd invoke GetLastError stdcall ShowErrorMessage,[hWnd],eax ret endp section '.data' data readable writeable mensajito db ? section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ GetLastError,'GetLastError',\ SetLastError,'SetLastError',\ FormatMessage,'FormatMessageA',\ LocalFree,'LocalFree',\ LoadLibrary,'LoadLibraryA',\ GetProcAddress,'GetProcAddress',\ VirtualProtect,'VirtualProtectEx' import user,\ MessageBox,'MessageBoxA' section '.edata' export data readable export 'ERRORMSG.DLL',\ ShowErrorMessage,'ShowErrorMessage',\ ShowLastError,'ShowLastError' section '.reloc' fixups data discardable
Esperando repuesta... salu2!
|
|
|
79
|
Seguridad Informática / Análisis y Diseño de Malware / Shell Remota en C
|
en: 27 Marzo 2011, 14:48 pm
|
Buenas, estoi intentando hacer una Shell Remota en C ya que nunca hice una en este lenguaje y me pica la curiosidad  el caso es que no me sale... El código que tengo es este: #include <windows.h> #include <stdlib.h> #include <stdio.h> int main() { PHANDLE leer; PHANDLE escribir; SECURITY_ATTRIBUTES sa; STARTUPINFO si; PROCESS_INFORMATION pi; DWORD bytes; CreatePipe(leer,escribir,&sa,0); si.cb = 68; si.dwFlags = 257; si.hStdError = escribir; si.hStdOutput = escribir; CreateProcessA(0,"cmd.exe /c ping 127.0.0.1", &sa, &sa, 1, NORMAL_PRIORITY_CLASS, 0, 0, &si, &pi); Sleep(100); CloseHandle(escribir); char buffer[1024]; char total[1024]; int ret = ReadFile(leer,buffer,250,&bytes,0); lstrcat(total,buffer); while(ret != 0) { ret = ReadFile(leer,buffer,250,&bytes,0); lstrcat(total,buffer); } MessageBoxA(0,total,0,0); return 0; }
Alguien sabe que hago mal? salu2!
|
|
|
80
|
Seguridad Informática / Análisis y Diseño de Malware / Una vez que te inyectas...??
|
en: 7 Febrero 2011, 20:41 pm
|
Buenas, bueno antes de nada, decir que nose si esto deberia ir aqui, pero como siempre se trata aqui el tema de inyecciones y tal... Mi duda es la siguiente: Una vez que te inyectas con una dll en un proceso. Es posible saber las funciones que tiene ese proceso cargadas??? de ser así como lo podria saber?? PD: espero que me hallan entendido  salu2!
|
|
|
|
|
|
|