mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
add tutorial for transparent proxying, other minor docs improvements
This commit is contained in:
parent
069aca1df4
commit
92966e7c48
@ -10,3 +10,7 @@ body {
|
|||||||
.nowrap {
|
.nowrap {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
line-height: 1.1;
|
||||||
|
}
|
@ -6,7 +6,7 @@
|
|||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</a>
|
</a>
|
||||||
<a class="brand" href="@!urlTo(idxpath)!@">mitmproxy 0.9 docs</a>
|
<a class="brand" href="@!urlTo(idxpath)!@">mitmproxy $!VERSION!$ docs</a>
|
||||||
</div><!--/.nav-collapse -->
|
</div><!--/.nav-collapse -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -51,9 +51,10 @@
|
|||||||
$!nav("transparent/linux.html", this, state)!$
|
$!nav("transparent/linux.html", this, state)!$
|
||||||
$!nav("transparent/osx.html", this, state)!$
|
$!nav("transparent/osx.html", this, state)!$
|
||||||
|
|
||||||
<li class="nav-header">Tutorials</li>
|
<li class="nav-header">Tutorials</li>
|
||||||
$!nav("tutorials/30second.html", this, state)!$
|
$!nav("tutorials/30second.html", this, state)!$
|
||||||
$!nav("tutorials/gamecenter.html", this, state)!$
|
$!nav("tutorials/gamecenter.html", this, state)!$
|
||||||
|
$!nav("tutorials/transparent-dhcp.html", this, state)!$
|
||||||
|
|
||||||
<li class="nav-header">Scripting mitmproxy</li>
|
<li class="nav-header">Scripting mitmproxy</li>
|
||||||
$!nav("scripting/inlinescripts.html", this, state)!$
|
$!nav("scripting/inlinescripts.html", this, state)!$
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import os, sys
|
import os, sys, datetime
|
||||||
import countershape
|
import countershape
|
||||||
from countershape import Page, Directory, PythonModule, markup, model
|
from countershape import Page, Directory, PythonModule, markup, model
|
||||||
import countershape.template
|
import countershape.template
|
||||||
sys.path.insert(0, "..")
|
sys.path.insert(0, "..")
|
||||||
from libmproxy import filt
|
from libmproxy import filt, version
|
||||||
|
|
||||||
MITMPROXY_SRC = "~/mitmproxy/mitmproxy"
|
MITMPROXY_SRC = os.path.abspath("..")
|
||||||
|
ns.VERSION = version.VERSION
|
||||||
|
|
||||||
if ns.options.website:
|
if ns.options.website:
|
||||||
ns.idxpath = "doc/index.html"
|
ns.idxpath = "doc/index.html"
|
||||||
@ -16,18 +17,20 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
ns.title = countershape.template.Template(None, "<h1>@!this.title!@</h1>")
|
ns.title = countershape.template.Template(None, "<h1>@!this.title!@</h1>")
|
||||||
this.titlePrefix = "mitmproxy 0.10 - "
|
this.titlePrefix = "%s - " % version.NAMEVERSION
|
||||||
this.markup = markup.Markdown(extras=["footnotes"])
|
this.markup = markup.Markdown(extras=["footnotes"])
|
||||||
|
|
||||||
ns.docMaintainer = "Aldo Cortesi"
|
ns.docMaintainer = "Aldo Cortesi"
|
||||||
ns.docMaintainerEmail = "aldo@corte.si"
|
ns.docMaintainerEmail = "aldo@corte.si"
|
||||||
ns.copyright = u"\u00a9 mitmproxy project, 2013"
|
ns.copyright = u"\u00a9 mitmproxy project, %s" % datetime.date.today().year
|
||||||
|
|
||||||
def mpath(p):
|
def mpath(p):
|
||||||
p = os.path.join(MITMPROXY_SRC, p)
|
p = os.path.join(MITMPROXY_SRC, p)
|
||||||
return os.path.expanduser(p)
|
return os.path.expanduser(p)
|
||||||
|
|
||||||
ns.index_contents = file(mpath("README.mkd")).read()
|
with open(mpath("README.mkd")) as f:
|
||||||
|
readme = f.read()
|
||||||
|
ns.index_contents = readme.split("\n", 1)[1] #remove first line (contains build status)
|
||||||
|
|
||||||
def example(s):
|
def example(s):
|
||||||
d = file(mpath(s)).read().rstrip()
|
d = file(mpath(s)).read().rstrip()
|
||||||
|
@ -38,3 +38,6 @@ iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8
|
|||||||
running as the default gateway.</li>
|
running as the default gateway.</li>
|
||||||
|
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
|
|
||||||
|
For a detailed walkthrough, have a look at the <a href="@!urlTo("tutorials/transparent-dhcp.html")!@"><i>Transparently proxify virtual machines</i></a> tutorial.
|
||||||
|
@ -3,4 +3,5 @@ from countershape import Page
|
|||||||
pages = [
|
pages = [
|
||||||
Page("30second.html", "Client playback: a 30 second example"),
|
Page("30second.html", "Client playback: a 30 second example"),
|
||||||
Page("gamecenter.html", "Setting highscores on Apple's GameCenter"),
|
Page("gamecenter.html", "Setting highscores on Apple's GameCenter"),
|
||||||
]
|
Page("transparent-dhcp.html", "Transparently proxify virtual machines")
|
||||||
|
]
|
54
doc-src/tutorials/transparent-dhcp.html
Normal file
54
doc-src/tutorials/transparent-dhcp.html
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
This walkthrough illustrates how to set up transparent proxying with mitmproxy. We use VirtualBox VMs with an Ubuntu proxy machine in this example, but the general principle can be applied to other setups.
|
||||||
|
|
||||||
|
1. **Configure VirtualBox Network Adapters for the proxy machine**
|
||||||
|
The network setup is simple: `internet <--> proxy vm <--> (virtual) internal network`.
|
||||||
|
For the proxy machine, *eth0* represents the outgoing network. *eth1* is connected to the internal network that will be proxified, using a static ip (192.168.3.1).
|
||||||
|
<hr>VirtualBox configuration:
|
||||||
|
<img src="@!urlTo("tutorials/transparent-dhcp/step1_vbox_eth0.png")!@"/><br><br>
|
||||||
|
<img src="@!urlTo("tutorials/transparent-dhcp/step1_vbox_eth1.png")!@"/>
|
||||||
|
<br>Proxy VM:
|
||||||
|
<img src="@!urlTo("tutorials/transparent-dhcp/step1_proxy.png")!@"/>
|
||||||
|
<hr>
|
||||||
|
2. **Configure DHCP and DNS**
|
||||||
|
We use dnsmasq to provide DHCP and DNS in our internal network.
|
||||||
|
Dnsmasq is a lightweight server designed to provide DNS (and optionally DHCP and TFTP) services to a small-scale
|
||||||
|
network.
|
||||||
|
|
||||||
|
- Before we get to that, we need to fix some Ubuntu quirks:
|
||||||
|
**Ubuntu >12.04** runs an internal dnsmasq instance (listening on loopback only) by default
|
||||||
|
<a href="https://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/">[1]</a>. For our use case, this needs to be
|
||||||
|
disabled by changing <br>`dns=dnsmasq` to `#dns=dnsmasq` in */etc/NetworkManager/NetworkManager.conf*
|
||||||
|
and running `sudo restart network-manager` afterwards.
|
||||||
|
- Now, dnsmasq can be be installed and configured:
|
||||||
|
`sudo apt-get install dnsmasq`
|
||||||
|
Replace */etc/dnsmasq.conf* with the following configuration:
|
||||||
|
<pre>\# Listen for DNS requests on the internal network
|
||||||
|
interface=eth1
|
||||||
|
\# Act as a DHCP server, assign IP addresses to clients
|
||||||
|
dhcp-range=192.168.3.10,192.168.3.100,96h
|
||||||
|
\# Broadcast gateway and dns server information
|
||||||
|
dhcp-option=option:router,192.168.3.1
|
||||||
|
dhcp-option=option:dns-server,192.168.3.1
|
||||||
|
</pre>
|
||||||
|
Apply changes:
|
||||||
|
`sudo service dnsmasq restart`
|
||||||
|
<hr>
|
||||||
|
Your proxied machine's network settings should now look similar to this:
|
||||||
|
<img src="@!urlTo("tutorials/transparent-dhcp/step2_proxied_vm.png")!@"/>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
3. **Set up traffic redirection to mitmproxy**
|
||||||
|
To redirect traffic to mitmproxy, we need to add two iptables rules:
|
||||||
|
<pre class="terminal">
|
||||||
|
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 \
|
||||||
|
-j REDIRECT --to-port 8080
|
||||||
|
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 443 \
|
||||||
|
-j REDIRECT --to-port 8080
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
4. If required, <a href="@!urlTo("ssl.html")!@">install the mitmproxy
|
||||||
|
certificates on the test device</a>.
|
||||||
|
|
||||||
|
5. Finally, we can run <code>mitmproxy -T</code>.
|
||||||
|
The proxied machine cannot to leak any data outside of HTTP or DNS requests.
|
||||||
|
|
BIN
doc-src/tutorials/transparent-dhcp/step1_proxy.png
Normal file
BIN
doc-src/tutorials/transparent-dhcp/step1_proxy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 241 KiB |
BIN
doc-src/tutorials/transparent-dhcp/step1_vbox_eth0.png
Normal file
BIN
doc-src/tutorials/transparent-dhcp/step1_vbox_eth0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
doc-src/tutorials/transparent-dhcp/step1_vbox_eth1.png
Normal file
BIN
doc-src/tutorials/transparent-dhcp/step1_vbox_eth1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
doc-src/tutorials/transparent-dhcp/step2_proxied_vm.png
Normal file
BIN
doc-src/tutorials/transparent-dhcp/step2_proxied_vm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
Loading…
Reference in New Issue
Block a user