azuretls

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 31 Imported by: 35

README

AzureTLS Client

The project aims to provide a simple way to modify and spoof TLS and HTTP2 information in Go.

Usage

Import
import (
    "github.com/Noooste/azuretls-client"
)
Create a Session
session := azuretls.NewSession()
Modify TLS

To modify TLS, you have 2 ways :

  • The first one is to use the session.ApplyJA3 method, which takes a (string, string) as parameter. The first one is the ja3 fingerprint and the second one is the target navigator (chrome, firefox, safari, ...).
  • The second one is to assign a method to session.GetClientHelloSpec that returns TLS configuration.
session := azuretls.NewSession()

// First way
ja3 := "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,45-13-43-0-16-65281-51-18-11-27-35-23-10-5-17513-21,29-23-24-25-26,0"
if err := session.ApplyJa3(ja3, azuretls.Chrome); err != nil {
    panic(err)
}

// Second way
session.GetClientHelloSpec = azuretls.GetLastChromeVersion

resp, err := session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}

fmt.Println(resp.StatusCode)
fmt.Println(string(resp.Body))
Modify HTTP2

To modify HTTP2, you have to apply the HTTP2 fingerprint to the session.

session := azuretls.NewSession()

http2 := "1:65536,2:0,3:1000,4:6291456,6:262144|15663105|0|m,s,a,p"

if err := session.ApplyHTTP2(http2); err != nil {
    panic(err)
}

resp, err := session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}

fmt.Println(resp.StatusCode)
fmt.Println(string(resp.Body))
Headers

You can set headers to the session in 2 different ways :

  • The first one would be to add the headers to the session with the session.Headers. However, you will need to apply the order of the headers with the session.HeadersOrder.
session := azuretls.NewSession()

session.Headers = http.Header{
    "user-agent": {"test"},
    "content-type": {"application/json"},
    "accept": {"application/json"},
}

session.HeadersOrder = azuretls.HeaderOrder{
    "user-agent",
    "content-type",
    "accept",
}

response, err := session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}

fmt.Println(response.StatusCode)
fmt.Println(string(response.Body))

session.Close()
  • The second one, which is the easiest one, is to use the session.OrderedHeaders method, which is [][]string. No need to apply the order of the headers, it's already done.
// Second way
session := azuretls.NewSession()

session.OrderedHeaders = azuretls.OrderedHeaders{
    {"user-agent", "test"},
    {"content-type", "application/json"},
    {"accept", "application/json"},
}

response, err = session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}

fmt.Println(response.StatusCode)
fmt.Println(string(response.Body))

session.Close()
Proxy

You can set a proxy to the session with the session.SetProxy method. It takes a string as parameter, which is the proxy address. Proxy format supported :

  • http://ip:port
  • http://username:password@ip:port
  • ip:port
  • ip:port:username:password
  • username:password:ip:port
  • username:password@ip:port
session := azuretls.NewSession()

session.SetProxy("http://username:password@ip:port")

response, err := session.Get("https://api.ipify.org")

if err != nil {
    panic(err)
}

fmt.Println(response.StatusCode)
fmt.Println(string(response.Body))

session.Close()
SSL Pinning

SSL pinning is enabled by default.

session := azuretls.NewSession()

// secured request
response, err := session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}

fmt.Println(response.StatusCode)
fmt.Println(string(response.Body))

session.Close()

You can set manual SSL Pinning to the session with method session.AddPins.

session := azuretls.NewSession()

session.AddPins(&url.URL{
        Scheme: "https",
        Host:   "httpbin.org",
    }, []string{
        "j5bzD/UjYVE+0feXsngcrVs3i1vSaoOOtPgpLBb9Db8=",
        "18tkPyr2nckv4fgo0dhAkaUtJ2hu2831xlO2SKhq8dg=",
        "++MBgDH5WGvL9Bcn5Be30cRcL0f5O+NyoXuWtQdX1aI=",
        "KwccWaCgrnaw6tsrrSO61FgLacNgG2MMLq8GE6+oP5I=",
})

_, err := session.Get("https://httpbin.org/get")

if err != nil {
    panic(err)
}

To diable SSL Pinning, you can do session.InsecureSkipVerify = true

session := azuretls.NewSession()

session.InsecureSkipVerify = true

// do it at your own risk !
_, err := session.Get("https://httpbin.org/get")

