ciproxy

package module
v0.0.0-...-1a24cbd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README




CiProxy

Introduce
use tcp implement, not http server, base on golang

golang request open sourse (shields.io) github (shields.io) gitee (shields.io) git (shields.io) img

Features

  1. 纯原生

Todo(需要实现)

个人没什么空余时间,希望可以有更多的人一起开发

  • restruct code style(重构代码风格规范,部分代码注释目前没有好的管控)
  • impelment proxy server controller(实现一个代理切换控制台)
  • impelment usage example
  • optimize performance, add sync
  • impelment test example

Install(安装)

go get github.com/opencvlzg/ciproxy

Example(示例)

(internal implement) ciproxy-master/cmd

go build ./cmd/proxyType/
./main -ip -port -method 

(external implement) ciproxy-example/cmd

External-Usage(使用)

// main implement a simple httpsproxy(only https)

package main

import (
	"flag"
	"github.com/opencvlzg/ciproxy/constants/proxyMethod"
	"github.com/opencvlzg/ciproxy/proxyServer/middleHandle"
	"github.com/opencvlzg/ciproxy/proxyServer/serve"
	"net"
)

func main() {
	ip := flag.String("ip", "127.0.0.1", "Server Ip Address")
	port := flag.String("port", "6677", "Server Port")
	method := flag.String("method", proxyMethod.HttpsProxy, "Server METHOD NORMAL,TUNNEL, SNIFF")
	protocol := flag.String("protocol", "TCP", "Connect Protocol")
	logPath := flag.String("log", "log/proxy.log", "log file path")
	flag.Parse()
	// proxyServer := ciproxy.NewProxyServe()
	proxyServe := serve.ProxyServe{
		Ip:       *ip,
		Port:     *port,
		Method:   *method,
		Protocol: *protocol,
		LogPath:  *logPath,
	}
	middleHandle.Add(func(client net.Conn, target net.Conn) {
		// Todo Some regular u want implement
	})
	proxyServe.Start()
}

HttpProxy

HttpsProxy

HttpsSniffProxy

TunnelProxy

Directory(目录说明)

├─cert (证书目录)
│      private.pem
│      root.crt
│      root.csr
│
├─cmd (例子目录)
│  ├─customProxyServer
│  │      main.go
│  │
│  ├─generateCert
│  │      common.txt
│  │      main.go
│  │
│  ├─httpsProxyServer
│  │      main.go
│  │
│  ├─httpsSniffProxyServer
│  │      main.go
│  │
│  ├─tunnelProxyClient
│  │      main.go
│  │
│  ├─tunnelProxyServer
│  │      main.go
│  │
│  └─websocketProxyServer
│          main.go
│
├─internal (内部包)
│  ├─middleware
│  └─util  (常用工具)
│          genHttp.go   (http内容生成)
│          regex.go	    (旧版解析信息用)
│          tlsUtil.go   (tls配置生成)
│          util.go	   
│          windowApi.go (windowApi业务)
│
├─log  (默认日志生成路径)
│      proxy.log
│
├─test
|       main.go
│  ciproxy.go			
│  constants.go			(配置常量)
│  context.go			(代理上下文)
│  data.txt				(例子生成的文件)
│  go.mod		
│  LICENSE
│  proxyHandle.go		 (代理请求处理)
│  README.md
│  serve.go				 (程序主入口)
│  serveHandle.go         (监听服务处理)
│  trafficHandle.go		  (网络流浪处理)


Contact(联系)

ciproxy communicate

google email cilanguser@gmail.com

Support(支持)

CiPorxy遵循Mit开源协议,如果你想请支持,可以点我

Documentation

Overview

Package ciproxy a proxy frame implement by tcp,udp

Package ciproxy proxyHandle 代理响应处理头

Package ciproxy 流量转发

Index

Constants

View Source
const (
	HttpProxy             = "HttpProxy"
	HttpsProxy            = "HttpsProxy"
	HttpsSniffProxy       = "HttpsSniffProxy"
	HttpsSniffDetailProxy = "HttpsSniffDetailProxy"
	WebsocketProxy        = "WebsocketProxy"
	TcpNormalProxy        = "TcpNormal"
	TcpTunnelProxy        = "TcpTunnel"
	PortProxy             = "PortProxy"
	DefaultProxy          = "All"
)

ProxyMethod constant proxyMethod

View Source
const (
	ProxyVersion = "v0.0.0"
	ProxyMode    = "Debug"

	// DefaultIp DefaultPort defaultServerConfig
	DefaultIp   = "127.0.0.1"
	DefaultPort = ""

	ProxyOrganization = "www.cilang.buzz"
)

Proxy Config

