wc2

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: GPL-3.0 Imports: 15 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{Generator: DefaultGenerator, Client: DefaultClient}

	// DefaultClient is the HTTP Client struct that is used when the provided client is nil.
	// This is a standard struct that uses DefaultTimeout as the timeout value.
	DefaultClient = &http.Client{Timeout: com.DefaultTimeout, Transport: DefaultTransport}

	// DefaultTransport is the default HTTP transport struct that contains the default settings
	// and timeout values used in DefaultClient. This struct uses any set proxy settings contained
	// in the execution environment.
	DefaultTransport = &http.Transport{
		Proxy:                 http.ProxyFromEnvironment,
		DialContext:           (&net.Dialer{Timeout: com.DefaultTimeout, KeepAlive: com.DefaultTimeout, DualStack: true}).DialContext,
		MaxIdleConns:          limits.SmallLimit(),
		IdleConnTimeout:       com.DefaultTimeout,
		TLSHandshakeTimeout:   com.DefaultTimeout,
		ExpectContinueTimeout: com.DefaultTimeout,
		ResponseHeaderTimeout: com.DefaultTimeout,
	}
)
View Source
var DefaultGenerator = Generator{
	URL:   text.Matcher("/news/post/%d/"),
	Agent: text.Matcher("Mozilla/5.0 (Windows NT 10; WOW64; rv:79.0) Gecko/20101%100d Firefox/79.0"),
}

DefaultGenerator is the generator used if no generator is provided when a client attempts a connection. The default values are a URL for an news post, Windows host and a Firefox version 70 user agent.

Functions

This section is empty.

Types

type Client

type Client struct {
	Generator Generator
	*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 DefaultClient struct.

func (Client) Connect

func (c Client) Connect(s string) (net.Conn, error)

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

type Generator

type Generator struct {
	URL, Host, Agent stringer
}

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

func (*Generator) Reset

func (g *Generator) Reset()

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

func (Generator) Rule

func (g Generator) 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 configuration will be empty.

type Rule

type Rule struct {
	URL, Host, Agent matcher
}

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

type Server

type Server struct {
	Generator Generator

	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 Mapper struct to provide 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.

func (*Server) Connect

func (s *Server) Connect(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(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.

Jump to

Keyboard shortcuts

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