if err != nil {
    panic(err)
}
Timeout

You can set a timeout to the session with the session.SetTimeout method. It takes a time.Duration as parameter, which is the timeout duration.

session := azuretls.NewSession()

session.SetTimeout(10 * time.Second)

response, err := session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}

fmt.Println(response.StatusCode)
fmt.Println(string(response.Body))

session.Close()
PreHook and CallBack

You can set pre hooks to the session with the session.PreHook method. It takes a func(*http.Request) error as parameter, which is the pre hook function.

session := azuretls.NewSession()

session.PreHook = func(req *http.Request) error {
    req.Header.Set("user-agent", "test")
    return nil
}

response, err := session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}

You can set call backs to the session with the session.CallBack method. It takes a func(*http.Response) error as parameter, which is the call back function.

session := azuretls.NewSession()

session.CallBack = func(request *Request, response *Response, err error) {
    fmt.Println(response.StatusCode)
    return nil
}

response, err := session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}
Cookies

You can set cookies to the session with the session.SetCookies method. It takes a []*http.Cookie as parameter, which is the cookies.

session := azuretls.NewSession()

parsed, err := url.Parse("https://tls.peet.ws/api/all")

session.CookieJar.SetCookies(parsed, []*http.Cookie{
    {
        Name:  "test",
        Value: "test",
    },
})

response, err := session.Get("https://tls.peet.ws/api/all")

if err != nil {
    panic(err)
}

Documentation

Index

Constants

View Source
const (
	Chrome  = "chrome"
	Firefox = "firefox"
	Opera   = "opera"
	Safari  = "safari"
	Edge    = "edge"
	Ios     = "ios"
	Android = "android" //deprecated
)
View Source
const (
	Path      = ":path"
	Method    = ":method"
	Authority = ":authority"
	Scheme    = ":scheme"
)
View Source
const (
	SchemeHttp  = "http"
	SchemeHttps = "https"
	SchemeWs    = "ws"
	SchemeWss   = "wss"
)

Variables

This section is empty.

Functions

func DecompressBody

func DecompressBody(Body []byte, encoding string) (parsedBody []byte)

DecompressBody unzips compressed data

func DeflateData

func DeflateData(data []byte) (resData []byte, err error)

func EnflateData

func EnflateData(data []byte) (resData []byte, err error)

func GUnzipData

func GUnzipData(data []byte) (resData []byte, err error)

func GetExtensions

func GetExtensions(extensions []string, specifications *TlsSpecifications, defaultPointsFormat []string, defaultCurves []string, navigator string) ([]tls.TLSExtension, uint16, uint16, error)

func GetLastChromeVersion

func GetLastChromeVersion() *tls.ClientHelloSpec

GetLastChromeVersion apply the latest Chrome version Current Chrome version : 114

func GetLastIosVersion

func GetLastIosVersion() *tls.ClientHelloSpec

func GetSupportedAlgorithms

func GetSupportedAlgorithms(navigator string) []tls.SignatureScheme

func GetSupportedVersion

func GetSupportedVersion(navigator string) ([]uint16, uint16, uint16)

func TurnToUint

func TurnToUint(ciphers []string, navigator string) ([]uint16, string)

func UnBrotliData

func UnBrotliData(data []byte) (resData []byte, err error)

Types

type ContextKeyHeader

type ContextKeyHeader struct{}

type DefaultPushHandler

type DefaultPushHandler struct {
	// contains filtered or unexported fields
}

DefaultPushHandler default push handler

func (*DefaultPushHandler) HandlePush

func (ph *DefaultPushHandler) HandlePush(r *http2.PushedRequest)

type HeaderOrder

type HeaderOrder []string

type OrderedHeaders

type OrderedHeaders [][]string

OrderedHeaders is a slice of headers.

func (*OrderedHeaders) Add

func (oh *OrderedHeaders) Add(field string, value ...string)

Add adds the value to the field. It appends to any existing values associated with the field.

func (*OrderedHeaders) Clone

func (oh *OrderedHeaders) Clone() OrderedHeaders

Clone returns a copy of the header.

func (*OrderedHeaders) Del

func (oh *OrderedHeaders) Del(field string) OrderedHeaders

Del removes the first instance of the field from the header. If the field is not present, it does nothing.

func (*OrderedHeaders) Get

func (oh *OrderedHeaders) Get(field string) string

Get returns the first value associated with the given field. If the field is not present, it returns an empty string.

func (*OrderedHeaders) Remove

func (oh *OrderedHeaders) Remove(field string) OrderedHeaders

Remove removes the first instance of the field from the header. If the field is not present, it does nothing. Deprecated: Use Del instead.

func (*OrderedHeaders) Set

func (oh *OrderedHeaders) Set(field string, value ...string)

Set sets the field to the given value. It replaces any existing values associated with the field.

type PHeader

type PHeader [4]string

func (PHeader) GetDefault

func (ph PHeader) GetDefault()

type PinManager added in v1.1.0

type PinManager struct {
	// contains filtered or unexported fields
}

func NewPinManager added in v1.1.0

func NewPinManager() *PinManager

func (*PinManager) AddPin added in v1.1.0

func (p *PinManager) AddPin(pin string)

func (*PinManager) New added in v1.1.0

func (p *PinManager) New(addr string) (err error)

func (*PinManager) Verify added in v1.1.0

func (p *PinManager) Verify(c *x509.Certificate) bool

type Request

type Request struct {
	HttpRequest *http.Request

	Method string

	Url string

	Body any

	PHeader PHeader

	Header      http.Header //deprecated, use OrderedHeaders instead
	HeaderOrder HeaderOrder //deprecated, use OrderedHeaders instead

	OrderedHeaders OrderedHeaders

	Proxy   string
	Browser string

	DisableRedirects bool
	NoCookie         bool

	TimeOut time.Duration

	IsRedirected bool

	FetchServerPush    bool
	InsecureSkipVerify bool

	IgnoreBody bool

	Proto string
	// contains filtered or unexported fields
}

func (*Request) CloseBody

func (r *Request) CloseBody()

func (*Request) SetContext

func (r *Request) SetContext(ctx context.Context)

func (*Request) String

func (r *Request) String() string

type RequestConn added in v1.1.0

type RequestConn struct {
	TLS   *tls.UConn
	HTTP2 *http2.ClientConn
	Conn  net.Conn

	Pins *PinManager
	// contains filtered or unexported fields
}

func NewRequestConn added in v1.1.0

func NewRequestConn() *RequestConn

func (*RequestConn) Close added in v1.1.0

func (rc *RequestConn) Close()

func (*RequestConn) NewConn added in v1.1.0

func (rc *RequestConn) NewConn(req *Request, doPins bool, getSpec func() *tls.ClientHelloSpec) (err error)

type RequestConnPool added in v1.1.0

type RequestConnPool struct {
	// contains filtered or unexported fields
}

func NewRequestConnPool added in v1.1.0

func NewRequestConnPool() *RequestConnPool

func (*RequestConnPool) Close added in v1.1.0

func (p *RequestConnPool) Close()

func (*RequestConnPool) Get added in v1.1.0

func (p *RequestConnPool) Get(u *url.URL) (c *RequestConn, err error)

func (*RequestConnPool) Remove added in v1.1.0

func (p *RequestConnPool) Remove(u *url.URL)

func (*RequestConnPool) Set added in v1.1.0

func (p *RequestConnPool) Set(u *url.URL, c *RequestConn)

type Response

type Response struct {
	Id         uint64
	StatusCode int
	Body       []byte
	RawBody    io.ReadCloser
	Header     http.Header
	Cookies    map[string]string
	Url        string
	IgnoreBody bool

	HttpResponse *http.Response

	Request *Request

	TLS *tls.ConnectionState

	ContentLength int64
}

func (*Response) CloseBody

func (r *Response) CloseBody()

func (*Response) Load added in v1.1.0

func (r *Response) Load(v any) error

func (*Response) MustLoad added in v1.1.0

func (r *Response) MustLoad(v any)

func (*Response) ReadBody

func (r *Response) ReadBody() ([]byte, error)

func (*Response) String

func (r *Response) String() string

type ServerPush

type ServerPush struct {
	StatusCode int               `json:"status_code"`
	Body       string            `json:"body"`
	Headers    map[string]string `json:"headers"`
	Cookies    map[string]string `json:"cookies"`
	Url        string            `json:"url"`
}

type Session

