系統環境要求:html
- Ubuntu 14.04 x64,CentOS 7 x64以上版本系統(建議使用xubuntu 14.04 x64,穩定硬件要求低)
- Python 2.7以上運行環境(MITM用Python寫的)
- Pip 7.1版本以上,這個用於安裝MITM Proxy
官方安裝指南:http://mitmproxy.org/doc/install.htmlpython
sudo apt-get update #更新遠程軟件倉庫列表 sudo apt-get install vim git openssh-server openssh-client #安裝工具vim,git,openssh-server,openssh-client git clone https://github.com/wuxinwei/MyConfig.git #從github上clone下來個人配置信息,裏面有vimrc,tmux,zsh的配置文件,我已經所有配好了,能夠覆蓋到/home/用戶名/就能夠 cp .../MyConfig/_vimrc ~/.vimrc #使用vim配置文件 sudo /etc/init.d/ssh start #啓動ssh服務,ssh-server配置文件位於/ etc/ssh/sshd_config,在這裏能夠定義SSH的服務端口,默認端口是22,你能夠本身定義成其餘端口號,如222 sudo apt-get install bridge-utils #安裝橋工具bridge-utils brctl addbr br0 #添加一個網橋 brctl addif br0 eth0 #將eth0加到網橋中去 brctl addif br0 eth1 #將eth1加到網橋中去
sudo vim /etc/sysctl.conf
:# 將所有內容改成以下: # # /etc/sysctl.conf - Configuration file for setting system variables # See /etc/sysctl.d/ for additional system variables. # See sysctl.conf (5) for information. # #kernel.domainname = example.com # Uncomment the following to stop low-level messages on console #kernel.printk = 3 4 1 3 ##############################################################3 # Functions previously found in netbase # # Uncomment the next two lines to enable Spoof protection (reverse-path filter) # Turn on Source Address Verification in all interfaces to # prevent some spoofing attacks #net.ipv4.conf.default.rp_filter=1 #net.ipv4.conf.all.rp_filter=1 # Uncomment the next line to enable TCP/IP SYN cookies # See http://lwn.net/Articles/277146/ # Note: This may impact IPv6 TCP sessions too #net.ipv4.tcp_syncookies=1 # Uncomment the next line to enable packet forwarding for IPv4 net.ipv4.ip_forward=1 # Uncomment the next line to enable packet forwarding for IPv6 # Enabling this option disables Stateless Address Autoconfiguration # based on Router Advertisements for this host net.ipv6.conf.all.forwarding=1 ################################################################### # Additional settings - these settings can improve the network # security of the host and prevent against some network attacks # including spoofing attacks and man in the middle attacks through # redirection. Some network environments, however, require that these # settings are disabled so review and enable them as needed. # # Do not accept ICMP redirects (prevent MITM attacks) net.ipv4.conf.all.accept_redirects = 0 net.ipv6.conf.all.accept_redirects = 0 # _or_ # Accept ICMP redirects only for gateways listed in our default # gateway list (enabled by default) # net.ipv4.conf.all.secure_redirects = 1 net.ipv4.conf.all.secure_redirects = 0 # # Do not send ICMP redirects (we are not a router) #net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.all.send_redirects = 0 # # Do not accept IP source route packets (we are not a router) #net.ipv4.conf.all.accept_source_route = 0 #net.ipv6.conf.all.accept_source_route = 0 net.ipv4.conf.all.accept_source_route = 0 net.ipv6.conf.all.accept_source_route = 0 # # Log Martian Packets #net.ipv4.conf.all.log_martians = 1 #
sudo vim /etc/network/interfaces//以管理員權限打開網絡配置文件
:# 把所有文件內容改成以下: # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto eth0 #網卡eth0 iface eth0 inet manual #設置eth0網卡爲手動配置,這樣不會自動獲取ip配置等 auto eth1 #網卡eth1 iface eth1 inet manual #設置eth0網卡爲手動配置,這樣不會自動獲取ip配置等 auto br0 #網橋0 iface br0 inet static #設置網橋br0爲靜態,這樣不會變化ip address 192.168.4.144 #這裏設置網橋IP netmask 255.255.255.0 #設置網橋子網掩碼 broadcast 192.168.4.255 #設置網橋廣播地址 gateway 192.168.4.2 #這是網橋網關 dns-nameservers 202.96.128.86 #設置網橋DNS bridge_ports eth0 eth1 //將eth0 和eth1網卡添加如網橋中去 bridge_stp off brideg_hello 2 bridge_fd 9 bridge_maxwait 0
iptables
設置在重啓系統後會失效,因此若是重啓過機器這裏須要從新設置):echo 0 | sudo tee /proc/sys/net/ipv4/conf/*/send_redirects */ service iptables start #開啓iptables過濾服務 service iptables save iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 -j REDIRECT --to-port 8080 #將80端口轉發給8080 iptables -t nat -A PREROUTING -i br0 -p tcp --dport 443 -j REDIRECT --to-port 8080 #將443端口數據轉發給8080 service iptables save
官方透明代理設置教程:
http://mitmproxy.org/doc/transparent/linux.html(物理機設置)
http://mitmproxy.org/doc/tutorials/transparent-dhcp.html(虛擬機設置)
通過以上配置,實現了創建網橋,打開路由轉發功能(用於MITM的透明代理)linux
sudo apt-get install python-pip python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev #安裝必要的運行環境 sudo pip install mitmproxy #安裝mitmproxy,安裝成功後會在生成兩個工具/usr/local/bin/mitmproxy與/usr/local/bin/mitmdump
- CA證書的安裝
要捕獲https證書,就得解決證書認證的問題,所以須要在通訊發生的客戶端安裝證書,而且設置爲受信任的根證書頒佈機構。下面介紹6種客戶端的安裝方法。
當咱們初次運行mitmproxy或mitmdump時,
會在當前目錄下生成 ~/.mitmproxy文件夾,其中該文件下包含4個文件,這就是咱們要的證書了。
mitmproxy-ca.pem 私鑰
mitmproxy-ca-cert.pem 非windows平臺使用
mitmproxy-ca-cert.p12 windows上使用
mitmproxy-ca-cert.cer 與mitmproxy-ca-cert.pem相同,android上使用
1. Firefox上安裝
preferences-Advanced-Encryption-View Certificates-Import (mitmproxy-ca-cert.pem)-trust this CA to identify web sites
2. chrome上安裝
設置-高級設置-HTTPS/SSL-管理證書-受信任的根證書頒發機構-導入mitmproxy-ca-cert.pem
2. osx上安裝
雙擊mitmproxy-ca-cert.pem - always trust
3.windows7上安裝
雙擊mitmproxy-ca-cert.p12-next-next-將全部的證書放入下列存儲-受信任的根證書發佈機構
4.iOS上安裝
將mitmproxy-ca-cert.pem發送到iphone郵箱裏,經過瀏覽器訪問/郵件附件
6.Android上安裝
將mitmproxy-ca-cert.cer 放到sdcard根目錄下
選擇設置-安全和隱私-從存儲設備安裝證書
一些額外的資料:
>* 官方教程: http://mitmproxy.org/doc/index.html
>* win七、linux安裝使用pip、mitmproxy
>* 推薦給開發人員的6個實用命令行工具
>* 使用mitmproxy進行Android的http抓包
>* mitmproxy 入門案例 -『抱抱』24小時銷燬的真相(iOS端)
>* mitmproxy實踐教程之調試 Android 上 HTTP流量android