c2

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: GPL-3.0 Imports: 49 Imported by: 0

README

C2

The c2 package contains the server-side command and control implementations. This code talks the sliver binary (client implementations are in sliver/transports). The currently supported procotols are mutual-TLS, HTTP(S), and DNS.

mTLS - tcp-mtls.go

Mutual-TLS is the recommended default transport mechanism for Sliver implants, it provides robust security and throughput. mTLS does require the implant to route TCP traffic directly to the internet, which may not be desirable depending on the target environment. mTLS connections are authenticated and encrypted using per-binary X.509 certificates that are embedded into the implant at compile-time (ECDSA). Certificates are signed using a per-server-instance ECDSA certificate authority that is generated the first time you execute the server binary. Only TLS v1.2 is supported, the only cipher suite enabled is TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384.

HTTP(S) - tcp-http.go

Sliver makes little distinction between HTTP and HTTPS C2 communication. This is because the C2 protocol implements it's own sub-HTTP authenticated encryption scheme and does not rely upon the HTTPS connection's certificate for security or authenticity. Therefore, secure communication is possible over a HTTPS connections with valid or invalid certificates, as well as "unencrypted" HTTP. By default Sliver using long-polling over HTTP 1.1 to achieve near-realtime communication over HTTP(S). System proxy setting are respected when present, however if the implant fails to connect using the system proxy settings it will also attempt a direct connection.

Sliver will attempt the following HTTP(S) connections per C2 domain:

  • HTTPS via proxy
  • HTTPS without proxy
  • HTTP via proxy
  • HTTP without proxy

DNS - udp-dns.go

DNS C2 is the slowest protocol but can offer various envasion properties. However, the current implementation is optimized for speed and stability, not for stealth. A stealthier version of the DNS implementation is planned for future versions of Sliver.

Documentation

Index

Constants

View Source
const (
	DefaultMaxBodyLength   = 2 * 1024 * 1024 * 1024 // 2Gb
	DefaultHTTPTimeout     = time.Minute
	DefaultLongPollTimeout = time.Second
	DefaultLongPollJitter  = time.Second
)
View Source
const (

	// ServerMaxMessageSize - Server-side max GRPC message size
	ServerMaxMessageSize = (2 * 1024 * 1024 * 1024) - 1
)

Variables

View Source
var (
	ErrInvalidMsg         = errors.New("invalid dns message")
	ErrNoOutgoingMessages = errors.New("no outgoing messages")
	ErrMsgTooLong         = errors.New("too much data to encode")
	ErrMsgTooShort        = errors.New("too little data to encode")
)
View Source
var (
	ErrMissingNonce   = errors.New("nonce not found in request")
	ErrInvalidEncoder = errors.New("invalid request encoder")
	ErrDecodeFailed   = errors.New("failed to decode request")
	ErrDecryptFailed  = errors.New("failed to decrypt request")
)

Functions

func SetupDefaultC2Profiles

func SetupDefaultC2Profiles()

func StartDNSListenerJob

func StartDNSListenerJob(dnsListener *clientpb.DNSListenerReq) (*core.Job, error)

StartDNSListenerJob - Start a DNS listener as a job

func StartHTTPListenerJob

func StartHTTPListenerJob(req *clientpb.HTTPListenerReq) (*core.Job, error)

StartHTTPListenerJob - Start a HTTP listener as a job

func StartMTLSListenerJob

func StartMTLSListenerJob(mtlsListener *clientpb.MTLSListenerReq) (*core.Job, error)

StartMTLSListenerJob - Start an mTLS listener as a job

func StartMutualTLSListener

func StartMutualTLSListener(bindIface string, port uint16) (net.Listener, error)

StartMutualTLSListener - Start a mutual TLS listener

func StartTCPListener

func StartTCPListener(bindIface string, port uint16, data []byte) (net.Listener, error)

StartTCPListener - Start a TCP listener

func StartTCPStagerListenerJob

func StartTCPStagerListenerJob(host string, port uint16, profileName string, shellcode []byte) (*core.Job, error)

StartTCPStagerListenerJob - Start a TCP staging payload listener

func StartWGListener

func StartWGListener(port uint16, netstackPort uint16, keyExchangeListenPort uint16) (net.Listener, *device.Device, *bytes.Buffer, error)

StartWGListener - First creates an inet.af network stack. then creates a Wireguard device/interface and applies configuration. Go routines are spun up to handle key exchange connections, as well as c2 comms connections.

func StartWGListenerJob

func StartWGListenerJob(wgListener *clientpb.WGListenerReq) (*core.Job, error)

StartWGListenerJob - Start a WireGuard listener as a job

Types

type DNSSession

type DNSSession struct {
	ID          uint32
	ImplantConn *core.ImplantConnection
	CipherCtx   *cryptography.CipherContext
	// contains filtered or unexported fields
}

