Disrupting Hell's Gate, Caro Kann, and GuLoader with DJB2 Hash Collisions

Disrupting Hell's Gate, Caro Kann, and GuLoader with DJB2 Hash Collisions

June 11, 2024 | Categories: Research

Shellcode Disruption Revisited with DJB2 Hash Collisions

Technical Details 📖 Easy Read

Shellcode leveraging the DJB2 hash algorithm is not quite as common as ROR13. See our previous blog here on disrupting ROR13 which includes disrupting a whole litany of things including Metasploit, Meterpreter, Cobalt Strike, and other malware, but it has been used in several prominent malware examples including GuLoader, Caro Kann, and Hell's Gate. The DJB2 algorithm, although simple, provides a robust means of obfuscating and resolving API function names, making detection and analysis more challenging. This blog delves into the techniques used in these frameworks and how defenders can disrupt such shellcode.

DJB2, another weak shellcode API hashing algorithm

The DJB2 hash function, created by Daniel J. Bernstein, is a simple yet effective hashing algorithm widely used in various applications, including shellcode obfuscation. Its effectiveness lies in its ability to generate a unique hash for each input string, making it difficult for security tools to detect obfuscated API calls through simple pattern matching.

GuLoader, Caro Kann, and Hell's Gate

GuLoader, a sophisticated malware loader, Caro Kann a shellcode that uses DJB2 for api resolution, and Hell's Gate, a technique for executing direct syscalls, are notable examples that use DJB2 hashing to obfuscate and resolve API function names. This technique involves hashing the names of API functions and comparing them with precomputed hashes within the shellcode. If a match is found, the shellcode can dynamically resolve and execute the desired function.

DJB2 Hash Function in Shellcode

The DJB2 hash function can be implemented in various programming languages. Below is a simple implementation in C:


unsigned long djb2(unsigned char *str) 
{
    unsigned long hash = 5381;
    int c;

    while (c = *str++) 
    {
        dwHash = ((dwHash << 5) + dwHash) + c;
    }

    return dwHash;
}

This function iterates over each character in the input string, updating the hash value through bitwise operations and additions. The resulting hash is a compact 32-bit integer representing the obfuscated function name.

Example in Hell's Gate and other Malware

Hell's Gate uses DJB2 hashing to dynamically resolve syscalls it needs for execution. Below is an excerpt from Hell's Gate illustrating this approach:


DWORD64 djb2(PBYTE str) 
{
    DWORD64 dwHash = 0x7734773477347734;
    INT c;

    while (c = *str++)
        dwHash = ((dwHash << 0x5) + dwHash) + c;

    return dwHash;
}

This hashing function is applied to native function names extracted from the Export Address Table (EAT) of ntdll.dll, allowing the shellcode to identify and use the correct system calls.

Finding DJB2 Hash Collisions

One effective way to disrupt shellcode using DJB2 hashing is by finding hash collisions. By identifying multiple strings that produce the same hash value, defenders can insert these collisions into the system to confuse or disrupt the shellcode.

Python Code to Find DJB2 Hash Collisions

Below is a Python script to find DJB2 hash collisions for specific target hashes:


import random
import string

def djb2(s: str) -> int:
    hash_val = 5381
    for char in s:
        hash_val = ((hash_val << 5) + hash_val) + ord(char)
    return hash_val & 0xFFFFFFFF

def next_string(s: str) -> str:
    charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_'
    if not s:
        return charset[0]
    s_list = list(s)
    idx = len(s_list) - 1
    while idx >= 0:
        char_idx = charset.index(s_list[idx])
        if char_idx < len(charset) - 1:
            s_list[idx] = charset[char_idx + 1]
            return ''.join(s_list)
        else:
            s_list[idx] = charset[0]
            idx -= 1
    return charset[0] + ''.join(s_list)

def find_collision(target_hashes):
    s = ''
    collisions = {}

    while len(collisions) < len(target_hashes):
        fuzzed_string = s
        hash_val = djb2(fuzzed_string)
        if hash_val in target_hashes and hash_val not in collisions:
            print(f"Found collision: '{fuzzed_string}' hashes to {hash_val:08x}")
            collisions[hash_val] = fuzzed_string
        s = next_string(s)
    return collisions

target_hashes = [0x7040ee75, 0x5fbff0fb, 0x668fcf2e, 0x382c0f97]
collisions = find_collision(target_hashes)

for hash_val, coll_str in collisions.items():
    print(f"Found collision: '{coll_str}' hashes to {hash_val:08x}")

This script generates random strings and computes their DJB2 hashes, checking for collisions with the target hashes.

Mitigating Shellcode with DJB2 Hashing

Defenders can exploit hash collisions to mitigate shellcode attacks by inserting precomputed collisions into the resolution path of shellcode routines. When a collision is encountered, the shellcode's execution can be intercepted and disrupted before it interacts with the system.

