from mitmproxy import ctx, flowfilter
class Recorder:
def requestheaders(self, flow):
ctx.log.info('requestheaders')
def request(self, flow):
# 日志打印
# ctx.log.info('-----------------------')
# ctx.log.error('-----------------------')
# request 常用api
# print(flow.request.host) # 當前請求的host
# print(flow.request.path) # 請求的接口地址
# print(flow.request.pretty_url) # 完整的url路徑
# print(flow.request.url) # 完整的url路徑
# print(flow.request.method) # 請求方式
# print(flow.request.scheme) # http請求還是https請求
# print(flow.request.headers) # 獲取所有頭信息,包含Host、User-Agent、Content-type等字段
# GET請求
# 獲取參數
# flow.request.query 請求參數 數據格式 mitmproxy數據類型 類似列表套著元組
# flow.request.query.keys() 請求參數key拆分成迭代器,所有keys
# flow.request.query.items() 同時循環請求參數的key value
# for k,v in flow.request.query.items():
# print(k)
# print(v)
# flow.request.query.values() 請求參數value拆分成迭代器,所有values
# flow.request.query.get('name') 通過指定key獲取value
# print(flow.request.query.get('name'))
# flow.request.query.get_all('name') 通過key 獲取所有這個key下的value
# print(flow.request.query.get_all('name'))
# flow.request.query.fields 元素的方式獲取所有的請求參數
# print(flow.request.query.fields)
# 修改更新參數
# flow.request.query.set_all('sign',['123']) 修改get請求的參數
# flow.request.query.update() 修改請求的參數 根據參數名 參數格式要求列表套元組 [('userid',2180),('sign','2beb50f2669b0531d7905e56a6e90bf4')]
# 增加參數
# flow.request.query.add('userid',2179) 增加get請求參數 參數1:key 參數2:value
# 刪除參數
# flow.request.query.pop('userid') 刪除指定某個請求參數 參數:key
# POST請求
# 獲取參數
# print(flow.request.get_text()) # 請求中body內容,那么可通過此方法獲取,字符串類型
# print(flow.request.urlencoded_form) # content-type:application/x-www-form-urlencoded時的請求參數
# print(flow.request.multipart_form) # content-type:multipart/form-data 的請求參數
# 修改更新參數
# flow.request.set_text('123') # 設置整體的請求參數 接收字符串
# print(dir(flow.request))
pass
def responseheaders(self, flow):
ctx.log.info('responseheaders')
def response(self, flow):
# print(flow.response.get_text()) 獲取返回值結果 結果類型是字符串
# print(flow.response.get_content()) 獲取返回值結果 結果類型是bytes
# print(flow.response.content) 獲取返回值結果 結果類型是bytes二進制
# print(flow.response.status_code) 狀態碼
# print(flow.response.text) 獲取返回值結果 結果類型是字符串
# flow.response.set_text('123') 修改返回值 需要字符串類型
# print(dir(flow.response))
pass
def error(self, flow):
print(f'HTTP Error With [{flow.response.reason}], and body: {flow.response.text}')
addons = [
Recorder()
浙公網安備 33010602011771號