Pillole di Malware Analysis: Tecniche di Antidebugging #3

Nella pillola precedente vi avevo parlato delle tecniche antidebugging utilizzate dai malware e vi avevo parlato dell'utilizzo della primitiva CreateToolhelp32Snapshot per ricercare un processo.
Oggi vi mostro una routine scritta in C per dimostrarvi come si può fare.
Ho commentato il codice per renderlo più leggibile.
Innanzitutto bisogna partire con un punto nel corpo del malware nel quale si esegue un if di questo tipo

if processExists("OllyDbg.exe")
     faiqualcosaltro();
else
     faidelmale();

In pratica la funzione processExists cerca in memoria il processo OllyDbg.exe (il debugger) e se lo trova al posto di comportarsi come vorrebbe fa qualcos'altro, inducendo in errore l'analista.
Il cuore di questa routine è processExists che vi metto qui sotto:


int processExists(const wstring nome_processo)
{
Int processFound=0; // processFound = 0 se il processo non viene trovato, altrimenti è 1
HANDLE Hsnapshot; // conterrà la fotografia della memoria con tutti i processi attivi
if ((Hsnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)) == INVALID_HANDLE_VALUE)
{
throw runtime_error("CreateToolhelp32Snapshot ha fallito con il seguente errore: " + to_string(GetLastError()));
}

PROCESSENTRY32 pe; // conterrà le informazioni sul processo corrente recuperato dallo snapshot
ZeroMemory(&pe, sizeof(PROCESSENTRY32W)); // pulisco l'area di memoria a cu punta pe rimpendola di zeri
pe.dwSize = sizeof(PROCESSENTRY32W);
Process32First(Hsnapshot, &pe); // prendo il primo processo nello snapshot. Qui avrei dovuto controllare l'eventuale errore di Process32First ;-)
if (pe.szExeFile == nome_processo) // Il campo szExeFile della struttura PROCESSENTRY32 contiene il nome del processo
    {
       processFound=1;
    }
else
    {
     while (Process32Next(Hsnapshot, &pe))
        {
            if (pe.szExeFile == nome_processo)
                {
                processFound=1;
                break;
                }
        }
    }
    return processFound;
}

 

 

#webapplicationsecurity #securityprofessionals #offensivesecurity #ethicalhacking #ethicalhacker #cybersecurity #cybersecurityawareness #informationsecurity #infosec #infosecurity #security #penetrationtesting #pentesting #pentest #pentester #securityawareness #redteam #redteaming #vulnerabilities #vulnerability #vulnerabilityscanning #vulnerabilityassessment #vulnerabilitymanagement #exploit #exploits #exploitation #codereview #securityadvisor #securityaudit #securityaudits #bughunter #bughunting #bugfixed #itsecurity #itsec #riskassessment #riskmanagement #ciso #owasp #owasptop10 #malware #malwareanalysis #cybersecurityUP

Pin It

Cyber Security UP

CybersecurityUP is a BU of Fata Informatica.
Since 1994, we have been providing IT security services to large civil and military organizations.
  • Ethical Hacking
  • Red Teaming
  • Penetration Testing
  • Security Code Review
  • SOC 24x7
  • Specialized Training
Image
Image
Image
Via Tiburtina 912,
CAP 00156,
ROMA

Monday-Friday
09:00 - 13:00
14:00 - 18:00

+39 06 4080 0490
amministrazione@fatainformatica.com

Contact us

Do you need our cybersecurity services?

Privacy policy

We invite you to read our
privacy policy for the protection of your personal data.
Disclaimer
Some of the photos on Cybersecurityup.it may have been taken from the Internet and therefore considered to be in the public domain. If the subjects or authors have any objections to their publication, they can report this by email to the editorial staff, who will promptly remove the images used.
© 2026 Fata Informatica. Tutti i diritti riservati.