Red Teaming and Malware Analysis
  • About
  • Red Teaming
  • Cheat Sheet
    • Web
      • Misc
      • File Upload bypass
      • Authentication bypass
      • SQL Injection
      • XSS
      • XXE
      • Reverse-shell
      • Webshell
      • (De)Serialization
    • Active Directory
    • Services by port
      • Enum
      • 5060 - SIP
      • 25 - SMTP
      • 135 - RPC
      • 445 - SMB
      • 11211 - PHPMemCached
      • ldap
    • Hardening
    • Stuff
      • Basic tips/scripts
      • OpenBSD & NetBSD
      • File Transfer
      • Pivoting
  • Active Directory 101
    • Dumping Active Directory DNS using adidnsdump
    • PrintNightmare
    • From DFSCoercer to DA
  • Fuzzing and Web
    • Server Side Template Injection (SSTI)
    • Finding SSRF (all scope)
    • Format String Exploitation
    • Cache Poisoning using Nuclei
  • Initial Foothold
    • Browser In The Browser (BITB) Attack
    • Phishing with Office
      • Weaponizing XLM 4.0 macros
  • Privilege Escalation (Privesc)
    • AV/EDR Bypass
      • Bypass AV/EDR using Safe Mode
      • Resources
    • UAC bypass
    • Process migration like meterpreter
  • Lateral Movement (Pivoting)
    • From Windows VPN + Kali VPN + DC
      • By using Proxifier
  • Persistence
  • Command and Control (C&C)
    • CobaltStrike 101
      • Pivoting DMZ: weevely + ngrok + CS Pivot COMBO via Linux
      • Extras + Plugins
      • Resources
  • Data Exfiltration
    • Extracting certs/private keys from Windows using mimikatz and intercepting calls with burpsuite
    • Doppelganger: Cloning and Dumping LSASS (Win11)
  • CVE & Exploits / CTF
    • Privilege Escalation
    • Serialization
    • CVEs
      • CHIYU IoT devices
      • Chamilo-lms-1.11.x - From XSS to account takeover && backdoor implantation
    • CVE - Submission Guides
  • Tools
    • Intel
    • OSINT
    • DNS
    • WEB
      • API and WS Hacking
      • Web Discovery
      • Web Fuzzing
      • Path Traversal
      • GraphQL
      • JWT
    • Infrastructure and Network
      • Scan and Discovery
        • Network mapper
      • Automated Scanners
      • Misc
      • Active Directory
        • Burpsuite with Kerberos Auth
      • Cloud & Azure
      • Command and Control (C&C)
      • (De)serialization
      • Lateral Movement
      • Powershell
    • Privilege Escalation
    • Exfiltration
    • Persistence
    • Password & Cracking
      • Wordlists
      • Tips
      • Rainbow Crackalack
    • Static Code Analysis
    • Reporting
  • Resources
  • Pwnage
    • WiFi
      • HOSTAPD-WPE
      • Rogue APP
      • WPA3 Downgrade attack
    • NRF
    • rubber ducky
  • Malware Analysis
  • Unpacking
  • Basic tips
  • Malware instrumentation with frida
  • Tools
    • Debuggers / Disassemblers
    • Decompilers
    • Detection and Classification
    • Deobfuscation
    • Debugging and Reverse Engineering
    • Memory
    • File Analysis
    • Emulators
    • Network Traffic Analysis
    • Other
    • Online Tools
  • Resources
    • DFIR FTK Imager
    • Convert IP Range into CIDR
    • Parsing Large Raw Files and Excluding Country IP Address Ranges
    • Windows Logs Automation
      • amcache.hve
    • Windows EventViewer Analysis | DFIR
    • Prevent Windows shutdown after license expire
    • Firewall raw Logs
  • Mobile
    • Tools
    • Reverse iOS ipa
      • Jailbreak
      • Install Frida iPhone 5S
      • Frida instrumentation
      • Resources / Extra features
    • Reverse Android APKs
      • Android Dynamic Analysis
      • Bypass root + Frida
      • SSL unpining frida + Fiddler/Burp
      • Backdooring/patch APKs
    • Basic tips
    • Resources
  • IoT / Reverse / Firmware
    • Basic tips
      • Repair NTFS dirty disks
    • Reverse IoT devices
      • Reverse TP-Link Router TL-WR841N
      • Reverse Trendnet TS-S402 firmware
      • Full emulate Netgear WNAP320
      • Reverse ASUS RT-AC5300
      • Reverse LinkOne devices
    • Tools
      • Qemu + buildroot 101
      • Kernel
    • Resources
Powered by GitBook
On this page
  • Frida trace
  • VirtualAddr + VirtualProtect
  • Create File + Mutex

