Low-Level Writing To NTFS File Systems: Rick Van Gorp
Low-Level Writing To NTFS File Systems: Rick Van Gorp
July 3, 2018
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 1 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Introduction
Research Question
In what way can data be written to an NTFS filesystem, such that hooks in write
operations in Windows are bypassed?
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 2 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Related work
Blackhat USA, Udi Yavo and Tomer Bitton (2016) - Identified security issues in the
Windows hooking methods and described different hooking engines.
1
https://github.com/clymb3r/PowerShell/tree/master/Invoke-NinjaCopy
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 3 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Methods
Research environment:
Windows 10 - Home Edition x64
Windows 7 - Home Edition x64 (Virtualbox and VMWare instance)
Methodology:
Desk research: Gather information regarding the Windows API and NTFS
Static analysis with IDA Free edition: Analyse Windows API user-mode and
kernel-mode
Write experiments: Test whether we can write directly to a raw disk or NTFS
volume
Attempt to verify the found implications
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 4 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
1
IRP = Input Output Request Packet
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 5 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Figure 2: Processing of IRP from the filter driver by storage class driver (Microsoft 20172 )
2
https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/filter-manager-concepts
2
SRB = SCSi Request Block
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 6 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Hooking - User-mode
Listen to or modify the behavior of a process by intercepting an instruction of a
program
3
https://userpc.net/wp-content/uploads/2017/12/InlineHook.png
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 7 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Hooking - Kernel-mode
System Service Dispatch Table: Replace pointers for Nt-functions with pointers to
own code.
IRP Major Function: Driver object contains function pointers, that are called from
other drivers through IoCallDriver. Other drivers could replace those pointers to
its own functions.
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 8 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Log, monitor, modify or prevent I/O operations related to the file system.
Priority controlled by altitudes: Multiple Endpoint security companies are
registered with Microsoft 4 .
Figure 4: Simplified I/O Stack with filter manager en three filter drivers (Microsoft, 2017 5 )
4
https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/allocated-altitudes
5
https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/filter-manager-concepts
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 9 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Attempt to write to NTFS boot sector, Master File Table and file system space
Experiment 1
Experiment 2
Experiment 3
Kernel-mode driver6 : Write directly to storage class driver with IRP_MJ_WRITE and
flag SL_FORCE_DIRECT_WRITE.
6
https://github.com/rickvg/low-level-ntfs
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 10 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 11 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
SATA & IDE: Invalid SCSI block request: No proper translation between IRP and
SRB.
Possible solution: Communicate with storage port drivers directly using own SRBs.
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 12 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Open a read handle to the raw disk and read its contents
Locate the NTFS volume: Identified by hex-string EB 52 90 4E 54 46 53
Parse the boot sector to identify the location of the Master File Table
Parse the Master File Table (MFT) to locate the data in the volume using data runs
Overwrite the file data at the location specified
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 13 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Data in table 4 resides in the BPB-section7 of the boot sector, starting at offset 0xB
7
Bios Parameter Block
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 14 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 15 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
First four bytes: Attribute type (30 00 00 00 for filename) (80 00 00 00 for data)
Attribute contains resident or non-resident header
If attribute does not match: Get attribute length at offset 0x4 and skip attribute
8
Logical Cluster Number
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 16 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Discussion
Access to raw disk, without communicating to the file system driver, results in
bypass of NTFS permissions: Write data to any file on the system.
Endpoint security software that blocks write operations at minifilter driver level can
be bypassed in that function, since the IRP does not pass the minifilter driver.
Malicious code can be written to any location on the disk.
9
https://github.com/hfiref0x/DSEFix
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 17 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Conclusion
From user-mode: the location pointer to the Master File table can be changed
using write handle to volume
From kernel-mode: Raw write access to the disk is possible by building an IRP.
Bypass NTFS Access lists
Bypass Endpoint security that operates at minifilter driver level
Bypass software hooks on write operations higher than the storage class layer
SL_FORCE_DIRECT_WRITE flag must be set.
User-mode application could send data to the driver to write
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 18 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Future work
Research lower level methods that directly communicate with the storage port
drivers. Requires specific commands for ATA and IDE based harddisks.
Verify whether the writing methods bypass Endpoint security solutions that might
be hooked to write-related functions on a lower level than storage class.
Research new techniques for loading unsigned kernel mode drivers or methods
that use vulnerabilities in already signed drivers to communicate with the storage
drivers.
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 19 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
1 2 3 4 5 6
Regular write 3 3 3 3 3 3
Loading driver 7 7 7 7 7 7
Communication with driver 7 7 7 7 7 7
DSEFix activity 7 7 7 7 7 3
Write from kernel driver to disk 7 7 7 7 7 7
Table 7: Detection of writing malicious code to the disk by Internet Security solutions from user-mode and kernel-
mode
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 19 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 19 / 19
Introduction Related work Methods Windows API Hooking Write experiments Writing to files Discussion & Conclusion Future work
To be verified:
Bypass Windows audit logs on important change or addition events?
Manipulate evidence by unnoticed writes?
Rick van Gorp University of Amsterdam Low-level writing to NTFS file systems July 3, 2018 19 / 19