By leveraging hash collisions, defenders can create robust protections that enhance overall security stopping malware in its tracks.

Conclusion

Disrupting shellcode that uses the DJB2 hash algorithm requires a deep understanding of the hashing process and the ability to identify collisions. By implementing techniques to find and exploit these collisions, defenders can effectively neutralize threats posed by advanced shellcode obfuscation methods.

For more information on our advanced Karma-X EDR platform and how it can protect your enterprise, reach out right away!


References:

https://www.hick.org/code/skape/papers/win32-shellcode.pdf
https://redops.at/en/blog/exploring-hells-gate
https://blog.sonicwall.com/en-us/2022/06/guloader-a-fileless-shellcode-based-malware-in-action/
https://github.com/Karma-X-Inc/Shellcode-Hash-Collisions
https://github.com/S3cur3Th1sSh1t/Caro-Kann/

Protect your systems for free today! You can start by accessing Vitamin-K here! (after signing up and logging in)

✨ Simplified Summary

What This Blog Is About (In Plain English)

The Bottom Line: Karma-X discovered another way to stop sophisticated malware by exploiting the same trick we used before—but this time against a different code system (DJB2) used by advanced threats like GuLoader, Hell's Gate, and Caro Kann. We're systematically defeating the hacker's playbook, one algorithm at a time.

Quick Recap: The Same Trick, Different Lock

Remember our previous blog about ROR13 hash collisions? We explained how hackers use secret codes to hide what they're doing, and how we create "fake keys" that confuse their code.

This blog is the sequel. Different secret code (DJB2 instead of ROR13), but the same winning strategy.

🔄 The Pattern

ROR13 Blog: We disrupted Metasploit, Meterpreter, Cobalt Strike, and hundreds of common hacking tools

This Blog (DJB2): We're disrupting GuLoader, Hell's Gate, Caro Kann, and other advanced malware families

Together, we're covering the entire spectrum of shellcode-based attacks.

What Is DJB2? (The Secret Code System)

DJB2 is another "scrambling system" (hash algorithm) that malware uses to hide what it's doing—just like ROR13, but with a different formula.

The burglar analogy (from our ROR13 blog):

  • 🔓 Instead of asking for "lockpick" by name (obvious)
  • 🔢 Hackers scramble it into a code number: "lockpick" → #7040ee75
  • 🚨 Security cameras see "#7040ee75" and don't recognize it as suspicious

DJB2 vs ROR13: Think of them like different brands of combination locks. They work on the same principle (scrambling words into numbers), but use different mechanisms. Hackers choose whichever one they think is less likely to be detected.

Meet the Bad Guys Using DJB2

Three notorious malware families rely heavily on DJB2:

1. GuLoader 🦠

What it does: A sophisticated "loader" malware that downloads and executes other malicious programs on your computer. It's like a criminal that breaks into your house and then opens the door for their accomplices.

Why it's dangerous: Can bypass most antivirus software and deliver ransomware, banking trojans, or spyware.

2. Hell's Gate 🔥

What it does: An advanced technique that allows malware to directly talk to the Windows kernel (the core of your operating system) while bypassing security software watching for suspicious behavior.

Why it's dangerous: It's like a burglar who can talk directly to the building's structural beams, bypassing all security cameras and alarms.

3. Caro Kann ♟️

What it does: A shellcode framework (hacking toolkit) that uses DJB2 to hide its API calls when attacking systems.

Why it's dangerous: Provides hackers with ready-made tools to bypass defenses, like buying a lockpicking kit instead of making your own.

How Karma-X Defeats Them (Hash Collisions)

Just like with ROR13, we exploit the weakness of DJB2 by creating hash collisions.

✅ The Winning Strategy (Simplified)

Step 1: The Hacker's Code

  • GuLoader wants to call a dangerous function: "VirtualProtect"
  • It scrambles the name using DJB2: "VirtualProtect" → #7040ee75
  • The malware asks the system: "Give me the function with code #7040ee75"

Step 2: Karma-X's Trap

  • We figured out that a harmless string like "X9bW2m" also hashes to #7040ee75
  • We insert "X9bW2m" into the system where the malware looks
  • Now there are TWO things with code #7040ee75: the real function AND our fake entry

Step 3: Attack Fails

  • The malware asks for #7040ee75
  • It gets our harmless "X9bW2m" instead of "VirtualProtect"
  • The malware tries to execute "X9bW2m" as if it were a dangerous function
  • 💥 Collision! The attack fails immediately and Karma-X safely responds immediately

Real-world comparison: It's like replacing a criminal's weapon with a toy that looks identical from far away. When they try to use it, they discover it doesn't work—too late.

Why This Matters (Technical Excellence)

Coverage Across the Threat Landscape

