Documentation
¶
Index ¶
- Constants
- Variables
- func BigEndianToIPv4(ipInt uint32) string
- func ConfigureCustomEBPFProgOutputPath(path string) error
- func CpuArch() string
- func DeleteAllBlacklistforSLDInEgressCache(tld string)
- func DeleteDomainBlackListInEgressCache(tld, fqdn string) error
- func ForceGc()
- func GenerateBigEndianIpv4(ipv4 string) uint32
- func GenerateBigEndianIpv6(ipv6 string) (uint64, uint64)
- func GenerateBpfFIlterForDNS(isEgress bool, isudp bool) string
- func GenerateC2BlacklistAddressChannels() (chan net.IP, chan net.IP)
- func GenerateLittelEndianIpv4(ipv4 string) uint32
- func GenerateUniqueConsumerGroupId() string
- func GetBlaclistedDomainsEgressCache() []string
- func GetBlaclistedDomainsIngressCache() []string
- func GetCPUCores() int
- func GetIpv4AddressUserSpaceDpIString(id int) string
- func GetIpv4AddressUserspaceDPI(id int) net.IP
- func GetKernelRelease() (string, error)
- func GetKernelReleaseSubVersions(release string) []string
- func GetKeyPresentInEgressBenignRemoteInferCache(tld, fqdn string) bool
- func GetKeyPresentInEgressCache(tld string) bool
- func GetNodeHostName() (string, error)
- func GetPacketPayloadSize(layer gopacket.Layer, protocol string) int
- func IngDeleteDomainBlackListInCache(tld string) bool
- func IngGetKeyPresentInCache(tld string) bool
- func IngUpdateDomainBlacklistInCache(tld string)
- func InitCMS(ip string, ct int) error
- func InitCache(conf *CacheConfig) error
- func InitGlobalErrorControlChannel() chan agenterr.AgentError
- func InitLogger()
- func IsValidProcVfsMounted(procId int) (bool, error)
- func KillProc(procId uint32) error
- func LittleEndianToIpv4(ipaddr uint32) string
- func Log(args ...any)
- func NewLogger(ctx context.Context)
- func ParseIp(saddr uint32) string
- func ParseIpV6(saddr uint64) string
- func ReadEbpfFromSpec(ctx context.Context, ebpfProgCode string) (*ebpf.CollectionSpec, error)
- func ReadEbpfProgRaw(path string) ([]byte, error)
- func UnPinPinnedMaps(collection *ebpf.Collection, unupinMaps []string) error
- func UpdateDomainNestedEgressCache(tld, fqdn string, isBlackListEgress bool)
- func VerifyKernelEgressTCClsactTaskCommSuppert() bool
- func VerifyKernelSupportTaskComms(processId uint32, threadId uint32) bool
- func VerifyNonDnsTransportPorts(port uint16) bool
- func VerifyTcxSupportEgressLink() bool
- func VerifyTopDomainsData() (string, error)
- type CacheConfig
- type ChunkRange
- type DomainNodeAgentCacheBlock
- type Limites
- type MaliciousKernelTaskCommExportedProcInfo
- type ProcessInfo
- type StreamEvents
- type TopDomains
- type Utsname
Constants ¶
const ( TC_CONTROL_PROG = "exfil_sec" // CLSACT QDISC TC_CONTROL_PROG_BRIDGE_INGRESS = "exfil_sec_bridge_ingress_filter" // CLSACT QDISC TC_CONTROL_PROG_BRIDGE_EGRESS = "exfil_sec_bridge_ingress_filter" // CLSACT QDISC TRACEPOINT_PROC_KILL_TRACEPOINT = "handle_mal_c2_proc_exit" // sched_process_exit SOCK_OPS_PROC_UDP_TRACEPOINT = "dns_udp_sock_ops" // cgroups_skb/egress XDP_CONTROL_PROG = "xdp" // XDP Non Offloaded BXDINAUB Fkiid orevebtuib ' LSM_CRYPTO_VERIFY_PROG = "bpf" // runs over lsm crypto for bpf_prog load lsm.o TC_CLSACT_PARENT_QDISC_HANDLE = 0xffff TC_CLSACT_PARENT_QDISC_PRIO = 1 DEFAULT_SK_BUFF_NUONCE = 0xffff )
kernel network traffic control and xdp ingress layer
const ( SUSPICIOUS_NETNS_IPV6 = "fe80::d091:3cff:fe25:6d96" MALICIOUS_NETNS_IPV6 = "fe80::d091:3cff:fe25:6d97" )
const ( PINPATH = "/sys/fs/bpf" CGROUPFS = "/sys/fs/cgroup" )
map pin vfs for bpf to mount pinned maps
const ( TCX_KERNEL_SUPPORT_MAJOR_RELEASE = 6 TCX_KERNEL_SUPPORT_PATCH_RELEASE = 6 TCX_KERNEL_SUPPORT_SUB_RELEASE = 10 )
const ( BRIDGE_IPAM_IPV4_CIDR = "10.200.0.0/24" BRIDGE_IPAM_IPV4_IP = "10.200.0." BRIDGE_IPAM_MAL_TUNNEL_IPV4_IP = "10.210.0.0" // send to the router bridge gateway for now )
const ( DNS_EGRESS_PORT uint16 = 53 DOT_EGRESS_PORT uint16 = 853 DNS_EGRESS_MULTICAST_PORT uint16 = 5353 LLMNR_EGRESS_LOCAL_MULTICAST_PORT uint16 = 5355 )
const ( MAX_NODE_AGENT_CACHE_SIZE = 1000 INFERENED_DOMAIN_CACHE_SIZE_PER_TLD = 1000 MAX_NODE_AGENT_CACHE_LOOKUP_SIZE = 1000 )
node agent caching from the userspace memory and not kernel heap pointed onto the kernel map FD
const (
DEFAULT_IPV6_CHECKSUM_MAP = 0xff
)
const (
DEFAULT_SIGKILL_MALICIOUS_EXFIL_THRESHOLD = 5
)
const (
ENABLE_KERNEL_DPI_IMPACT_MEASURE_TIME = true
)
capture performance benchmark details
const (
NODE_CONFIG_FILE = "config.yaml"
)
const (
REDIRECT_SKB_MARK = 0xff
)
kernel skb makr from tc qdisc over netns filter or netfilter chain
Variables ¶
var ( NODE_AGENT_BLACKLISTED_DOMAINS *expirable.LRU[string, *expirable.LRU[string, bool]] NODE_AGENT_INGRESS_BACKLISTED_DOMAINS *expirable.LRU[string, bool] NODE_AGENT_REMOTE_INFERENCE_READ_THROUGH_CACHE *lru.Cache[string, *lru.Cache[string, bool]] // the SLD send for remote inference --> actual fqdn inferred result, must always contain benign domains sent and cached for lookup, considering malicious domain are stored in malicious cache )
all the LRU caches for eBPF agent in userspace, must reside in the agent userspace heap memory apart from the eBPF maps in the kernel prceossing packet payload over kernel datapath, the userspace caches accelerate inference and per packet processing speed
var ( TC_EGRESS_ROOT_NETIFACE_INT = "ebpf/tc.o" NF_EGRESS_BRIDGE_NETIFACE_INT = "ebpf/bridge_ing.o" NF_INGRESS_BRIDGE_NETIFACE_INT = "ebpf/bridge_ing.o" TC_EGRESS_TUNNEL_NETIFACE_INT = "ebpf/tun.o" SOCK_TUNNEL_CODE_EBPF = "ebpf/netlink.o" TRACEPOINT_KERNEL_PROG = "ebpf/tracepoint.o" LSM_CRYPTO_BPF_VERIFER_PROG = "ebpf/lsm_bpf.o" SOCK_SKB_OP_CODE_EBPF = "ebpf/sock.o" // kernel egress sock prog for sock op over a cgroup // sdr sock_ops and sock_filter for skb_buff SDR_SOCK_NETIFACT_FILTER = "ebpf/sock.o" )
used to guard exfiltration against host net_device for egress traffic
var ( // google DNS servers GLOBAL_ROUTE_IPV6_TRANSFER_LINKS = []string{ "2001:4860:4860::8888", "2001:4860:4860::8844", "2606:4700:4700::1111", "2606:4700:4700::1001", } GLOBAL_ROUTE_IPV4_TRANSFER_LINKS = []string{ "8.8.8.8", "8.8.4.4", "1.1.1.1", } )
var ( EXFIL_PROCESS_CACHE_CLEAN_INTERVAL = time.Second * 10 // use to prune the map which ensure the required EXFIL_PROCESS_CACHE_CLEAN_THRESHOLD = DEFAULT_SIGKILL_MALICIOUS_EXFIL_THRESHOLD // ideally the c2 implant malware would starve and kill itself, but if keeps retrying the security node agent will kill the process, used for overlayed DNS over random UDP port EXFIL_PROCESS_CACHE_CLEAN_THRESHOLD_BENIGN_PORT = DEFAULT_SIGKILL_MALICIOUS_EXFIL_THRESHOLD // higher threshold compared to tunnelle c2 for random DNS tunnel which must be lower to stop breach asap EXFIL_PROCESS_CACHE_CLEAN_MALICIOUS_PORT_INGRESS_SNIF_THRESHOLD = 5 )
var DEBUG = false
var (
Logger *log.Logger = nil
)
Functions ¶
func BigEndianToIPv4 ¶
func DeleteAllBlacklistforSLDInEgressCache ¶
func DeleteAllBlacklistforSLDInEgressCache(tld string)
func DeleteDomainBlackListInEgressCache ¶
Delete the tld and fqdn from the egress cache
func GenerateBigEndianIpv4 ¶
func GenerateBigEndianIpv6 ¶
func GenerateBpfFIlterForDNS ¶
Generate the bpf filter for sniff in zero copy of DNS over udp or TCP
func GenerateC2BlacklistAddressChannels ¶
generate the required chanel for controller to stream those remote ipv4 / ipv6 c2 server addresses
func GenerateUniqueConsumerGroupId ¶
func GenerateUniqueConsumerGroupId() string
func GetBlaclistedDomainsEgressCache ¶
func GetBlaclistedDomainsEgressCache() []string
Get the blacklisted domains from the egress cache
func GetBlaclistedDomainsIngressCache ¶
func GetBlaclistedDomainsIngressCache() []string
Get the list of tld present in the ingress cache
func GetCPUCores ¶
func GetCPUCores() int
func GetKernelRelease ¶
func GetKeyPresentInEgressCache ¶
Get the tld from the egress cache
func GetNodeHostName ¶
func IngDeleteDomainBlackListInCache ¶
Delete the tld from the ingress cache
func IngGetKeyPresentInCache ¶
Check if the tld is present in the ingress cache and return value if present
func IngUpdateDomainBlacklistInCache ¶
func IngUpdateDomainBlacklistInCache(tld string)
Ingress cache processing for the eBPF node-agent LRU cache Add the tld to the ingress cache
func InitCMS ¶
offload heavy task loaded lookup for performance to countminsketch, only if the cache become to heavy for lookup
func InitCache ¶
func InitCache(conf *CacheConfig) error
Init the cache for the eBPF node agent in user space
func InitGlobalErrorControlChannel ¶
func InitGlobalErrorControlChannel() chan agenterr.AgentError
func InitLogger ¶
func InitLogger()
func IsValidProcVfsMounted ¶
func LittleEndianToIpv4 ¶
func ReadEbpfFromSpec ¶
func ReadEbpfProgRaw ¶
func UnPinPinnedMaps ¶
func UnPinPinnedMaps(collection *ebpf.Collection, unupinMaps []string) error
Removes the pinned eBPF maps mounts from bpf fs
func UpdateDomainNestedEgressCache ¶
Egress cache processing for the eBPF node-agent LRU cache tld and the value
func VerifyKernelEgressTCClsactTaskCommSuppert ¶
func VerifyKernelEgressTCClsactTaskCommSuppert() bool
func VerifyTcxSupportEgressLink ¶
func VerifyTcxSupportEgressLink() bool
func VerifyTopDomainsData ¶
Types ¶
type CacheConfig ¶
type ChunkRange ¶
type MaliciousKernelTaskCommExportedProcInfo ¶
works as a bridge between kernel netdev (tc) layer and kernel syscall layer eBPF hooks to kill if multiple malicious count found
type ProcessInfo ¶
type ProcessInfo struct {
Pid string
PPid string
ThreadId string
GroupId string
Command string
ProcComm string
OpenFiles []string
UserOwner string
}
the same can be returned from kernel using bpf_get_curr_comm() task_struct, and bpf_get_current_pid_tgid, bpf_get_current_pid_ugid since running in user space use the kernel mounted process file system
func GetProcessInfo ¶
func GetProcessInfo(pid int) (*ProcessInfo, error)
Get the process infor from the kernel proces vfs
type StreamEvents ¶
type StreamEvents struct{}
type TopDomains ¶
func ReadTldDomainsData ¶
func ReadTldDomainsData() (*TopDomains, error)
func (*TopDomains) UpdateDomainDomainTLDCache ¶
func (t *TopDomains) UpdateDomainDomainTLDCache(domain string)