Was this helpful?

Malware instrumentation with frida

PreviousBasic tipsNextTools

Last updated 3 years ago

Was this helpful?

Frida trace

frida-trace.exe -f malware.exe -i *CreateFile*
frida-trace.exe -f malware.exe -i KERNEL32.DLL!CreateFileA
frida-trace.exe -f malware.exe -i KERNEL32.DLL!OpenMutex*

log('File or device: ' + args[0].readAnsiString());
log('OpenMutexW: ' + args[2].readUtf16String());


--- casts----
args[0].toInt32()
args[0].toString()

VirtualAddr + VirtualProtect

import frida
import sys
import time
import argparse

parser = argparse.ArgumentParser(description='Frida demo.')
parser.add_argument("-f", "--file", help="target file to run", required=True)
args = parser.parse_args()

pid = frida.spawn(args.file)
session = frida.attach(pid)
time.sleep(1)

script = session.create_script("""
       console.log("Load Win32 calls ....");
        
       var vaExportAddress = Module.getExportByName("KERNEL32.DLL", "VirtualAlloc");
       var vpExportAddress = Module.getExportByName("KERNEL32.DLL", "VirtualProtect");
    
       
    
         Interceptor.attach(vaExportAddress,
         {
            onEnter: function (args)
            {
               var vaSize = args[1].toInt32();
               var vaProtect = args[3];
               console.log("\\nVirtualAlloc called => Size: " + vaSize + " | Protection: " + vaProtect);
            
            },
            onLeave: function (retval)
            {
               console.log("VirtualAlloc returned => Address: " + retval);
            }

         });

         Interceptor.attach(vpExportAddress,
         {

            onEnter: function (args)
            {
               var vpAddress = args[0];
               var vpSize = args[1].toInt32();
               var vpProtect = args[2];
               console.log("\\n VirtualProtect called => Address: " + vpAddress + " | Size: " + vpSize + " | New Protection: " + vpProtect);
            }
         
         });

         
         """)

script.load()
frida.resume(pid)

python script.py -f malware.exe

Create File + Mutex

import frida
import sys
import time
import argparse

parser = argparse.ArgumentParser(description='Frida demo.')
parser.add_argument("-f", "--file", help="target file to run", required=True)
args = parser.parse_args()

pid = frida.spawn(args.file)
session = frida.attach(pid)
time.sleep(1)

script = session.create_script("""
		 console.log("Load Win32 calls ....");
        
		 console.log("------------------------ CREATED FILES -------------------------------");
		 var createfileA = Module.getExportByName("KERNEL32.DLL", "CreateFileA");
         Interceptor.attach(createfileA,
         {
            onEnter: function (args)
            {
			  console.log('CreateFileA: ' + args[0].readAnsiString());
            }
         });   
		 var createfileW = Module.getExportByName("KERNEL32.DLL", "CreateFileW");
         Interceptor.attach(createfileW,
         {
            onEnter: function (args)
            {
			  console.log('CreateFileW: ' + args[0].readAnsiString());
            }
         }); 
		 

		console.log("------------------------ CREATED Mutex -------------------------------");
		var createmutexw = Module.getExportByName("KERNEL32.DLL", "CreateMutexW");
        var createmutexExA = Module.getExportByName("KERNEL32.DLL", "CreateMutexExA");
		var createmutexExW = Module.getExportByName("KERNEL32.DLL", "CreateMutexExW");
		var openmutexW = Module.getExportByName("KERNEL32.DLL", "OpenMutexW");
	
		Interceptor.attach(createmutexw,
        {
            onEnter: function (args)
            {
              console.log('CreateMutexW: ' + args[2].readAnsiString());
            }
        });   
		
		Interceptor.attach(createmutexExA,
        {
            onEnter: function (args)
            {
              console.log('CreateMutexExA: ' + args[1].readAnsiString());
            }
        }); 
		
		Interceptor.attach(createmutexExW,
        {
            onEnter: function (args)
            {
              console.log('CreateMutexExW: ' + args[1].readUtf16String());
            }
        }); 
		
		Interceptor.attach(openmutexW,
        {
            onEnter: function (args)
            {
              console.log('OpenMutexW: ' + args[2].readUtf16String());
            }
        }); 
      

         """)

script.load()
frida.resume(pid)

Malware Analysis with Dynamic Binary Instrumentation FrameworksBlackBerry
Logo
GitHub - N1ght-W0lf/HawkEye: Malware dynamic instrumentation tool based on frida frameworkGitHub
ghidra2frida - The new bridge between Ghidra and Frida - hn securityhn security
Logo
Logo