Tuesday, December 15, 2009

Journey down bmap lane.

Bmap is quite the obscure tool. (reference) Not only is it difficult to find, but, good luck with any documentation. The --help is all you've got! I was able to find the source at packetstormsecurity but had problems compiling. But, we can fast forward to the part where it is working.

Hiding ASCII in Slack

Let me walk through the example that everyone uses for bmap with the file test.gif:

> du -sch test.gif
16.0K total

> echo "redleatheryellowleather" | bmap --putslack test.gif
>du -sch test.gif
16.0K total

>echo "redleatheryellowleather" > text
>du -sch text
4.0K total

So, we can see here, that there du command should be showing a change in the file size due to the slack data. Of which it is not.

>bmap --slack test.gif
getting from block 2051
file was: 13166
slack size: 3218
block size: 4096
redleatheryellowleather

>bmap --slack --outfile sometext test.gif

The 'outfile' option dumps the contents into the file sometext.

>file sometext
sometext: ASCII text

>less sometext
redleatheryellowleather
(it actually gave me a binary file but contained the phrase I was looking for)

The md5 hash of test.gif before and after slack space has been manipulated is exactly the same. However, the cp command does not copy slack. Which I just happened to stumble upon, but was interesting none-the-less. Knowing this, I decided to delete the file with slack space stuffed to see if magicrescue would restore the document with slack in tact. After the search, rescue and another cup of coffee the results are in. The document was recovered but the slack space was empty. This result makes sense. Magicrescue will carve out only the file contents. Which also leads me to believe that a file just stored in slack space will not be recovered by magicrescue as a lost document. Or will it?

Hiding Files in Slack

Hiding ASCII in slack space is similar to carving a file into slack space. Here's how I did it:

>bmap --carve ppt2.ppt | bmap --putslack test.gif

I am testing to see if magicrescue will find ppt2.ppt, thinking it is an unallocated file needing recovery. While working with magicrescue I have noticed that it only recovers data that needed to be recovered. Meaning, files that haven't been deleted don't appear in the results. Of course data that matches the mask you throw at it. So, if something is stuffed in a file's slack space and the file is still considered allocated space, my assumption is that it will get overlooked. Well, that assumption was correct. Multiple scans of one partition with data stored in slack recovered nothing. It did recover one document that was purposefully deleted, yet the slack data was missing.

Other tools?

I haven't found any other tools that detect slack space contents, in a limited amount of searching. Sleuthkit had the ability to search through slack space, but in recent revisions of the app ils, this feature was removed. (reference) Which makes this method of hiding information very tough to detect. I would rank this method of hiding data right up there with alternate data streams in terms of quick and dirty. Now, if anyone really wanted to hide something, one could couple these methods with encrypted filesystems...but that's a topic for another time.

Concluding Remarks

I feel as though I haven't even begun to scratch the surface with forensics. When at the same time, I really learned a lot. My goal out of this course was just to basically broaden my overall understanding of forensic analysis. That was accomplished. The two books proved for perfect stepping stones to get started. They focused mainly on case studies in forensic analysis and business aspects. Also, the details of inspections and analysis were discussed, which lead me down other avenues to research.

What I really liked about this course was the fact that I got to wear the white and the black hat. Answering questions like: How do you hide information? How do you hide information on different file systems? Now that it's hidden, how would you attempt to detect/find it? What tools are are used?

It wasn't until researching these topics that I found out about HPA space on hard disks, ext2 and ext3 slack space stuffing, and NTFS alternate data streams. These three areas are where I spent most of my time. Which lead to work with Sleuthkit, TCT, magicrescue, recuva, bmap and netcat. Each of these tools were fun to learn and essential for proper analysis.

This class piqued my interest again in studying forensics and security. Next semester I am going to be taking a course on the mathematics of encryption. Which sounds very cool! I'm hoping to pair up forensics and encryption to see if anything looks promising for a research topic.

Friday, December 11, 2009

Fun with ADS

I'm surprised how easy it is to hide data via alternate data streams (ADS) in Windows. It's a quick and dirty way of hiding information. However, you must know the exact file name in order to view the contents of the hidden document. It's kind of like the Room of Requirement in Hogwarts. If you don't know where it is, you can't get to it. Although, ADS data won't just reveal itself if you really need it, like the room will... did I go too far with the Harry Potter reference? Anyways, in order to test ADS, I decided to test out Identity Finder. Identity Finder is the application that ensures each workstation does not house any FERPA protected data. So, I would assume, that this application would be aware of alternate data streams or would simply detect something in an ADS file.

The Setup

I created two text files; one with the contents being "Hello World!", the other containing "ssn: 333-44-5555." Identity finder will flag any files with a social security number or a credit card number or anything close. I probably didn't even need to put the fake ssn in that format, as Identity Finder will flag any file with a 9 digit number in it. None-the-less, I did, and the file should be flagged.

Now, to ADS-ing a document. From the command line I ran:

> type ads_data.txt > doc1.txt:a.txt

Voila! That's it! An ADS file has been created. Again, while in a shell, if you run 'notepad doc1.txt', you will see "Hello World!" However, if you run 'notepad doc1.txt:a.txt' you will see the contents of the ADS file. The neat thing is that the containing folder only contains one document. That being the doc1.txt file. The alternate data stream is not visible at all. Pretty cool stuff huh? Well, I thought it was! Okay so ADS hiding is more like using the invisibility cloak than the room of requirement. And that will be my last Harry Potter reference.

Identity Finder Scan

So, now it's time to scan my machine to see if Identity finder would locate the ADS file. I separated the ads_data.txt and doc1.txt files into different folders just for safe keeping. The scan completed in approximately 2 hours. The end result is, insert drum roll here, Alternate Data Stream wins! Identity Finder flagged the ads_data.txt file, but did not catch the doc1.txt:a.txt file. I expected it to find something in doc1.txt. I thought Identity Finder would run a more thorough scan, but apparently it does not.

So, what's next?

I'm going to see if I can get bmap running and try to do some slack space packing. (I've got a copy of the BCCD, since I can't get it compiled on my own.)

References

http://www.windowsecurity.com/articles/Alternate_Data_Streams.html
http://support.microsoft.com/kb/105763
http://www.informit.com/articles/article.aspx?p=413685&seqNum=3
http://www.linuxsecurity.com/content/view/117638/49/