Documentation
¶
Index ¶
- Constants
- Variables
- func CacheCleanerTask()
- func GetInodeFromNetstat(netEntry *netstat.Entry, inodeList *[]int, protocol string, srcIP net.IP, ...) bool
- func GetMonitorMethod() string
- func GetPIDFromINode(inode int, inodeKey string) int
- func MethodIsAudit() bool
- func MethodIsEbpf() bool
- func MethodIsProc() bool
- func MonitorProcEvents(stop <-chan struct{})
- func SetMonitorMethod(newMonitorMethod string)
- type CacheInodes
- type CacheProcs
- type EventsStore
- func (e *EventsStore) Add(proc *Process)
- func (e *EventsStore) AddChecksumHash(hash string)
- func (e *EventsStore) ComputeChecksums(proc *Process) bool
- func (e *EventsStore) DelChecksumHash(hash string)
- func (e *EventsStore) Delete(key int)
- func (e *EventsStore) DeleteOldItems()
- func (e *EventsStore) DisableChecksums()
- func (e *EventsStore) GetComputeChecksums() bool
- func (e *EventsStore) IsInStore(key int, proc *Process) (item ExecEventItem, needsUpdate, found bool)
- func (e *EventsStore) IsInStoreByPID(key int) (item ExecEventItem, found bool)
- func (e *EventsStore) Len() int
- func (e *EventsStore) ReplaceItem(oldProc, newProc *Process)
- func (e *EventsStore) SetComputeChecksums(compute bool)
- func (e *EventsStore) Update(oldProc, proc *Process)
- func (e *EventsStore) UpdateItem(proc *Process)
- type ExecEventItem
- type InodeItem
- type MemoryMapping
- type ProcItem
- type Process
- func (p *Process) BuildTree()
- func (p *Process) ChecksumsCount() int
- func (p *Process) CleanArgs()
- func (p *Process) CleanPath()
- func (p *Process) ComputeChecksum(algo string)
- func (p *Process) ComputeChecksums(hashes map[string]uint)
- func (p *Process) DumpImage() ([]byte, error)
- func (p *Process) GetDetails() error
- func (p *Process) GetExtraInfo() error
- func (p *Process) GetParent()
- func (p *Process) IsAlive() bool
- func (p *Process) IsChild() bool
- func (p *Process) Lock()
- func (p *Process) RLock()
- func (p *Process) RUnlock()
- func (p *Process) ReadCmdline()
- func (p *Process) ReadComm() error
- func (p *Process) ReadCwd() error
- func (p *Process) ReadEnv()
- func (p *Process) ReadExeLink() (string, error)
- func (p *Process) ReadMaps()
- func (p *Process) ReadPPID()
- func (p *Process) ReadPath() error
- func (p *Process) ReadStatm()
- func (p *Process) ResetChecksums()
- func (p *Process) Serialize() *protocol.Process
- func (p *Process) SetPath(path string)
- func (p *Process) Unlock()
- type ProcessEvent
Constants ¶
const ( MethodProc = "proc" MethodAudit = "audit" MethodEbpf = "ebpf" KernelConnection = "Kernel connection" ProcSelf = "/proc/self/" HashMD5 = "process.hash.md5" HashSHA1 = "process.hash.sha1" )
monitor method supported types
Variables ¶
var (
Ctx, CancelTasks = context.WithCancel(context.Background())
)
Functions ¶
func CacheCleanerTask ¶
func CacheCleanerTask()
CacheCleanerTask checks periodically if the inodes in the cache must be removed.
func GetInodeFromNetstat ¶
func GetInodeFromNetstat(netEntry *netstat.Entry, inodeList *[]int, protocol string, srcIP net.IP, srcPort uint, dstIP net.IP, dstPort uint) bool
GetInodeFromNetstat tries to obtain the inode of a connection from /proc/net/*
func GetMonitorMethod ¶
func GetMonitorMethod() string
GetMonitorMethod configures a new method for parsing connections.
func GetPIDFromINode ¶
GetPIDFromINode tries to get the PID from a socket inode following these steps: 1. Get the PID from the cache of Inodes. 2. Get the PID from the cache of PIDs. 3. Look for the PID using one of these methods:
- audit: listening for socket creation from auditd.
- proc: search /proc
If the PID is not found by one of the 2 first methods, it'll try it using /proc.
func MethodIsAudit ¶
func MethodIsAudit() bool
MethodIsAudit returns if the process monitor method is eBPF.
func MethodIsEbpf ¶
func MethodIsEbpf() bool
MethodIsEbpf returns if the process monitor method is eBPF.
func MethodIsProc ¶
func MethodIsProc() bool
func MonitorProcEvents ¶
func MonitorProcEvents(stop <-chan struct{})
MonitorProcEvents listen for process events from kernel, via netlink.
func SetMonitorMethod ¶
func SetMonitorMethod(newMonitorMethod string)
SetMonitorMethod configures a new method for parsing connections.
Types ¶
type CacheInodes ¶
CacheInodes holds the cache of Inodes. The key is formed as follow: inode+srcip+srcport+dstip+dstport
func NewCacheOfInodes ¶
func NewCacheOfInodes() *CacheInodes
NewCacheOfInodes returns a new cache for inodes.
type CacheProcs ¶
CacheProcs holds the cache of processes that have established connections.
type EventsStore ¶
type EventsStore struct {
// contains filtered or unexported fields
}
EventsStore is the cache of exec events
var ( // EventsCache is the cache of processes EventsCache *EventsStore )
func NewEventsStore ¶
func NewEventsStore() *EventsStore
NewEventsStore creates a new store of events.
func (*EventsStore) Add ¶
func (e *EventsStore) Add(proc *Process)
Add adds a new process to cache. If computing checksums is enabled, new checksums will be computed if needed, or reused existing ones otherwise.
func (*EventsStore) AddChecksumHash ¶
func (e *EventsStore) AddChecksumHash(hash string)
AddChecksumHash adds a new hash algorithm to compute checksums
func (*EventsStore) ComputeChecksums ¶
func (e *EventsStore) ComputeChecksums(proc *Process) bool
ComputeChecksums obtains the checksums of the process
func (*EventsStore) DelChecksumHash ¶
func (e *EventsStore) DelChecksumHash(hash string)
DelChecksumHash deletes a hash algorithm from the list
func (*EventsStore) Delete ¶
func (e *EventsStore) Delete(key int)
Delete schedules an item to be deleted from cache.
func (*EventsStore) DeleteOldItems ¶
func (e *EventsStore) DeleteOldItems()
DeleteOldItems deletes items that have exited and exceeded the TTL. Keeping them in cache for a short period of time sometimes helps to link some connections to processes. Alived processes are not deleted.
func (*EventsStore) DisableChecksums ¶
func (e *EventsStore) DisableChecksums()
DisableChecksums disables computing checksums functionality.
func (*EventsStore) GetComputeChecksums ¶
func (e *EventsStore) GetComputeChecksums() bool
GetComputeChecksums returns if computing checksums is enabled or not. Disabled -> if there're no rules with checksum field. Disabled -> if events monitors are not available. Disabled -> if the user disables it globally. TODO: Disabled -> if there were n rules with checksums, but the user delete them.
func (*EventsStore) IsInStore ¶
func (e *EventsStore) IsInStore(key int, proc *Process) (item ExecEventItem, needsUpdate, found bool)
IsInStore checks if a PID is in the store. If the PID is in cache, we may need to update it if the PID is reusing the PID of the parent.
func (*EventsStore) IsInStoreByPID ¶
func (e *EventsStore) IsInStoreByPID(key int) (item ExecEventItem, found bool)
IsInStoreByPID checks if a pid exists in cache.
func (*EventsStore) ReplaceItem ¶
func (e *EventsStore) ReplaceItem(oldProc, newProc *Process)
ReplaceItem replaces an existing process with a new one.
func (*EventsStore) SetComputeChecksums ¶
func (e *EventsStore) SetComputeChecksums(compute bool)
SetComputeChecksums configures if we compute checksums of processes. When enabling this functionality, some already stored process may don't have the checksums computed yet, so when enabling compute them.
func (*EventsStore) UpdateItem ¶
func (e *EventsStore) UpdateItem(proc *Process)
UpdateItem updates a cache item
type ExecEventItem ¶
ExecEventItem represents an item of the cache
type MemoryMapping ¶
MemoryMapping represents a memory mapping region
type Process ¶
type Process struct { Statm *procStatm Parent *Process IOStats *procIOstats NetStats *procNetStats Env map[string]string Checksums map[string]string Status string Stat string Stack string Maps string Comm string // Path is the absolute path to the binary Path string // RealPath is the path to the binary taking into account its root fs. // The simplest form of accessing the RealPath is by prepending /proc/<pid>/root/ to the path: // /usr/bin/curl -> /proc/<pid>/root/usr/bin/curl RealPath string CWD string Tree []*protocol.StringInt Descriptors []*procDescriptors // Args is the command that the user typed. It MAY contain the absolute path // of the binary: // $ curl https://... // -> Path: /usr/bin/curl // -> Args: curl https://.... // $ /usr/bin/curl https://... // -> Path: /usr/bin/curl // -> Args: /usr/bin/curl https://.... Args []string Starttime int64 ID int PPID int UID int // contains filtered or unexported fields }
Process holds the details of a process.
func FindProcess ¶
FindProcess checks if a process exists given a PID. If it exists in /proc, a new Process{} object is returned with the details to identify a process (cmdline, name, environment variables, etc).
func NewProcess ¶
NewProcess returns a new Process structure.
func NewProcessEmpty ¶
NewProcessEmpty returns a new Process struct with no details.
func NewProcessWithParent ¶
NewProcessWithParent returns a new Process structure.
func (*Process) BuildTree ¶
func (p *Process) BuildTree()
BuildTree returns all the parents of this process.
func (*Process) ChecksumsCount ¶
ChecksumsCount returns the number of checksums of this process.
func (*Process) CleanArgs ¶
func (p *Process) CleanArgs()
CleanArgs applies fixes on the cmdline arguments.
- AppImages cmdline reports the execuable launched as /proc/self/exe, instead of the actual path to the binary.
func (*Process) CleanPath ¶
func (p *Process) CleanPath()
CleanPath applies fixes on the path to the binary:
- Remove extra characters from the link that it points to. When a running process is deleted, the symlink has the bytes " (deleted") appended to the link.
- If the path is /proc/self/exe, resolve the symlink that it points to.
func (*Process) ComputeChecksum ¶
ComputeChecksum calculates the checksum of a the process path to the binary
func (*Process) ComputeChecksums ¶
ComputeChecksums calculates the checksums of a the process path to the binary. Users may want to use different hashing alogrithms.
func (*Process) DumpImage ¶
DumpImage reads the memory of the current process, and returns it as byte array.
func (*Process) GetDetails ¶
GetDetails collects information of a process.
func (*Process) GetExtraInfo ¶
GetExtraInfo collects information of a process.
func (*Process) GetParent ¶
func (p *Process) GetParent()
GetParent obtains the information of this process' parent.
func (*Process) ReadCmdline ¶
func (p *Process) ReadCmdline()
ReadCmdline reads the cmdline of the process from ProcFS /proc/<pid>/cmdline This file may be empty if the process is of a kernel task. It can also be empty for short-lived processes.
func (*Process) ReadCwd ¶
ReadCwd reads the current working directory name from ProcFS /proc/<pid>/cwd
func (*Process) ReadEnv ¶
func (p *Process) ReadEnv()
ReadEnv reads and parses the environment variables of a process.
func (*Process) ReadExeLink ¶
ReadExeLink reads the link that /proc/<pid>/exe points to. This is the real path to the path that was executed and loaded in memory. It may or not be the same binary that exists on disk (for example when a binary is executed, and later updated or deleted). If a process is launched from a chroot, this link will point to the absolute path, including the host path to the chroot.
func (*Process) ReadPPID ¶
func (p *Process) ReadPPID()
ReadPPID obtains the pid of the parent process
func (*Process) ReadPath ¶
ReadPath reads the symbolic link that /proc/<pid>/exe points to. Note 1: this link might not exist on the root filesystem, it might have been executed from a container, so the real path would be: /proc/<pid>/root/<path that 'exe' points to>
Note 2: There're at least 3 things that a (regular) kernel connection meets from userspace POV: - /proc/<pid>/cmdline and /proc/<pid>/maps empty - /proc/<pid>/exe can't be read
func (*Process) ReadStatm ¶
func (p *Process) ReadStatm()
ReadStatm reads and parses the /proc/<pid>/statm file. Memory usage is measured in pages.
func (*Process) ResetChecksums ¶
func (p *Process) ResetChecksums()
ResetChecksums initializes checksums
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package audit reads auditd events from the builtin af_unix plugin, and parses the messages in order to proactively monitor pids which make connections.
|
Package audit reads auditd events from the builtin af_unix plugin, and parses the messages in order to proactively monitor pids which make connections. |