View Source
const (
	DefaultConnectProtocol = "Tcp"
	DefaultOutTime         = 10 * time.Second
)

connectConfig Connect Config Constant

Variables

View Source
var DefaultCert = []byte("-----BEGIN CERTIFICATE-----\nMIIDrzCCApcCFCO3T1AFJW49FIgStat27CO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Q7B9QkdQ4c6Ly\nHbhsAfj4ULCeaJyqFXf1Ar+A2XDxR2C/aXM6fKFwyD+0xciQTXNbA/VH2WSokESJ\nM3fE8stCi3chChqqbAaMSsu1a6hQzqfPM/KdowvjED/M3DPliJ83SVxGeyblV1/j\n877WLawMwlMEUn35+8SQBVTyEM4EEnG8wH/35kdrIxSVqnQ=\n-----END CERTIFICATE-----\n")

DefaultCert 默认证书

View Source
var DefaultCertKey = []byte("-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDb52u1P+BlDRCY\nxBLfiywnNWewD0sNEa3CXZyWSzhkCOgaMO1AwXHljmh3DwhI2zEaD1BFkOJPJd8L\nw+QaFoSEe+wS5uqPOTylK0OUfGbku1SV48mkhcirA5hs3zDw65pRm8H7UOTIlqtc\nT0LEKXlTibx2iSNCZ+u0U2QUfAtWgWVrL75ssOKpz4CmpV31xbLrDpL3itcZVXj+\nw5qtL77xg9r5mAcaLft88MjS7XffNW68HsIJ0zXoaLLvr9HXdS6kr51CXYJc0RZh\ngljPQHLd/i/GIBzhu3t72yqTDQ9EoiDJ/BVt2mwNbM7bQJw+TLlhS4cWKqrU1sXo\nJ0iMVd3hAgMBAAECggEAEdMcIupVLDu3EnrwmktNcYKQ4tXkHBOu+I539W+OPmWO\nbFkQHuvPNjx116vrQv4paIn0B4xRgix5FbRzyXDCN+IhMslu59vlQFbvOM3HCIrt\n6OLSFgWvsogtecQZoBDcE5NcuBwVf1p4wP6K7ejJG24sGmIBVQ4K+zUea2tzZWtP\nKGqyGC2uDK0wmtjkmLnhIIyXTB0ZaxiDnskVmFbqeCZlY5784cAFxCLkl72g1ask\nu5ht7a+c83lg3Yo77ocuF+LQIp5NRIwd4BivdaoJjnbOWeImT5soGqt3JGzDLzLT\nzFYerDIgwjlBJS+xJOYzfk4m/fye5PAtiRskTY4vNQKBgQD2z34x8U1t7wbLWy6B\nldZ30SFWFUwT8AmyTOn6ZghS1rxZ260FxgPcTI9/YPbZf/jE8l0DuSny8fMThdRy\nSoy8vL7goHmZwXiT4WtveAIZJwH2WMfSQjl7cBDLEfM25eCN783Qt1nNqpZehscv\nW10zgHf0RhgTcxZpScxUHPrYhwKBgQDkF3bxdS7IK2eFuoBN3RA/rZP+3dmuJnmq\n6aP7GPPqVTPv295a3GU1Pj8dAHj+4lshJoHHReXsLR786Gu9gV2di2ibI14xn5ZY\n6TIkORJDrU9wkpKGlZsreXcH8lXD8GX2eW+/9eSMtkPkPx1CN/dl0QSC84VyHOl3\nEkUkpnF4VwKBgQDBsA4h1XNlTYqwdgsmKNeZSeZ2bto4X0zMvy1zkzT/BYPkpM/A\n0yfeb7rBRPATuikZLfYu4NX50URoUsNpOfX+e8Tz9RvYvQsKSoIMhUpoQMN6dyvB\nZrVDmKulIZ4TvA0gdku3etwf2bqNzglssa+Ppkb8zTFBujShRgfzDpcQ6wKBgQDC\nlFHfwjvaf0ydBHEX+5I1AHrUXaWpryDz8MT3HF5Ydb8My+BwWrvsI+Hrd8/AgJGF\nQjhMKxDt3cAluJDQ5V9bWuYuEon0g1PbHXSs+hLesSanviJJta7d84zbtpv7v0T8\ncrQmajpC3+oi+MSZDO18akcS/3PD2W5BKdDaZzM9mQKBgHpkLEww2/NthFXg5F0E\nPS23WmBtz5921tVdg1MlAXtZzs8ordT0+w8enGJHglWdBVzrF4qdcTN2tjnlu2e/\nNhGyJiJZ65+dINTibcV3712ChCwvjbf0rTGnpbXaXQHqWmZaC36DchCkdfbJMUCY\nsXnkBxS7/+CrzLBtcmLhaKVJ\n-----END PRIVATE KEY-----\n")

