|
Mostrar Temas
|
Páginas: 1 2 [3] 4
|
22
|
Seguridad Informática / Análisis y Diseño de Malware / Ejemplo de infección mediante TLS Callbacks
|
en: 16 Mayo 2011, 02:16 am
|
Que tal amigos, he leído un poco acerca del tema y haciendo pruebas logré instalar una rutina en el TLS Callbacks y quise compartirlo, espero sus críticas opiniones y recomendaciones. Espero me disculpen si hay errores técnicos, Un saludo. PD: Quiero agradecer a trompetin17evony y apokliptiko por sus recomendaciones. Link: http://www.box.net/shared/h0ra1953cn
|
|
|
23
|
Seguridad Informática / Análisis y Diseño de Malware / [MASM32] KernelBase Address + GetProcAddress
|
en: 9 Mayo 2011, 02:23 am
|
.386 .model flat, stdcall option casemap:none assume fs:nothing .data GPA db "GetProcAddress",0 Cont dd 0 .code start: mov eax, fs:[030h] ; Get pointer of the PEB mov eax, [eax + 0ch] ; Get pointer of PPEB_LDR_DATA mov eax, [eax + 0ch] ; Get pointer of InLoadOrderModuleList mov eax, [eax] ; Get InLoadOrderModuleList of next library "ntdll" mov eax, [eax] ; Get InLoadOrderModuleList of next library "kernel32" mov eax, [eax + 018h] ; Get BaseAddress of "kernel32" mov ecx, dword ptr[eax + 03ch] ; Set PE Offset add ecx, 078h ; Set in DirectoryTable[0] mov edx, dword ptr [eax + ecx] ; Get Export Table RVA add edx, eax ; Add KernelBase Address xor ebx, ebx ; Clean EBX add edx, 020h ; Set in addressofnames RVA mov ebx, dword ptr [edx] ; Get RVA AddressOfNames Table add ebx, eax ; Add KernelBase Address COMP: ; Rutine of compare strings with "GetProcAddress", incrementing Cont add ebx, 4 inc [Cont] mov esi, dword ptr [ebx] add esi, eax lea edi, [GPA] mov ecx, 0Eh repe cmpsb jnz COMP ;GetAddress xor ebx, ebx ; Clean EBX add edx, 04h ; Set on Table Ordinal RVA mov ebx, dword ptr[edx] ; Get first RVA of Ordinal add ebx, eax ; Add KernelBase Address mov edi, eax ; Save KernelBase Address in EDI xor eax, eax ; Clean EAX mov al, 02h ; Base of WORD mov esi, edx ; Save Address of RVA Ordinal Table mul word ptr[Cont] ; Mul Cont for get WORD mov [Cont], eax ; Get new value in Cont xor eax, eax ; Clean EAX add ebx, [Cont] ; Add Cont to Address of Ordinal Table mov ax,word ptr[ebx] ; Get Ordinal of GetProcAddress sub esi, 08h ; Set in AddressOfFunctions mov ecx, [esi] ; Get First pointer to Functions RVA add ecx, edi ; Add KernelBase Address xor ebx, ebx ; Clean EBX mov ebx, eax ; Mov Ordinal to EBX for MUL mov eax, 04h ; Base of DWORD mul ebx ; Calcule spaces to Get address bassed in (Address of First Function + Ordinal GetProcAddress add ecx, eax ; Add spaces for Set Address in RVA of GetProcAddress mov ecx, [ecx] ; Get RVA of GetProcAddress add ecx, edi ; Add KernelBase Address end start
Agradecimientos a Shaddy, [Zero], Lelo, Thor, Psymera & todos los que me han ayudado.
|
|
|
24
|
Seguridad Informática / Análisis y Diseño de Malware / [ASM] Find Kernel Base Address (XP,Vista,7 - x86, x64)
|
en: 1 Mayo 2011, 18:31 pm
|
mov eax, fs:[030h] mov eax, [eax + 0ch] mov eax, [eax + 0ch] mov eax, [eax] mov eax, [eax] mov eax, [eax + 018h]
Bueno leyendo un poco acerca de la PEB y entendiendo como localizaban el BaseAddress de kernel32, recordé que había un código que hicieron rehicieron y mejor dicho xD, bueno ese código dejo de funcionar en 7 donde se agrego Kernelbase.dll y obligó a cambiar el código. Tras pruebas mi código se baso en buscar el orden de carga de las librerías, y ese orden se respeta desde XP hasta 7 tanto en 64 como 32 bits. Un agradecimiento a Lord, y ya implementaré un método genérico . Saludos!
|
|
|
25
|
Programación / Programación C/C++ / [C/SRC] Realign PE (Actualizado)
|
en: 27 Enero 2011, 01:24 am
|
/* ----------------------------------------------------------- - Function: RealignPE v2 - - Programmer: The Swash - - Web: http://www.h-sec.org - - Dedicated: Thor, Psymera, Steve10120, [Zero], Karcrack - ----------------------------------------------------------- */ #include <windows.h> #include <stdio.h> #include <stdlib.h> #define ReadWriteBinary "r+b" int AlingNum(int num, int aling); char * BytesAling(int number); int main(void) { printf("%i ",RealignPE ("C:\\hi.exe")); } int RealignPE(char * lpFile) { IMAGE_DOS_HEADER IDH; IMAGE_FILE_HEADER IFH; IMAGE_OPTIONAL_HEADER IOH; IMAGE_SECTION_HEADER ISH; DWORD PESignature = 0; FILE * lFile; int OriSize = 0; int ActSize = 0; int Alingned = 0; lFile = fopen(lpFile ,ReadWriteBinary ); if (lFile == NULL) {return -1;} else { fread(&IDH , 64, 1, lFile ); fseek(lFile , IDH. e_lfanew , SEEK_SET ); fread(&PESignature , 4, 1, lFile ); if (IDH. e_magic != IMAGE_DOS_SIGNATURE ) {fclose (lFile ); return -2;} else { if(PESignature != IMAGE_NT_SIGNATURE ) {fclose (lFile ); return -3;} else { fseek(lFile , IDH. e_lfanew + 4, SEEK_SET ); fread(&IFH , sizeof(IFH ), 1, lFile ); fseek(lFile , IDH. e_lfanew + 4 + sizeof(IFH ), SEEK_SET ); fread(&IOH , IFH. SizeOfOptionalHeader, 1, lFile ); fseek(lFile , IDH. e_lfanew + 4 + sizeof(IFH ) + IFH. SizeOfOptionalHeader + (sizeof(ISH )*(IFH. NumberOfSections-1)),SEEK_SET ); fread(&ISH , sizeof(ISH ), 1, lFile ); fseek(lFile , 0, SEEK_END ); OriSize = ISH.PointerToRawData + ISH.SizeOfRawData; if (ActSize - OriSize > 0) { Alingned = AlingNum(ActSize - OriSize, IOH.FileAlignment); ISH.SizeOfRawData += Alingned; ISH.Misc.VirtualSize += Alingned; IOH.SizeOfImage = ISH.Misc.VirtualSize + ISH.VirtualAddress; IOH.SizeOfInitializedData += Alingned; if (ISH.VirtualAddress == IOH.DataDirectory[2].VirtualAddress) { IOH.DataDirectory[2].Size += Alingned; } fseek(lFile , IDH. e_lfanew + 4 + sizeof(IFH ), SEEK_SET ); fwrite(&IOH , 1, IFH. SizeOfOptionalHeader, lFile ); fseek(lFile , IDH. e_lfanew + 4 + sizeof(IFH ) + IFH. SizeOfOptionalHeader + (sizeof(ISH )*(IFH. NumberOfSections-1)),SEEK_SET ); fwrite(&ISH , 1, sizeof(ISH ), lFile ); if (Alingned - (ActSize - OriSize) > 0) { fseek(lFile , ActSize , SEEK_SET ); fwrite(BytesAling (Alingned -(ActSize - OriSize )), 1, Alingned -(ActSize - OriSize ), lFile ); } return 0; } else {return 1;} } } } } int AlingNum(int num, int aling) { if(num % aling == 0) { return num; } else if(num < aling) { return aling; } else { return (num / aling) * aling + aling; } } char * BytesAling(int number) { char * sTemp = (char *) malloc(number + 1); int i; for (i=0; i<number; i++) { sTemp[i] = '\0'; } return sTemp; }
Bueno amigos, ya había trabajado en la versión 1 de esta funcion, la mejore mucho en cuanto al código y lo mejor que corregí los fallos que tenía! Saludos
|
|
|
26
|
Programación / Programación C/C++ / [C] PEFileSize function
|
en: 25 Enero 2011, 05:58 am
|
/* [Get size of file to base of PE] - Programmer: The Swash - Dedicated: Zero, Thor Psymera, Steve10120 */ #include <windows.h> #include <stdio.h> #define RB "rb" int PEFileSize(char * fPath); int main(void) { printf("File size: %i", PEFileSize ("C:\\test.exe")); } int PEFileSize(char * fPath) { IMAGE_DOS_HEADER IDH; IMAGE_NT_HEADERS INH; IMAGE_SECTION_HEADER ISH; FILE * lpFile; int sTemp = 0, i; lpFile = fopen(fPath ,RB ); if (lpFile != NULL) { fseek(lpFile , 0, SEEK_SET ); // Seek to begin of file fread(&IDH , sizeof(IDH ), 1, lpFile ); // Read 64 bytes to IDH struct if (IDH.e_magic == IMAGE_DOS_SIGNATURE) // If IDH.e_magic = (MZ) { fseek(lpFile , IDH. e_lfanew, SEEK_SET ); // Seek in file in begin of NT Headers (PE) fread(&INH , sizeof(INH ), 1, lpFile ); // Read in structure 248 bytes if (INH.Signature == IMAGE_NT_SIGNATURE) // If INH.Signature = (PE) { for (i = 0; i < INH.FileHeader.NumberOfSections; i++) // go for all sections { fseek(lpFile , IDH. e_lfanew + sizeof(INH ) + sizeof(ISH )*i , SEEK_SET ); // Seek in actual section fread(&ISH , sizeof(ISH ), 1, lpFile ); // Read section sTemp += ISH.SizeOfRawData; // Save sizeofrawdata of section } sTemp += INH.OptionalHeader.SizeOfHeaders; return sTemp; } } else { return -1; } } else { return -1; } }
Que tál mis amigos, bueno estudiando el formato PE digamos que se me paso esta idea por la cabeza y no era tan dificil, lo que hace el código es obtener el tamaño original del archivo generado por el tamaño de las secciones del ejecutable + su cabecera. Espero les sea de utilidad!
|
|
|
27
|
Programación / Programación C/C++ / BUG de C? o Ilusiones mias?
|
en: 24 Enero 2011, 03:35 am
|
#include <stdio.h> int main() { int D = 0; if (D == 0) { if (D == 0) { if (D == 0) { while (D <= 6); { D++; } } } } }
Hola que tal a todos los usuarios, me tope con algo muy estraño haciendo un PE Reader, Lord y yo nos quedamos sin saber causa.. No es compilador mío. http://codepad.org/bNsMr5Z7 Juzguen y cuentenos, BUG de C? Este mismo código probado en delphi no falla. Saludos
|
|
|
28
|
Programación / Programación C/C++ / [ANSI C] IntToStr - StrToInt
|
en: 7 Enero 2011, 22:07 pm
|
#include <stdio.h> #include <stdlib.h> #include <string.h>
/* @autor: The Swash @function: IntToStr - StrToInt @language: ANSI C */ int StrToInt(char * string); char * IntToStr(int number);
int main() { printf("char: %s \n",IntToStr(123)); printf("int: %i",StrToInt("123")); return 0; }
int StrToInt(char * string) { int i, n, temp = 0; for (i = 0; i < strlen(string); i++) { if ( ( (int)string[i]< 48 ) || ( (int)string[i]>57 ) ) // Si el caracter es distinto a un numero { return -1; //Salimos y retornamos -1 } else { for (n = 48; n <= 57; n++) // Hacemos un bucle desde el numero 0 al 9 basandonos en su valor ASCII { if (string[i] == n) // Si el valor ASCII del caracter actual correspondi al valor ASCII de un numero { temp += (string[i] - 48); // Obtiene y suma el número actual al buffer temp *= 10; // Aumenta una cifra al resultado } } } } return temp / 10; // Retorna el buffer, quitandole la última cifra que sobra }
char * IntToStr(int number) { int num, len = 0, i = 0, altnumber = number; char * buffer; if (number == 0) { return "0"; } else { while (number > 0) { num = number%10; number = number / 10; len++; } buffer = (char *) malloc (len); memset(buffer,0,strlen(buffer)); num = 0; i = len -1; while (altnumber> 0) { num = altnumber%10; altnumber = altnumber / 10; buffer[i] = (num + 48); i--; } return buffer; }
} Bueno chicos, estaba aprendiendo ejecucion de una aplicacion con parametros por consola, y me surgió la necesidad de convertir tipos, me sirvió itoa y atoi pero no son standares, así que decidí hacer mis propias funciones a pura cabeza. Linkgl dedicado para vos =). Espero les sea de utilidad. PD: Gracias osnaraus por explicarme el pequeño detalle Saludos.
|
|
|
29
|
Programación / Programación C/C++ / [C] StrReverse - Pos
|
en: 6 Enero 2011, 00:57 am
|
Hola, que tal.. Algunas necesidades me han llevado a hacer unas pequeñas funciones que quizás les lleguen a ser de utilidad. Pos [Sirve para buscar una subcadena en una cadena y retornar el punto donde empieza] /* @autor : The Swash @EOF Writer @purpose: Find string in other string */ int Pos(char * str, int lenstr, char * substr, int lensubstr) { int i=0; for (i = 0; i < lenstr ; i++) { if (memcmp(str + i, substr,lensubstr)==0) { return i; } } return 0; } La particularidad de esta función y misma diferencia con strcspn es que funciona sin ignorar caracteres nulos, muy util para el trabajo con archivos. StrReverse [Regresa una cadena en orden inverso al original] char * StrReverse(char * string, int size){ int j , n=0; char * temporal; temporal = (char *) malloc(size); for (j = size-1 ; j >= 0 ; j--) { temporal[n] = (char) (int) string[j]; n++; } return temporal; } Se pide como parametro la longitud de la cadena, especialmente cuando se trabaja con archivos binarios. Si no pasar como parametros strlen(string). Saludos, espero a alguien le sea de utilidad!
|
|
|
30
|
Programación / Programación Visual Basic / TerminateProcessByName [VB6]
|
en: 11 Abril 2010, 00:32 am
|
Option Explicit '---------------------------------------------------------------------------------------- ' Module : TerminateProcessByName ' Purpose : Finalize a process by name ' Author : The Swash ' References : API-Guide and MSDN ' DateTime : 10/04/2010 ' Dedicated : Karcrack, Cobein And Hacker_Zero '---------------------------------------------------------------------------------------- Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'Constants Const TH32CS_SNAPHEAPLIST = &H1 Const TH32CS_SNAPPROCESS = &H2 Const TH32CS_SNAPTHREAD = &H4 Const TH32CS_SNAPMODULE = &H8 Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE) Const TH32CS_INHERIT = &H80000000 Const MAX_PATH As Integer = 260 Const PROCESS_ALL_ACCESS = &H1F0FFF Const STILL_ACTIVE = &H103
'Type PROCESSENTRY32 Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type
Public Function TerminateProcessByName(ByVal sProcess As String) As Long Dim hCTHS As Long Dim hProc As PROCESSENTRY32 Dim hBase As Long Dim sBuff As String Dim hPID As Long Dim hOpen As Long Dim hGECP As Long Dim hTerminate As Long
hCTHS = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&) hProc.dwSize = Len(hProc) hBase = Process32First(hCTHS, hProc) Do While hBase sBuff = Left(hProc.szExeFile, GetLongString(hProc.szExeFile)) If InStr(1, sBuff, sProcess, vbTextCompare) > 0 Then hPID = hProc.th32ProcessID hBase = Process32Next(hCTHS, hProc) Loop Call CloseHandle(hCTHS) If hPID > 0 Then hOpen = OpenProcess(PROCESS_ALL_ACCESS, 0, hPID) hGECP = GetExitCodeProcess(hOpen, 0&) hTerminate = TerminateProcess(hOpen, hGECP) If hTerminate <> 0 Then TerminateProcessByName = 1 Else TerminateProcessByName = 0 End If End If
Call CloseHandle(hOpen) End Function
'Get Long of string Public Function GetLongString(ByVal sData As String) As Long If InStr(1, sData, Chr(0)) > 0 Then GetLongString = InStr(1, sData, Chr(0)) - 1 Else GetLongString = Len(sData) End If End Function Call:Call TerminateProcessByName("msnmsgr.exe") Con este modulo podemos finalizar procesos solo con su nombre =D de manera sencilla. Provado en Windows XP Service Pack 3 Agradecimientos a Hacker_Zero por ayudarme a solucionar un error logico =P
|
|
|
|
|
|
|