util

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: GPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToString

func ByteToString(orig []byte) string

func CheckUnpriUserNS added in v1.0.6

func CheckUnpriUserNS() error

CheckUnpriUserNS checks if the current host enable unprivileged user namespace. reference:

https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/
https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/

exceptional case:

the sysctl files(/proc/sys/kernel/unprivileged_userns_clone) only exist in Debian, Ubuntu.
We can not check the sysctl file in other distros, test in CentOS Linux release 8.4.2105 (Core).

func ContainsStrInSlice added in v1.0.6

func ContainsStrInSlice(elem string, sli []string) bool

func FileExist added in v1.0.3

func FileExist(path string) bool

func FindTargetDeviceID

func FindTargetDeviceID(mi *MountInfo) bool

find block device id

func GetAllCGroupSubSystem added in v1.0.6

func GetAllCGroupSubSystem() ([]string, error)

func GetCgroupVersion added in v1.0.6

func GetCgroupVersion() (int, error)

get cgroup version V1/V2 hybrid mode will not work in container

func GetKernelVersion added in v1.0.6

func GetKernelVersion() ([]int, error)

get kernel version

func HttpSendJson added in v0.1.10

func HttpSendJson(method string, url string, data string) (string, error)

func IntContains added in v1.0.4

func IntContains(s []int, e int) bool

IntContains check string array contains a int number

func IsDir

func IsDir(FilePath string) bool

func IsDirectory added in v1.0.2

func IsDirectory(path string) bool
func IsSoftLink(FilePath string) bool

func MakeDev

func MakeDev(major, minor string) int

func RandString

func RandString(n int) string

func ReadLines added in v1.0.3

func ReadLines(path string) ([]string, error)

ReadLines reads a whole file into memory and returns a slice of its lines. from https://stackoverflow.com/questions/5884154/read-text-file-into-string-array-and-write

func RemoveDuplicateElement

func RemoveDuplicateElement(addrs []string) []string

func RewriteFile

func RewriteFile(path string, content string, perm os.FileMode)

func SetBlockAccessible

func SetBlockAccessible(path string) error

set all block device accessible

func ShellExec

func ShellExec(shellPath string) error

ShellExec run shell script by bash

func StringContains added in v1.0.4

func StringContains(s []string, e string) bool

StringContains check string array contains a string

func UnixHttpSend

func UnixHttpSend(method string, unixPath string, uri string, data string) (string, error)

ref https://docs.docker.com/engine/api/v1.24/

func WriteFile

func WriteFile(path string, content string) error

func WriteFileAdd added in v1.0.1

func WriteFileAdd(path string, content string) error

func WriteShellcodeToCrontab added in v1.0.1

func WriteShellcodeToCrontab(header string, filePath string, shellcode string) error

Types

type CgroupInfo added in v1.0.6

type CgroupInfo struct {
	HierarchyID   int
	ControllerLst string // split by "," but should not be split
	CgroupPath    string
}

func GetAllCGroup added in v1.0.6

func GetAllCGroup() ([]CgroupInfo, error)

type MountInfo

type MountInfo struct {
	Device            string
	Fstype            string
	Root              string
	MountPoint        string
	Opts              []string
	Major             string
	Minor             string
	SuperBlockOptions []string
}

func GetMountInfo

func GetMountInfo() ([]MountInfo, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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