Hash Algorithm Malware Disrupted
ROR13
(Previous blog)
Metasploit, Meterpreter, Cobalt Strike, Sliver, Brute Ratel, most common attack frameworks
DJB2
(This blog)
GuLoader, Hell's Gate, Caro Kann, sophisticated evasive malware
Future Algorithms
(Coming soon)
We've already cracked algorithms hackers haven't even deployed yet 🎯

The Karma-X Advantage: Thinking Ahead

Here's what makes Karma-X special:

  • 🛡️ We don't wait for attacks to happen — We study hacker techniques and develop defenses proactively
  • 🔬 We research the algorithms they use — ROR13, DJB2, and others
  • 💡 We find mathematical weaknesses — Hash collisions that break their code
  • We deploy protections before attacks scale — Your systems are already protected
  • 🔮 We're working on future threats — Disrupting algorithms hackers will use next year

How This Works in Practice

Traditional Security Approach:

  1. GuLoader infects your system
  2. It starts downloading additional malware
  3. Antivirus detects suspicious behavior (maybe)
  4. Alert goes to security team
  5. By the time they respond, damage is done

Karma-X Protection Approach:

  1. GuLoader tries to infect your system
  2. It attempts to resolve API functions using DJB2 hashes
  3. Karma-X hash collisions intercept the resolution
  4. 💥 GuLoader is stopped immediately
  5. Attack failed. No alert needed. No damage possible.

For Technical Readers: The DJB2 Algorithm

DJB2 (created by Daniel J. Bernstein) is a simple hash function that works like this:

Start with hash = 5381
For each character in the string:
    hash = (hash × 33) + character_value
Return hash

Why it's used in malware:

  • ✅ Simple and fast (few CPU instructions)
  • ✅ Produces consistent results
  • ✅ Generates 32-bit hashes that fit in a register
  • ✅ Good distribution (reduces obvious patterns)

Why it's vulnerable:

  • ❌ Collisions are mathematically findable
  • ❌ No cryptographic security
  • ❌ Predictable behavior can be exploited

Real-World Impact

Organizations protected by Karma-X:

  • 🏥 Healthcare: GuLoader often delivers ransomware to hospitals—Karma-X stops it cold
  • 🏦 Finance: Banking trojans use sophisticated loaders—can't work if the loader is broken
  • 🏭 Manufacturing: Hell's Gate techniques target industrial control systems—disrupted before execution
  • 💼 Enterprises: Advanced persistent threats use these techniques—neutralized at the kernel level

The Research Continues

This is the second blog in our shellcode disruption series, but it won't be the last:

🔬 Ongoing Research at Karma-X

  • ROR13: Disrupted (see blog post #30)
  • DJB2: Disrupted (this blog)
  • 🔄 Other algorithms: Research in progress
  • 🎯 Future algorithms: Already solved (we're not telling hackers which ones yet!)

Goal: Make ALL hash-based shellcode obfuscation techniques obsolete.

Key Takeaways

📋 What You Need to Know

For Business Leaders:

  • 🎯 Karma-X is systematically defeating advanced malware techniques
  • 🛡️ We protect against threats most security products can't even detect
  • ⚡ Protection happens at the foundational level—attacks fail before they execute
  • 🔮 We're already prepared for future attack techniques

For Security Teams:

  • 📚 Understanding shellcode hash algorithms helps you assess risk
  • 🔬 Hash collisions are a powerful defensive technique
  • 🛠️ This isn't available in traditional security products—it requires deep research
  • 💪 Karma-X gives you an asymmetric advantage over attackers

For Everyone:

  • 🔐 Sophisticated malware exists and constantly evolves
  • 🧠 Defending against it requires constant research and innovation
  • 🛡️ Karma-X is doing that research and deploying the results
  • ✅ You can benefit from this protection today

The Bottom Line

Hackers think they're clever by using DJB2 hashing to hide their malware. We're cleverer.

By exploiting the mathematical weaknesses in their obfuscation techniques, we make their attacks fail at the most fundamental level. GuLoader can't load. Hell's Gate can't open. Caro Kann can't resolve.

Attack. Not. Worky. 💪


Protect Your Organization

Shellcode disruption is just ONE layer of Karma-X's protection. We defend against entire classes of attacks at the kernel level.

Whether adversary nation or criminal actors, Karma-X significantly reduces exploitation risk of any organization.

document
Easy Install

From small business to enterprise, Karma-X installs simply and immediately adds peace of mind

shop
Integration Ready

Karma-X doesn't interfere with other software, only malware and exploits, due to its unique design.

time-alarm
Reduce Risk

Whether adversary nation or criminal actors, Karma-X significantly reduces exploitation risk of any organization

office
Updated Regularly

Update to deploy new defensive techniques to suit your organization's needs as they are offered

box-3d-50

Deploy
Karma-X

Get Karma-X!
💬 Ask our AI Assistant Kali