aboutsummaryrefslogtreecommitdiffstats
path: root/doc-src/tutorials/transparent-dhcp.html
blob: ce8a10fd8807190d88749fe6c5bc2c8d21abf40a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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.
DCARD ((u_int)~0) /* CAM Status field values */ typedef enum { /* CCB request is in progress */ CAM_REQ_INPROG = 0x3F, /* Some value unused by Linux */ /* CCB request completed without error */ CAM_REQ_CMP = DID_OK, /* CCB request aborted by the host */ CAM_REQ_ABORTED = DID_ABORT, /* Unable to abort CCB request */ CAM_UA_ABORT = DID_ERROR, /* CCB request completed with an error */ CAM_REQ_CMP_ERR = DID_ERROR, /* CAM subsytem is busy */ CAM_BUSY = DID_BUS_BUSY, /* CCB request was invalid */ CAM_REQ_INVALID = DID_BAD_TARGET, /* Supplied Path ID is invalid */ CAM_PATH_INVALID = DID_BAD_TARGET, /* Target Selection Timeout */ CAM_SEL_TIMEOUT = DID_NO_CONNECT, /* Command timeout */ CAM_CMD_TIMEOUT = DID_ERROR, /* * Should never occur in Linux * as the upper level code * handles all timeout processing. */ /* SCSI error, look at error code in CCB */ CAM_SCSI_STATUS_ERROR = DID_OK, /* Linux looks at status byte */ /* SCSI Bus Reset Sent/Received */ CAM_SCSI_BUS_RESET = DID_RESET, /* Uncorrectable parity error occurred */ CAM_UNCOR_PARITY = DID_PARITY, /* Autosense: request sense cmd fail */ CAM_AUTOSENSE_FAIL = DID_ERROR, /* No HBA Detected Error */ CAM_NO_HBA = DID_ERROR, /* Data Overrun error */ CAM_DATA_RUN_ERR = DID_ERROR, /* Unexpected Bus Free */ CAM_UNEXP_BUSFREE = DID_ERROR, /* CCB length supplied is inadequate */ CAM_CCB_LEN_ERR = DID_ERROR, /* Unable to provide requested capability */ CAM_PROVIDE_FAIL = DID_ERROR, /* A SCSI BDR msg was sent to target */ CAM_BDR_SENT = DID_RESET, /* CCB request terminated by the host */ CAM_REQ_TERMIO = DID_ERROR, /* Unrecoverable Host Bus Adapter Error */ CAM_UNREC_HBA_ERROR = DID_ERROR, /* The request was too large for this host */ CAM_REQ_TOO_BIG = DID_ERROR, /* * This request should be requeued to preserve * transaction ordering. This typically occurs * when the SIM recognizes an error that should * freeze the queue and must place additional * requests for the target at the sim level * back into the XPT queue. */ CAM_REQUEUE_REQ = DID_BUS_BUSY, CAM_STATUS_MASK = 0x3F } cam_status; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) #define SCSI_DATA_READ 1 #define SCSI_DATA_WRITE 2 #define SCSI_DATA_NONE 3 #endif /* * Definitions for the asynchronous callback CCB fields. */ typedef enum { AC_GETDEV_CHANGED = 0x800,/* Getdev info might have changed */ AC_INQ_CHANGED = 0x400,/* Inquiry info might have changed */ AC_TRANSFER_NEG = 0x200,/* New transfer settings in effect */ AC_LOST_DEVICE = 0x100,/* A device went away */ AC_FOUND_DEVICE = 0x080,/* A new device was found */ AC_PATH_DEREGISTERED = 0x040,/* A path has de-registered */ AC_PATH_REGISTERED = 0x020,/* A new path has been registered */ AC_SENT_BDR = 0x010,/* A BDR message was sent to target */ AC_SCSI_AEN = 0x008,/* A SCSI AEN has been received */ AC_UNSOL_RESEL = 0x002,/* Unsolicited reselection occurred */ AC_BUS_RESET = 0x001 /* A SCSI bus reset occurred */ } ac_code; typedef enum { CAM_DIR_IN = SCSI_DATA_READ, CAM_DIR_OUT = SCSI_DATA_WRITE, CAM_DIR_NONE = SCSI_DATA_NONE } ccb_flags; #endif /* _AIC7XXX_CAM_H */