DNSSession - Holds DNS session information

func (*DNSSession) ClearOutgoingEnvelope

func (s *DNSSession) ClearOutgoingEnvelope(msgID uint32)

ClearOutgoingEnvelope - Clear an outgoing envelope this will generally, but not always, be the first value in the list

func (*DNSSession) ForwardCompletedEnvelope

func (s *DNSSession) ForwardCompletedEnvelope(msgID uint32, pending *PendingEnvelope)

ForwardCompletedEnvelope - Reassembles and forwards envelopes to core

func (*DNSSession) IncomingPendingEnvelope

func (s *DNSSession) IncomingPendingEnvelope(msgID uint32, size uint32) *PendingEnvelope

IncomingPendingEnvelope - Get a pending message linked list, creates one if it doesn't exist

func (*DNSSession) OutgoingRead

func (s *DNSSession) OutgoingRead(msgID uint32, start uint32, stop uint32) ([]byte, error)

OutgoingRead - Read request from implant

func (*DNSSession) PopOutgoingMsgID

func (s *DNSSession) PopOutgoingMsgID(msg *dnspb.DNSMessage) (uint32, uint32, error)

PopOutgoingMsgID - Pop the next outgoing message ID, FIFO returns msgID, len, err

func (*DNSSession) StageOutgoingEnvelope

func (s *DNSSession) StageOutgoingEnvelope(envelope *sliverpb.Envelope) error

StageOutgoingEnvelope - Stage an outgoing envelope

type HTTPHandler

type HTTPHandler func(resp http.ResponseWriter, req *http.Request)

HTTPHandler - Path mapped to a handler function

type HTTPSession

type HTTPSession struct {
	ID          string
	ImplantConn *core.ImplantConnection
	CipherCtx   *cryptography.CipherContext
	Started     time.Time
	C2Profile   string
}

HTTPSession - Holds data related to a sliver c2 session

type HTTPSessions

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

HTTPSessions - All currently open HTTP sessions

func (*HTTPSessions) Add

func (s *HTTPSessions) Add(session *HTTPSession)

Add - Add an HTTP session

func (*HTTPSessions) Get

func (s *HTTPSessions) Get(sessionID string) *HTTPSession

Get - Get an HTTP session

func (*HTTPSessions) Remove

func (s *HTTPSessions) Remove(sessionID string)

Remove - Remove an HTTP session

type PendingEnvelope

type PendingEnvelope struct {
	Size uint32
	// contains filtered or unexported fields
}

PendingEnvelope - Holds data related to a pending incoming message

func (*PendingEnvelope) Insert

func (p *PendingEnvelope) Insert(dnsMsg *dnspb.DNSMessage) bool

Insert - Pending message, returns true if message is complete

func (*PendingEnvelope) Reassemble

func (p *PendingEnvelope) Reassemble() ([]byte, error)

Reassemble - Reassemble a completed message

type SliverDNSServer

type SliverDNSServer struct {
	TTL          uint32
	MaxTXTLength int
	EnforceOTP   bool
	// contains filtered or unexported fields
}

SliverDNSServer - DNS server implementation

func StartDNSListener

func StartDNSListener(bindIface string, lport uint16, domains []string, canaries bool, enforceOTP bool) *SliverDNSServer

StartDNSListener - Start a DNS listener

func (*SliverDNSServer) HandleDNSRequest

func (s *SliverDNSServer) HandleDNSRequest(domains []string, canaries bool, writer dns.ResponseWriter, req *dns.Msg)

--------------------------- DNS Handler --------------------------- Handles all DNS queries, first we determine if the query is C2 or a canary

func (*SliverDNSServer) ListenAndServe

func (s *SliverDNSServer) ListenAndServe() error

ListenAndServe - Listen for DNS requests and respond

func (*SliverDNSServer) Shutdown

func (s *SliverDNSServer) Shutdown() error

Shutdown - Shutdown the DNS server

type SliverHTTPC2

type SliverHTTPC2 struct {
	HTTPServer   *http.Server
	ServerConf   *clientpb.HTTPListenerReq // Server config (user args)
	HTTPSessions *HTTPSessions
	Cleanup      func()
	// contains filtered or unexported fields
}

SliverHTTPC2 - Holds refs to all the C2 objects

func StartHTTPListener

func StartHTTPListener(req *clientpb.HTTPListenerReq) (*SliverHTTPC2, error)

StartHTTPListener - Start an HTTP(S) listener, this can be used to start both

HTTP/HTTPS depending on the caller's conf

TODO: Better error handling, configurable ACME host/port

func (*SliverHTTPC2) DefaultRespHeaders

func (s *SliverHTTPC2) DefaultRespHeaders(next http.Handler) http.Handler

DefaultRespHeaders - Configures default response headers

Jump to

Keyboard shortcuts

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