我玩了几天。我们可以从 IE 中获取 hwnd,但不能获取 PID。所以我能看到将 HWnd 与 PID 匹配的唯一方法是调用 Win32API 调用。那么如何在 VBS 中做到这一点。
所有计算机都安装了 4 个 VB.NET 编译器。所以我们需要做的就是编写一个包装GetWindowThreadProcessId的com服务器。
在您的脚本中,将以下行写入文本文件。我为此重新使用了不同的脚本,所以方法名称很愚蠢。
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.Net.Mail
Namespace SendMail
<Guid("85B4AD6D-2E89-4869-9BBC-69E42738FCFC"), _
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface _SendMail
<DispId(1)> Function Send(ByVal hWnd As Integer) As Integer
End Interface
<Guid("C91EDEB2-3756-4893-905B-0E4E2150C7FD"), _
ClassInterface(ClassInterfaceType.None), _
ProgId("Scripting.SendMail")> Public Class SendMail
Implements _SendMail
Public SendMail()
Public Declare Auto Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
Public Function Send(HWnd as Integer) As Integer Implements _SendMail.Send
Dim X as Integer
Dim M as Integer
M=1
X=GetWindowThreadProcessID(HWnd,M)
msgbox(X & " " & M & " " & HWnd & " " & Err.LastDllError)
Send = M
End Function
End Class
End Namespace
然后编译WSHShell。运行以下命令隐藏修复路径。
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:library /out:"%userprofile%\desktop\sendmail\sendmail.dll" "%userprofile%\desktop\sendmail\sendmail.cls" /verbose
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm" /codebase "%userprofile%\desktop\sendmail\sendmail.dll" /tlb:"%userprofile%\desktop\sendmail\sendmail.tlb" /v
然后在脚本中使用
Set x = CreateObject("Scripting.SendMail")
Msgbox x.Send(&h1a013e)
现在我已经生成了 GUID 用于动态创建 com 对象。因为它们现在是公共代码,所以您(以及任何其他复制此代码的人)必须销毁脚本中的对象。使用 /u 运行 Regasm 命令。或者生成新的 GUID。