DefaultCertKey 默认私钥

View Source
var DefaultWriter io.Writer = os.Stdout

DefaultWriter reference gin

Functions

func HttpProxyHandle

func HttpProxyHandle(c *Context)

HttpProxyHandle Http处理

func HttpsProxyHandle

func HttpsProxyHandle(c *Context)

HttpsProxyHandle Https处理

func HttpsSniffDetailProxyHandle

func HttpsSniffDetailProxyHandle(c *Context)

HttpsSniffDetailProxyHandle https中间人处理

func HttpsSniffProxyHandle

func HttpsSniffProxyHandle(c *Context)

HttpsSniffProxyHandle https中间人处理

func ServeProxy

func ServeProxy(p *ProxyServe)

ServeProxy 启动监听

func TeeDoRequestTransfer

func TeeDoRequestTransfer(c *Context)

TeeDoRequestTransfer traffic transfer 流量Io转发,手动处理请求

func TeeTransfer

func TeeTransfer(destination io.WriteCloser, source io.ReadCloser)

TeeTransfer traffic transfer 流量Io转发

func Transfer

func Transfer(destination io.WriteCloser, source io.ReadCloser)

Transfer traffic transfer 流量Io转发

func TunnelProxyHandle

func TunnelProxyHandle(c *Context)

TunnelProxyHandle 加密代理

func TunnelTransfer

func TunnelTransfer()

TunnelTransfer 加密流量转发

func WebsocketProxyHandle

func WebsocketProxyHandle(c *Context)

WebsocketProxyHandle websocket 代理

Types

type Context

type Context struct {
	// ConnStatus conn status connecting closed nil
	ConnStatus string
	// ClientConn client net conn
	ClientConn net.Conn
	// TlsClientConn client tls net conn
	TlsClientConn net.Conn
	Request       *http.Request

	// ServerConn server net conn
	ServerConn net.Conn
	// TslServerConn server tls net conn
	TslServerConn net.Conn
	Response      http.Response
	// contains filtered or unexported fields
}

Context reference from go-proxy and gin

func (*Context) Abort

func (c *Context) Abort()

Abort set the abort index

func (*Context) IsAbort

func (c *Context) IsAbort() bool

IsAbort return abort label

func (*Context) Next

func (c *Context) Next()

Next set to next handle

func (*Context) SetClientConn

func (c *Context) SetClientConn(ClientConn net.Conn)

SetClientConn set client conn

func (*Context) SetRequest

func (c *Context) SetRequest()

SetRequest set the request to the context.Request

func (*Context) SetResponse

func (c *Context) SetResponse()

SetResponse set the response to the context.Response

func (*Context) SetServerConn

func (c *Context) SetServerConn(ServerConn net.Conn)

SetServerConn set the server conn

type ProxyHandle

type ProxyHandle func(ctx *Context)

ProxyHandle define the proxyHandle to handle proxyRequest and used by middleware

type ProxyHandlersChain

type ProxyHandlersChain []ProxyHandle

ProxyHandlersChain define proxyHandle slice

type ProxyServe

type ProxyServe struct {
	Ip       string `json:"ip,omitempty"`
	Port     string `json:"port,omitempty"`
	Method   string `json:"method,omitempty"`
	Protocol string `json:"protocol,omitempty"`
	LogPath  string `json:"logPath,omitempty"`
	Host     string

	// ProxyHandle use custom proxy need
	ProxyHandlersChain ProxyHandlersChain
	// contains filtered or unexported fields
}

func Default

func Default() *ProxyServe

Default 返回默认服务实例

func NewProxyServe

func NewProxyServe() *ProxyServe

NewProxyServe 返回服务实例

func (*ProxyServe) AddHandle

func (p *ProxyServe) AddHandle(proxyHandle ProxyHandle)

AddHandle 设置自定义代理响应处理 从尾部添加响应处理 set the custom proxyHandle if u choose the customMethod

func (*ProxyServe) AddMiddleware

func (p *ProxyServe) AddMiddleware(proxyHandle ProxyHandle)

AddMiddleware 从头部添加中间件 set the custom middleware

func (*ProxyServe) ServerHandleListen

func (p *ProxyServe) ServerHandleListen()

ServerHandleListen ServerHandle 服务代理处理

func (*ProxyServe) Start

func (p *ProxyServe) Start()

Start 服务启动主入口 running the server

Directories

Path Synopsis
cmd
internal
util
Package util 生成Http响应内容
Package util 生成Http响应内容

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL