Showing posts with label kernel. Show all posts
Showing posts with label kernel. Show all posts

Sunday, May 16, 2010

Kernel: Finding drivers that are not digitally signed

Problem Statement:
Finding drivers on a user system that are not digitally signed.

Solution:
Windows provides a tool that hist the nail on its head. File Signature Verification Tool by Windows helps the user to find files that are not digitally signed. Since we are interested in drivers, we could target a folder C:\Windows\System32\drivers and find all the driver (.sys) files that are not digitally signed.

Using File Signature Verification Tool:


StartUp:
1. Goto Start->Run.
2. Type in sigverif. This will start the tool (sigverif.exe) and a file signature
verification window pops-up.

Searching Options:
User can search files of specified extensions in a specified folder.
- Check the option that says "Lokk for other files that are not digitally signed"
Under Serach Options:
- Select the file type that can be used for scanning. (like *.sys, *.dll or*.*)
- Select the folder "Look in this folder" option by browsing to the location.
- Check "Include subfolders" for recursive directory listing.

Logging Options:
User can configure the logging options as follows:
- Check the "Save the file signature verification results to a log file"
Under logging options:
- Select "Append/Overwrite existing log file" to either append the results of differents tests in a log file or overwrite the log file for a new test that's triggered every time.
- Log file name: Mention the log file name with appropriate path. Note: Pathnames need not to have (\\) as escape sequences.

Running the tool:
After configuring the tool. click OK and press Start. The tool now starts scanning all the files in all the configured folders to find all the files matching the configuration criterion that are not digitally signed.

Report:
A report of the test is genetated in a log file (configured by user in logging options) that gibes information on:
- Files that are scanned with the folder structure path.
- Files that are digitally signed with information on:
* File Modified date.
* File Version Information, if available.
* Catalog file information in which the file can be found.
* Signing Authority.
- Files that could not be scanned.


Case Study:
Let's say we want to find all the drivers present in C:\Windows\System32\drivers folders and check if they are digitally signed or not. Here are some snapshots that depict the configuration required.

System Specs:
Running the test on WINXP SP3 32 bit system.
2 GB RAM and 320 GB HDD.

Searching Options:



Logging Options:



We have now configured the tool check:
- All the driver files
- Under C:\Windows\System32\drivers folder
- Log the results in SIGVERIF.TXT file.
- Running the tool would yield the results on a UI (in case of files that are not digitally signed) and in the log file.

Results of case Study:
While running the test for the case study, it found some drivers on my laptop that were not digitally signed. Here's a snapshot depicting the unsigned driver files.


Contents of SIGVERIF.TXT Log File:
********************************

Microsoft Signature Verification

Log file generated on 5/17/2010 at 9:59 AM
OS Platform: Windows 2000 (x86), Version: 5.1, Build: 2600, CSDVersion: Service Pack 3
Scan Results: Total Files: 237, Signed: 229, Unsigned: 7, Not Scanned: 1

User-specified search path: *.*
User-specified search pattern: C:\WINDOWS\system32\drivers

File Modified Version Status Catalog Signed By
------------------ ------------ ----------- ------------ ----------- -------------------
[c:\windows\system32\drivers]
1028_dell_lat_d820.m 2/25/2009 None Not Signed N/A
1394bus.sys 4/14/2008 2:5.1 Signed NT5.CAT Microsoft Windows Component Publisher
acpi.sys 4/14/2008 2:5.1 Signed NT5.CAT Microsoft Windows Component Publisher
acpiec.sys 4/14/2008 2:5.1 Signed NT5.CAT Microsoft Windows Component Publisher
aec.sys 4/13/2008 2:5.1 Signed NT5.CAT Microsoft Windows Component Publisher
aegisp.sys 2/25/2009 3.4.9.0 Not Signed N/A
afd.sys 8/14/2008 2:5.1 Signed KB956803.cat Microsoft Windows Component Publisher

Unscanned Files:
------------------
[c:\windows\system32\drivers]
sptd.sys The process cannot access the file because it is being used by another process.

Thus the user gets the information on all the Digitally Signed and Unsigned driver files.

Kernel: Finding drivers loaded on user system

Problem Statement:
Find all the drivers that are loaded on user system and get the information pertaining to code, initialiazed and un- initialiazed static data and driver paging.

Solution:
Drivers.exe, a tool from WinDDK helps the user in finding all the drivres that are loaded on user system.

Drivers tool can be found at C:\winddk\7600.16385.1\tools\Other\i386 location of Winddk once the kit is installed on your system.

Using the tool:
1. Go to the command prompt.
2. Browse to the location where drivers.exe is present.
3. Run the command: "drivers.exe >> C:\report.txt"

This will save the information on all the drivers that were loaded on the user system on the harddisk location C:\report.txt.

Information obtained from the tool:
ModuleName: Represents the driver filename.
Code: Indicates the non-paged code in the driver file in bytes.
Data: Represents the initialiazed static data of the driver file in bytes.
BSS: Un-initialized static data in the image. Generally initialized to 0 or NULL.
Paged: Represets the data that is paged by the driver, in Bytes.
Init: Indicates the data that is not needed after the driver is initialized. Represented inBytes.
LinkDate: Its the date when the driver was linked.

Drivers.exe Output:
------------------------------------------------------------------------------
ModuleName Code Data Bss Paged Init LinkDate
------------------------------------------------------------------------------
ntkrnlpa.exe 479232 106496 0 1183744 180224 Tue Feb 16 18:55:00 2010
hal.dll 35968 42496 0 30976 15488 Mon Apr 14 00:01:27 2008
KDCOM.DLL 2560 256 0 1280 512 Sat Aug 18 02:19:10 2001
BOOTVID.dll 5632 3584 0 0 512 Sat Aug 18 02:19:09 2001


Tool Utility:
1. The tool can be used to identify if a particular driver is loaded on the user system.
2. Could verify if a driver loads on different operating systems and in different modes like Normal or Safe operating modes.
3. User can run the tool twice with in specified time frame and compare the results to check if there are any issues loading a driver under test.

Supported OS:
I have used the tool on the following platforms and it works fine.
- WINXP SP3 x32
- WIN 7 Ultimate x32