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
  • 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. Tools for Examining XOR Obfuscation for Malware Analysis
370x370_Lenny-Zeltser.jpg
Lenny Zeltser

Tools for Examining XOR Obfuscation for Malware Analysis

May 14, 2013

There are numerous ways of concealing sensitive data and code within malicious files and programs. Fortunately, attackers use one particular XOR-based technique very frequently, because offers sufficient protection and is simple to implement. Here's a look at several tools for deobfuscating XOR-encoded data during static malware analysis. We'll cover XORSearch, XORStrings, xorBruteForcer, brutexor and NoMoreXOR.

The XOR-based approach to obfuscating contents often works like this:

  1. The attacker picks a 1-byte value to act as the key. The possible key values range from 0 to 255 (in decimal).
  2. The attacker's code iterates through every byte of the data that needs to be encoded, XOR'ing each byte with the selected key.

Sometimes, attackers pick longer keys and use variations of the technique above. However, this particular algorithm is so common, that it's worth knowing how to locate and decode contents encoded using this method.

To deobfuscate the protected string, the attacker's code repeats step #2, this time XOR'ing each byte in the encoded string with the key value.

XORSearch

XORSearch by Didier Stevens examines the file's contents, looking for contents encoded using the XOR-based algorithm outlined above as well as several other commonly-used algorithms. For XOR, the tool brute-forces all possible one-byte key values. However, you need to know what string you are looking for before you can find it. One good value to look for is "http", because attackers often wish to conceal URLs within malicious code. Another good string might be "This program", because that might identify an embedded XOR-encoded Windows executable, which typically has the string "This program cannot be run in DOS mode" in its header.

Furthermore, you can direct XORSearch to attempt decoding all strings within the file using the discovered key. In the example below, XORSearch discovered the string "http:" encoded in the executable using XOR key 0x05 in the file hubert.dll. It then decoded all bytes in the file using this XOR key, generating the file hubert.dll.XOR.05. If you look at this file using a hex editor, you can locate several decoded strings for assessing the nature of the malicious file.

image.png

XORStrings

XORStrings by Didier Stevens builds upon the capabilities of XORSearch to count the strings decoded using all applicable key values. An analyst can use XORStrings to determine which key to try based on the analytics that the tool presents. These include the number of strings found, average string length and maximum string length for every key. For instance, a key that decoded the largest number of possible strings beyond a certain average length might be worth investigating further. Though this approach doesn't work well for the example mentioned above (hubert.dll), it is worth considering for other situations.

image.png

xorBruteForcer

xorBruteForcer by Jose Miguel Esparza decodes contents of a given file using all possible 1-byte XOR key values. The resulting output is highly voluminous; however, it provides the analyst with data to examine without knowing what obfuscated string to look for in advance. xorBruteForcer can also examine the file for a specific string and can decode the file's contents using a specified XOR key, rather than brute-forcing key values.

In the example below, I used xorBruteForcer to decode contents of hubert.dll using all possible 1-byte XOR key values, extracting ASCII strings from the output and saving the result in file hubert.dll.XOR.strings.

xorbruteforcer.png

The output of the tool contains lots of noise, xorBruteForcer shows potential string values for all possible 1-byte XOR key values. I scrolled past the meaningless strings and eventually arrived at meaningful English text. Above the text the tool included the tag "[0x5]", indicating that these strings were obfuscated using XOR key 0x5.

brutexor

brutexor (sometimes called iheartxor) by Alexander Hanel brute-forces all possible 1-byte XOR key values and examines the file for strings that might have been encoded with these keys.

The brutexor tool provides a handy way to brute-force simple XOR keys without looking for any particular string. In this, it is similar to xorBruteForcer. However, the output of brutexor is less noisy than that of xorBruteForcer, because brutexor only shows ASCII data located between null bytes ("\x00") by default. , Still, the tool's output contains plenty of noise in the form of false positives.

Consider the malicious file hubert.dll. Scanning it with brutexor produces lots of strings. In this example, I saved them to file hubert.XOR.strings. Some of these strings correspond to actual English text. The tool's output indicates that this text was encoded in hubert.dll using XOR key 0x5.

The hubert.XOR.strings file is relatively noisy, because it includes strings that brutexor attempted to decode with other (ultimately invalid) XOR keys. If you'd like to focus only on the strings obfuscated with XOR key 0x5, you can examine hubert.dll with brutexor again, this time telling the tool to use the this particular key.

image.png

NoMoreXOR

NoMoreXOR by Glenn Edwards attempts to guess XOR 256-byte long XOR key values. It uses Yara signatures to determine whether a potential key value worked: If the decoded content matches one of the signatures in you file, then probably the key was guessed correctly. In that case, the tool deobfuscates corresponding contents and extracts them from the original file.

You can create your own Yara signatures file to determine contents that you want NoMoreXOR to look for, such as Michael Hale's capabilities.yara file.

A good way to get started with NoMoreXOR is to review an example that its author published on his blog in early 2013. That article explains how the tool works and walks you through several analysis workflow options.

For instance, consider a malicious Microsoft Word document pear.doc. Examining this .doc file would reveal that it contains an embedded Flash program. You could extract it using xxxswf by Alexander Hanel; you could use swfdump to decode contents of the embedded SWF file and locate embedded shellcode.

If you scanned pear.doc using NoMoreXOR, you would notice that it contains contents encoded using a 256-byte-long XOR key that starts with "c4c5c6c7". As you can see below, NoMoreXOR guessed several possible key values, and decided to use this particular key because the decoded contents matched the Yara signature for am embedded executable file. NoMoreXOR extracted the deobfuscated contents into the file pear.doc.0.unxored. You could examine this decoded file further, perhaps by looking at the strings embedded into it.

image.png

All the tools mentioned above with the exception of XORStrings are installed on REMnux, which is a lightweight Linux distribution for assisting malware analysts with reverse-engineering malicious software.

Thank you to the authors of these tools for taking the time to not only create these utilities, but also sharing them with the community.

Lenny Zeltser teaches malware analysis at SANS Institute and focuses on safeguarding customers' IT operations at NCR Corp. He is active on Twitter and writes a security blog.

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
October 16, 2020
Installing the REMnux Virtual Appliance for Malware Analysis
Learn how to import the REMnux virtual appliance into VMware or VirtualBox to set up a powerful system for malware analysis.
370x370_Lenny-Zeltser.jpg
Lenny Zeltser
read more
Blog
_MUST_HAVE_RESOURCES_for_malware_analysis.png
Digital Forensics and Incident Response, Cyber Defense Essentials
June 8, 2020
"Must Have" Free Resources for Malware Analysis
Malware keeps getting more sophisticated, here are some free resources to help you be a step ahead
SANS Institute
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