Giter VIP home page Giter VIP logo

g3's Introduction

minimum rustc: 1.77 License: Apache 2.0

G3 Project

中文版 README

About

This is the project we used to build enterprise-oriented generic proxy solutions, including but not limited to proxy / reverse proxy (WIP) / load balancer (TBD) / nat traversal (TBD).

Components

G3 Project is made up of many components.

The project-level documents resides in the doc subdirectory, and you should see the links below for the important ones. Each component will have its own documents in its doc subdirectory.

g3proxy

A generic forward proxy solution, but you can also use it as tcp streaming / transparent proxy / reverse proxy as we have basic support built in.

Feature highlights

  • Async Rust: fast and reliable
  • Http1 / Socks4 / Socks5 forward proxy protocol, SNI Proxy and TCP TPROXY
  • TLS over OpenSSL or BoringSSL or AWS-LC or Tongsuo, and even rustls
  • TLS MITM interception, decrypted traffic dump, HTTP1 and HTTP2 interception
  • ICAP audit protocol
  • Graceful reload
  • Customizable load balancing and failover strategies
  • Support for a variety of observability tools

See g3proxy for detailed introduction.

g3tiles

A work in progress reverse proxy solution.

g3bench

A benchmark tool that supports HTTP 1.x, HTTP 2, HTTP 3, TLS Handshake, DNS and Cloudflare Keyless.

See g3bench for detailed introduction.

g3mkcert

A tool to make root CA / intermediate CA / TLS server / TLS client certificates.

g3fcgen

Fake certificate generator for g3proxy.

g3iploc

IP location lookup service for g3proxy GeoIP support.

g3keymess

A simple implementation of Cloudflare keyless server.

Target Platform

Only Linux is fully supported yet. The code will compile on FreeBSD, NetBSD, macOS and Windows, but we haven't tested it there.

Feel free to open PRs to add support for other platforms.

Dev-env Setup Guide

Follow Dev-Setup.

Standards

Follow Standards.

Release and Packaging

We will set tags for each release of each component in the form <name>-v<version>. You can use these tags to generate source tarballs. And we have added deb and rpm package files for each component that is ready for distribution.

If you want to do a release build:

  1. generate a release tarball

    # if we have a tag <name>-v<version>
    ./scripts/release/build_tarball.sh <name>-v<version>
    # if no tags usable, you need to specify the git revision (e.g. HEAD)
    ./scripts/release/build_tarball.sh <name> <rev>

    All vendor sources will be added to the source tarball, so you can save the source tarball and build it offline at anywhere that has the compiler and dependencies installed.

  2. build the package

    For deb package:

    tar xf <name>-<version>.tar.xz
    cd <name>-<version>
    ./build_deb_from_tar.sh

    For rpm package:

    rpmbuild -ta ./<name>-<version>.tar.xz
    # if failed, you can run the following commands manually:
    tar xvf <name>-<version>.tar.xz ./<name>-<version>/<name>.spec
    cp <name>-<version>.tar.xz ~/rpmbuild/SOURCES/
    rpmbuild -ba ./<name>-<version>/<name>.spec

If you want to build a package directly from the git repo:

  • For deb package:

    ./build_deb_from_git.sh <name>
  • For rpm package:

    ./build_rpm_from_git.sh <name>

Pre-Built Packages

It is recommended to build packages yourself if you want to install them in a production environment.

For testing purpose, we have built and uploaded some packages to cloudsmith, you can find installation instructions there.

Static Linking

See Static Linking.

Build with different OpenSSL variants

See OpenSSL Variants.

LTS Version

See Long-Term Support.

Contribution

Please check Contributing for more details.

Code of Conduct

Please check Code of Conduct for more details.

Security

If you discover a potential security issue in this project, or think you may have discovered a security issue, we ask that you notify Bytedance Security via our security center or vulnerability reporting email.

Please do not create a public GitHub issue.

License

This project is licensed under the Apache-2.0 License.

g3's People

Contributors

