Documentation
¶
Index ¶
- Constants
- Variables
- func AlgoNameFromType(data string) string
- func IsAuthKeyFile(fullPath string) bool
- func IsSourceFile(fullPath string) bool
- type AuthorizedKeysFileInfo
- type DataSet
- type DataSource
- type DataSourceMetadata
- type GroupFileInfo
- type GroupInfo
- type GroupRecord
- type PasswdFileInfo
- type PasswdRecord
- type PasswordHash
- type Report
- type ShadowFileInfo
- type ShadowRecord
- type SshKeyRecord
- type UserInfo
Constants ¶
View Source
const ( PasswdFilePath = "/etc/passwd" ShadowFilePath = "/etc/shadow" GshadowFilePath = "/etc/gshadow" GroupFilePath = "/etc/group" LoginDefsFilePath = "/etc/login.defs" SudoersFilePath = "/etc/sudoers" AuthKeysFileName = "authorized_keys" //todo: move to one of the runtime detection packages AuthLogFilePath = "/var/log/auth.log" )
View Source
const ( HashTypeDES = "" //yes, it's empty HashTypeMD5 = "1" HashTypeBlowfish = "2a" HashTypeBcrypt = "2b" HashTypeEksblowfish = "2y" HashTypeSHA256 = "5" HashTypeSHA512 = "6" HashTypeYescrypt = "y" HashTypeGostYescrypt = "gy" HashTypeScrypt = "7" )
View Source
const ( NoPasswordLoginUser = "!" NoPasswordLoginService = "*" )
View Source
const FieldNotSet = -1
View Source
const (
HasShadowFileRecord = "x"
)
Variables ¶
View Source
var HashTypes = map[string]string{ HashTypeDES: "DES", HashTypeMD5: "MD5", HashTypeBlowfish: "blowfish", HashTypeBcrypt: "bcrypt", HashTypeEksblowfish: "eksblowfish", HashTypeSHA256: "SHA256", HashTypeSHA512: "SHA512", HashTypeYescrypt: "yescrypt", HashTypeGostYescrypt: "gost-yescrypt", HashTypeScrypt: "scrypt", }
View Source
var NoLoginShells = map[string]struct{}{
"/sbin/nologin": {},
"/usr/sbin/nologin": {},
"/bin/false": {},
}
Functions ¶
func AlgoNameFromType ¶
func IsAuthKeyFile ¶
func IsSourceFile ¶
Types ¶
type AuthorizedKeysFileInfo ¶
type AuthorizedKeysFileInfo struct {
Records []SshKeyRecord `json:"records"`
}
type DataSet ¶
type DataSet struct {
PasswdFilePath string
PasswdData []byte
ShadowFilePath string
ShadowData []byte
GroupFilePath string
GroupData []byte
AuthKeysData map[string][]byte
}
func NewDataSet ¶
func NewDataSet() *DataSet
type DataSource ¶
type DataSource struct {
FilePath string `json:"file_path"`
Metadata DataSourceMetadata `json:"metadata"`
}
type DataSourceMetadata ¶
type GroupFileInfo ¶
type GroupFileInfo struct {
Records []GroupRecord `json:"records"`
}
func ReadGroupData ¶
func ReadGroupData(data []byte) (*GroupFileInfo, error)
func ReadGroupFile ¶
func ReadGroupFile(filePath string) (*GroupFileInfo, error)
type GroupRecord ¶
type GroupRecord struct {
Group string `json:"gid"` //group name
Password string `json:"password"` //password hash, usually empty / unused (actual password hashes are in gshadow)
GID int `json:"gid"`
MembersRaw string `json:"members_raw"`
Members []string `json:"members"`
RawData string `json:"raw_data"`
}
func ParseGroupRecord ¶
func ParseGroupRecord(line string) (GroupRecord, error)
type PasswdFileInfo ¶
type PasswdFileInfo struct {
Records []PasswdRecord `json:"records"`
}
func ReadPasswdData ¶
func ReadPasswdData(data []byte) (*PasswdFileInfo, error)
func ReadPasswdFile ¶
func ReadPasswdFile(filePath string) (*PasswdFileInfo, error)
type PasswdRecord ¶
type PasswdRecord struct {
Username string `json:"username"`
Password string `json:"password"` //password hash, "x" if the actual password hash is in the shadow file
UID int `json:"uid"`
GID int `json:"gid"`
Info string `json:"info"` //additional user identity info / GECOS
Home string `json:"home"` //home directory
Shell string `json:"shell"` //shell executed when user logs in
RawData string `json:"raw_data"`
NoLoginShell bool `json:"no_login_shell"`
}
func ParsePasswdRecord ¶
func ParsePasswdRecord(line string) (PasswdRecord, error)
func (PasswdRecord) UsesShadow ¶
func (ref PasswdRecord) UsesShadow() bool
type PasswordHash ¶
type PasswordHash struct {
AlgoTypeRaw string `json:"algo_type_raw,omitempty"`
AlgoType string `json:"algo_type,omitempty"`
AlgoParam string `json:"algo_param,omitempty"` //encoded (need to decode)
Salt string `json:"salt,omitempty"`
Hash string `json:"hash,omitempty"`
NoPasswordLogin bool `json:"no_password_login"`
}
func NewPasswordHash ¶
func NewPasswordHash(data string) PasswordHash
func (PasswordHash) UsesWeakAlgo ¶
func (ref PasswordHash) UsesWeakAlgo() bool
type Report ¶
type Report struct {
Users map[string]*UserInfo `json:"users"`
Groups map[string]*GroupInfo `json:"groups"`
Sources []*DataSource `json:"sources"`
}
func NewReportFromData ¶
func (*Report) StringJSONPretty ¶
type ShadowFileInfo ¶
type ShadowFileInfo struct {
Records []ShadowRecord `json:"records"`
}
func ReadShadowData ¶
func ReadShadowData(data []byte) (*ShadowFileInfo, error)
func ReadShadowFile ¶
func ReadShadowFile(filePath string) (*ShadowFileInfo, error)
type ShadowRecord ¶
type ShadowRecord struct {
Username string
PasswordRaw string
Password PasswordHash
LastChangeRaw int
LastChangeDate time.Time
MinimumAge int
MaximumAge int
WarningPeriod int
InactiveDays int
ExpirationRaw int
ExpirationDate time.Time
Reserved string
RawData string
}
func ParseShadowRecord ¶
func ParseShadowRecord(line string) (ShadowRecord, error)
func (ShadowRecord) LoginWithoutPassword ¶
func (ref ShadowRecord) LoginWithoutPassword() bool
type SshKeyRecord ¶
type SshKeyRecord struct {
KeyType string `json:"key_type"`
Key string `json:"key"` //base64 encoded
Comment string `json:"comment"`
Command string `json:"command,omitempty"`
Environments []string `json:"environments,omitempty"`
OtherOptions []string `json:"other_options,omitempty"`
RawData string `json:"raw_data"`
FilePath string `json:"file_path"`
}
type UserInfo ¶
type UserInfo struct {
Username string `json:"username"`
PasswdPassword string `json:"passwd_password"`
ShadowPassword PasswordHash `json:"shadow_password"`
UID int `json:"uid"`
GID int `json:"gid"`
ExtraInfo string `json:"extra_info"`
Home string `json:"home"`
Shell string `json:"shell"`
NoLoginShell bool `json:"no_login_shell"`
LastChangeRaw int `json:"last_change_raw"`
LastChangeDate time.Time `json:"last_change_date"`
MinimumAge int `json:"minimum_age"`
MaximumAge int `json:"maximum_age"`
WarningPeriod int `json:"warning_period"`
InactiveDays int `json:"inactive_days"`
ExpirationRaw int `json:"expiration_raw"`
ExpirationDate time.Time `json:"expiration_date"`
SshKeys []*SshKeyRecord `json:"ssh_keys,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.