浏览代码

Add fqdn variable support in header replacements

pull/58/head
父节点
当前提交
97808d0333
共有 1 个文件被更改,包括 11 次插入4 次删除
  1. +11
    -4
      bubble-server/src/main/resources/packer/roles/mitmproxy/files/bubble_api.py

+ 11
- 4
bubble-server/src/main/resources/packer/roles/mitmproxy/files/bubble_api.py 查看文件

@@ -450,7 +450,7 @@ def original_flex_ip(client_addr, fqdns):
return None return None




def _replace_in_headers(headers, pattern: str, replacement: str):
def _replace_in_headers(headers: nheaders.Headers, pattern: str, replacement: str):
""" """
Taken from original mitmproxy's Header class implementation with sligh change to allow replacement with empty string Taken from original mitmproxy's Header class implementation with sligh change to allow replacement with empty string
(resulting with actual removal/skip of the header line). (resulting with actual removal/skip of the header line).
@@ -489,17 +489,19 @@ def _replace_in_headers(headers, pattern: str, replacement: str):




def response_header_modify(flow): def response_header_modify(flow):
return None if flow.response is None else _header_modify(flow.client_conn.address[0], flow.response.headers)
if flow.response is None:
return None
return _header_modify(flow.client_conn.address[0], flow.server_conn.address[0], flow.response.headers)




def _header_modify(client_addr, headers):
def _header_modify(client_addr: str, server_addr: str, headers: nheaders.Headers):
modifiers_set = 'responseHeaderModifierLists~' + client_addr + '~UNION' modifiers_set = 'responseHeaderModifierLists~' + client_addr + '~UNION'
modifiers = REDIS.smembers(modifiers_set) modifiers = REDIS.smembers(modifiers_set)


repl_count = 0 repl_count = 0
if modifiers: if modifiers:
for modifier in modifiers: for modifier in modifiers:
modifier_config = json.loads(modifier)
modifier_config = _extract_modifier_config(modifier, server_addr)
repl_count += _replace_in_headers(headers, modifier_config['regex'], modifier_config['replacement']) repl_count += _replace_in_headers(headers, modifier_config['regex'], modifier_config['replacement'])


if bubble_log.isEnabledFor(DEBUG): if bubble_log.isEnabledFor(DEBUG):
@@ -508,6 +510,11 @@ def _header_modify(client_addr, headers):
return repl_count return repl_count




def _extract_modifier_config(modifier: str, server_addr: str):
modifier.replace('{{fqdn}}', re.escape(server_addr))
return json.loads(modifier)


def health_check_response(flow): def health_check_response(flow):
# if bubble_log.isEnabledFor(DEBUG): # if bubble_log.isEnabledFor(DEBUG):
# bubble_log.debug('health_check_response: special bubble health check request, responding with OK') # bubble_log.debug('health_check_response: special bubble health check request, responding with OK')


正在加载...
取消
保存