02. The Architecture of Deception

ANALYZING THE HARDWARE & FIRMWARE LOGIC

03. The Brain: Understanding Microcontrollers

A BadUSB device is not a standard flash drive. Inside a standard flash drive, there is a specialized controller dedicated to managing storage memory (NAND Flash). However, inside a BadUSB, there is a general-purpose Microcontroller Unit (MCU) capable of emulation.

The most common chips used in these attacks are the ATtiny85 (found in Digispark) and the ATmega32U4 (found in Arduino Pro Micro and USB Rubber Ducky).

03. මොළය: මයික්‍රොකන්ට්‍රෝලර් තාක්ෂණය
සාමාන්‍ය පෙන් ඩ්‍රයිව් එකක් ඇතුළේ තියෙන්නේ මෙමරි එක (Storage) පාලනය කරන චිප් එකක් විතරයි. ඒත් BadUSB එකක් ඇතුළේ ඊට වඩා බලගතු, අපිට ඕන විදිහට ප්‍රෝග්‍රෑම් කරන්න පුළුවන් "මයික්‍රොකන්ට්‍රෝලර්" (MCU) එකක් තියෙනවා. මේ චිප් එකට පුළුවන් කම්පියුටර් එකට බොරු කියන්න. බහුලවම පාවිච්චි වෙන්නේ ATtiny85 (Digispark එකේ තියෙන චිප් එක) සහ ATmega32U4 (Arduino Pro Micro එකේ තියෙන චිප් එක) යි.

[ ATtiny85 PINOUT DIAGRAM ] +---v---+ PB5 --|1 8|-- VCC (5V) PB3 --|2 7|-- PB2 (SCK) PB4 --|3 6|-- PB1 (MISO) --> [USB DATA-] GND --|4 5|-- PB0 (MOSI) --> [USB DATA+] +-------+ * This tiny 8-pin chip is enough to hack a PC.

04. The Mask: VID & PID Spoofing

How does the computer know what device you plugged in? It checks the ID Card. Every USB device has two crucial numbers:

  • VID (Vendor ID): Who made this device? (e.g., HP, Dell, Logiech).
  • PID (Product ID): What is this device? (e.g., Keyboard, Mouse, Webcam).

BadUSB devices perform "Spoofing" by copying the VID/PID of a legitimate keyboard (e.g., a standard Dell Keyboard). The OS sees a trusted ID and loads the drivers immediately.

04. වෙස් මුහුණ: VID සහ PID වෙනස් කිරීම
කම්පියුටර් එක කොහොමද දැනගන්නේ ඔයා ගැහුවේ මවුස් එකක්ද නැත්නම් පෙන් එකක්ද කියලා? ඒක බලන්නේ අයිඩෙන්ටිටි කාඩ් එකෙන්. USB ඩිවයිස් එකක අංක දෙකක් තියෙනවා:
1. VID (Vendor ID): නිෂ්පාදකයා කවුද? (උදා: Dell, HP).
2. PID (Product ID): භාණ්ඩය මොකක්ද? (උදා: කීබෝඩ් එකක්).

BadUSB එක කරන්නේ මේ අංක දෙක හොරෙන් මාරු කරගන්න එකයි. එයා කම්පියුටර් එකට කියනවා "මම Dell සමාගමේ කීබෝඩ් එකක්" කියලා. එතකොට කම්පියුටර් එක කිසි සැකයක් නැතුව දොර අරිනවා.

Parameter Real Pen Drive BadUSB (Spoofed)
Device Class Mass Storage HID (Keyboard)
VID Example 0x0781 (SanDisk) 0x413C (Dell)
Driver Loaded USBSTOR.SYS KBDHID.SYS
Trust Level Low (Scanned by Antivirus) High (Trusted Input)

05. The Code Injection Logic

Once connected as a keyboard, the microcontroller executes the "Payload". Unlike a human who types at ~60 Words Per Minute (WPM), a BadUSB can inject keystrokes at 1000+ WPM. This speed allows it to open a terminal, type a script, execute it, and close the window before the user blinks.

05. වේගය සහ ප්‍රහාරය
කීබෝඩ් එකක් විදිහට සම්බන්ධ වුණාට පස්සේ, මයික්‍රොකන්ට්‍රෝලර් එක එයාගේ මෙමරි එකේ තියෙන "Payload" එක රන් කරනවා. සාමාන්‍ය මනුස්සයෙක්ට විනාඩියකට වචන 60ක් විතර ටයිප් කරන්න පුළුවන් වුණාට, BadUSB එකකට විනාඩියකට වචන 1000කට වඩා ටයිප් කරන්න පුළුවන්.
ඇහැ පිය ගහන වේගෙන් CMD (Terminal) එක ඕපන් කරලා, හැකින් කමාන්ඩ් එක ගහලා, CMD එක වහලා දාන්න මේකට පුළුවන්.

// SIMPLE ARDUINO HID LOGIC (CONCEPT)
void setup() {
  Keyboard.begin(); // Spoofing starts here
  delay(1000);
  Keyboard.press(KEY_LEFT_GUI); // Windows Key
  Keyboard.press('r');
  Keyboard.releaseAll();
  Keyboard.print("cmd"); // Opening Terminal
  Keyboard.press(KEY_RETURN);
}