Hibernation File Attack Presentation
Hibernation File Attack Presentation
About me
Training: Hibernation File, Page File Lunch Training: Attacking the Hibernation File
Topics: Hibernation File, Page File, gathering information from them and attacking them, including bootkit possibilities
S4
When hibernating, the system stores everything to the hibernation file and enters S4.
4
Stores entire physical RAM based in pages, is at least 50% size of memory pre-allocated. powercfg h on|off to activate/deactivate Shutdown /h to hibernate (or Start -> Hibernate)
Important! Hibernation is an ACPI state! Thus our BIOS wants to boot original OS and does not provide the BIOS setup or menu.
Windows, however, checks only signature in hibernation file. The contents is by default not cleared.
Escaping from S4 Why? - To analyze an original hibernated hiberfil.sys. How? 1. Pressing the power button for more than 3 seconds -> G3 2. Restarting system in BIOS through Ctrl + Alt + Entf -> G2 Windows does not care if started in S4, G2 or G3, it always checks the hibernation file signature. The BIOS cares, it wont let start us from another device.
Windows Vista/7: New Hybrid Sleep state Hybrid sleep saves the OS state into RAM, but it also writes it all to the hard drive as well (sort of like hibernate does). This ensures that even if power is lost, the data will remain. [2] The computer uses the Hiberfil.sys file to store a copy of the system memory on the hard disk when the hybrid sleep setting is turned on. We can analyze RAM at time of Hybrid Sleep
Encryption (1) Bitlocker always supported it (Microsoft) TrueCrypt [3], back in 2008:
* Disclaimer: As Microsoft does not provide any API for handling hibernation, non-Microsoft developers of disk encryption software are forced to modify undocumented components of Windows in order to allow users to encrypt hibernation files. Therefore, no disk encryption software (except for Microsoft's BitLocker) can currently guarantee that hibernation files will always be encrypted. At anytime, Microsoft can arbitrarily modify components of Windows (using the Auto Update feature of Windows) that are not publicly documented or accessible via a public API. Any such change, or the use of an untypical or custom storage device driver, may cause any non-Microsoft disk encryption software to fail to encrypt the hibernation file. Note: We plan to file a complaint with Microsoft (and if rejected, with the European Commission) about this issue, also due to the fact that Microsoft's disk encryption software, BitLocker, is not disadvantaged by this.
10
Encryption (2)
[Update 2008-04-02: Although we have not filed any complaint with Microsoft yet, we were contacted (on March 27) by Scott Field, a lead Architect in the Windows Client Operating System Division at Microsoft, who stated that he would like to investigate our requirements and look at possible solutions. We responded on March 31 providing details of the issues and suggested solutions.] [Update 2009-05-10: Since April 2008, we have been working with Microsoft to explore possible ways to solve this issue. We have private access to a draft version of a document specifying the future API, which should allow us to solve the issue on Windows Vista and later versions of Windows. Note: We have been asked not to disclose the content of the document to any third parties, so please do not ask us to send you a copy of the document.] Current status: TrueCrypt works with hibernation under Vista and 7.
11
Pagefile
When the system is hibernated, the pagefile is still valid!
We also have to care about the page file
12
You can simply read or modify these files when the OS is not active.
Live demo!
13
Pagefile Attack
Black Hat USA 2006 Subverting Vista Kernel By Joanna Rutkowska and Alexander Tereshkin I met Alex in a taxi cab in Las Vegas! In Vista RC1 they overwrote pages in the pagefile through raw sector access. CreateFile(\\.\C:) - handle to partition CreateFile(\\.\PHYSICALDRIVE0)) - handle to entire disk
With Vista RC2 Microsoft prevents all write access to mounted partitions.
Live demo!
14
If
fSuspend = false, then the system hibernates. Requires SE_SHUTDOWN_NAME privileges. Marked as deprecated, SetSuspendState should be used instead.
PowrProf.dll
BOOLEAN __in __in __in ); WINAPI SetSuspendState( BOOLEAN Hibernate, BOOLEAN ForceCritical, BOOLEAN DisableWakeEvent
16
17
The file is organized as pages (4 KB). The header contains in the first 4 bytes a signature:
HIBR WAKE
0000h
Active hibernation file, system shall process resume from hibernation Inactive hibernation file, system shall ask user
Successful restoration (entire first page is cleared)
18
Wake signature
Live demo!
19
20
Each table (except the last) contains 255 entries. The checksum is unused. Each entry describes a physical range of pages:
struct MEMORY_TABLE_ENTRY { UINT32 PageCompressedData; UINT32 PhysicalStartPage; UINT32 PhysicalEndPage; DWORD CheckSum; };
These two structures are not exported as symbols and are different in 7.
21
Live demo!
22
Live demo!
23
Live demo!
24
Vista Signature ImageType CheckSum LengthSelf = 240 PageSelf PageSize SystemTime InterruptTime FeatureFlags HiberFlags Spare NoHiberPtes Signature ImageType Checksum
Signature
LengthSelf =224 PageSelf PageSize SystemTime InterruptTime FeatureFlags HiberFlags Spare NoHiberPtes
25
PerfInfo
PerfInfo
27
Other OS differences
Windows 2000
Different compression algorithm: LZNT1, internal function XpressEncode() according to Matthieu Suiche [7]
Uses checksums? With XP the checksums (except in the header) are all set to zero. Windows 7 Different structure for Memory Tables. Use the LengthSelf field in the header to determine the operating system: 168 = XP, 240 = Vista, 224 = 7
28
29
References
[1] Frontpage picture by Ela2007 http://www.flickr.com/photos/64479867@N00/523730762 [2] Hybrid Sleep State http://www.howtogeek.com/howto/windows-vista/disable-hybrid-sleep-mode/
[3] TrueCrypt about the Hibernation File http://www.truecrypt.org/docs/?s=hibernation-file [4] Clear virtual memory pagefile when system shuts down http://msdn.microsoft.com/en-us/library/ms814147.aspx [5] Pagefile Attack (french) http://www.ivanlef0u.tuxfamily.org/?p=77
[6] Null Device Driver http://msdn.microsoft.com/en-us/library/aa939249(WinEmbedded.5).aspx [7] Matthieu Suiche, Windows hibernation file for fun n profit http://msuiche.net/con/bhusa2008/Windows_hibernation_file_for_fun_'n'_profit-0.6.pdf
30