Welcome to the 10th installment of
Thick Client Proxying.
A series running since 2016. Woot! Today I will talk about traffic redirection
using the hosts
file.
Yeah! I realized I have talked about it in 19 different posts but never explicitly wrote about it. I just assumed readers would know this.
If you are already familiar with these concepts please directly go to the How Do We Proxy With This? section.
The hosts
file is located at C:\Windows\System32\Drivers\etc\hosts
. Each
line in the file looks like this:
IP-Address domain
.127.0.0.1 google.com
Any change in this file results in a change in the Windows DNS cache. Note that you need admin access to edit this file.
On nix-based operating systems (e.g., GNU/Linux1 and Apple stuff) the
hosts
file has the same format and functionality. BUT there is no local DNS
cache on Linux (not sure about Apple operating systems). The OS checks this file
before making a DNS request. You could say this file IS the DNS cache. See the
hosts manual page for more information.
For the rest of the blog I am going to talk about Windows but the same principle applies to others.
The complete name for this entity is local DNS resolver cache
but I will just
call it the Windows DNS cache. When the OS wants to resolve a domain, it will
first look in this cache to see if it's already been resolved. If the entry has
expired or an entry for that domain does not exist the OS will do a lookup.
Start your favorite Windows VM (also works on your host) and start doing things.
For some reason, Hyper-V Windows VMs do not update their local DNS cache. It remains empty. I do not know the reason but the solution is to manually configure a DNS server in the VM.
Control Panel > Network and Internet > Network Connections
in the VM.Ethernet Adapter
and select Properties
.Internet Protocol Version 4 (TCP/IPv4)
and click the Properties
button.Use the following DNS server addresses
radio button.8.8.8.8
(or your preferred DNS server like 1.1.1.1
).Hyper-V guest with manual DNS server
ipconfig /displaydns
or Get-DnsClientCache
.ipconfig /flushdns
or Clear-DnsClientCache
ipconfig /flushdns
asks for elevation but
Clear-DnsClientCache
works in a non-elevated PowerShell prompt.No we can see the DNS cache in our VM.
ping example.net
or nslookup example.net
DNS cache after resolving example.net
Each line in the hosts file becomes an entry in the DNS cache. Do some experiments:
hosts
file in an elevated editor (e.g., notepad as admin).127.0.0.1 example.net
.example.net entry from the hosts file
I have two proxy usecases for the Windows DNS cache.
If your application is using HTTP but is not proxy-aware then you can redirect its endpoints to your proxy listener.
PortSwigger has a great page on invisible proxying. Be sure to read it:
example.net:443
.93.184.216.34
.localhost
) using the hosts file.127.0.0.1 example.net
.localhost:443
. The hosts file does not
change the destination port so the Burp listener should be on the same port.invisible proxying
for the Burp listener above.Proxy > Option > Select the listener > Edit > Request Handling > Check 'Support invisible ...
.Project Options > Connections > Hostname Resolution
.Now we can open our browser and go to http://example.net
.
example.net proxied in Burp
If your application is not using HTTP then Burp's invisible proxying does not
work. It relies on the Host
header in the request to identify the endpoint.
There are some cases where the application uses a text-based protocol that can be proxied with Burp.
If there is only one endpoint, then we can use the Request Handling
tab of the
proxy listener (where invisible proxying was). It has a redirection setting. You
can redirect everything that comes to a specific listener to a specific host and
port. Checking Force use of TLS
just automatically populates the port field
with 443
.
Request Handling tab
If we have multiple endpoints but each use a different port then our work is still easy. We create one listener for each port and use the same technique.
Then tough luck. I mean, yeah. This is commonly the case where the thickclient
talks to several endpoints over TLS on port 443. The problem is that we have no
way of telling Burp to differentiate between traffic going to example.net
and
ea.com
without the Host
header.
In these cases I usually just proxied one endpoint at a time to see the traffic.
The Burp documentation for invisible proxying (linked above) has a section named
Redirecting outbound requests
(the page does not have anchors so I cannot
directly link to the section). It says:
Request Handling
tab above to redirect it to the endpoint.It's a pain to accomplish as you can imagine. This works if you have a couple of endpoints.
It's not always easy like our example.net
example. In fact, it's never easy
like this. This section discusses the issues I have usually seen.
After browsing to http://example.net
the Burp's web interface shows up or it
does not connect.
Hostname Resolution
?localhost:443
which is the proxy listener.443
(or whatever port the
application is trying to connect to)?This method has a few limitations:
hosts
file.