elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Temas
Páginas: 1 2 [3] 4
21  Seguridad Informática / Análisis y Diseño de Malware / [Tutorial-SC]Cargando funciones importadas a mano! en: 22 Mayo 2011, 22:54 pm
Hola amigos, después de exactamente una semana vengo con otro documento que le tenía ganas y lo que más satisfacción me dio fue el código en ensamblador en el cual tardé 2 días pero bueno.
Espero les guste y hasta la próxima.

The Swash

Link:
Código:
http://www.box.net/shared/0alan9bock

Un saludo y agradecimientos especiales a [Zero]  ;)
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:
Código:
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
Código
  1. .386
  2. .model flat, stdcall
  3. option casemap:none
  4. assume fs:nothing
  5.  
  6. .data
  7. GPA db "GetProcAddress",0
  8. Cont dd 0
  9.  
  10. .code
  11. start:
  12. mov eax, fs:[030h]    ; Get pointer of the PEB
  13. mov eax, [eax + 0ch]  ; Get pointer of PPEB_LDR_DATA
  14. mov eax, [eax + 0ch]  ; Get pointer of InLoadOrderModuleList
  15. mov eax, [eax]        ; Get InLoadOrderModuleList of next library "ntdll"
  16. mov eax, [eax]        ; Get InLoadOrderModuleList of next library "kernel32"
  17. mov eax, [eax + 018h] ; Get BaseAddress of "kernel32"
  18.  
  19. mov ecx, dword ptr[eax + 03ch]   ; Set PE Offset
  20. add ecx, 078h                    ; Set in DirectoryTable[0]
  21. mov edx, dword ptr [eax + ecx]   ; Get Export Table RVA
  22. add edx, eax                     ; Add KernelBase Address
  23. xor ebx, ebx                     ; Clean EBX
  24. add edx, 020h                    ; Set in addressofnames RVA
  25. mov ebx, dword ptr [edx]         ; Get RVA AddressOfNames Table
  26. add ebx, eax                     ; Add KernelBase Address
  27.  
  28. COMP:                   ; Rutine of compare strings with "GetProcAddress", incrementing Cont
  29. add ebx, 4
  30. inc [Cont]
  31. mov esi, dword ptr [ebx]
  32. add esi, eax
  33. lea edi, [GPA]
  34. mov ecx, 0Eh
  35. repe cmpsb
  36. jnz COMP
  37.  
  38. ;GetAddress
  39. xor ebx, ebx            ; Clean EBX
  40. add edx, 04h            ; Set on Table Ordinal RVA
  41. mov ebx, dword ptr[edx] ; Get first RVA of Ordinal
  42. add ebx, eax            ; Add KernelBase Address
  43. mov edi, eax            ; Save KernelBase Address in EDI
  44. xor eax, eax            ; Clean EAX
  45. mov al, 02h             ; Base of WORD
  46. mov esi, edx            ; Save Address of RVA Ordinal Table
  47. mul word ptr[Cont]      ; Mul Cont for get WORD
  48. mov [Cont], eax         ; Get new value in Cont
  49. xor eax, eax            ; Clean EAX
  50. add ebx, [Cont]         ; Add Cont to Address of Ordinal Table
  51. mov ax,word ptr[ebx]    ; Get Ordinal of GetProcAddress
  52. sub esi, 08h            ; Set in AddressOfFunctions
  53. mov ecx, [esi]          ; Get First pointer to Functions RVA
  54. add ecx, edi            ; Add KernelBase Address
  55. xor ebx, ebx            ; Clean EBX
  56. mov ebx, eax            ; Mov Ordinal to EBX for MUL
  57. mov eax, 04h            ; Base of DWORD
  58. mul ebx                 ; Calcule spaces to Get address bassed in (Address of First Function + Ordinal GetProcAddress
  59. add ecx, eax            ; Add spaces for Set Address in RVA of GetProcAddress
  60. mov ecx, [ecx]          ; Get RVA of GetProcAddress
  61. add ecx, edi            ; Add KernelBase Address
  62. 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
Código
  1. mov eax, fs:[030h]
  2. mov eax, [eax + 0ch]
  3. mov eax, [eax + 0ch]
  4. mov eax, [eax]
  5. mov eax, [eax]
  6. 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  :P.
Saludos!
25  Programación / Programación C/C++ / [C/SRC] Realign PE (Actualizado) en: 27 Enero 2011, 01:24 am
Código
  1. /*
  2.   -----------------------------------------------------------
  3.   - Function: RealignPE v2                                  -
  4.   - Programmer: The Swash                                   -
  5.   - Web: http://www.h-sec.org                               -
  6.   - Dedicated: Thor, Psymera, Steve10120, [Zero], Karcrack  -
  7.   -----------------------------------------------------------
  8. */
  9.  
  10. #include <windows.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #define ReadWriteBinary "r+b"
  14.  
  15. int AlingNum(int num, int aling);
  16. char * BytesAling(int number);
  17.  
  18. int main(void)
  19. {
  20.    printf("%i ",RealignPE("C:\\hi.exe"));
  21.    getchar();
  22.  
  23. }
  24.  
  25. int RealignPE(char * lpFile)
  26. {
  27.    IMAGE_DOS_HEADER IDH;
  28.    IMAGE_FILE_HEADER IFH;
  29.    IMAGE_OPTIONAL_HEADER IOH;
  30.    IMAGE_SECTION_HEADER ISH;
  31.  
  32.    DWORD PESignature = 0;
  33.    FILE * lFile;
  34.    int OriSize = 0;
  35.    int ActSize = 0;
  36.    int Alingned = 0;
  37.  
  38.    lFile = fopen(lpFile,ReadWriteBinary);
  39.    if (lFile == NULL) {return -1;}
  40.    else
  41.    {
  42.        fread(&IDH, 64, 1, lFile);
  43.        fseek(lFile, IDH.e_lfanew , SEEK_SET);
  44.        fread(&PESignature, 4, 1, lFile);
  45.        if (IDH.e_magic != IMAGE_DOS_SIGNATURE) {fclose (lFile); return -2;}
  46.        else
  47.        {
  48.            if(PESignature != IMAGE_NT_SIGNATURE) {fclose (lFile); return -3;}
  49.            else
  50.            {
  51.  
  52.                fseek(lFile, IDH.e_lfanew + 4, SEEK_SET);
  53.                fread(&IFH, sizeof(IFH), 1, lFile);
  54.                fseek(lFile, IDH.e_lfanew + 4 + sizeof(IFH), SEEK_SET);
  55.                fread(&IOH, IFH.SizeOfOptionalHeader, 1, lFile);
  56.                fseek(lFile, IDH.e_lfanew + 4 + sizeof(IFH) + IFH.SizeOfOptionalHeader + (sizeof(ISH)*(IFH.NumberOfSections-1)),SEEK_SET);
  57.                fread(&ISH, sizeof(ISH), 1, lFile);
  58.                fseek(lFile, 0, SEEK_END);
  59.                ActSize = ftell(lFile);
  60.                OriSize = ISH.PointerToRawData + ISH.SizeOfRawData;
  61.                if (ActSize - OriSize > 0)
  62.                {
  63.                    Alingned = AlingNum(ActSize - OriSize, IOH.FileAlignment);
  64.                    ISH.SizeOfRawData += Alingned;
  65.                    ISH.Misc.VirtualSize += Alingned;
  66.                    IOH.SizeOfImage = ISH.Misc.VirtualSize + ISH.VirtualAddress;
  67.                    IOH.SizeOfInitializedData += Alingned;
  68.                    if (ISH.VirtualAddress == IOH.DataDirectory[2].VirtualAddress)
  69.                    {
  70.                        IOH.DataDirectory[2].Size += Alingned;
  71.                    }
  72.                    fseek(lFile, IDH.e_lfanew + 4 + sizeof(IFH), SEEK_SET);
  73.                    fwrite(&IOH, 1, IFH.SizeOfOptionalHeader, lFile);
  74.                    fseek(lFile, IDH.e_lfanew + 4 + sizeof(IFH) + IFH.SizeOfOptionalHeader + (sizeof(ISH)*(IFH.NumberOfSections-1)),SEEK_SET);
  75.                    fwrite(&ISH, 1, sizeof(ISH), lFile);
  76.                    if (Alingned - (ActSize - OriSize) > 0)
  77.                    {
  78.                       fseek(lFile, ActSize, SEEK_SET);
  79.                       fwrite(BytesAling(Alingned-(ActSize - OriSize)), 1, Alingned-(ActSize - OriSize), lFile);
  80.                    }
  81.                    return 0;
  82.                }
  83.                else {return 1;}
  84.            }
  85.        }
  86.    }
  87. }
  88.  
  89.  
  90. int AlingNum(int num, int aling)
  91. {
  92.    if(num % aling == 0)
  93.    { return num; }
  94.    else if(num < aling)
  95.    { return aling; }
  96.    else { return (num / aling) * aling + aling; }
  97. }
  98.  
  99. char * BytesAling(int number)
  100. {
  101.     char * sTemp = (char *) malloc(number + 1);
  102.     int i;
  103.     for (i=0; i<number; i++)
  104.     {
  105.         sTemp[i] = '\0';
  106.     }
  107.     return sTemp;
  108. }

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
Código
  1. /*
  2.    [Get size of file to base of PE]
  3.    - Programmer: The Swash
  4.    - Dedicated: Zero, Thor Psymera, Steve10120
  5. */
  6.  
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #define RB "rb"
  10.  
  11. int PEFileSize(char * fPath);
  12.  
  13.  
  14. int main(void)
  15. {
  16.    printf("File size: %i", PEFileSize("C:\\test.exe"));
  17.    getchar();
  18. }
  19.  
  20. int PEFileSize(char * fPath)
  21. {
  22.    IMAGE_DOS_HEADER IDH;
  23.    IMAGE_NT_HEADERS INH;
  24.    IMAGE_SECTION_HEADER ISH;
  25.    FILE * lpFile;
  26.    int sTemp = 0, i;
  27.  
  28.    lpFile = fopen(fPath,RB);
  29.    if (lpFile != NULL)
  30.    {
  31.               fseek(lpFile, 0, SEEK_SET); // Seek to begin of file
  32.               fread(&IDH, sizeof(IDH), 1, lpFile); // Read 64 bytes to IDH struct
  33.               if (IDH.e_magic == IMAGE_DOS_SIGNATURE) // If IDH.e_magic = (MZ)
  34.               {
  35.                               fseek(lpFile, IDH.e_lfanew, SEEK_SET); // Seek in file in begin of NT Headers (PE)
  36.                               fread(&INH, sizeof(INH), 1, lpFile); // Read in structure 248 bytes
  37.                               if (INH.Signature == IMAGE_NT_SIGNATURE) // If INH.Signature = (PE)
  38.                               {
  39.                                                 for (i = 0; i < INH.FileHeader.NumberOfSections; i++) // go for all sections
  40.                                                 {
  41.                                                     fseek(lpFile, IDH.e_lfanew + sizeof(INH) + sizeof(ISH)*i, SEEK_SET); // Seek in actual section
  42.                                                     fread(&ISH, sizeof(ISH), 1, lpFile); // Read section
  43.                                                     sTemp += ISH.SizeOfRawData; // Save sizeofrawdata of section
  44.                                                 }
  45.                                                 sTemp += INH.OptionalHeader.SizeOfHeaders;
  46.                                                 fclose(lpFile);
  47.                                                 return sTemp;
  48.                               }
  49.               }
  50.               else
  51.               {
  52.                   return -1;
  53.               }
  54.    }
  55.    else
  56.    {
  57.        return -1;
  58.    }
  59. }

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
Código
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.  
  6.    int D = 0;
  7.  
  8.    if (D == 0)
  9.    {
  10.  
  11.        printf("etapa 1");
  12.        if (D == 0)
  13.        {
  14.  
  15.                     printf("etapa 2");
  16.  
  17.                     if (D == 0)
  18.                     {
  19.                           printf("etapa 3");
  20.  
  21.                           while (D <= 6);
  22.                           {
  23.                              D++;
  24.  
  25.                           }
  26.                           printf("etapa 5");
  27.  
  28.                     }
  29.  
  30.         }
  31.  
  32.    }
  33. }

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.
Código:
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
Código:
#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]

Código:
/*  @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.

Código:
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
Código:
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:
Código:
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
Páginas: 1 2 [3] 4
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines