httprelay

package module
v0.0.0-...-d12c2a5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 15 Imported by: 0

README

HTTP proxy to SOCKS 5 proxy relay

Single-purpose HTTP proxy relaying requests to an existing (external) SOCKS 5 proxy server. This tool is useful in the case where the SOCKS proxy is the only proxy available, but the application that you wish to use does not support SOCKS. This little program is a welcome addition to SSH's capability of setting up a SOCKS proxy server.

Please note: This implementation is specifically limited to this use case only. Other use cases may be trivial to create, however they are not part of this implementation.

Usage

./relay -listen :8080 -socks localhost:8000 -socks-user socksUsername -socks-pass socksPassword -block "127.0.0.1,localhost,192.168/16"

Start a HTTP relay proxy that listens on port 8080 of every interface and connects to a SOCKS proxy server on localhost port 8000 for relaying your requests. Block requests that attempt to access 127.0.0.1, 'localhost' or any address in the ip range 192.168.0.0-192.168.255.255.

./proxy -listen localhost:8080 -block "127.0.0.1,localhost,192.168.0.1/16"

Start a (tiny) generic HTTP proxy server that listens on port 8080 of 'localhost' and proxies requests directly to the internet. Block any requests to 127.0.0.1, 'localhost' or any address in the ip range 192.168.0.0-192.168.255.255.

Program arguments

The program arguments that are available to both programs.

  • -block provide any number of network addresses/ranges to protect from access through the proxy/relay.
  • -blocklist specify a hosts-formatted blocklist to be loaded and used.
  • -listen specify the address and port on which to listen for incoming proxy connections.

The following program arguments are applicable to relay only.

  • -socks the SOCKS proxy to which to forward http proxy requests.
  • -socks-user the username of SOCKS5 proxy server.
  • -socks-pass the password of SOCKS5 proxy server.

Building

The simplest way to build is: make.

This build will use the build flag -tags netgo to make the result independent of gcc. Refer to Makefile for details.

Changelog

  • 2023-08-15 Command-line flags to provide username/password authentication for SOCKS5 proxy (relay) by developbranch-cn.
  • 2020-02-04 Added support for loading in blocklists that are checked as part of the proxying process.
    The program argument -blocklist <filename> allows loading hostname blocklists formatted as the OS hosts file. Blocklists in these formats can be downloaded from various places, such as NoTracking and EnergizedPro.
  • 2019-12-22 Added support for Go modules.
  • way back Support for http proxy/relay, with -block parameter to protect local network and/or specific addresses/networks from being accessed.

References

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockedHost = errors.NewStringError("host is blocked")

ErrBlockedHost indicates that host is blocked.

Functions

func Fuzz

func Fuzz(data []byte) int

Fuzz is go-fuzz's fuzzing function. Though there is not much to fuzz.

func LoadHostsFile

func LoadHostsFile(dialer *BlocklistDialer, filename string) error

LoadHostsFile loads a `hosts`-formatted blocklist into provided BlocklistDialer.

Types

type BlocklistDialer

type BlocklistDialer struct {
	List   map[string]struct{}
	Dialer proxy.Dialer
}

BlocklistDialer checks the loaded blocklist before dialing.

func (*BlocklistDialer) Dial

func (b *BlocklistDialer) Dial(network, addr string) (net.Conn, error)

Dial checks the address against the blocklist and if not present uses the provided dialer to dial the address.

func (*BlocklistDialer) Load

func (b *BlocklistDialer) Load(in io.Reader) error

Load loads a blocklist from provided reader that has content formatted like the operating system 'hosts' files.

type HTTPProxyHandler

type HTTPProxyHandler struct {
	// Dialer is the dialer for connecting to the SOCKS5 proxy.
	Dialer    proxy.Dialer
	UserAgent string
}

HTTPProxyHandler is a proxy handler that passes on request to a SOCKS5 proxy server.

func (*HTTPProxyHandler) ServeHTTP

func (h *HTTPProxyHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request)

type NopDialer

type NopDialer struct{}

NopDialer does not perform dialing operation as host is blocked.

func (NopDialer) Dial

func (NopDialer) Dial(network, addr string) (net.Conn, error)

Dial performs no-op dial operation.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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