danielhaimanot avatar dependabot[bot] avatar mengjie-byted avatar mspublic avatar zh-jq avatar zh-jq-b avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

g3's Issues

Track upstream features that we want to use

Missing Feature

h2:

New Features

cargo:

OpenSSL:

Rustls:

Unsound Problems

QAT Engine:

  • intel/QAT_Engine#292
    Currently we have to use a really large timeout value to workaround this problem.

OpenSSL:

Performance

OpenSSL:

Rustls:

配置文件存放路径文档不对

使用发行版原生安装包安装的,已经安装了systemd参数化服务配置文件,参数就是进程组名称, 对应的入口配置文件存放路径为/etc/g3proxy/<daemon_group>/main.yml。

这里看起来应该是“/etc/<daemon_group>/main.yml”, 比如"/etc/g3proxy/simple_fwd_proxy/main.yml"

Docker container support

Building and running in docker would help speed up development and adoption with new developers. In addition to allowing fast deployment to kubernetes clusters.

I am working on getting a dockerfile working properly with G3 but in case someone already has one I wanted to create an issue.

If no one has one I will submit a PR once it’s done.

rustls server performance doesn't scale well

See
https://bytedance.feishu.cn/docx/TSqmdLNIyozJdCx4rzqcjPyonjd for AWS c6gn 32c64g
https://bytedance.feishu.cn/docx/Icind5zlMowawRx1hVtcGyc9nNf for Intel 96c384g

After change the rustls server session cache to RustlsTrickServerSessionCache introduced in commit 2b4e269, the aws 32c64g performance scale well again, but there are still some problems with Intel 96c384g.

And RustlsTrickServerSessionCache isn't ideal, we need a better solution as suggested in rustls/rustls#1503.

And we should try aws-lc after rustls/rustls#1414 is merged.

Allow hostnames in the config

Hello!

I'm working with @mspublic to get g3proxy running in Docker. Currently, it's not possible to stream the udpdump traffic to Wireshark on the host machine because g3-yaml only accepts ip:host. In order to get this working, we need to use host.docker.internal:5555 in the config.

If you don't mind, I have a PR that changes calls to SocketAddr::from_str() to ToSocketAddrs::to_socket_addrs() in a couple of places related to config parsing, mainly in g3-yaml.

Ability to disable HTTP2 connections?

I may have missed the setting somewhere - but is it possible to disable HTTP2 (and 3) proxing via configuration? I would like to force all client/server connections to use HTTP1. If not is there a specific location you recommend we make the change in code?

Thanks!

Feature Request: Full remote certificate inspection and duplication for TLS MITM

Non critical Feature Request:
When doing TLS MITM the certificate provided to the client currently only has a matching SNI. In an ideal scenario the certificate provided to the client should match as many fields as possible from the remote server certificate (outside of ones such as serial etc). This may cause a small performance hit but since the code already pulls the SNI do I not believe it will be major.

Currently this is not causing major issues anywhere. But is something to keep in mind to feature match closed source proxies.

Issues with SSL interception

I am trying to configure g3proxy to do HTTP forward proxying with SSL inspection (and ICAP adaptation).

Using the examples I found I was able to create the following config file. It will forward HTTP traffic but does not seem to do SSL interception or send ICAP adaptation requests.

It looks like you have fixed the initial g3fcgen issue I was running into. But I have found some more issues which seem to be causing failures.

Documentation Improvements

G3 is a great project! The documentation on how to fully setup everything end to end unfortunately is a bit lacking.

I am creating this issue to track improvements in documentation.

I will definitely help on the English side/work with the team to translate as best as possible/submit PRs for them. Also I would like to help submit new example configs as well.

@zh-jq - would you like me to create new issues for all areas that are needing documentation or should we keep that just under this main issue?

Example:

  1. How would I use g3proxy to do forward proxying with SSL inspection? (Needing to use g3fcgen etc).

  2. How do I configure a “frontend” with g3fcgen?

These as just examples. @zh-jq if it’s easier to quickly right your docs in Chinese I can use tools to translate - but will need to have you review for accuracy.

