hulksmash

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: MIT Imports: 9 Imported by: 0

README

Hulk Smash GoDoc Go Report Card

HulkSmash Logo

This is a very easy-to-use library for building a custom brute-force requester for QA purposes. This tool can be useful, for example, for performance and load testing or for testing your rate-limiter. This tool automatically adds randomized headers to anonymize the request such as X-Forwarded-For and User-Agent.

This tool is to be used only for benign purposes!

Usage

To use it, simply import "github.com/ynori7/hulksmash". Then construct a request builder, which is a function to get the request you want to perform. This request builder accepts an index in case you want to send requests to a variety of endpoints, with varying payloads, or with a cachebreaker. Then you simply create your smasher instance and tell it to start smashing.

requestBuilder := func(item string) (*http.Request, error) {
    return http.NewRequest(http.MethodGet, url, nil)
}

hulksmash.NewSmasher(hulksmash.WithIterations(5)).Smash(context.Background(), requestBuilder)

The smasher comes with some configurable options with safe defaults. Here is a list of the options:

Option Description Default
WithClient Allows you to override the HTTP Client hulksmash's http.NewClient()
WithWorkerCount Sets the number of workers which will send requests in parallel 1
WithErrorFunc Function which is called in case of an error while performing the request Simply logs it to stdout
WithSuccessResponseCallback Function which is called in case of a successful request Simply logs the http status code and response body
WithIterations The number of calls to make 1
WithStartIndex The start index to use when iterating. Can be useful if you want to resume a previous experiment 0
WithAnonymizeRequests Can be used to disable the logic to automatically add headers to make reqeusts look more organic true
WithSequenceFunc Can be used to specify the way the iteration sequence should be built, for example numeric or alphanumeric. Some presets are available in the sequence package sequence.Numeric

A basic and advanced example can be found in example.

Attribution

Icon from Sujud.icon (CC BY 3.0)

Uses refraction-networking/utls to randomize the TCP Hello fingerprint.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSmasher

func NewSmasher(options ...SmasherOption) *smasher

NewSmasher returns a new smasher with the specified configuration

Types

type BuildRequestFunc

type BuildRequestFunc func(item string) (*nethttp.Request, error)

BuildRequestFunc is a function which accepts a iteration item and returns an http request

type HttpClient added in v1.0.0

type HttpClient interface {
	Do(req *nethttp.Request) (*nethttp.Response, error)
}

type SmasherOption

type SmasherOption func(s *smasher)

SmasherOption is a functional option for overriding the default configuration

func WithAnonymizeRequests

func WithAnonymizeRequests(anonymize bool) SmasherOption

WithAnonymizeRequests overrides the default flag to indicate whether reqeusts should be anonymized (by adding additional headers)

func WithClient

func WithClient(c HttpClient) SmasherOption

WithClient allows you to override the default http client, for example if you want to add your own round-tripper or timeouts

func WithErrorFunc

func WithErrorFunc(f func(err error)) SmasherOption

WithErrorFunc overrides the default error callback, which simply logs the error to stdout. This function is called in case of an error while performing the request (not in case of an error response)

func WithIterations

func WithIterations(i int) SmasherOption

WithIterations sets the number of calls the smasher should make (default is 1)

func WithSequenceFunc

func WithSequenceFunc(f sequence.SequenceFunc) SmasherOption

func WithStartIndex

func WithStartIndex(i int) SmasherOption

WithStartIndex overrides the default start index for each iteration in case, for example, you want to resume from a previous position

func WithSuccessResponseCallback

func WithSuccessResponseCallback(f SuccessResponseCallback) SmasherOption

WithSuccessResponseCallback overrides the default success callback which handles all http responses. The default simply logs the response body

func WithWorkerCount

func WithWorkerCount(c int) SmasherOption

WithWorkerCount overrides the default worker count (default is 1, so a single thread)

type SuccessResponse

type SuccessResponse struct {
	StatusCode   int
	RequestBody  []byte
	ResponseBody []byte

	RawRequest  *nethttp.Request
	RawResponse *nethttp.Response
}

SuccessResponse is sent to the success callback. This response contains the original request as well as the response.

type SuccessResponseCallback

type SuccessResponseCallback func(resp SuccessResponse)

SuccessResponseCallback is a callback function which is called after a successful http request is performed

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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