Docs
Консоль

HAProxy в качестве HTTP CONNECT прокси

Данное руководство описывает настройку HAProxy в режиме TCP-прокси для работы в качестве HTTP CONNECT forward-proxy.

Важно

HAProxy не расшифровывает TLS, он лишь устанавливает TCP-туннель после успешного HTTP CONNECT.

Спецификация метода CONNECT: MDN — HTTP CONNECT

Архитектура решения

[ Agent ]
    |
    |  CONNECT console.exploitdog.ru:443
    v
[ HAProxy :3128 ]
    |
    |  TCP tunnel (no TLS inspection)
    v
[ Backend server :443 ]
  1. Agent отправляет HTTP CONNECT запрос
  2. HAProxy принимает TCP-соединение
  3. Lua-скрипт анализирует HTTP-заголовок
  4. Проверяется разрешённый target
  5. При успехе HAProxy отвечает HTTP/1.1 200 OK
  6. TCP-соединение переводится в режим туннеля

Листинг проекта

project/
├── docker-compose.yaml     # Docker Compose конфигурация
└── haproxy/
    ├── haproxy.cfg         # Конфигурация HAProxy
    └── http-connect.lua    # Lua-скрипт обработки CONNECT
docker-compose.yaml
services:
  haproxy:
    image: haproxy:3.3-trixie
    container_name: haproxy-connect
    volumes:
      - ./haproxy:/usr/local/etc/haproxy/:ro
    ports:
      - "3128:3128"
haproxy.cfg
global
    log stdout format raw daemon info
    tune.lua.bool-sample-conversion normal
    lua-load-per-thread /usr/local/etc/haproxy/http-connect.lua
    tune.lua.log.loggers on
    tune.lua.log.stderr auto

defaults
    mode tcp
    timeout connect 10s
    timeout client  1m
    timeout server  1m

# http CONNECT proxy server (forward proxy)
frontend http-connect
    bind :3128
    log stdout format raw daemon debug
    tcp-request inspect-delay 2s
    tcp-request content set-var(txn.target) str("console.exploitdog.ru:443")
    tcp-request content reject if !METH_CONNECT
    tcp-request content lua.http-connect
    default_backend ed

backend ed
    server ed 178.216.96.182:443

http-connect.lua

local function http_connect(txn)
    local data = txn.req:data(0)
    local target = "undefined"
    if data:sub(-4) == "\r\n\r\n" then
        txn.req:remove(0, data:len())
        target = data:match("^CONNECT ([^ ]+)", 1)
        if target == txn.get_var(txn, "txn.target") then
            txn.res:send("HTTP/1.1 200 OK\r\n\r\n")
            txn:log(core.info,  string.format("Connect from %s:%s to %s CONTINUE (http-connect/LUA)", txn.sf:src(), txn.sf:src_port(), target))
            return act.CONTINUE
        end
    end
    txn:log(core.notice, string.format("Connect from %s:%s to %s DENY (http-connect/LUA)", txn.sf:src(), txn.sf:src_port(), target))
    return act.DENY
end

core.register_action("http-connect", { 'tcp-req' }, http_connect, 0)

Запуск

Сохраните файлы согласно структуре проекта.

Для self-hosted решения:

  • замените console.exploitdog.ru:443
  • замените server ed 178.216.96.182:443
docker-compose up -d

После запуска HAProxy будет слушать порт 3128.

Проверка работы

curl -x http://127.0.0.1:3128 https://console.exploitdog.ru

При успешной настройке соединение будет установлено.


Настройка агента

{ipaddress} — IP-адрес сервера с HAProxy

Windows

Соберите MSI-пакет агента через центр обновления и укажите proxy:

http://{ipaddress}:3128

Linux

При установке через Ansible:

exploitdog_agent_proxy: "http://{ipaddress}:3128"

macOS (Darwin)

Настройте proxy через GUI:

Proxy Укажите:

http://{ipaddress}:3128