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

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


  Mostrar Temas
Páginas: [1]
1  Programación / .NET (C#, VB.NET, ASP) / Escanear memoria. en: 22 Julio 2017, 12:37 pm
Hola, estoy programando un programa que detecta malware según ciertos patrones que tenga.
La verdad es que soy novato con lo relacionado con memoria y no estoy seguro de cómo hacerlo, estoy interesado en escanear cadenas/strings que son estáticas en la memoria pero no he encontrado ninguna forma eficaz de hacerlo.

He encontrado esto en un foro, pero siempre devuelve 0

Código
  1.            public static List<MEMORY_BASIC_INFORMATION> MemReg { get; set; }
  2.  
  3.            public static void MemInfo(IntPtr pHandle)
  4.            {
  5.                IntPtr Addy = new IntPtr();
  6.                while (true)
  7.                {
  8.                    MEMORY_BASIC_INFORMATION MemInfo = new MEMORY_BASIC_INFORMATION();
  9.                    int MemDump = VirtualQueryEx(pHandle, Addy, out MemInfo, Marshal.SizeOf(MemInfo));
  10.                    if (MemDump == 0) break;
  11.                    if ((MemInfo.State & 0x1000) != 0 && (MemInfo.Protect & 0x100) == 0)
  12.                        MemReg.Add(MemInfo);
  13.                    Addy = new IntPtr(MemInfo.BaseAddress.ToInt32() + MemInfo.RegionSize);
  14.                }
  15.            }
  16.            public static IntPtr _Scan(byte[] sIn, byte[] sFor)
  17.            {
  18.                int[] sBytes = new int[256]; int Pool = 0;
  19.                int End = sFor.Length - 1;
  20.                for (int i = 0; i < 256; i++)
  21.                    sBytes[i] = sFor.Length;
  22.                for (int i = 0; i < End; i++)
  23.                    sBytes[sFor[i]] = End - i;
  24.                while (Pool <= sIn.Length - sFor.Length)
  25.                {
  26.                    for (int i = End; sIn[Pool + i] == sFor[i]; i--)
  27.                        if (i == 0) return new IntPtr(Pool);
  28.                    Pool += sBytes[sIn[Pool + End]];
  29.                }
  30.                return IntPtr.Zero;
  31.            }
  32.            public static IntPtr AobScan(string ProcessName, byte[] Pattern)
  33.            {
  34.                Process[] P = Process.GetProcessesByName(ProcessName);
  35.                if (P.Length == 0) return IntPtr.Zero;
  36.                MemReg = new List<MEMORY_BASIC_INFORMATION>();
  37.                MemInfo(P[0].Handle);
  38.                for (int i = 0; i < MemReg.Count; i++)
  39.                {
  40.                    byte[] buff = new byte[MemReg[i].RegionSize];
  41.                    ReadProcessMemory(P[0].Handle, MemReg[i].BaseAddress, buff, MemReg[i].RegionSize, 0);
  42.  
  43.                    IntPtr Result = _Scan(buff, Pattern);
  44.                    if (Result != IntPtr.Zero)
  45.                        return new IntPtr(MemReg[i].BaseAddress.ToInt32() + Result.ToInt32());
  46.                }
  47.                return IntPtr.Zero;
  48.            }
  49.  
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines