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
    • Group Purchasing
    • Why Work with SANS
    • Build Your Team
    • Hire Cyber Talent
    • Team Development
    • Private Training
    • Security Awareness Training
    • Leadership Training
    • Industries
  • 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
    • Work Study
    • Teach for SANS
    • Partnerships
    • Sponsorship Opportunities
    • Join the Community
  • About
    • About SANS
    • Instructors
    • Mission
    • Initiatives
    • Diversity
    • Awards
    • Contact
    • Frequently Asked Questions
    • Customer Reviews
    • Press
  • 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. Digital Forensics: Finding Encoded Evidence
Dave Hull

Digital Forensics: Finding Encoded Evidence

Recently I was asked to recover images from a suspect machine. Numerous tools have the ability to categorize files based on type.

January 9, 2011

Recently I was asked to recover images from a suspect machine. Numerous tools have the ability to categorize files based on type. Students of SANS 508 get a look under the hood at how this is done using the "magic numbers" found at or near the start of files with well-known formats. Fortunately, most of the files we deal with have reliable file headers.

However, because these tools rely on magic numbers, there are countless ways files of a given type can be obfuscated and therefore go undetected. I encountered this on my recent case, not because the suspect was particularly savvy, but because the instant messaging client the suspect used to send and receive images. The client software maintained log files containing portions of conversations including image file transfers.

The images weren't found for two reasons, first they were embedded in the log files so the magic number sequences were not near the beginning of the files and second the images were base64 encoded so that they could be transferred as ASCII text via the chat client. The good news is that base64 is deterministic, that is to say, given a certain byte string, it will always produce the same encoding and fixed format files for common image types have well defined headers that will reliably produce the same base64 encoded values.

I only had to figure out what these magic numbers looked like when base64 encoded. On my SIFT system I ran the following command:

for i in $(locate gif | grep "gif$"); do base64 $i | head -c4; echo " (gif)"; done | sort | uniq —c

and received the following result:

    1 iVBO (gif)
1173 R0lG (gif)

Let's go over this command and what it does. It uses the "for i in" construct to build a list of values that it will perform operations on. In this case, the list is comprised of results returned by the $(locate gif | grep "gif$") command. This compound command returns files on the system that end in gif and are assumed to be gif images (whether or not this is a valid assumption is beyond the scope of this post). Each file in the list is then base64 encoded and that encoding is passed to head —c4, which prints the first four characters of the encoded image, the echo command adds a newline and the loop finishes, all of the results are then sorted and passed to uniq —c, which prints a count of each encoding variation.

The whole statement allows me to quickly see the most common base64 encodings for the given file type's magic number.

I repeated this command substituting "jpg" for "gif", then "png" and so on. The results came back as follows:

704 /9j/ (jpg)
0003 AQAA (jpg)
    7 f0VM (png)
22700 iVB0 (png)
     1 R0lG (png)
     8 UE5H (png)
...

You can see that "/9j/" is a common base64 encoding for both jpg and png images and that "iVB0" is the most common base64 encoded magic number for png files.

Armed with this information, I initiated string searches for these common encodings. Lo and behold, I had a number of hits that when decoded using "base64 —d" resulted in the recovery of additional images that had an impact on the case. If you're not familiar with base64, you may want to have a look at RFC 3548, which defines the base64 standard. Below is a base64 encoded bmp image, picking the encodings out of byte streams is not too difficult, though doing it manually certainly won't scale.

Qk02AwAAAAAAADYAAAAoAAAAEAAAABAAAAABABgAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAA////////////////////////////////////////////////////////////////////////////////////////////////Vb9V////////////////////////////////////////////////////////Vb9VVb9VVb9V////AL//AL//////////////////////////////////////Vb9VVb9VVb9VVb9VAL//AL//AL//////////////////////////////////Vb9VVb9VVb9VVb9Vqj8qAL//AL//AL//AL//////////////////////////////AJ8CAJ8CAJ8Cqj8qqj8qAL//AL//AL//AL//AL///////////////////////58AAJ8CAJ8CAJ8Cqj8qAH//AH//AH//AH//AL//AL///////////////////58A/58AAJ8CAJ8Cqj8qqj8qAH//AH//AH//AH//AH//AL///////////////58A/58A/58AVZ8AAJ8Cqj8qVV+qAH//AH//AH//AH//AH//AD///////////58A/58A/58A/58A/58Aqp8Aqj8qAH//AH//AH//AH//AH//AD//AD///////////58A/58A/58A/58A/58A////AD//AD//AD//AD//AD//AD//AD//AD///////////58A/58A/58A/58A////////////AD//AD//AD//AD//AD//AD//AD///////////58A/58A////////////////////////AD//AD//AD//AD//AD//AD//////////////////////////////////////////////AD//AD//AD//AD//AD//////////////////////////////////////////////////////AD//AD//////////////////////////////////////////////////////////////////////////

Next time you're faced with searching a drive, consider the elements of the case. Are there applications involved that may store evidence in an encoded form such as base64 and would searching for those encoded variants affect the outcome of your case?

Update I put together a text file containing a more complete set of base64 encoded magic byte sequences for common image types. The file is hosted at http://trustedsignal.com/forensics/b64_enc_img_types.txt.

Dave Hull is a forensic analyst at Trusted Signal and a Community Instructor with the SANS Institute. He'll be teaching Forensics 408: Computer Forensics Essentials in Boston, MA from Feb. 28 - Mar. 4.

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
DFIR_FOR509_Countdown_Social4.jpg
Digital Forensics and Incident Response, Cloud Security
April 9, 2021
NEW FOR509: Enterprise Cloud Forensics & Incident Response - Beta coming June 2021
The new Enterprise Cloud Forensics course brings examiners up to speed with the rapidly changing world of enterprise cloud
SANS DFIR
read more
Blog
3_Min_Max_(58).png
Digital Forensics and Incident Response
March 30, 2021
3MinMax Series Topic Review - Apple Acquisition
Apple devices that we must be aware of in order to perform forensic acquisitions
370x370_Kevin-Ripa.jpg
Kevin Ripa
read more
Blog
3_Min_Max_(56).png
Digital Forensics and Incident Response
March 30, 2021
3MinMax Series Topic Review - Using KAPE in Forensics
KAPE is an efficient and highly configurable triage program that will target essentially any device or storage location, find forensically
370x370_Kevin-Ripa.jpg
Kevin Ripa
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