homepage
Open menu Go one level top
  • Train and Certify
    • Get Started in Cyber
    • Courses & Certifications
    • Training Roadmap
    • Search For Training
    • Online Training
    • OnDemand
    • Live Training
    • Summits
    • Cyber Ranges
    • College Degrees & Certificates
    • NICE Framework
    • DoDD 8140
    • Specials
  • Manage Your Team
    • Overview
    • Security Awareness Training
    • Voucher Program
    • Private Training
    • Workforce Development
    • Skill Assessments
    • Hiring Opportunities
  • Resources
    • Overview
    • Reading Room
    • Webcasts
    • Newsletters
    • Blog
    • Tip of The Day
    • Posters
    • Top 25 Programming Errors
    • The Critical Security Controls
    • Security Policy Project
    • Critical Vulnerability Recaps
    • Affiliate Directory
  • Focus Areas
    • Blue Team Operations
    • Cloud Security
    • Digital Forensics & Incident Response
    • Industrial Control Systems
    • Leadership
    • Offensive Operations
  • Get Involved
    • Overview
    • SANS Community
    • CyberTalent
    • Work Study
    • Instructor Development
    • Sponsorship Opportunities
    • COINS
  • About
    • About SANS
    • Why SANS?
    • Instructors
    • Cybersecurity Innovation Awards
    • Contact
    • Frequently Asked Questions
    • Customer Reviews
    • Press Room
    • PGP Key
  • Log In
  • Join
  • Contact Us
  • SANS Sites
    • GIAC Security Certifications
    • Internet Storm Center
    • SANS Technology Institute
    • Security Awareness Training
  • Search
  1. Home >
  2. Blog >
  3. De-mystifying Defrag: Identifying When Defrag Has Been Used for Anti-Forensics (Part 1 - Windows XP)
370x370_Chad-Tilbury.jpg
Chad Tilbury

De-mystifying Defrag: Identifying When Defrag Has Been Used for Anti-Forensics (Part 1 - Windows XP)

August 5, 2009

I have seen the following Windows Prefetch entries in nearly every Windows XP / Vista machine that I have reviewed over the past several years.Their existence always reminds me of the imperfect nature of information gained via individual artifacts.Does this mean that a user ran the Microsoft Defragmenter application on July 16, 2009 at 1:19PM?Or was the defragmenter started automatically by Windows?The defragmenter tool has been used very effectively as an anti-forensic tool since it was first introduced.In cases where data spoliation could be important, it is critical for the examiner to be able to identify any overt actions by a user.Complicating this is that starting with Windows XP, the operating system conducts limited defragmentation approximately every three days. [1] This post seeks to identify forensic artifacts which can help us determine if a user initiated the defrag application.

Figure_1
Figure 1: Defrag entries in C:\Windows\Prefetch directory

We will focus on two primary methods a user can invoke the Windows Defragmenter tool:

  1. Running defragmenter from a graphical user interface (GUI)
  2. Running defrag from the command line using defrag.exe

Defragmenter Artifacts in Windows XP — Identifying GUI Usage

The GUI defragmenter tool leaves a wealth of artifacts that can distinguish user execution of defrag from system execution.It is commonly accessed from the Start Menu -> Accessories -> System Tools menu.We will query the following artifacts to identify user actions:

  1. Prefetch Entries
  2. UserAssist Registry Key
  3. Registry MMC Recent File list
  4. File Access Timestamps

Prefetch Entries

The addition of Windows Prefetch in XP has provided investigators with an excellent artifact for identifying applications executed on a system.While it won't give us everything we need in this situation, it is an excellent starting point.Entries are located in the C:\Windows\Prefetch directory and can be parsed using Mark McKinnon's Prefetch Parser or your favorite forensic suite.

When the defragmenter is run using the GUI, only the dfrgntfs.exe entry is updated within the Prefetch directory (with an updated access time stamp and execution count).This immediately reveals that the artifacts shown in Figure 1 were not left by the GUI tool.It may also explain why we often see higher execution counts for dfrgntfs.exe than defrag.exe when parsing the Prefetch entries.As an aside, it is interesting to note that I found differences in how the execution count was updated.When using the GUI, the execution value for dfrgntfs.exe was incremented by one and when using the command line application, the counts were incremented by three.

