Access 2000 資料庫密碼保護極脆弱,一小段 VB6 程式即可破解。本文深入分析破解原理並提供兩層防護對策。
破解程式核心:比對「空白資料庫」與「加密資料庫」在位移 &H43 處的差異。Access 2000 僅使用資料庫建立日期 作為加密金鑰(每字元 2 位元組,最長 20 字元)。
' 破解程式關鍵片段
Const Offset = &H43
For i = 1 To 20
Get #1, , bEmpty ' 空白資料庫
Get #2, , bPass ' 加密資料庫
If (bEmpty(1) Xor bPass(1)) <> 0 Then
Password = Password + Chr(bEmpty(1) Xor bPass(1))
End If
Next
關鍵發現:加密金鑰 = 資料庫內部記錄的「建立日期」(非檔案系統日期)。兩者通常相同,故破解者可用檔案系統日期作為初始嘗試。
SetFileTime 將檔案建立日期偽裝為普通日期(如 2001/03/13)。' VB6 修改檔案建立日期程式 Private Type FILETIME: dwLowDateTime As Long: dwHighDateTime As Long: End Type Private Type SYSTEMTIME: wYear As Integer: wMonth As Integer: wDayOfWeek As Integer: wDay As Integer wHour As Integer: wMinute As Integer: wSecond As Integer: wMilliseconds As Integer: End Type Private Declare Function SetFileTime Lib "kernel32" Alias "SetFileTime" _ (ByVal hFile As Long, lpCreationTime As FILETIME, ByVal lpLastAccessTime As Long, ByVal lpLastWriteTime As Long) As Long Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _ (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _ ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _ ByVal hTemplateFile As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long Function ModifyFileStamp(Filename As String, TimeStamp As Variant) As Integer Dim X As Long, Handle As Long, System_Time As SYSTEMTIME Dim File_Time As FILETIME, Local_Time As FILETIME System_Time.wYear = Year(TimeStamp): System_Time.wMonth = Month(TimeStamp) System_Time.wDay = Day(TimeStamp): System_Time.wDayOfWeek = Weekday(TimeStamp) - 1 System_Time.wHour = Hour(TimeStamp): System_Time.wMinute = Minute(TimeStamp) System_Time.wSecond = Second(TimeStamp): System_Time.wMilliseconds = 0 X = SystemTimeToFileTime(System_Time, Local_Time) X = LocalFileTimeToFileTime(Local_Time, File_Time) Handle = CreateFile(Filename, &H40000000, &H1 Or &H2, ByVal 0&, 3, 0, 0) X = SetFileTime(Handle, File_Time, ByVal 0&, ByVal 0&) CloseHandle Handle End Function
效果:破解者需嘗試大量日期組合,若真實與偽裝日期相差百年,需數萬次嘗試,大幅提高破解成本。
透過「安全性精靈」建立工作群組檔案 (MDW)、使用者/群組帳號、指派物件權限。雖增加使用不便(需登入),但提供真正的權限控管,非密碼可比擬。
「道高一尺魔高一丈」,無絕對安全。方法一提高破解成本,方法二增加保護層次,兩者結合足阻絕大多數攻擊。建立安全意識,防患未然,才是正確選擇。