Thanks again for all your work!!

ICAP issues

I have g3 running and have started testing ICAP integration but have run into weird issues.

When I start g3 it sends an initial OPTIONS to the ICAP server. But after that it does not send reqmod/respmod to the server even with the ratio set to 1. If I turn down the ratio to .5 it will occasionally send a Icap res/req. Maybe 1/100. I am wondering if it could be an issue with the ratio code. I have not seen any errors in the g3 logs.

I have started trying to track down where the issue might be but I wanted to file a ticket in case you might know or have suggestions. I will also add more general logging output to the Icap while going through this then file a PR.

I am using the open source icapeg server for testing. Below is my config

auditor:
  - name: default
    protocol_inspection: {} # Enable protocol recognition, use default parameters
    tls_cert_generator: {}  # Enable TLS hijacking, use default parameters
    tls_interception_client: {} # Can configure proxy to target address TLS connection parameters
    h1_interception: {}         # HTTP/1.0 parsing parameters
    h2_interception: {}         # HTTP/2 parsing parameters
    icap_reqmod_service: icap://127.0.0.1:1344/echo   # ICAP REQMOD service configuration
    icap_respmod_service: icap://127.0.0.1:1344/echo # ICAP RESPMOD service configuration
    application_audit_ratio: 1.0 

g3proxy: Ability to change ClientHello sent to upstream server

When using g3proxy it is sometime detected by websites running on cloudflare and other sites using TLS fingerprinting such as https://github.com/salesforce/ja3. Having the ability to modify the ClientHello will make the proxy less detectable/less fingerprintable and more usable in enterprise environments.

The ideal “solution” would be to be able to set a ja3 fingerprint and have the proxy send it.

I have not found a way to modify it via OpenSSL but it appears rustls may give access to the ClientHello https://docs.rs/reqwest/latest/reqwest/struct.ClientBuilder.html#method.use_preconfigured_tls

Here is a bit more info and code examples:

https://medium.com/cu-cyber/impersonating-ja3-fingerprints-b9f555880e42

https://github.com/refraction-networking/utls

https://github.com/Danny-Dasilva/CycleTLS

https://github.com/LyleMi/ja3proxy

https://github.com/Kolosok86/http-tls-proxy

G3proxy is unable to connect to g3fcgen on MacOS

I know Mac isn't officially supported but I wanted to log this issue.

G3proxy errors out when starting on MacOS if its configured to connect to g3fcgen.

I start g3fcgen using the basic config supposed in examples. It starts fine and I confirmed it opens a socket on UDP port 2999. When I start g3proxy it immediately errors out with the error below. Attached is the config and startup log for it.
crash_config.yml.txt
g3proxy_macos.txt

May 14 09:51:21.609 ERRO failed to spawn all servers

Caused by:
    0: failed to build audit handle
    1: failed to spawn cert generator task
    2: failed to connect to peer address 127.0.0.1:2999: Os { code: 22, kind: InvalidInput, message: "Invalid argument" } <g3proxy(main.rs:86)>
Error: failed to spawn all servers