type Session struct {
	Headers      http.Header //deprecated, use OrderedHeaders instead
	HeadersOrder HeaderOrder //deprecated

	PHeader PHeader

	OrderedHeaders OrderedHeaders

	CookieJar *cookiejar.Jar
	Browser   string

	Connections *RequestConnPool

	GetClientHelloSpec func() *tls.ClientHelloSpec

	Proxy       string
	RotateProxy bool

	Verbose           bool
	VerbosePath       string
	VerboseIgnoreHost []string

	VerboseFunc func(request *Request, response *Response, err error)

	TimeOut time.Duration

	PreHook  func(request *Request) error
	Callback func(request *Request, response *Response, err error)

	VerifyPins         bool // deprecated, this parameter is ignored as verify pins is always true. To disable pin verification, use the InsecureSkipVerify parameter instead
	InsecureSkipVerify bool

	UserAgent, SecChUa string

	ServerPush chan *Response
	// contains filtered or unexported fields
}

func NewSession

func NewSession() *Session

NewSession creates a new session It is recommended to use this function to create a new session instead of creating a new Session struct This function will set the default values for the session

func NewSessionWithContext

func NewSessionWithContext(ctx context.Context) *Session

func (*Session) AddPins added in v1.1.0

func (s *Session) AddPins(u *url.URL, pins []string) error

func (*Session) ApplyHTTP2

func (s *Session) ApplyHTTP2(fp string) error

func (*Session) ApplyJa3

func (s *Session) ApplyJa3(ja3, navigator string) error

func (*Session) ApplyJa3WithSpecifications

func (s *Session) ApplyJa3WithSpecifications(ja3 string, specifications TlsSpecifications, navigator string) error

func (*Session) ClearPins added in v1.1.0

func (s *Session) ClearPins(u *url.URL) error

func (*Session) Close

func (s *Session) Close()

func (*Session) Delete added in v1.1.0

func (s *Session) Delete(url string, args ...any) (*Response, error)

Delete provides shortcut for sending DELETE request

func (*Session) Do

func (s *Session) Do(request *Request, args ...any) (*Response, error)

Do sends a request and returns a response

func (*Session) EnableVerbose

func (s *Session) EnableVerbose(path string, ignoreHost []string)

func (*Session) Get

func (s *Session) Get(url string, args ...any) (*Response, error)

Get provides shortcut for sending GET request

func (*Session) GetCookies

func (s *Session) GetCookies(u string) map[string]string

func (*Session) Head added in v1.1.0

func (s *Session) Head(url string, args ...any) (*Response, error)

Head provides shortcut for sending HEAD request

func (*Session) Ip

func (s *Session) Ip() (ip string, err error)

func (*Session) LoadCookie

func (s *Session) LoadCookie(cookies string) []*http.Cookie

func (*Session) Options added in v1.1.0

func (s *Session) Options(url string, args ...any) (*Response, error)

Options provides shortcut for sending OPTIONS request

func (*Session) Patch added in v1.1.0

func (s *Session) Patch(url string, data any, args ...any) (*Response, error)

Patch provides shortcut for sending PATCH request²

func (*Session) Post

func (s *Session) Post(url string, data []byte, args ...any) (*Response, error)

Post provides shortcut for sending POST request

func (*Session) Put

func (s *Session) Put(url string, data []byte, args ...any) (*Response, error)

Put provides shortcut for sending PUT request

func (*Session) SetContext added in v1.1.0

func (s *Session) SetContext(ctx context.Context)

func (*Session) SetProxy

func (s *Session) SetProxy(proxy string)

func (*Session) SetTimeout

func (s *Session) SetTimeout(timeout time.Duration)

type TlsSpecifications

type TlsSpecifications struct {
	AlpnProtocols                           []string
	SignatureAlgorithms                     []tls.SignatureScheme
	SupportedVersions                       []uint16
	CertCompressionAlgos                    []tls.CertCompressionAlgo
	DelegatedCredentialsAlgorithmSignatures []tls.SignatureScheme
	PSKKeyExchangeModes                     []uint8
	SignatureAlgorithmsCert                 []tls.SignatureScheme
	ApplicationSettingsProtocols            []string
	RenegotiationSupport                    tls.RenegotiationSupport
}

func DefaultTlsSpecifications

func DefaultTlsSpecifications() TlsSpecifications

type TlsVersion

type TlsVersion uint16

Directories

Path Synopsis
examples
headers command
http2 command
ja3 command
proxy command

Jump to

Keyboard shortcuts

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