wc2

package
v0.3.4-b3 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Default is the default web c2 client that can be used to create client
	// connections.
	Default = &Client{Client: DefaultHTTP}

	// DefaultHTTP is the HTTP Client struct that is used when the provided
	// client is nil.
	DefaultHTTP = &http.Client{Jar: jar, Transport: DefaultTransport}

	// DefaultTransport is the default HTTP transport struct that contains the
	// default settings and timeout values used in DefaultHTTP. This struct uses
	// any set proxy settings contained in the execution environment.
	DefaultTransport = &http.Transport{
		Proxy:                 device.Proxy,
		DialContext:           (&net.Dialer{Timeout: com.DefaultTimeout, KeepAlive: com.DefaultTimeout, DualStack: true}).DialContext,
		MaxIdleConns:          64,
		IdleConnTimeout:       com.DefaultTimeout,
		ForceAttemptHTTP2:     false,
		TLSHandshakeTimeout:   com.DefaultTimeout,
		ExpectContinueTimeout: com.DefaultTimeout,
		ResponseHeaderTimeout: com.DefaultTimeout,

		ReadBufferSize:  1,
		WriteBufferSize: 1,

		DisableKeepAlives: true,
	}
)
View Source
var RuleAny = Rule{URL: text.MatchAny, Host: text.MatchAny, Agent: text.MatchAny}

RuleAny is a Rule that can be used to match any Request that comes in.

Useful for debugging.

Functions

This section is empty.

Types

type Client

type Client struct {
	Target *Target
	*http.Client
	// contains filtered or unexported fields
}

Client is a simple struct that supports the C2 client connector interface. This can be used by clients to connect to a Web instance.

By default, this struct will use the DefaultHTTP struct.

The initial unspecified Target state will be empty and will use the default (Golang) values.

func NewClient added in v0.1.0

func NewClient(d time.Duration, t *Target) *Client

NewClient returns a new WC2 client instance with the supplied timeout and Target options.

If the durartion is less than one or equals 'com.DefaultTimeout' than this function will use the cached 'DefaultTransport' variable instead.

func (*Client) Connect

func (c *Client) Connect(x context.Context, a string) (net.Conn, error)

Connect creates a C2 client connector that uses the same properties of the Client and Target instance parents.

func (*Client) Insecure added in v0.0.6

func (c *Client) Insecure(i bool) *Client

Insecure will set the TLS verification status of the Client to the specified boolean value and return itself.

type Matcher added in v0.1.0

type Matcher interface {
	MatchString(string) bool
}

Matcher is a utility interface that takes a single 'MatchString(string) bool' function and reports true if the string matches.

type Rule

type Rule struct {
	URL, Host, Agent Matcher
	Headers          map[string]Matcher
}

Rule is a struct that represents a rule set used by the Web server to determine the difference between normal and C2 traffic.

func (*Rule) Header added in v0.1.0

func (r *Rule) Header(k string, v Matcher)

Header adds the matcher too the Rule's header set.

This function will create the headers map if it's nil.

type Server

type Server struct {
	Target Target

	Client *http.Client
	// contains filtered or unexported fields
}

Server is a C2 profile that mimics a standard web server and client setup. This struct inherits the http.Server struct and can be used to serve real files and pages.

Use the Target Rules a URL mapping that can be used by clients to access the C2 functions.

func New

func New(t time.Duration) *Server

New creates a new Web C2 server instance. This can be passed to the Listen function of a controller to serve a Web Server that also acts as a C2 instance.

This struct supports all the default Golang http.Server functions and can be used to serve real web pages. Rules must be defined using the 'Rule' function to allow the server to differentiate between C2 and real traffic.

func NewTLS

func NewTLS(t time.Duration, c *tls.Config) *Server

NewTLS creates a new TLS wrapped Web C2 server instance. This can be passed to the Listen function of a Controller to serve a Web Server that also acts as a C2 instance. This struct supports all the default Golang http.Server functions and can be used to serve real web pages. Rules must be defined using the 'Rule' function to allow the server to differentiate between C2 and real traffic.

func (*Server) Close

func (s *Server) Close() error

Close terminates this Web instance and signals all current listeners and clients to disconnect. This will close all connections related to this struct.

This function does not block.

func (*Server) Connect

func (s *Server) Connect(x context.Context, a string) (net.Conn, error)

Connect creates a C2 client connector that uses the same properties of the Web struct parent.

func (*Server) Handle

func (s *Server) Handle(p string, h http.Handler)

Handle registers the handler for the given pattern. If a handler already exists for pattern, Handle panics.

func (*Server) HandleFunc

func (s *Server) HandleFunc(p string, h func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern.

func (*Server) Listen

func (s *Server) Listen(x context.Context, a string) (net.Listener, error)

Listen returns a new C2 listener for this Web instance. This function creates a separate server, but still shares the handler for the base Web instance that it's created from.

func (*Server) Rule

func (s *Server) Rule(r ...Rule)

Rule adds the specified rules to the Web instance to assist in determing real and C2 traffic.

func (*Server) Serve

func (s *Server) Serve(p, f string) error

Serve attempts to serve the specified filesystem path 'f' at the URL mapped path 'p'. This function will determine if the path represents a file or directory and will call 'ServeFile' or 'ServeDirectory' depending on the path result. This function will return an error if the filesystem path does not exist or is invalid.

func (*Server) ServeDirectory

func (s *Server) ServeDirectory(p, f string) error

ServeDirectory attempts to serve the specified filesystem path 'f' at the URL mapped path 'p'. This function is used to serve directories and will return an error if the filesystem path does not exist or the path destination is not a directory.

func (*Server) ServeFile

func (s *Server) ServeFile(p, f string) error

ServeFile attempts to serve the specified filesystem path 'f' at the URL mapped path 'p'. This function is used to serve files and will return an error if the filesystem path does not exist or the path destination is not a file.

func (*Server) TargetAsRule added in v0.1.0

func (s *Server) TargetAsRule()

TargetAsRule will take the server 'Target' and create a matching ruleset using the 'Rule' function.

type Stringer added in v0.1.0

type Stringer interface {
	String() string
}

Stringer is a utility interface that takes a single 'String() string' function for returning a string to be used as a Target.

type Target added in v0.1.0

type Target struct {
	URL, Host, Agent Stringer
	Headers          map[string]Stringer
	// contains filtered or unexported fields
}

Target is a struct that is composed of three separate Stringer interfaces. These are called via their 'String' function to specify the User-Agent, URL and Host string values. They can be set to static strings using the 'text.String' wrapper. This struct can be used as a C2 client connector. If the Client property is not set, the DefaultClient value will be used.

var TargetEmpty Target

TargetEmpty is a Target that does not have anything set and will not mutate a Request.

func (*Target) Header added in v0.1.0

func (t *Target) Header(k string, v Stringer)

Header adds the stringer too the Target's header set.

This function will create the headers map if it's nil.

func (*Target) Reset added in v0.1.0

func (t *Target) Reset()

Reset sets all the Target values to nil. This allows for an empty Target to be used.

func (Target) Rule added in v0.1.0

func (t Target) Rule() Rule

Rule will attempt to generate a Rule that matches this generator using the current configuration.

Rules will only be added if the settings implement the 'MatchString(string) bool' function. Otherwise, the specified rule will attempt to match using a Text Matcher.

Empty Target return an empty rule.

Jump to

Keyboard shortcuts

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