Since the GUI version of the defragmenter is essentially a Microsoft Management Console (MMC) snap-in, an entry for MMC.exe is also created in the Prefetch folder.It is important to note that MMC.exe can be present in the Prefetch due to the use of other snap-ins (such as viewing the event logs).Its proximity to the dfrgntfs.exe entry is one clue, but Prefetch files can also show what was loaded by the application, and further investigation reveals that dfrgres.dll and dfrgui.dll are both loaded by MMC.exe whenever it facilitates the defragmenter snap-in.

Figure_2
Figure 2: Prefetch entries indicating the GUI defragmenter tool was run

UserAssist Registry Key

Prefetch can indicate that the GUI application was run, but it gives no information regarding user attribution.Luckily we have an artifact available in the NTUSER.dat hive file that does both.The UserAssist registry key, HKCU\Software\Microsoft\Windows\Currentversion\Explorer\UserAssist\{GUID}\Count, stores information on applications run per user.This is a terrific artifact for proving user activity and can be easily viewed using UserAssist.exe written by Didier Stevens.Evidence of manual execution can be found within this registry key when the defragmenter is accessed via the GUI interface.You should be looking for entries for "Disk Defragmenter.lnk" and "mmc.exe".The "Last" time indicates when the application was last run by the user.One unfortunate limitation of this artifact is that applications run from the command line are not recorded.

Figure_3
Figure 3: Using UserAssist.exe to parse the registry values

Registry MMC Recent File List

Since we know that the MMC is utilized by the defragmenter GUI, there is an additional registry artifact dedicated to recording MMC usage.Looking at HKCU\Software\Microsoft\Microsoft Management Console\Recent File List, we should see an entry for dfrg.msc, which is the Microsoft Common Console file for the defragmenter snap-in.If this is the last value recorded, the key last write time will indicate when the defragmenter was last run.Additionally, note that this registry key is under HKey_Current_User (NTUSER.dat hive), giving us another artifact for proving user attribution.

Figure_4
Figure 4: MMC Recent File List reviewed using regedit.exe

File Access Timestamps

Finally, we can tie everything together neatly by doing a timestamp analysis.The access timestamps for the following files indicate when these files were last run.Any mismatch with the times indicated in the Prefetch and UserAssist artifacts can tell us if there was any additional defrag activity after the GUI was run:

  • C:\Windows\System32\Dfrgntfs.exe
  • C:\Windows\System32\Dfrg.msc
  • C:\Documents and Settings\All Users\Start Menu\Programs\Accessories\SystemTools\Disk Defragmenter.lnk

Defragmenter Artifacts in Windows XP — Identifying Command Line Usage

In contrast to our investigation of artifacts generated by the GUI interface, command line use of the defrag tool gives us much fewer artifacts to work with.We will be required to focus on:

  1. Prefetch entries (including timestamps)
  2. Timeline analysis of contemporaneous events
  3. Layout.ini
Figure_5
Figure 5: Example of running defrag.exe from the XP command line

Prefetch Entries

Unlike the artifacts for the GUI defragmenter, the Prefetch artifacts left by command line execution of defrag.exe are the same as those left by the Windows automated process.Upon command line execution both defrag.exe and dfrgntfs.exe are created in the Prefetch directory.Further, their last access times are updated to the time the application was run.This tells us when the defrag tool was last run, but does not allow us to differentiate between system defrags and user generated activity.Therefore we will need to turn to timeline analysis.

Timeline Analysis

With very limited artifacts, old fashioned timeline analysis will likely be our best bet to identify user defrag activity.This is not a theoretical exercise.We have seen instances of the defrag tool used as an anti-forensics tool in recent intrusion cases.Often this plays out with the intruder installing their payload on the system, deleting it, and then running defrag.exe to prevent the malware from being recovered by incident responders.

Figure_6
Figure 6: Sorting Prefetch entries by last accessed time and reviewing nearby applications

In this situation we will often be looking for the opening of a command shell (cmd.exe) near the time that defrag.exe was run.This is a key differentiator since Windows does not require an interactive command shell when kicking off automated processes.Figure 6 shows how this might look in the Prefetch directory.In addition to just Prefetch entries, other timeline entries like created and deleted files can provide further context.Admittedly, this evidence is very temporal and presumes that collection occurs as close a possible to the time the intrusion occurred.

