国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

python如何利用Mitmproxy抓包

瀏覽:6日期:2022-07-08 17:26:39

一、使用

安裝

pip install mitmproxy mitmproxy 是具有控制臺界面的交互式,支持SSL的攔截代理 mitmdump是mitmproxy的命令行版本。想想tcpdump為HTTP mitmweb 是一個基于web的界面,適用于mitmproxy

mitmproxy(mac)、mitmdump、mitmweb(win) 這三個命令中的任意一個即可

mitmweb -s mitm.py 命令行啟動默認端口8080mitmweb -p 8888 -s mitm.py 指定端口8888ctrl+c退出

啟動后設(shè)置電腦或手機代理(電腦ip,端口8888),安裝證書打開 cmd,執(zhí)行 'C:Program Files (x86)GoogleChromeApplicationchrome.exe' --proxy-server=10.12.2.28:8888 --ignore-certificate-errors

二、過濾、修改

'''flow.request.scheme 請求協(xié)議flow.request.host 請求hostflow.request.url 請求URL鏈接flow.request.method 請求方法flow.request.query 請求URL查詢參數(shù)flow.request.path 請求URL https://www.baidu.com/ flow.request.path_components #請求URL不包含域名的元祖 (’project’, ’classify’, ’list’)flow.request.urlencoded_form 請求POST數(shù)據(jù)flow.response.status_code HTTP響應(yīng)狀態(tài)碼flow.response.headers HTTP響應(yīng)頭信息flow.response.get_text HTTP響應(yīng)內(nèi)容'''class Counter: def __init__(self): self.result = {} # 存接口請求和返回信息 # url filter 去掉 self.url_filter = [’baidu.com’,’qq.com’,’360’] # url screen 僅訪問 self.url_race = [’10.162.16.39:8091’] # http static extension self.static_ext = [’js’, ’css’, ’ico’, ’jpg’, ’png’, ’gif’, ’jpeg’, ’bmp’,’xml’] # http Content-Type self.static_files = [’text/css’,’image/jpeg’, ’image/gif’,’image/png’,’text/html’,’application/octet-stream’,’application/x-protobuf’] # http Content-Type media resource files type self.media_types = [’image’, ’video’, ’audio’] def parser_data(self,query,data = {}): for key, value in query.items(): data[key] = value return data def get_extension(self, url_tup): if not url_tup: return ’’ else: end_path = url_tup[-1] split_ext = end_path.split(’.’) #1148e88a9d97.jpg #list return ’’ if not split_ext or len(split_ext) == 1 else split_ext[-1] # 拒絕連接 def http_connect(self, flow: mitmproxy.http.HTTPFlow): for i in self.url_filter: #過濾url if i in flow.request.host: flow.response = http.HTTPResponse.make(404) #存在篩選就返回true攔截,F(xiàn)lase通過 def capture_pass(self,request,response): if self.url_race: if request.host not in self.url_race: #篩選url return True url_tup = request.path_components #獲取url的tup extension = self.get_extension(url_tup) if extension in self.static_ext: #判斷后綴 return True try: content_type = response.headers[’Content-Type’].split(’;’)[0] if not content_type: return False elif content_type in self.static_files: #判斷Content-Type return True else: http_mime_type = content_type.split(’/’)[0] if http_mime_type in self.media_types: #判斷Content-Type的files type return True else: return False except Exception: return False def request(self, flow: mitmproxy.http.HTTPFlow): request = flow.request # 修改請求頭 # request.headers['shuzf'] = 'shuzf' # # 修改get參數(shù) # if 'shuzf' in flow.request.query.keys(): # request.query.set_all('shuzf', ['舒志福']) # # 修改post參數(shù) # if 'shuzf' in flow.request.urlencoded_form.keys(): # request.urlencoded_form.set_all(’shuzf’, ’舒志福’) scheme = request.scheme domain = request.host self.result[’url’] = parse.unquote(request.url) # url解碼 self.result[’method’] = request.method self.result[’request_headers’] = {} for item in request.headers: self.result[’request_headers’][item] = request.headers[item] self.result[’get_data’] = self.parser_data(request.query) # 將表單轉(zhuǎn)字典 self.result[’post_data’] = self.parser_data(request.urlencoded_form) # 將表單轉(zhuǎn)字典 def response(self, flow: mitmproxy.http.HTTPFlow): request = flow.request response = flow.response # # 修改返回頭 # response.headers['shuzf'] = 'shuzf' # # 修改返回體 # text = response.text # text = text.replace('shuzf', '舒志福') # flow.response.set_text(text) if not self.capture_pass(request,response): print(request.url) self.result[’status_code ’] = response.status_code self.result[’response_headers’] = {} for item in response.headers: self.result[’response_headers’][item] = response.headers[item] # HTTPResponse內(nèi)部使用了iso-8859-1編碼,先進行解碼為Unicode再進行utf-8編碼 response.text.encode('iso-8859-1').decode('utf-8') self.result[’response_content’] = response.text # 添加result至數(shù)據(jù)庫 new_url = Proxy(url=self.result[’url’],res=self.result[’response_content’], content=json.dumps(self.result)) session.add(new_url) session.commit() # 關(guān)閉session: # session.close()addons = [Counter()] # 實例類

以上就是python利用Mitmproxy抓包的詳細內(nèi)容,更多關(guān)于python Mitmproxy抓包的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产一级在线观看www色 | 国产视频二 | 国产成人在线视频播放 | 亚洲精品韩国美女在线 | 特黄aaaaaa久久片 | 亚洲欧美不卡中文字幕 | 国产成人精品免费 | 手机在线成人精品视频网 | 九九国产精品九九 | 国产亚洲精品网站 | 亚洲视频手机在线观看 | 欧美精品一区二区三区视频 | 一级毛片一级毛片a毛片欧美 | 日本黄色免费大片 | 免费一级在线 | 日韩欧美视频一区二区 | 亚洲精品国产第一区二区三区 | 日本经典在线三级视频 | 中文字幕日韩精品有码视频 | 99热成人精品热久久66 | 亚洲国产成人超福利久久精品 | 男女免费观看视频 | 国产精品九九九久久九九 | 欧美一级大片免费看 | 女人张腿让男桶免费视频网站 | 亚洲综合网在线观看首页 | 国产精品区在线12p 国产精品人成 | 手机看成人免费大片 | 国内精品久久久久久野外 | 成人黄色免费网址 | 久久久久久久综合 | 成人一级大片 | 午夜三级成人三级 | 国产精品久久视频 | 97视频免费在线观看 | 欧美片能看的一级毛片 | 成人免费在线观看视频 | 欧美在线亚洲国产免m观看 欧美在线一级精品 | 亚洲精选在线观看 | 亚洲欧美在线一区二区 | 国内精品免费一区二区三区 |