
SOCKS5-to-HTTP 프록시 브리지로, 임의의 TCP 스트림(SSH, SMTP, TLS)을 표준 HTTP 요청을 통해 터널링하여 네트워크 트래픽 난독화와 방화벽 우회를 가능하게 합니다.

이 프로그램은 일반적인 HTTP 요청(PUT, PATCH, POST, GET)을 통해 TCP 스트림 패킷을 보낼 수 있는 아이디어를 시험하기 위한 개념 증명으로 작성했습니다. CONNECT 메서드와 같은 프록시 방식을 사용하지 않고 말이죠. 또한 Rust 언어에 대한 초보자 실력을 연습하기 위한 연습 과제이기도 합니다.
이 도구는 서버와 클라이언트 두 부분으로 구성됩니다.
서버는 단일 PHP 파일로, TCP 소켓을 사용하여 상태 저장 연결을 유지하고 들어오는 HTTP 요청을 처리하는 로직을 포함합니다. 현재 이 로직은 Linux 서버에서만 작동합니다.
Apache+mod_php, nginx+php-fpm 및 내장 PHP 서버(php -S)에서 테스트했습니다.
클라이언트는 Socks5 서버로, 들어오는 클라이언트 연결을 수신하고 바이트 문자열을 패킷화하여 서버에 HTTP 요청을 보냅니다. 응답을 받으면 다시 클라이언트에 씁니다.
이 클라이언트는 Rust로 작성되었으며, Socks5 구현은 v2socks 프로젝트에서 차용했습니다. ylxdzsw님께 감사드립니다.
이 예제를 실행하려면 Proxychains가 필요합니다.
hbserver/hbserver.php 서버 파일을 PHP를 지원하는 웹 서버에 업로드하거나, 아래와 같이 로컬 서버를 실행합니다. 이 명령은 Docker 컨테이너를 생성하여 8080 포트에서 수신 대기합니다.
docker run --rm -it --net host --name apache-webserver -v "$PWD/hbserver:/app -v "$PWD/tools/ports.conf:/etc/apache2/ports.conf" webdevops/php-apache:7.3
클라이언트는 컴파일이 필요하므로, Rust 컴파일러를 설치하거나 rustup에서 가져와야 합니다.
cd client &&\
cargo build &&\
./target/debug/hbsc
Proxychains를 로컬 Socks5 포트를 가리키도록 구성합니다.
echo "socks5 127.0.0.1 1986" >> $HOME/.proxychains/proxychains.conf
모든 준비가 완료되면 몇 가지 테스트를 수행합니다.
icanhazip.com
alejandro@0x2e ~ $ proxychains curl -v icanhazip.com
[proxychains] config file found: /home/alejandro/.proxychains/proxychains.conf
[proxychains] preloading /usr/lib64/libproxychains.so.4.14
* Trying 224.0.0.1:80...
* Connected to icanhazip.com (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: icanhazip.com
> User-Agent: curl/7.72.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 25 Feb 2021 18:08:04 GMT
< Content-Type: text/plain
< Content-Length: 15
< Connection: close
< Set-Cookie: __cfduid=dd994605ef1b77d0aa6dc46b6fdbb4c8d1614276484; expires=Sat, 27-Mar-21 18:08:04 GMT; path=/; domain=.icanhazip.com; HttpOnly; SameSite=Lax
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET
< X-RTFM: Learn about this site at http://bit.ly/icanhazip-faq
< X-THANK-YOU: Many thanks to the fine people at Cloudflare for keeping this site afloat!
< cf-request-id: 087bf977730000e790d13c4000000001
< Server: cloudflare
< CF-RAY: 62735e9f1ec9e790-MDE
< alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
<
XXX.33.235.XXX
* Closing connection 0
http://httpbin.org/headers
alejandro@0x2e ~ $ proxychains curl -v http://httpbin.org/headers
[proxychains] config file found: /home/alejandro/.proxychains/proxychains.conf
[proxychains] preloading /usr/lib64/libproxychains.so.4.14
* Trying 224.0.0.1:80...
* Connected to httpbin.org (127.0.0.1) port 80 (#0)
> GET /headers HTTP/1.1
> Host: httpbin.org
> User-Agent: curl/7.72.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 25 Feb 2021 18:05:51 GMT
< Content-Type: application/json
< Content-Length: 173
< Connection: keep-alive
< Server: gunicorn/19.9.0
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
<
{
"headers": {
"Accept": "*/*",
"Host": "httpbin.org",
"User-Agent": "curl/7.72.0",
"X-Amzn-Trace-Id": "Root=1-6037e6ff-06059b933c2d8c495ecee43a"
}
}
* Connection #0 to host httpbin.org left intact
https://mozilla.org
alejandro@0x2e ~ $ proxychains curl -v https://mozilla.org
[proxychains] config file found: /home/alejandro/.proxychains/proxychains.conf
[proxychains] preloading /usr/lib64/libproxychains.so.4.14
* Trying 224.0.0.1:443...
* Connected to mozilla.org (127.0.0.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=mozilla.org
* start date: Jan 1 19:11:54 2021 GMT
* expire date: Apr 1 19:11:54 2021 GMT
* subjectAltName: host "mozilla.org" matched cert's "mozilla.org"
* issuer: C=US; O=Let's Encrypt; CN=R3
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x562758dbab60)
> GET / HTTP/2
> Host: mozilla.org
> user-agent: curl/7.72.0
> accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 301
< date: Thu, 25 Feb 2021 18:03:56 GMT
< content-type: text/html
< content-length: 162
< location: https://www.mozilla.org/
< strict-transport-security: max-age=60; includeSubDomains
< x-backend-server: TS
< cache-control: max-age=3600
< x-frame-options: SAMEORIGIN
< content-security-policy: frame-ancestors 'none'
<
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
* Connection #0 to host mozilla.org left intact
smtp.gmail.com
alejandro@0x2e ~ $ proxychains nc -v smtp.gmail.com 25
[proxychains] config file found: /home/alejandro/.proxychains/proxychains.conf
[proxychains] preloading /usr/lib64/libproxychains.so.4.14
Connection to smtp.gmail.com 25 port [tcp/smtp] succeeded!
220 smtp.gmail.com ESMTP z1sm4022921qtu.83 - gsmtp
EHLO smtp.gmail.com
250-smtp.gmail.com at your service, [XXX.33.235.XXX]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
^C
alejandro@0x2e ~ $ proxychains ssh localhost 'ps axl --sort=-pcpu|tail -n 5'
[proxychains] config file found: /home/alejandro/.proxychains/proxychains.conf
[proxychains] preloading /usr/lib64/libproxychains.so.4.14
Password:
4 0 65375 1242 20 0 9516 6988 - Ss ? 0:00 sshd: alejandro [priv]
5 1000 65420 65375 20 0 9516 4320 - S ? 0:00 sshd: alejandro@notty
0 1000 65421 65420 20 0 218168 3260 - Ss ? 0:00 bash -c ps axl --sort=-pcpu|tail -n 5
4 1000 65422 65421 20 0 220568 3484 - R ? 0:00 ps axl --sort=-pcpu
0 1000 65423 65421 20 0 216756 748 - S ? 0:00 tail -n 5
alejandro@0x2e ~ $