proxy

package module
v0.0.0-...-6a155a4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 7 Imported by: 0

README

tcp-proxy

go-tcp-proxy CI Maintainability

A small TCP proxy written in Go

This project was intended for debugging text-based protocols. The next version will address binary protocols.

Install

Source

$ go get -v github.com/lutfailham96/go-http-injector/cmd/tcp-proxy

Usage

$ tcp-proxy --help
Usage of tcp-proxy:
  -c: output ansi colors
  -h: output hex
  -l="localhost:9999": local address
  -n: disable nagles algorithm
  -r="localhost:80": remote address
  -s="server address / sni address": server:443
  -rp="use as reverse proxy"
  -in-payload="payload to be used as incoming TCP packet"
  -out-payload="payload to be used as outbound TCP packet"
  -v: display server actions
  -vv: display server actions and all tcp data

Note: Regex match and replace only works on text strings and does NOT work across packet boundaries

Client Example

Use custom payload

$ go run cmd/tcp-proxy/main.go \
    -l 127.0.0.1:9999 \
    -r 127.0.0.1:10443 \
    -s myserver:443 \
    -out-payload="GET ws://cloudflare.com HTTP/1.1[crlf]Host: [host][crlf]Upgrade: websocket[crlf]Connection: keep-alive[crlf][crlf]"

Proxying from 127.0.0.1:9999 to 104.15.50.1:443

stunnel configuration

[ws]
client = yes
accept = 127.0.0.1:10443
connect = 104.15.50.5:443
sni = cloudflare.com
cert = /etc/stunnel/ssl/stunnel.pem

Tunnel over SSH conneciton

$ ssh -o "ProxyCommand=corkscrew 127.0.0.1 9999 %h %p" -v4ND 1080 my-user@localhost
Todo
  • Implement tcpproxy.Conn which provides accounting and hooks into the underlying net.Conn
  • Verify wire protocols by providing encoding.BinaryUnmarshaler to a tcpproxy.Conn
  • Modify wire protocols by also providing a map function
  • Implement SOCKS v5 to allow for user-decided remote addresses

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorLogger

type ColorLogger struct {
	VeryVerbose bool
	Verbose     bool
	Prefix      string
	Color       bool
}

ColorLogger - A Logger that logs to stdout in color

func (ColorLogger) Debug

func (l ColorLogger) Debug(f string, args ...interface{})

Debug - Log a debug message

func (ColorLogger) Info

func (l ColorLogger) Info(f string, args ...interface{})

Info - Log a general message

func (ColorLogger) Trace

func (l ColorLogger) Trace(f string, args ...interface{})

Trace - Log a very verbose trace message

func (ColorLogger) Warn

func (l ColorLogger) Warn(f string, args ...interface{})

Warn - Log a warning

type Logger

type Logger interface {
	Trace(f string, args ...interface{})
	Debug(f string, args ...interface{})
	Info(f string, args ...interface{})
	Warn(f string, args ...interface{})
}

Logger - Interface to pass into Proxy for it to log messages

type NullLogger

type NullLogger struct{}

NullLogger - An empty logger that ignores everything

func (NullLogger) Debug

func (l NullLogger) Debug(f string, args ...interface{})

Debug - no-op

func (NullLogger) Info

func (l NullLogger) Info(f string, args ...interface{})

Info - no-op

func (NullLogger) Trace

func (l NullLogger) Trace(f string, args ...interface{})

Trace - no-op

func (NullLogger) Warn

func (l NullLogger) Warn(f string, args ...interface{})

Warn - no-op

type Proxy

type Proxy struct {

	// Settings
	Nagles    bool
	Log       Logger
	OutputHex bool
	// contains filtered or unexported fields
}

Proxy - Manages a Proxy connection, piping data between local and remote.

func New

func New(lconn *net.TCPConn, laddr, raddr *net.TCPAddr, saddr string) *Proxy

New - Create a new Proxy instance. Takes over local connection passed in, and closes it when finished.

func NewTLSUnwrapped

func NewTLSUnwrapped(lconn *net.TCPConn, laddr, raddr *net.TCPAddr, saddr, addr string) *Proxy

NewTLSUnwrapped - Create a new Proxy instance with a remote TLS server for which we want to unwrap the TLS to be able to connect without encryption locally

func (*Proxy) SetIncomingConnPayload

func (p *Proxy) SetIncomingConnPayload(payload string)

func (*Proxy) SetMaxFilterInBuff

func (p *Proxy) SetMaxFilterInBuff(bufferSize uint64)

func (*Proxy) SetMaxFilterOutBuff

func (p *Proxy) SetMaxFilterOutBuff(bufferSize uint64)

func (*Proxy) SetOutboundConnPayload

func (p *Proxy) SetOutboundConnPayload(payload string)

func (*Proxy) SetReverseProxy

func (p *Proxy) SetReverseProxy(enabled bool)

func (*Proxy) Start

func (p *Proxy) Start()

Start - open connection to remote and start proxying data.

Directories

Path Synopsis
cmd
tcp-proxy command

Jump to

Keyboard shortcuts

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