Layout.ini

The layout.ini file is located in the C:\Windows\Prefetch directory and is used by the Prefetch process to more efficiently place system and frequently used applications during the limited defrag sequence.It is not used during a standard manual defragmentation.Therefore it can be a good indicator for distinguishing between user and system actions.In the example shown in Figure 7, the modification time of the layout.ini coincides with the defrag applications and indicates that they were run by the operating system (not the user).

A Note Regarding Event Logs

In Windows XP, there is no native capability to record defragmenter usage in the event logs.[2]Thus we will not be able to leverage this source of information as we could for other actions like task scheduler usage.

Conclusion

We stand our best chance of tying defragmenter execution to a user account if it was conducted via the GUI interface.Many of our most valuable Windows artifacts are not updated when an application is run from the command line.However, we will often be able to turn to old-fashioned timeline analysis to assist in these circumstances.

It should be noted that there are plenty of legitimate reasons for running the defragmenter tool.Other contemporaneous actions need to be reviewed to assess a user's true intent.

The Vista operating system changes many of the artifacts covered in this post.Part 2 will cover performing this analysis on a Vista system.

References

  1. http://msdn.microsoft.com/en-us/magazine/cc302206.aspx
  2. http://support.microsoft.com/kb/294743

Chad Tilbury, GCFA, has spent over ten years conducting computer crime investigations ranging from hacking to espionage to multi-million dollar fraud cases. He teaches FOR408 Windows Forensics and FOR508 Advanced Computer Forensic Analysis and Incident Response for the SANS Institute. Find him on Twitter @chadtilbury or at http://ForensicMethods.com.

Share:
TwitterLinkedInFacebook
Copy url Url was copied to clipboard
Subscribe to SANS Newsletters
Join the SANS Community to receive the latest curated cybersecurity news, vulnerabilities, and mitigations, training opportunities, plus our webcast schedule.
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kingdom of Saudi Arabia
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia (Slovak Republic)
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Swaziland
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Yugoslavia
Zambia
Zimbabwe

Tags:
  • Digital Forensics and Incident Response

Related Content

Blog
Digital Forensics and Incident Response
January 7, 2021
How You Can Start Learning Malware Analysis
Lenny Zeltser shares a roadmap for getting into malware analysis, with pointers to 10 hours of free recorded content and additional references.
370x370_Lenny-Zeltser.jpg
Lenny Zeltser
read more
Blog
Digital Forensics and Incident Response
September 26, 2019
The State of Malware Analysis: Advice from the Trenches
What malware analysis approaches work well? Which don’t? How are the tools and methodologies evolving? The following discussion–captured as an MP3 audio file–offers friendly advice from 5 malware analysts. These are some of the practitioners who teach the reverse-engineering malware course...
370x370_Lenny-Zeltser.jpg
Lenny Zeltser
read more
Blog
Digital Forensics and Incident Response
September 13, 2017
4 Cheat Sheets for Malware Analysis
What tools can assess a suspicious RTF file? How to deobfuscate a JavaScript attachment? Where to set breakpoints for unpacking a malicious executable? What utilities can intercept C2 traffic in the lab? How do the various reverse-engineering methods fit together? So much to remember! I created 4...
370x370_Lenny-Zeltser.jpg
Lenny Zeltser
read more
  • Register to Learn
  • Courses
  • Certifications
  • Degree Programs
  • Cyber Ranges
  • Job Tools
  • Security Policy Project
  • Posters
  • The Critical Security Controls
  • Focus Areas
  • Blue Team Operations
  • Cloud Security
  • Cybersecurity Leadership
  • Digital Forensics
  • Industrial Control Systems
  • Offensive Operations
Subscribe to SANS Newsletters
Join the SANS Community to receive the latest curated cybersecurity news, vulnerabilities, and mitigations, training opportunities, plus our webcast schedule.
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kingdom of Saudi Arabia
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia (Slovak Republic)
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Swaziland
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Yugoslavia
Zambia
Zimbabwe
  • © 2021 SANS™ Institute
  • Privacy Policy
  • Contact
  • Twitter
  • Facebook
  • Youtube
  • LinkedIn