aboutsummaryrefslogtreecommitdiffstats
path: root/examples/cmos/counter.v
blob: f21658724f641e05fb5b0a3c0e7845da9044a3e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
module counter (clk, rst, en, count);

   input clk, rst, en;
   output reg [2:0] count;

   always @(posedge clk)
      if (rst)
         count <= 3'd0;
      else if (en)
         count <= count + 3'd1;

endmodule
hlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
.. _transparent-dhcp:

Transparently proxify virtual machines
======================================

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 *Internet <--> Proxy VM <--> (Virtual) Internal Network* setup can be applied to
other setups.

1. Configure Proxy VM
---------------------

On the proxy machine, **eth0** is connected to the internet. **eth1** is connected to the internal
network that will be proxified and configured to use a static ip (192.168.3.1).

VirtualBox configuration
^^^^^^^^^^^^^^^^^^^^^^^^

.. image:: transparent-dhcp/step1_vbox_eth0.png

.. image:: transparent-dhcp/step1_vbox_eth1.png

VM Network Configuration
^^^^^^^^^^^^^^^^^^^^^^^^

.. image:: transparent-dhcp/step1_proxy.png
    :align: center

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
    `[1] <https://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/>`_. For our use case, this needs
    to be disabled by changing ``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:

    .. code-block:: none

        # 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

    Apply changes:

    >>> sudo service dnsmasq restart

    Your **proxied machine** in the internal virtual network should now receive an IP address via DHCP:

    .. image:: transparent-dhcp/step2_proxied_vm.png

3. Redirect traffic to mitmproxy
------------------------------------------

To redirect traffic to mitmproxy, we need to add two iptables rules:

.. code-block:: none

    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

4. Run mitmproxy
----------------

Finally, we can run mitmproxy in transparent mode with

>>> mitmproxy -T

The proxied machine cannot to leak any data outside of HTTP or DNS requests.
If required, you can now :ref:`install the mitmproxy certificates on the proxied machine
<certinstall>`.