-- Nodes recognizer for ieee.numeric_std and ieee.numeric_bit. -- Copyright (C) 2016 Tristan Gingold -- -- GHDL is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free -- Software Foundation; either version 2, or (at your option) any later -- version. -- -- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY -- WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- -- You should have received a copy of the GNU General Public License -- along with GHDL; see the file COPYING. If not, write to the Free -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. with Types; use Types; with Vhdl.Std_Package; with Std_Names; use Std_Names; with Vhdl.Errors; use Vhdl.Errors; with Vhdl.Ieee.Std_Logic_1164; with Vhdl.Utils; use Vhdl.Utils; package body Vhdl.Ieee.Numeric is type Pkg_Kind is (Pkg_Std, Pkg_Bit); type Sign_Kind is (Type_Signed, Type_Unsigned, Type_Log, Type_Slv, Type_Suv); subtype Sign_Num_Kind is Sign_Kind range Type_Signed .. Type_Unsigned; type Arg_Kind is (Arg_Vect, Arg_Scal); type Args_Kind is (Arg_Vect_Vect, Arg_Vect_Scal, Arg_Scal_Vect, Arg_Vect_Log, Arg_Log_Vect); type Binary_Pattern_Type is array (Pkg_Kind, Sign_Num_Kind, Args_Kind) of Iir_Predefined_Functions; type Unary_Pattern_Type is array (Pkg_Kind, Sign_Num_Kind) of Iir_Predefined_Functions; type Shift_Pattern_Type is array (Type_Signed .. Type_Unsigned) of Iir_Predefined_Functions; Add_Patterns : constant Binary_Pattern_Type := (Pkg_Std => (Type_Unsigned => (Arg_Vect_Vect => Iir_Predefined_Ieee_Numeric_Std_Add_Uns_Uns, Arg_Vect_Scal => Iir_Predefined_Ieee_Numeric_Std_Add_Uns_Nat, Arg_Scal_Vect => Iir_Predefined_Ieee_Numeric_Std_Add_Nat_Uns, Arg_Vect_Log => Iir_Predefined_Ieee_Numeric_Std_Add_Uns_Log, Arg_Log_Vect => Iir_Predefined_Ieee_Numeric_Std_Add_Log_Uns), Type_Signed => (Arg_Vect_Vect => Iir_Predefined_Ieee_Numeric_Std_Add_Sgn_Sgn, Arg_Vect_Scal => Iir_Predefined_Ieee_Numeric_Std_Add_Sgn_Int, Arg_Scal_Vect => Iir_Predefined_Ieee_Numeric_Std_Add_Int_Sgn, Arg_Vect_Log => Iir_Predefined_Ieee_Numeric_Std_Add_Sgn_Log, Arg_Log_Vect => Iir_Predefined_Ieee_Numeric_Std_Add_Log_Sgn)), Pkg_Bit => (others => (others => Iir_Predefined_None))); Sub_Patterns : constant Binary_Pattern_Type := (Pkg_Std => (Type_Unsigned => (Arg_Vect_Vect => Iir_Predefined_Ieee_Numeric_Std_Sub_Uns_Uns, Arg_Vect_Scal => Iir_Predefined_Ieee_Numeric_Std_Sub_Uns_Nat, Arg_Scal_Vect => Iir_Predefined_Ieee_Numeric_Std_Sub_Nat_Uns, Arg_Vect_Log => Iir_Predefined_Ieee_Numeric_Std_Sub_Uns_Log, Arg_Log_Vect => Iir_Predefined_Ieee_Numeric_Std_Sub_Log_Uns), Type_Signed => (Arg_Vect_Vect => Iir_Predefined_Ieee_Numeric_Std_Sub_Sgn_Sgn, Arg_Vect_Scal => Iir_Predefined_Ieee_Numeric_Std_Sub_Sgn_Int, Arg_Scal_Vect => Iir_Predefined_Ieee_Numeric_Std_Sub_Int_Sgn, Arg_Vect_Log => Iir_Predefined_Ieee_Numeric_Std_Sub_Sgn_Log, Arg_Log_Vect => Iir_Predefined_Ieee_Numeric_Std_Sub_Log_Sgn)), Pkg_Bit => (others => (others => Iir_Predefined_None))); Mul_Patterns : constant Binary_Pattern_Type := (Pkg_Std => (Type_Unsigned => (Arg_Vect_Vect => Iir_Predefined_Ieee_Numeric_Std_Mul_Uns_Uns, Arg_Vect_Scal => Iir_Predefined_Ieee_Numeric_Std_Mul_Uns_Nat, Arg_Scal_Vect => Iir_Predefined_Ieee_Numeric_Std_Mul_Nat_Uns, Arg_Vect_Log => Iir_Predefined_None, Arg_Log_Vect => Iir_Predefined_None), Type_Signed => (Arg_Vect_Vect => Iir_Predefined_Ieee_Numeric_Std_Mul_Sgn_Sgn, Arg_Vect_Scal => Iir_Predefined_Ieee_Numeric_Std_Mul_Sgn_Int, Arg_Scal_Vect => Iir_Predefined_Ieee_Numeric_Std_Mul_Int_Sgn, Arg_Vect_Log => Iir_Predefined_None, Arg_Log_Vect => Iir_Predefined_None)), Pkg_Bit => (others => (others => Iir_Predefined_None))); Div_Patterns : constant Binary_Pattern_Type := (Pkg_Std => (Type_Unsigned => (Arg_Vect_Vect => Iir_Predefined_Ieee_Numeric_Std_Div_Uns_Uns, Arg_Vect_Scal => Iir_Predefined_Ieee_Numeric_Std_Div_Uns_Nat, Arg_Scal_Vect => Iir_Predefined_Ieee_Numeric_Std_Div_Nat_Uns, Arg_Vect_Log => Iir_Predefined_None, Arg_Log_Vect => Iir_Predefined_None), Type_Signed => (Arg_Vect_Vect => Iir_Predefined_Ieee_Numeric_Std_Div_Sgn_Sgn, Arg_Vect_Scal => Iir_Predefined_Ieee_Numeric_Std_Div_Sgn_Int, Arg_Scal_Vect => Iir_Predefined_Ieee_Numeric_Std_Div_Int_Sgn, Arg_Vect_Log => Iir_Predefined_None, Arg_Log_Vect => Iir
"""
This script makes it possible to use mitmproxy in scenarios where IP spoofing
has been used to redirect connections to mitmproxy. The way this works is that
we rely on either the TLS Server Name Indication (SNI) or the Host header of the
HTTP request. Of course, this is not foolproof - if an HTTPS connection comes
without SNI, we don't know the actual target and cannot construct a certificate
that looks valid. Similarly, if there's no Host header or a spoofed Host header,
we're out of luck as well. Using transparent mode is the better option most of
the time.
Usage:
mitmproxy
-p 443
-s dns_spoofing.py
# Used as the target location if neither SNI nor host header are present.
-R http://example.com/
# To avoid auto rewriting of host header by the reverse proxy target.
--keep-host-header
mitmdump
-p 80
-R http://localhost:443/
(Setting up a single proxy instance and using iptables to redirect to it
works as well)
"""
import re
# This regex extracts splits the host header into host and port.
# Handles the edge case of IPv6 addresses containing colons.
# https://bugzilla.mozilla.org/show_bug.cgi?id=45891
parse_host_header = re.compile(r"^(?P<host>[^:]+|\[.+\])(?::(?P<port>\d+))?$")
class Rerouter:
def request(self, flow):
if flow.client_conn.ssl_established:
flow.request.scheme = "https"
sni = flow.client_conn.connection.get_servername()
port = 443
else:
flow.request.scheme = "http"
sni = None
port = 80
host_header = flow.request.host_header
m = parse_host_header.match(host_header)
if m:
host_header = m.group("host").strip("[]")
if m.group("port"):
port = int(m.group("port"))
flow.request.host_header = host_header
flow.request.host = sni or host_header
flow.request.port = port
addons = [Rerouter()]