Caused by:
    0: failed to build audit handle
    1: failed to spawn cert generator task
    2: failed to connect to peer address 127.0.0.1:2999: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }`

How do I add an upstream certificate for proxy chaining?

Hello @zh-jq
We are trying to debug some issues with our environment. We would like to setup g3 as part of a proxy chain with the upstream proxy also doing MITM. But haven’t figured out how to configure g3 to trust the upstream rootCA. Your advice on how to configure this would be much appreciated.

thanks!

Issues with TLS Stream Dump

We have been running into a few issues with the TLS stream dump functionality. I followed the udp dump/exported_pdu instructions in wireshark.

  1. Wireshark is not able to fully parse the different streams (TCP/HTTP/etc). For example when you right click on an HTTP request then select follow-HTTP. It is unable to reassemble and follow the stream. Even if the dump has been running for a while with many requests wireshark identifies newer requests as an early tcp.stream (for example 1 or 2). This leads me to believe it's not able to properly discern between different TCP streams.

  2. The source and destination are of the proxy server and the udpdump receiver. Ideally these would be of the connecting client and remote server. Or at least between the proxy and the remote server.

  3. I believe due to issue 1 we are seeing HTTP [Malformed Packet] errors often.

Thanks for any help/suggestions!

Evaluate Profile-Guided Optimization (PGO) and LLVM BOLT

Hi!

Recently I checked Profile-Guided Optimization (PGO) improvements on multiple projects. The results are here. E.g. PGO helps with optimizing Envoyproxy. PGO results for other proxies like HAProxy, Nginx, httpd you can be found in the repo above. According to the multiple tests, PGO can help with improving performance in many other cases. That's why I think trying to optimize g3 with PGO can be a good idea.

I can suggest the following action points:

  • Perform PGO benchmarks on g3. And if it shows improvements - add a note about possible improvements in g3 performance with PGO.
  • Providing an easier way (e.g. a build option) to build scripts with PGO can be helpful for the end-users and maintainers since they will be able to optimize g3 according to their own workloads.
  • Optimize pre-built binaries

Maybe testing Post-Link Optimization techniques (like LLVM BOLT) would be interesting too (Clang and Rustc already use BOLT as an addition to PGO) but I recommend starting from the usual PGO.

For the Rust projects, I recommend starting experimenting with PGO with cargo-pgo.

Here are some examples of how PGO optimization is integrated in other projects:

g3-io-ext 编译出错

wsl2-archlinux编译,默认Features,请问怎么解决?
Compiling g3-io-ext v0.6.0 (/home/debu/git/rust/g3/lib/g3-io-ext) error: cannot constructmsghdrwith struct literal syntax due to private fields --> lib/g3-io-ext/src/udp/ext.rs:134:9 | 134 | libc::msghdr { | ^^^^^^^^^^^^ | = note: ...and other private fields__pad1and__pad2` that were not provided

error: cannot construct msghdr with struct literal syntax due to private fields
--> lib/g3-io-ext/src/udp/ext.rs:179:9
|
179 | libc::msghdr {
| ^^^^^^^^^^^^
|
= note: ...and other private fields __pad1 and __pad2 that were not provided

error[E0308]: mismatched types
--> lib/g3-io-ext/src/udp/ext.rs:337:21
|
333 | libc::sendmmsg(
| -------------- arguments to this function are incorrect
...
337 | libc::MSG_DONTWAIT | libc::MSG_NOSIGNAL,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found i32
|
note: function defined here
--> /home/debu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.153/src/unix/linux_like/linux/musl/mod.rs:828:12
|
828 | pub fn sendmmsg(
| ^^^^^^^^
help: you can convert an i32 to a u32 and panic if the converted value doesn't fit
|
337 | (libc::MSG_DONTWAIT | libc::MSG_NOSIGNAL).try_into().unwrap(),
| + +++++++++++++++++++++

error[E0308]: mismatched types
--> lib/g3-io-ext/src/udp/ext.rs:397:21
|
393 | libc::recvmmsg(
| -------------- arguments to this function are incorrect
...
397 | libc::MSG_DONTWAIT,
| ^^^^^^^^^^^^^^^^^^ expected u32, found i32
|
note: function defined here
--> /home/debu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.153/src/unix/linux_like/linux/musl/mod.rs:834:12
|
834 | pub fn recvmmsg(
| ^^^^^^^^
help: you can convert an i32 to a u32 and panic if the converted value doesn't fit
|
397 | libc::MSG_DONTWAIT.try_into().unwrap(),
| ++++++++++++++++++++

For more information about this error, try rustc --explain E0308.
error: could not compile g3-io-ext (lib) due to 4 previous errors `

请教完整的tlcp代理示例

感谢
我们现在需要让两台服务器之间使用国密https通讯,需要双向认证,但是不知道g3proxy如何配置,如何使用,有没有示例,多谢了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.