wc2

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package wc2 contains a HTTP/Web based communication channel, which follows the Golang 'net.Conn' interface and is very configurable.

Index

Constants

This section is empty.

Variables

View Source
var Default = new(Client)

Default is the default web c2 client that can be used to create client connections. This has the default configuration and may be used "out-of-the-box".

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

	Timeout time.Duration
	// 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 creates a new WC2 Client with the supplied Timeout.

This can be passed to the Connect function in the 'c2' package to connect to a web server that acts as a C2 server.

func NewClientTLS added in v0.5.0

func NewClientTLS(d time.Duration, c *tls.Config, t *Target) *Client

NewClientTLS creates a new WC2 Client with the supplied Timeout and TLS configuration.

This can be passed to the Connect function in the 'c2' package to connect to a web server that acts as a C2 server.

func (*Client) Client added in v0.5.0

func (c *Client) Client() *http.Client

Client returns the internal 'http.Client' struct to allow for extra configuration. To prevent any issues, it is recommended to NOT overrite or change the Transport of this Client.

The return value will ALWAYS be non-nil.

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.

The returned result is NOT a copy.

func (*Client) SetTLS added in v0.5.0

func (c *Client) SetTLS(t *tls.Config) *Client

SetTLS will set the TLS configuration of the Client to the specified value and returns itself.

The returned result is NOT a copy.

func (*Client) Transport added in v0.5.0

func (c *Client) Transport() *http.Transport

Transport returns the internal 'http.Transport' struct to allow for extra configuration. To prevent any issues, it is recommended to NOT overrite or change any of the 'Dial*' functions of this Transoport.

The return value will ALWAYS be non-nil.

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 to the Rule's header set.

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

type Server

type Server struct {
	Target Target

	Timeout time.Duration
	// 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 NewServer added in v0.5.0

func NewServer(t time.Duration) *Server

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

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 NewServerTLS added in v0.5.0

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

NewServerTLS creates a new TLS wrapped Web C2 server instance. This can be passed to the Listen function of a 'c2.Server' to serve a Web Server that also acts as a C2 server.

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) Client

func (s *Server) Client() *http.Client

Client returns the internal 'http.Client' struct to allow for extra configuration. To prevent any issues, it is recommended to NOT overrite or change the Transport of this Client.

The return value will ALWAYS be non-nil.

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 determine 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.

func (*Server) Transport added in v0.5.0

func (s *Server) Transport() *http.Transport

Transport returns the internal 'http.Transport' struct to allow for extra configuration. To prevent any issues, it is recommended to NOT overrite or change any of the 'Dial*' functions of this Transoport.

The return value will ALWAYS be non-nil.

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
}

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 to 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