Coverage Report
Generated on 27 Oct 20 10:38 -0400 with
gocov-htmlPackage Overview: agent 26.90%
This is a coverage report created after analysis of the agent package. It
has been generated with the following command:
gocov test agent | gocov-html
Here are the stats. Please select a function name to view its implementation and see what's left for testing.
func UserIPWhiteList.In
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 281 | func (wl *UserIPWhiteList) In(user string, ip string) bool { |
| 282 | if wl == nil { |
| 283 | return false |
| 284 | } |
| 285 | |
| 286 | wl.Update() |
| 287 | |
| 288 | ipNet := net.ParseIP(ip) |
| 289 | |
| 290 | var exist bool |
| 291 | if wl.users != nil && ipNet != nil { |
| 292 | wl.RLock() |
| 293 | item, got := wl.users[user] |
| 294 | if got { |
| 295 | contains, err := item.Contains(ipNet) |
| 296 | exist = (err == nil) && (contains == true) |
| 297 | } |
| 298 | wl.RUnlock() |
| 299 | } |
| 300 | |
| 301 | return exist |
| 302 | } |
func License.Signed
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 41 | func (lic *License) Signed(pubKey *rsa.PublicKey) bool { |
| 42 | lic.Sign = "" |
| 43 | signed := lic.signedContent() |
| 44 | for _, sigB64 := range lic.Signatures { |
| 45 | sig, err := base64.StdEncoding.DecodeString(sigB64) |
| 46 | if err != nil { |
| 47 | continue |
| 48 | } |
| 49 | hashed := sha512.Sum512(signed) |
| 50 | if err := rsa.VerifyPKCS1v15(pubKey, crypto.SHA512, hashed[:], []byte(sig)); err == nil { |
| 51 | lic.Sign = sigB64 |
| 52 | return true |
| 53 | } |
| 54 | } |
| 55 | return false |
| 56 | } |
func LicenseWatcher.validLicense
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 170 | func (lw *LicenseWatcher) validLicense(lic *License) bool { |
| 171 | f, err := os.Open(lw.pubKeyPath) |
| 172 | if err != nil { |
| 173 | Errlog.Errorf("fs.Open(%#v) failed: %v", lw.pubKeyPath, err) |
| 174 | return false |
| 175 | } |
| 176 | defer f.Close() |
| 177 | pubKey, err := LoadPublicKey(f) |
| 178 | if err != nil { |
| 179 | Errlog.Errorf("LoadPublicKey() failed: %s", err) |
| 180 | return false |
| 181 | } |
| 182 | // NOTE: we do not check if license is expired, which may be wrong, |
| 183 | // but that is what agent does at the moment. |
| 184 | return lic.Signed(pubKey) |
| 185 | } |
func UserWhiteList.In
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 145 | func (wl *UserWhiteList) In(key string) bool { |
| 146 | if wl == nil { |
| 147 | return false |
| 148 | } |
| 149 | |
| 150 | wl.Update() |
| 151 | |
| 152 | var exist bool |
| 153 | wl.RLock() |
| 154 | if wl.users != nil { |
| 155 | _, exist = wl.users[key] |
| 156 | } |
| 157 | wl.RUnlock() |
| 158 | return exist |
| 159 | } |
func Record.MarshalMsg
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/record_msgp.go:
| 10 | func (z *Record) MarshalMsg(b []byte) (o []byte, err error) { |
| 11 | o = msgp.Require(b, z.Msgsize()) |
| 12 | // map header, size 2 |
| 13 | // string "e" |
| 14 | o = append(o, 0x82, 0xa1, 0x65) |
| 15 | o = msgp.AppendInt64(o, z.LockExpireAt) |
| 16 | // string "a" |
| 17 | o = append(o, 0xa1, 0x61) |
| 18 | o = msgp.AppendMapHeader(o, uint32(len(z.Attempts))) |
| 19 | for za0001, za0002 := range z.Attempts { |
| 20 | o = msgp.AppendString(o, za0001) |
| 21 | o = msgp.AppendInt64(o, za0002) |
| 22 | } |
| 23 | return |
| 24 | } |
func NewWhiteList
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 53 | func NewWhiteList(fileNameList []string, ResetHandler func(), LoadLineHandler func(line string)) *WhiteList { |
| 54 | wl := &WhiteList{ |
| 55 | file: make(map[string]time.Time, len(fileNameList)), |
| 56 | lastCheckTime: make(chan time.Time, 1), |
| 57 | ResetHandler: ResetHandler, |
| 58 | LoadLineHandler: LoadLineHandler, |
| 59 | } |
| 60 | |
| 61 | for _, fileName := range fileNameList { |
| 62 | wl.file[fileName] = time.Time{} |
| 63 | } |
| 64 | wl.reload() |
| 65 | wl.lastCheckTime <- time.Now() |
| 66 | return wl |
| 67 | } |
func WhiteList.reload
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 83 | func (wl *WhiteList) reload() { |
| 84 | if wl.ResetHandler != nil { |
| 85 | wl.ResetHandler() |
| 86 | } |
| 87 | for fileName, _ := range wl.file { |
| 88 | fileModTime, err := readWhiteList(fileName, wl.LoadLineHandler) |
| 89 | if err == nil { |
| 90 | wl.file[fileName] = fileModTime |
| 91 | } |
| 92 | } |
| 93 | } |
func Record.Msgsize
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/record_msgp.go:
| 93 | func (z *Record) Msgsize() (s int) { |
| 94 | s = 1 + 2 + msgp.Int64Size + 2 + msgp.MapHeaderSize |
| 95 | if z.Attempts != nil { |
| 96 | for za0001, za0002 := range z.Attempts { |
| 97 | _ = za0002 |
| 98 | s += msgp.StringPrefixSize + len(za0001) + msgp.Int64Size |
| 99 | } |
| 100 | } |
| 101 | return |
| 102 | } |
func @118:8
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 118 | func() []string { |
| 119 | rbl := i.Section("").Key("rbl").Strings(",") |
| 120 | if len(rbl) > 0 { |
| 121 | return rbl |
| 122 | } |
| 123 | return []string{"net-brute.rbl.imunify.com"} |
| 124 | } |
func LicenseWatcher.notify
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 162 | func (lw *LicenseWatcher) notify(lic *License, valid bool) { |
| 163 | lw.lock.Lock() |
| 164 | for _, f := range lw.subs { |
| 165 | f(*lic, valid) |
| 166 | } |
| 167 | lw.lock.Unlock() |
| 168 | } |
func License.UnmarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license_proto_easyjson.go:
| 171 | func (v *License) UnmarshalJSON(data []byte) error { |
| 172 | r := jlexer.Lexer{Data: data} |
| 173 | easyjson2c6259e0Decode1(&r, v) |
| 174 | return r.Error() |
| 175 | } |
func LicenseWatcher.readLicenseAndNotify
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 130 | func (lw *LicenseWatcher) readLicenseAndNotify() { |
| 131 | if lic := lw.rereadLicense(); lic != nil { |
| 132 | lw.notify(lic, lw.validLicense(lic)) |
| 133 | } |
| 134 | readLicenseAndNotifyDone() |
| 135 | } |
func LicenseWatcher.Subscribe
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 194 | func (lw *LicenseWatcher) Subscribe(f LicenseListener) { |
| 195 | lw.lock.Lock() |
| 196 | lw.subs = append(lw.subs, f) |
| 197 | lw.lock.Unlock() |
| 198 | } |
func Response.MarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 77 | func (v Response) MarshalJSON() ([]byte, error) { |
| 78 | w := jwriter.Writer{} |
| 79 | easyjson3c9d2b01Encode1(&w, v) |
| 80 | return w.Buffer.BuildBytes(), w.Error |
| 81 | } |
func Record.Marshal
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/record.go:
| 10 | func (r Record) Marshal() []byte { |
| 11 | b, _ := r.MarshalMsg(nil) |
| 12 | return b |
| 13 | } |
func ModuleStringResponse
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/module.go:
| 45 | func ModuleStringResponse(action, message string) []byte { |
| 46 | b, _ := Response{Action: action, Message: message}.MarshalJSON() |
| 47 | return b |
| 48 | } |
func errlog.Errorf
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/errlog.go:
| 25 | func (*errlog) Errorf(format string, args ...interface{}) { |
| 26 | log.Errorf(format, args...) |
| 27 | sentrySend(format, args...) |
| 28 | } |
func Record.Unmarshal
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/record.go:
| 15 | func (r *Record) Unmarshal(data []byte) error { |
| 16 | _, err := r.UnmarshalMsg(data) |
| 17 | return err |
| 18 | } |
func errlog.Warnf
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/errlog.go:
| 20 | func (*errlog) Warnf(format string, args ...interface{}) { |
| 21 | log.Warnf(format, args...) |
| 22 | sentrySend(format, args...) |
| 23 | } |
func loadLockConfigIP
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 185 | func loadLockConfigIP(s *ini.Section, defaultWhitelist string, defaultIncludeList string) LockConfig { |
| 186 | return LockConfig{ |
| 187 | Timeout: rangeInt64(s.Key("IP_LOCK_TIMEOUT"), 5, 0, 9999999) * 60, |
| 188 | Attempts: rangeInt(s.Key("IP_LOCK_ATTEMPTS"), 10, 0, 100), |
| 189 | Period: rangeInt64(s.Key("IP_LOCK_MINUTES"), 5, 0, 9999999) * 60, |
| 190 | WhitelistFileName: s.Key("whitelisted_ips_path").MustString(defaultWhitelist), |
| 191 | WhitelistInclude: s.Key("whitelisted_ips_include").MustString(defaultIncludeList), |
| 192 | } |
| 193 | } |
func NewLicenseWatcher
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 92 | func NewLicenseWatcher(licPath, pubKeyPath string, interval time.Duration) *LicenseWatcher { |
| 93 | return &LicenseWatcher{ |
| 94 | done: make(chan struct{}), |
| 95 | interval: interval, |
| 96 | licPath: licPath, |
| 97 | pubKeyPath: pubKeyPath, |
| 98 | subs: make([]LicenseListener, 0, 1), |
| 99 | } |
| 100 | } |
func IPWhiteList.reset
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 190 | func (wl *IPWhiteList) reset() { |
| 191 | wl.ipRanger = cidranger.NewPCTrieRanger() |
| 192 | } |
func LockConfig.IsEnabled
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 63 | func (l LockConfig) IsEnabled() bool { |
| 64 | return l.Timeout > 0 && l.Attempts > 0 && l.Period > 0 |
| 65 | } |
func UserIPWhiteList.reset
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 247 | func (wl *UserIPWhiteList) reset() { |
| 248 | wl.users = make(map[string]cidranger.Ranger) |
| 249 | } |
func UserWhiteList.reset
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 134 | func (wl *UserWhiteList) reset() { |
| 135 | // root user is the must have default |
| 136 | wl.users = map[string]struct{}{ |
| 137 | "root": struct{}{}, |
| 138 | } |
| 139 | } |
func UserWhiteList.loadLine
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 141 | func (wl *UserWhiteList) loadLine(line string) { |
| 142 | wl.users[line] = struct{}{} |
| 143 | } |
func loadLockConfigUserIP
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 195 | func loadLockConfigUserIP(s *ini.Section, defaultWhitelist string) LockConfig { |
| 196 | return LockConfig{ |
| 197 | Timeout: rangeInt64(s.Key("USER_IP_LOCK_TIMEOUT"), 5, 0, 9999999) * 60, |
| 198 | Attempts: rangeInt(s.Key("USER_IP_LOCK_ATTEMPTS"), 10, 0, 100), |
| 199 | Period: rangeInt64(s.Key("USER_IP_LOCK_MINUTES"), 5, 0, 9999999) * 60, |
| 200 | WhitelistFileName: s.Key("whitelisted_user_ip_path").MustString(defaultWhitelist), |
| 201 | } |
| 202 | } |
func loadLockConfigUser
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 176 | func loadLockConfigUser(s *ini.Section, defaultWhitelist string) LockConfig { |
| 177 | return LockConfig{ |
| 178 | Timeout: rangeInt64(s.Key("USER_LOCK_TIMEOUT"), 5, 0, 9999999) * 60, |
| 179 | Attempts: rangeInt(s.Key("USER_LOCK_ATTEMPTS"), 10, 0, 100), |
| 180 | Period: rangeInt64(s.Key("USER_LOCK_MINUTES"), 5, 0, 9999999) * 60, |
| 181 | WhitelistFileName: s.Key("whitelisted_users_path").MustString(defaultWhitelist), |
| 182 | } |
| 183 | } |
func License.signedContent
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 58 | func (lic License) signedContent() []byte { |
| 59 | return []byte(fmt.Sprintf("%s%s%s%d%d%d", lic.ID, lic.Status, lic.Group, lic.Limit, lic.TokenCreatedUTC, lic.TokenExpireUTC)) |
| 60 | } |
func IPWhiteList.In
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 212 | func (wl *IPWhiteList) In(ipString string) bool { |
| 213 | if wl == nil { |
| 214 | return false |
| 215 | } |
| 216 | |
| 217 | wl.Update() |
| 218 | |
| 219 | ip := net.ParseIP(ipString) |
| 220 | |
| 221 | var exist bool |
| 222 | if wl.ipRanger != nil && ip != nil { |
| 223 | wl.RLock() |
| 224 | contains, err := wl.ipRanger.Contains(ip) |
| 225 | exist = (err == nil) && (contains == true) |
| 226 | wl.RUnlock() |
| 227 | } |
| 228 | |
| 229 | return exist |
| 230 | } |
func IPWhiteList.loadLine
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 194 | func (wl *IPWhiteList) loadLine(item string) { |
| 195 | if strings.Contains(item, "/") == true { |
| 196 | _, ipNet, err := net.ParseCIDR(item) |
| 197 | if err == nil { |
| 198 | wl.ipRanger.Insert(cidranger.NewBasicRangerEntry(*ipNet)) |
| 199 | } |
| 200 | } else { |
| 201 | ip := net.ParseIP(item) |
| 202 | if ip != nil { |
| 203 | mask := net.CIDRMask(32, 32) |
| 204 | if ip.To4() == nil { |
| 205 | mask = net.CIDRMask(128, 128) |
| 206 | } |
| 207 | wl.ipRanger.Insert(cidranger.NewBasicRangerEntry(net.IPNet{IP: ip, Mask: mask})) |
| 208 | } |
| 209 | } |
| 210 | } |
func LicenseWatcher.rereadLicense
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 137 | func (lw *LicenseWatcher) rereadLicense() *License { |
| 138 | fi, err := os.Stat(lw.licPath) |
| 139 | if err != nil { |
| 140 | Errlog.Errorf("fs.Stat(%#v) failed: %s", lw.licPath, err) |
| 141 | return nil |
| 142 | } |
| 143 | mt := fi.ModTime() |
| 144 | if !mt.After(lw.lastModified) { |
| 145 | return nil |
| 146 | } |
| 147 | f, err := os.Open(lw.licPath) |
| 148 | if err != nil { |
| 149 | Errlog.Errorf("fs.Open(%#v) failed: %s", lw.licPath, err) |
| 150 | return nil |
| 151 | } |
| 152 | defer f.Close() |
| 153 | lic, err := LoadLicense(f) |
| 154 | if err != nil { |
| 155 | Errlog.Errorf("LoadLicense() failed: %s", err) |
| 156 | return nil |
| 157 | } |
| 158 | lw.lastModified = mt |
| 159 | return &lic |
| 160 | } |
func UserIPWhiteList.loadLine
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 251 | func (wl *UserIPWhiteList) loadLine(item string) { |
| 252 | fields := strings.Fields(item) |
| 253 | if len(fields) < 2 { |
| 254 | return |
| 255 | } |
| 256 | |
| 257 | user := fields[0] |
| 258 | if _, ok := wl.users[user]; !ok { |
| 259 | wl.users[user] = cidranger.NewPCTrieRanger() |
| 260 | } |
| 261 | |
| 262 | for _, item := range fields[1:] { |
| 263 | if strings.Contains(item, "/") == true { |
| 264 | _, ipNet, err := net.ParseCIDR(item) |
| 265 | if err == nil { |
| 266 | wl.users[user].Insert(cidranger.NewBasicRangerEntry(*ipNet)) |
| 267 | } |
| 268 | } else { |
| 269 | ip := net.ParseIP(item) |
| 270 | if ip != nil { |
| 271 | mask := net.CIDRMask(32, 32) |
| 272 | if ip.To4() == nil { |
| 273 | mask = net.CIDRMask(128, 128) |
| 274 | } |
| 275 | wl.users[user].Insert(cidranger.NewBasicRangerEntry(net.IPNet{IP: ip, Mask: mask})) |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | } |
func easyjson3c9d2b01Encode1
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 53 | func easyjson3c9d2b01Encode1(out *jwriter.Writer, in Response) { |
| 54 | out.RawByte('{') |
| 55 | first := true |
| 56 | _ = first |
| 57 | if in.Action != "" { |
| 58 | const prefix string = ",\"action\":" |
| 59 | first = false |
| 60 | out.RawString(prefix[1:]) |
| 61 | out.String(string(in.Action)) |
| 62 | } |
| 63 | if in.Message != "" { |
| 64 | const prefix string = ",\"message\":" |
| 65 | if first { |
| 66 | first = false |
| 67 | out.RawString(prefix[1:]) |
| 68 | } else { |
| 69 | out.RawString(prefix) |
| 70 | } |
| 71 | out.String(string(in.Message)) |
| 72 | } |
| 73 | out.RawByte('}') |
| 74 | } |
func readWhiteList
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 24 | func readWhiteList(fileName string, lineHandler func(line string)) (fileModTime time.Time, err error) { |
| 25 | var ( |
| 26 | file *os.File |
| 27 | info os.FileInfo |
| 28 | ) |
| 29 | |
| 30 | file, err = os.Open(fileName) |
| 31 | if err != nil { |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | info, err = file.Stat() |
| 36 | if err != nil { |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | fileModTime = info.ModTime() |
| 41 | |
| 42 | sc := bufio.NewScanner(file) |
| 43 | for sc.Scan() { |
| 44 | if line := strings.TrimSpace(sc.Text()); line != "" { |
| 45 | lineHandler(line) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | err = sc.Err() |
| 50 | return |
| 51 | } |
func LoadPublicKey
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 20 | func LoadPublicKey(r io.Reader) (*rsa.PublicKey, error) { |
| 21 | p, err := ioutil.ReadAll(r) |
| 22 | if err != nil { |
| 23 | return nil, err |
| 24 | } |
| 25 | block, _ := pem.Decode(p) |
| 26 | if block == nil { |
| 27 | return nil, fmt.Errorf("failed to load PEM data") |
| 28 | } |
| 29 | key, err := x509.ParsePKIXPublicKey(block.Bytes) |
| 30 | if err != nil { |
| 31 | return nil, err |
| 32 | } |
| 33 | pubKey, ok := key.(*rsa.PublicKey) |
| 34 | if !ok { |
| 35 | return nil, fmt.Errorf("public key is not RSA: %v", key) |
| 36 | } |
| 37 | return pubKey, nil |
| 38 | } |
func Database.writeAttempt
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 318 | func (db *Database) writeAttempt(batch *leveldb.Batch, key, hash string, cfg *LockConfig) error { |
| 319 | var changed bool |
| 320 | |
| 321 | if !cfg.IsEnabled() { |
| 322 | return nil |
| 323 | } |
| 324 | |
| 325 | record, err := db.readRecord(key) |
| 326 | if err != nil { |
| 327 | return err |
| 328 | } |
| 329 | |
| 330 | ts := time.Now().Unix() |
| 331 | |
| 332 | // Remove expired attempts first |
| 333 | for hash, expiredAt := range record.Attempts { |
| 334 | if expiredAt < ts { |
| 335 | delete(record.Attempts, hash) |
| 336 | changed = true |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | // Write current attempt if not exist |
| 341 | if _, ok := record.Attempts[hash]; !ok { |
| 342 | if record.Attempts == nil { |
| 343 | record.Attempts = make(map[string]int64, 1) |
| 344 | } |
| 345 | |
| 346 | record.Attempts[hash] = ts + cfg.Period |
| 347 | changed = true |
| 348 | } |
| 349 | |
| 350 | // Remove lock if expired |
| 351 | if record.LockExpireAt != 0 && record.LockExpireAt < ts { |
| 352 | record.LockExpireAt = 0 |
| 353 | changed = true |
| 354 | } |
| 355 | |
| 356 | // Lock if no lock and attempts too much |
| 357 | if record.LockExpireAt == 0 && len(record.Attempts) >= cfg.Attempts { |
| 358 | record.LockExpireAt = ts + cfg.Timeout |
| 359 | changed = true |
| 360 | } |
| 361 | |
| 362 | // Write changes if needed |
| 363 | if changed { |
| 364 | db.writeRecord(batch, key, &record) |
| 365 | } |
| 366 | |
| 367 | return nil |
| 368 | } |
func LoadLicense
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 63 | func LoadLicense(r io.Reader) (License, error) { |
| 64 | var lic License |
| 65 | b, err := ioutil.ReadAll(r) |
| 66 | if err != nil { |
| 67 | return lic, err |
| 68 | } |
| 69 | err = json.Unmarshal(b, &lic) |
| 70 | return lic, err |
| 71 | } |
func Database.CheckLock
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 128 | func (db *Database) CheckLock(ip string, user string) (LockStatus, error) { |
| 129 | if atomic.LoadInt64(&db.closed) != 0 { |
| 130 | return NoLock, ErrClosed |
| 131 | } |
| 132 | |
| 133 | ts := time.Now().Unix() |
| 134 | |
| 135 | var ( |
| 136 | record Record |
| 137 | err error |
| 138 | lockStatus LockStatus |
| 139 | ) |
| 140 | |
| 141 | if db.cfg.UserLock.IsEnabled() && !db.usersWhitelist.In(user) { |
| 142 | record, err = db.readRecord(user) |
| 143 | if err != nil { |
| 144 | return NoLock, fmt.Errorf("read user record: %v", err) |
| 145 | } |
| 146 | if record.LockExpireAt >= ts { |
| 147 | lockStatus |= UserLock |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if db.cfg.IPLock.IsEnabled() && ip != "" { |
| 152 | record, err = db.readRecord(ip) |
| 153 | if err != nil { |
| 154 | return NoLock, fmt.Errorf("read ip record: %v", err) |
| 155 | } |
| 156 | if record.LockExpireAt >= ts { |
| 157 | lockStatus |= IPLock |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if db.cfg.UserIPLock.IsEnabled() && ip != "" && !db.userIPWhitelist.In(user, ip) { |
| 162 | record, err = db.readRecord(ip + "/" + user) |
| 163 | if err != nil { |
| 164 | return NoLock, fmt.Errorf("read user/ip record: %v", err) |
| 165 | } |
| 166 | if record.LockExpireAt >= ts { |
| 167 | lockStatus |= UserIPLock |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | return lockStatus, nil |
| 172 | } |
func NewIPWhiteList
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 167 | func NewIPWhiteList(file string) (*IPWhiteList, error) { |
| 168 | if file == "" { |
| 169 | return nil, nil |
| 170 | } |
| 171 | |
| 172 | var ( |
| 173 | err error |
| 174 | fileNames []string |
| 175 | ) |
| 176 | |
| 177 | // Split file paths by ',' |
| 178 | r := csv.NewReader(strings.NewReader(file)) |
| 179 | r.Comma = ',' |
| 180 | fileNames, err = r.Read() |
| 181 | if err != nil { |
| 182 | return nil, err |
| 183 | } |
| 184 | |
| 185 | wl := &IPWhiteList{} |
| 186 | wl.WhiteList = NewWhiteList(fileNames, wl.reset, wl.loadLine) |
| 187 | return wl, err |
| 188 | } |
func NewUserIPWhiteList
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 238 | func NewUserIPWhiteList(file string) *UserIPWhiteList { |
| 239 | if file == "" { |
| 240 | return nil |
| 241 | } |
| 242 | wl := &UserIPWhiteList{} |
| 243 | wl.WhiteList = NewWhiteList([]string{file}, wl.reset, wl.loadLine) |
| 244 | return wl |
| 245 | } |
func NewUserWhiteList
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 124 | func NewUserWhiteList(file string) *UserWhiteList { |
| 125 | if file == "" { |
| 126 | return nil |
| 127 | } |
| 128 | |
| 129 | wl := &UserWhiteList{} |
| 130 | wl.WhiteList = NewWhiteList([]string{file}, wl.reset, wl.loadLine) |
| 131 | return wl |
| 132 | } |
func Database.WriteAttempts
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 275 | func (db *Database) WriteAttempts(ip string, user string, hash string) error { |
| 276 | batch := new(leveldb.Batch) |
| 277 | |
| 278 | if atomic.LoadInt64(&db.closed) != 0 { |
| 279 | return ErrClosed |
| 280 | } |
| 281 | |
| 282 | db.lock.Lock() |
| 283 | defer db.lock.Unlock() |
| 284 | |
| 285 | if user != "" { |
| 286 | err := db.writeAttempt(batch, user, hash, &db.cfg.UserLock) |
| 287 | if err != nil { |
| 288 | return fmt.Errorf("USER_LOCK: %v", err) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | if ip != "" && ip != "127.0.0.1" { |
| 293 | err := db.writeAttempt(batch, ip, hash, &db.cfg.IPLock) |
| 294 | if err != nil { |
| 295 | return fmt.Errorf("IP_LOCK: %v", err) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if user != "" && ip != "" { |
| 300 | err := db.writeAttempt(batch, ip+"/"+user, hash, &db.cfg.UserIPLock) |
| 301 | if err != nil { |
| 302 | return fmt.Errorf("USER_IP_LOCK: %v", err) |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if batch.Len() == 0 { |
| 307 | return nil |
| 308 | } |
| 309 | |
| 310 | err := db.db.Write(batch, nil) |
| 311 | if err != nil { |
| 312 | return fmt.Errorf("batch write: %v", err) |
| 313 | } |
| 314 | |
| 315 | return nil |
| 316 | } |
func Database.writeRecord
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 393 | func (db Database) writeRecord(batch *leveldb.Batch, key string, record *Record) { |
| 394 | if record.LockExpireAt == 0 && len(record.Attempts) == 0 { |
| 395 | batch.Delete([]byte(key)) |
| 396 | } |
| 397 | batch.Put([]byte(key), record.Marshal()) |
| 398 | |
| 399 | log.WithField("record", record).Tracef("---[db]->> %v", key) |
| 400 | } |
func DatabaseOpen
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 30 | func DatabaseOpen(cfg *Config) (db *Database, err error) { |
| 31 | var database *leveldb.DB |
| 32 | |
| 33 | path := filepath.Join(cfg.Database, "/leveldb") |
| 34 | database, err = leveldb.OpenFile(path, nil) |
| 35 | if err != nil { |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | db = &Database{ |
| 40 | cfg: cfg, |
| 41 | path: path, |
| 42 | db: database, |
| 43 | stopExpireOld: make(chan bool, 1), |
| 44 | } |
| 45 | |
| 46 | var nextExpire int64 |
| 47 | nextExpire, err = db.expireOld() |
| 48 | if err == nil { |
| 49 | db.waitExpireOld.Add(1) |
| 50 | go db.serveExpireOld(nextExpire) |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | err = fmt.Errorf("expire old: %v", err) |
| 55 | _ = db.db.Close() |
| 56 | return nil, err |
| 57 | } |
func Database.readRecord
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 370 | func (db Database) readRecord(key string) (record Record, err error) { |
| 371 | var data []byte |
| 372 | data, err = db.db.Get([]byte(key), nil) |
| 373 | if err == leveldb.ErrNotFound { |
| 374 | err = nil |
| 375 | log.WithField("record", "nil").Tracef("<--[db]--- %v", key) |
| 376 | return |
| 377 | } |
| 378 | if err != nil { |
| 379 | err = fmt.Errorf("get record: %v", err) |
| 380 | return |
| 381 | } |
| 382 | |
| 383 | err = record.Unmarshal(data) |
| 384 | if err != nil { |
| 385 | err = fmt.Errorf("unmarshal: %v", err) |
| 386 | return |
| 387 | } |
| 388 | |
| 389 | log.WithField("record", record).Tracef("<--[db]--- %v", key) |
| 390 | return |
| 391 | } |
func ConfigLoad
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 67 | func ConfigLoad(path string) (cfg *Config, err error) { |
| 68 | var i *ini.File |
| 69 | |
| 70 | i, err = ini.Load(path) |
| 71 | if err != nil { |
| 72 | err = fmt.Errorf("fail to read config: %v", err) |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | cfg = &Config{ |
| 77 | LogFilename: i.Section(""). |
| 78 | Key("log"). |
| 79 | MustString(""), |
| 80 | |
| 81 | Sentry: i.Section(""). |
| 82 | Key("sentry"). |
| 83 | MustString("https://sentry.cloudlinux.com/sentry/i360-pam-imunify/"), |
| 84 | |
| 85 | Database: i.Section(""). |
| 86 | Key("mod_db_path"). |
| 87 | MustString("/opt/i360_pam_imunify/db"), |
| 88 | |
| 89 | Socket: i.Section(""). |
| 90 | Key("socket"). |
| 91 | MustString("/opt/i360_pam_imunify/pam_imunify360.sock"), |
| 92 | |
| 93 | ResolvConf: i.Section(""). |
| 94 | Key("RBL_nameserver"). |
| 95 | MustString("ns1-rbl.imunify.com:53"), |
| 96 | |
| 97 | SharedKey: loadKeyFile(i.Section(""). |
| 98 | Key("shared_key_file"). |
| 99 | MustString("/opt/i360_pam_imunify/key"), "7raXUdtFcBSr2Bes"), |
| 100 | |
| 101 | PublicKeyPath: i.Section(""). |
| 102 | Key("public_key_path"). |
| 103 | MustString("/opt/alt/python35/share/imunify360/cln-pub.key"), |
| 104 | |
| 105 | LicensePath: i.Section(""). |
| 106 | Key("license_path"). |
| 107 | MustString("/var/imunify360/license.json"), |
| 108 | |
| 109 | SendStats: i.Section(""). |
| 110 | Key("send_stats").MustBool(true), |
| 111 | |
| 112 | SendStatsSuccessfulAggTime: i.Section(""). |
| 113 | Key("send_stats_success_agg_time").MustInt64(30 * 60), |
| 114 | |
| 115 | SendStatsUnsuccessfulAggTime: i.Section(""). |
| 116 | Key("send_stats_unsuccess_agg_time").MustInt64(60), |
| 117 | |
| 118 | RBL: func() []string { |
| 119 | rbl := i.Section("").Key("rbl").Strings(",") |
| 120 | if len(rbl) > 0 { |
| 121 | return rbl |
| 122 | } |
| 123 | return []string{"net-brute.rbl.imunify.com"} |
| 124 | }(), |
| 125 | RBLTimeout: i.Section(""). |
| 126 | Key("RBL_timeout").MustInt64(5), |
| 127 | RBLCacheTTL: i.Section(""). |
| 128 | Key("RBL_cache_ttl").MustInt64(600), |
| 129 | RBLCacheSize: i.Section(""). |
| 130 | Key("RBL_cache_size").MustInt(65535), |
| 131 | UserLock: loadLockConfigUser(i.Section(""), "/var/i360_pam_imunify/users/users.txt"), |
| 132 | IPLock: loadLockConfigIP(i.Section(""), |
| 133 | "/var/i360_pam_imunify/wl/ips.txt", |
| 134 | "/etc/apache2/conf.d/modsec_vendor_configs/imunify360_full_apache/rbl_whitelist,"+ |
| 135 | "/etc/httpd/conf/modsecurity.d/rules/custom/rbl_whitelist"), |
| 136 | UserIPLock: loadLockConfigUserIP(i.Section(""), ""), |
| 137 | |
| 138 | CPanelFtpAuthInSocket: i.Section(""). |
| 139 | Key("cpanel_ftp_auth_in_socket"). |
| 140 | MustString("/var/run/ftpd.imunify360.sock"), |
| 141 | CPanelFtpAuthOutSocket: i.Section(""). |
| 142 | Key("cpanel_ftp_auth_out_socket"). |
| 143 | MustString("/var/run/ftpd.sock"), |
| 144 | CPanelFtpAuthOutTimeout: i.Section(""). |
| 145 | Key("cpanel_ftp_auth_out_timeout").MustInt64(15), |
| 146 | } |
| 147 | |
| 148 | return |
| 149 | } |
func easyjson2c6259e0Decode1
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license_proto_easyjson.go:
| 20 | func easyjson2c6259e0Decode1(in *jlexer.Lexer, out *License) { |
| 21 | isTopLevel := in.IsStart() |
| 22 | if in.IsNull() { |
| 23 | if isTopLevel { |
| 24 | in.Consumed() |
| 25 | } |
| 26 | in.Skip() |
| 27 | return |
| 28 | } |
| 29 | in.Delim('{') |
| 30 | for !in.IsDelim('}') { |
| 31 | key := in.UnsafeFieldName(false) |
| 32 | in.WantColon() |
| 33 | if in.IsNull() { |
| 34 | in.Skip() |
| 35 | in.WantComma() |
| 36 | continue |
| 37 | } |
| 38 | switch key { |
| 39 | case "group": |
| 40 | out.Group = string(in.String()) |
| 41 | case "id": |
| 42 | out.ID = string(in.String()) |
| 43 | case "limit": |
| 44 | out.Limit = int(in.Int()) |
| 45 | case "message": |
| 46 | out.Message = string(in.String()) |
| 47 | case "sign": |
| 48 | out.Sign = string(in.String()) |
| 49 | case "signatures": |
| 50 | if in.IsNull() { |
| 51 | in.Skip() |
| 52 | out.Signatures = nil |
| 53 | } else { |
| 54 | in.Delim('[') |
| 55 | if out.Signatures == nil { |
| 56 | if !in.IsDelim(']') { |
| 57 | out.Signatures = make([]string, 0, 4) |
| 58 | } else { |
| 59 | out.Signatures = []string{} |
| 60 | } |
| 61 | } else { |
| 62 | out.Signatures = (out.Signatures)[:0] |
| 63 | } |
| 64 | for !in.IsDelim(']') { |
| 65 | var v1 string |
| 66 | v1 = string(in.String()) |
| 67 | out.Signatures = append(out.Signatures, v1) |
| 68 | in.WantComma() |
| 69 | } |
| 70 | in.Delim(']') |
| 71 | } |
| 72 | case "status": |
| 73 | out.Status = string(in.String()) |
| 74 | case "token_created_utc": |
| 75 | out.TokenCreatedUTC = int(in.Int()) |
| 76 | case "token_expire_utc": |
| 77 | out.TokenExpireUTC = int(in.Int()) |
| 78 | case "upgrade_url": |
| 79 | out.UpgradeURL = string(in.String()) |
| 80 | default: |
| 81 | in.SkipRecursive() |
| 82 | } |
| 83 | in.WantComma() |
| 84 | } |
| 85 | in.Delim('}') |
| 86 | if isTopLevel { |
| 87 | in.Consumed() |
| 88 | } |
| 89 | } |
func Database.serveExpireOld
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 80 | func (db *Database) serveExpireOld(nextExpire int64) { |
| 81 | defer db.waitExpireOld.Done() |
| 82 | var err error |
| 83 | for { |
| 84 | ts := time.Now().Unix() |
| 85 | |
| 86 | if nextExpire < ts+60 { |
| 87 | nextExpire = 60 |
| 88 | } else { |
| 89 | nextExpire -= ts |
| 90 | } |
| 91 | |
| 92 | timer := time.NewTimer(time.Duration(nextExpire) * time.Second) |
| 93 | |
| 94 | select { |
| 95 | case <-db.stopExpireOld: |
| 96 | return |
| 97 | case <-timer.C: |
| 98 | nextExpire, err = db.expireOld() |
| 99 | if err != nil { |
| 100 | return |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
func rangeInt64
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 204 | func rangeInt64(k *ini.Key, defaultVal, min, max int64) int64 { |
| 205 | val := k.MustInt64(defaultVal) |
| 206 | if val < min || val > max { |
| 207 | Errlog.Errorf("Value in config file is out of range %d", val) |
| 208 | return defaultVal |
| 209 | } |
| 210 | return val |
| 211 | } |
func rangeInt
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 213 | func rangeInt(k *ini.Key, defaultVal, min, max int) int { |
| 214 | val := k.MustInt(defaultVal) |
| 215 | if val < min || val > max { |
| 216 | Errlog.Errorf("Value in config file is out of range %d", val) |
| 217 | return defaultVal |
| 218 | } |
| 219 | return val |
| 220 | } |
func Record.UnmarshalMsg
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/record_msgp.go:
| 27 | func (z *Record) UnmarshalMsg(bts []byte) (o []byte, err error) { |
| 28 | var field []byte |
| 29 | _ = field |
| 30 | var zb0001 uint32 |
| 31 | zb0001, bts, err = msgp.ReadMapHeaderBytes(bts) |
| 32 | if err != nil { |
| 33 | err = msgp.WrapError(err) |
| 34 | return |
| 35 | } |
| 36 | for zb0001 > 0 { |
| 37 | zb0001-- |
| 38 | field, bts, err = msgp.ReadMapKeyZC(bts) |
| 39 | if err != nil { |
| 40 | err = msgp.WrapError(err) |
| 41 | return |
| 42 | } |
| 43 | switch msgp.UnsafeString(field) { |
| 44 | case "e": |
| 45 | z.LockExpireAt, bts, err = msgp.ReadInt64Bytes(bts) |
| 46 | if err != nil { |
| 47 | err = msgp.WrapError(err, "LockExpireAt") |
| 48 | return |
| 49 | } |
| 50 | case "a": |
| 51 | var zb0002 uint32 |
| 52 | zb0002, bts, err = msgp.ReadMapHeaderBytes(bts) |
| 53 | if err != nil { |
| 54 | err = msgp.WrapError(err, "Attempts") |
| 55 | return |
| 56 | } |
| 57 | if z.Attempts == nil { |
| 58 | z.Attempts = make(map[string]int64, zb0002) |
| 59 | } else if len(z.Attempts) > 0 { |
| 60 | for key := range z.Attempts { |
| 61 | delete(z.Attempts, key) |
| 62 | } |
| 63 | } |
| 64 | for zb0002 > 0 { |
| 65 | var za0001 string |
| 66 | var za0002 int64 |
| 67 | zb0002-- |
| 68 | za0001, bts, err = msgp.ReadStringBytes(bts) |
| 69 | if err != nil { |
| 70 | err = msgp.WrapError(err, "Attempts") |
| 71 | return |
| 72 | } |
| 73 | za0002, bts, err = msgp.ReadInt64Bytes(bts) |
| 74 | if err != nil { |
| 75 | err = msgp.WrapError(err, "Attempts", za0001) |
| 76 | return |
| 77 | } |
| 78 | z.Attempts[za0001] = za0002 |
| 79 | } |
| 80 | default: |
| 81 | bts, err = msgp.Skip(bts) |
| 82 | if err != nil { |
| 83 | err = msgp.WrapError(err) |
| 84 | return |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | o = bts |
| 89 | return |
| 90 | } |
func ReverseIP
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/rbl.go:
| 46 | func ReverseIP(ip net.IP) string { |
| 47 | if ip.To4() != nil { |
| 48 | splitAddress := strings.Split(ip.String(), ".") |
| 49 | |
| 50 | for i, j := 0, len(splitAddress)-1; i < len(splitAddress)/2; i, j = i+1, j-1 { |
| 51 | splitAddress[i], splitAddress[j] = splitAddress[j], splitAddress[i] |
| 52 | } |
| 53 | |
| 54 | return strings.Join(splitAddress, ".") |
| 55 | } else if ip.To16() != nil { |
| 56 | ipv6 := ip.To16() |
| 57 | hexDigit := "0123456789abcdef" |
| 58 | |
| 59 | s := make([]string, len(ipv6)*2) |
| 60 | for i := 0; i < net.IPv6len; i += 1 { |
| 61 | s[i*2], s[i*2+1] = string(hexDigit[ipv6[i]>>4]), string(hexDigit[ipv6[i]&0xf]) |
| 62 | } |
| 63 | for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { |
| 64 | s[i], s[j] = s[j], s[i] |
| 65 | } |
| 66 | return strings.Join(s, ".") |
| 67 | } |
| 68 | return "" |
| 69 | } |
func loadKeyFile
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 151 | func loadKeyFile(filename, defaultKey string) string { |
| 152 | b, err := ioutil.ReadFile(filename) |
| 153 | if err != nil { |
| 154 | Errlog.Warnf("Key file %s read error (default value used): %v", filename, err) |
| 155 | return defaultKey |
| 156 | } |
| 157 | |
| 158 | b = bytes.TrimSpace(b) |
| 159 | if len(b) == 0 { |
| 160 | Errlog.Warnf("Key file %s read error (default value used): empty", filename) |
| 161 | return defaultKey |
| 162 | } |
| 163 | |
| 164 | return string(b) |
| 165 | } |
func WhiteList.Update
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 95 | func (wl *WhiteList) Update() { |
| 96 | select { |
| 97 | case lastCheckTime := <-wl.lastCheckTime: |
| 98 | timeNow := time.Now() |
| 99 | if timeNow.Before(lastCheckTime.Add(1 * time.Second)) { |
| 100 | wl.lastCheckTime <- lastCheckTime |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | if !wl.isNeedUpdate() { |
| 105 | wl.lastCheckTime <- timeNow |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | wl.Lock() |
| 110 | wl.reload() |
| 111 | wl.Unlock() |
| 112 | |
| 113 | wl.lastCheckTime <- timeNow |
| 114 | default: |
| 115 | } |
| 116 | } |
func Database.expireOld
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 201 | func (db *Database) expireOld() (nextExpiration int64, err error) { |
| 202 | if atomic.LoadInt64(&db.closed) != 0 { |
| 203 | return 0, ErrClosed |
| 204 | } |
| 205 | |
| 206 | ts := time.Now().Unix() |
| 207 | |
| 208 | batch := new(leveldb.Batch) |
| 209 | |
| 210 | db.lock.Lock() |
| 211 | defer db.lock.Unlock() |
| 212 | |
| 213 | iter := db.db.NewIterator(nil, nil) |
| 214 | for iter.Next() { |
| 215 | var ( |
| 216 | changed bool |
| 217 | record Record |
| 218 | ) |
| 219 | |
| 220 | key := iter.Key() |
| 221 | value := iter.Value() |
| 222 | |
| 223 | err := record.Unmarshal(value) |
| 224 | if err != nil { |
| 225 | // Cleanup bad records |
| 226 | batch.Delete(key) |
| 227 | log.Tracef("---[db]->> del %v", key) |
| 228 | } |
| 229 | |
| 230 | // Remove expired attempts |
| 231 | for hash, expiredAt := range record.Attempts { |
| 232 | if expiredAt < ts { |
| 233 | delete(record.Attempts, hash) |
| 234 | changed = true |
| 235 | continue |
| 236 | } |
| 237 | if nextExpiration > expiredAt { |
| 238 | nextExpiration = expiredAt |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // Remove lock if expired |
| 243 | if record.LockExpireAt != 0 && record.LockExpireAt < ts { |
| 244 | record.LockExpireAt = 0 |
| 245 | changed = true |
| 246 | } |
| 247 | |
| 248 | if record.LockExpireAt != 0 && record.LockExpireAt < nextExpiration { |
| 249 | nextExpiration = record.LockExpireAt |
| 250 | } |
| 251 | |
| 252 | if changed { |
| 253 | db.writeRecord(batch, string(key), &record) |
| 254 | } |
| 255 | } |
| 256 | iter.Release() |
| 257 | |
| 258 | err = iter.Error() |
| 259 | if err != nil { |
| 260 | return 0, fmt.Errorf("iterator: %v", err) |
| 261 | } |
| 262 | |
| 263 | if batch.Len() == 0 { |
| 264 | return |
| 265 | } |
| 266 | |
| 267 | err = db.db.Write(batch, nil) |
| 268 | if err != nil { |
| 269 | err = fmt.Errorf("batch write: %v", err) |
| 270 | } |
| 271 | |
| 272 | return |
| 273 | } |
func sentrySend
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/errlog.go:
| 35 | func sentrySend(format string, args ...interface{}) { |
| 36 | if !Errlog.isSentryEnabled { |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | scope := sentry.CurrentHub().PushScope() |
| 41 | defer sentry.CurrentHub().PopScope() |
| 42 | scope.SetFingerprint([]string{format}) |
| 43 | scope.SetExtra("format", format) |
| 44 | for i, arg := range args { |
| 45 | // Here we use 'a', 'b', ... mnemonics for func fmt.Sprintf argument list |
| 46 | scope.SetTag(string('a' + byte(i)), fmt.Sprintf("%v", arg)) |
| 47 | } |
| 48 | sentry.CaptureMessage(fmt.Sprintf(format, args...)) |
| 49 | } |
func Process.ProcessCPanelFtpAuthRequest
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/cpanel.go:
| 62 | func (p *Process) ProcessCPanelFtpAuthRequest(data []byte) []byte { |
| 63 | var request CPanelAuthMsg |
| 64 | request.Unmarshal(data) |
| 65 | if request.Account == "" || request.Password == "" { |
| 66 | Errlog.Errorf("parse request: No user credentials") |
| 67 | return nil |
| 68 | } |
| 69 | request.Peer = ToIP(request.Peer) |
| 70 | |
| 71 | if request.Peer == "" || p.wlIP.In(request.Peer) == false { |
| 72 | result, err := p.db.CheckLock(request.Peer, request.Account) |
| 73 | if err != nil { |
| 74 | Errlog.Errorf("check lock: %v", err) |
| 75 | } |
| 76 | |
| 77 | if result&UserLock != NoLock { |
| 78 | p.syslog.Err(fmt.Sprintf( |
| 79 | "pam_imunify(cpanel_ftp_auth:auth): [IM360_UL] The account %s has been temporarily locked by Imunify PAM(%s)", |
| 80 | request.Account, request.Peer)) |
| 81 | return ResponseCPanelAuthFtpdReject |
| 82 | } |
| 83 | if result&IPLock != NoLock { |
| 84 | p.syslog.Err(fmt.Sprintf( |
| 85 | "pam_imunify(cpanel_ftp_auth:auth): [IM360_IPL] The IP %s has been locked by Imunify PAM", |
| 86 | request.Peer)) |
| 87 | return ResponseCPanelAuthFtpdReject |
| 88 | } |
| 89 | if result&UserIPLock != NoLock { |
| 90 | p.syslog.Err(fmt.Sprintf( |
| 91 | "pam_imunify(cpanel_ftp_auth:auth): [IM360_IPUL] The account %s has been locked for the attacker IP %s", |
| 92 | request.Account, request.Peer)) |
| 93 | return ResponseCPanelAuthFtpdReject |
| 94 | } |
| 95 | |
| 96 | if result&UserLock != NoLock || result&IPLock != NoLock || result&UserIPLock != NoLock { |
| 97 | |
| 98 | } |
| 99 | |
| 100 | if request.Peer != "" && p.cfg.RBLTimeout > 0 && p.rbl != nil { |
| 101 | value, err := p.rbl.Check(request.Peer) |
| 102 | if err != nil { |
| 103 | noSuchHost := strings.HasSuffix(err.Error(), "no such host") |
| 104 | if _, ok := err.(*net.DNSError); !ok || err.(*net.DNSError).IsTimeout || !noSuchHost { |
| 105 | log.Errorf("RBL check: %v", err) |
| 106 | } |
| 107 | } |
| 108 | if value { |
| 109 | p.syslog.Err(fmt.Sprintf( |
| 110 | "pam_imunify(cpanel_ftp_auth:auth): [IM360_RBL] The IP %s has been locked due to Imunify RBL", |
| 111 | request.Peer)) |
| 112 | return ResponseCPanelAuthFtpdReject |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | cpanelConn, err := net.DialTimeout("unix", p.cfg.CPanelFtpAuthOutSocket, time.Duration(p.cfg.CPanelFtpAuthOutTimeout)*time.Second) |
| 118 | if err != nil { |
| 119 | Errlog.Errorf("CPanel auth ftpd connect: %v", err) |
| 120 | return nil |
| 121 | } |
| 122 | defer cpanelConn.Close() |
| 123 | |
| 124 | _ = cpanelConn.SetDeadline(time.Now().Add(time.Duration(p.cfg.CPanelFtpAuthOutTimeout) * time.Second)) |
| 125 | |
| 126 | _, err = cpanelConn.Write(data) |
| 127 | if err != nil { |
| 128 | Errlog.Errorf("CPanel auth ftpd write: %v", err) |
| 129 | return nil |
| 130 | } |
| 131 | |
| 132 | var responseData []byte |
| 133 | responseData, err = CPanelFtpAuthRecv(cpanelConn) |
| 134 | if err != nil { |
| 135 | Errlog.Errorf("CPanel auth ftpd read: %v", err) |
| 136 | return nil |
| 137 | } |
| 138 | |
| 139 | var response CPanelAuthMsg |
| 140 | response.Unmarshal(responseData) |
| 141 | |
| 142 | switch response.AuthOk { |
| 143 | case "1": |
| 144 | err := p.db.RemoveSuccess(request.Peer, request.Account) |
| 145 | if err != nil { |
| 146 | Errlog.Errorf("write filed attempt: %v", err) |
| 147 | } |
| 148 | p.WriteStat(true, "cpanel_ftp_auth", request.Peer, request.Account, "e") |
| 149 | case "-1", "0": |
| 150 | hash := fmt.Sprintf("%x", xxh3.HashString(request.Account+request.Password)) |
| 151 | err := p.db.WriteAttempts(request.Peer, request.Account, hash) |
| 152 | if err != nil { |
| 153 | Errlog.Errorf("write filed attempt: %v", err) |
| 154 | } |
| 155 | p.WriteStat(false, "cpanel_ftp_auth", request.Peer, request.Account, hash) |
| 156 | default: |
| 157 | Errlog.Errorf("CPanel auth ftpd: bad auth response \"%s\"", response.AuthOk) |
| 158 | } |
| 159 | |
| 160 | return responseData |
| 161 | } |
func Process.Start
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 78 | func (p *Process) Start(iniPath string) (err error) { |
| 79 | p.cfg, err = ConfigLoad(iniPath) |
| 80 | if err != nil { |
| 81 | return fmt.Errorf("config load: %v", err) |
| 82 | } |
| 83 | |
| 84 | if p.cfg.IsLogfileEnabled() { |
| 85 | var logfile *os.File |
| 86 | logfile, err = os.OpenFile(p.cfg.LogFilename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0660) |
| 87 | if err != nil { |
| 88 | return fmt.Errorf("log open: %v", err) |
| 89 | } |
| 90 | log.SetOutput(logfile) |
| 91 | } else if p.cfg.IsSentryEnabled() { |
| 92 | p.sentryLogger, err = NewSentryLogger(filepath.Base(os.Args[0]), PackageVersion) |
| 93 | if err == nil { |
| 94 | Errlog.Configure(p.cfg.IsSentryEnabled()) |
| 95 | } else { |
| 96 | Errlog.Errorf("sentry reporting will be disabled: %v", err) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if p.cfg.IsVerboseLoggingMode() { |
| 101 | log.SetLevel(log.TraceLevel) |
| 102 | } else { |
| 103 | log.SetLevel(log.InfoLevel) |
| 104 | } |
| 105 | |
| 106 | p.syslog, err = syslog.New(syslog.LOG_AUTHPRIV, "pam_imunify") |
| 107 | |
| 108 | p.db, err = DatabaseOpen(p.cfg) |
| 109 | if err != nil { |
| 110 | dbOpenErr := err |
| 111 | |
| 112 | // Plan B: start from scratch |
| 113 | err = DatabaseDrop(p.cfg) |
| 114 | if err == nil { |
| 115 | p.db, err = DatabaseOpen(p.cfg) |
| 116 | } |
| 117 | if err != nil { |
| 118 | return fmt.Errorf("database failover: %v", err) |
| 119 | } else { |
| 120 | Errlog.Warnf("database failover success: %v", dbOpenErr) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if p.cfg.SendStats { |
| 125 | p.statSuccessfulRecords = make(map[string]*StatRecord) |
| 126 | p.statUnsuccessfulRecords = make(map[string]*StatRecord) |
| 127 | p.statCh = make(chan map[string]*StatRecord) |
| 128 | |
| 129 | ver, err := packageVersion(agentPackageName) |
| 130 | if err != nil { |
| 131 | Errlog.Warnf("failed to detect version of %s package: %s", agentPackageName, err) |
| 132 | ver = "unknown" |
| 133 | } |
| 134 | |
| 135 | p.sendMessageAPI = NewSendMessageAPI(apiURL, ver, sendMessageAPITimeout) |
| 136 | |
| 137 | p.lw = NewLicenseWatcher(p.cfg.LicensePath, p.cfg.PublicKeyPath, licenseReadInterval) |
| 138 | p.lw.Subscribe(func(l License, valid bool) { |
| 139 | var lic *License |
| 140 | if valid { |
| 141 | lic = &l |
| 142 | } |
| 143 | atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&p.license)), unsafe.Pointer(lic)) |
| 144 | }) |
| 145 | p.lw.Start() |
| 146 | |
| 147 | p.statWait.Add(1) |
| 148 | go p.ServeSendStat() |
| 149 | } |
| 150 | |
| 151 | p.wlUser = NewUserWhiteList(p.cfg.UserLock.WhitelistFileName) |
| 152 | p.wlIP, _ = NewIPWhiteList(p.cfg.IPLock.WhitelistFileName + "," + p.cfg.IPLock.WhitelistInclude) |
| 153 | p.wlUserIP = NewUserIPWhiteList(p.cfg.UserIPLock.WhitelistFileName) |
| 154 | |
| 155 | p.db.WithUserWhitelist(p.wlUser).WithUserIPWhitelist(p.wlUserIP) |
| 156 | |
| 157 | if p.cfg.RBLTimeout > 0 { |
| 158 | p.rbl = NewRBL(RBLConfig{ |
| 159 | ResolverAddr: p.cfg.ResolvConf, |
| 160 | RBLServers: p.cfg.RBL, |
| 161 | RequestTimeout: time.Duration(p.cfg.RBLTimeout) * time.Second, |
| 162 | CacheSize: p.cfg.RBLCacheSize, |
| 163 | CacheTimeout: time.Duration(p.cfg.RBLCacheTTL) * time.Second, |
| 164 | }) |
| 165 | } |
| 166 | |
| 167 | p.acceptList = make(map[net.Listener]struct{}) |
| 168 | p.connList = make(map[net.Conn]struct{}) |
| 169 | |
| 170 | err = p.Serve("unix", p.cfg.Socket, p.ProcessModuleConn) |
| 171 | if err != nil { |
| 172 | return fmt.Errorf("listen: %v", err) |
| 173 | } |
| 174 | |
| 175 | if p.cfg.CPanelFtpAuthInSocket != "" && p.cfg.CPanelFtpAuthOutSocket != "" && p.cfg.CPanelFtpAuthOutTimeout > 0 { |
| 176 | err = p.Serve("unix", p.cfg.CPanelFtpAuthInSocket, p.ProcessCPanelFtpAuthConn) |
| 177 | if err != nil { |
| 178 | return fmt.Errorf("listen: %v", err) |
| 179 | } |
| 180 | } |
| 181 | return |
| 182 | } |
func easyjson3c9d2b01Encode11
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 161 | func easyjson3c9d2b01Encode11(out *jwriter.Writer, in Request) { |
| 162 | out.RawByte('{') |
| 163 | first := true |
| 164 | _ = first |
| 165 | if in.Type != "" { |
| 166 | const prefix string = ",\"type\":" |
| 167 | first = false |
| 168 | out.RawString(prefix[1:]) |
| 169 | out.String(string(in.Type)) |
| 170 | } |
| 171 | if in.Service != "" { |
| 172 | const prefix string = ",\"service\":" |
| 173 | if first { |
| 174 | first = false |
| 175 | out.RawString(prefix[1:]) |
| 176 | } else { |
| 177 | out.RawString(prefix) |
| 178 | } |
| 179 | out.String(string(in.Service)) |
| 180 | } |
| 181 | if in.User != "" { |
| 182 | const prefix string = ",\"user\":" |
| 183 | if first { |
| 184 | first = false |
| 185 | out.RawString(prefix[1:]) |
| 186 | } else { |
| 187 | out.RawString(prefix) |
| 188 | } |
| 189 | out.String(string(in.User)) |
| 190 | } |
| 191 | if in.Host != "" { |
| 192 | const prefix string = ",\"host\":" |
| 193 | if first { |
| 194 | first = false |
| 195 | out.RawString(prefix[1:]) |
| 196 | } else { |
| 197 | out.RawString(prefix) |
| 198 | } |
| 199 | out.String(string(in.Host)) |
| 200 | } |
| 201 | if len(in.Hash) != 0 { |
| 202 | const prefix string = ",\"hash\":" |
| 203 | if first { |
| 204 | first = false |
| 205 | out.RawString(prefix[1:]) |
| 206 | } else { |
| 207 | out.RawString(prefix) |
| 208 | } |
| 209 | { |
| 210 | out.RawByte('[') |
| 211 | for v2, v3 := range in.Hash { |
| 212 | if v2 > 0 { |
| 213 | out.RawByte(',') |
| 214 | } |
| 215 | out.String(string(v3)) |
| 216 | } |
| 217 | out.RawByte(']') |
| 218 | } |
| 219 | } |
| 220 | if in.Sign != "" { |
| 221 | const prefix string = ",\"sign\":" |
| 222 | if first { |
| 223 | first = false |
| 224 | out.RawString(prefix[1:]) |
| 225 | } else { |
| 226 | out.RawString(prefix) |
| 227 | } |
| 228 | out.String(string(in.Sign)) |
| 229 | } |
| 230 | out.RawByte('}') |
| 231 | } |
func Process.ProcessModuleRequest
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/module.go:
| 50 | func (p *Process) ProcessModuleRequest(data []byte) []byte { |
| 51 | var r Request |
| 52 | err := r.UnmarshalJSON(data) |
| 53 | if err != nil { |
| 54 | Errlog.Errorf("parse request: %v", err) |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | if !r.CheckSign(Secret, p.cfg.SharedKey) { |
| 59 | Errlog.Errorf("Incorrect signature from %s:%s", r.Host, r.User) |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | r.Host = ToIP(r.Host) |
| 64 | |
| 65 | switch r.Type { |
| 66 | case "check": |
| 67 | if r.Host != "" && p.wlIP.In(r.Host) { |
| 68 | return ResponseOK |
| 69 | } |
| 70 | |
| 71 | result, err := p.db.CheckLock(r.Host, r.User) |
| 72 | if err != nil { |
| 73 | Errlog.Errorf("check lock: %v", err) |
| 74 | return ResponseFailure |
| 75 | } |
| 76 | |
| 77 | var response string |
| 78 | |
| 79 | if result&UserLock != NoLock { |
| 80 | response = fmt.Sprintf( |
| 81 | "[IM360_UL] The account %s has been temporarily locked by Imunify PAM(%s)", |
| 82 | r.User, r.Host) |
| 83 | } |
| 84 | if result&IPLock != NoLock { |
| 85 | response = fmt.Sprintf("[IM360_IPL] The IP %s has been locked by Imunify PAM", r.Host) |
| 86 | } |
| 87 | if result&UserIPLock != NoLock { |
| 88 | response = fmt.Sprintf( |
| 89 | "[IM360_IPUL] The account %s has been locked for the attacker IP %s", |
| 90 | r.User, r.Host) |
| 91 | } |
| 92 | |
| 93 | if p.cfg.RBLTimeout > 0 && p.rbl != nil { |
| 94 | value, err := p.rbl.Check(r.Host) |
| 95 | if err != nil { |
| 96 | noSuchHost := strings.HasSuffix(err.Error(), "no such host") |
| 97 | if _, ok := err.(*net.DNSError); !ok || err.(*net.DNSError).IsTimeout || !noSuchHost { |
| 98 | log.Errorf("RBL check: %v", err) |
| 99 | } |
| 100 | } |
| 101 | if value { |
| 102 | response = fmt.Sprintf( |
| 103 | "[IM360_RBL] The IP %s has been locked due to Imunify RBL", r.Host) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if len(response) > 0 { |
| 108 | return ModuleStringResponse("I360_BLOCKED", response) |
| 109 | } |
| 110 | |
| 111 | return ResponseOK |
| 112 | case "failed": |
| 113 | for _, hash := range r.Hash { |
| 114 | err := p.db.WriteAttempts(r.Host, r.User, hash) |
| 115 | if err != nil { |
| 116 | Errlog.Errorf("write filed attempt: %v", err) |
| 117 | } |
| 118 | p.WriteStat(false, r.Service, r.Host, r.User, hash) |
| 119 | } |
| 120 | return nil |
| 121 | case "success": |
| 122 | err := p.db.RemoveSuccess(r.Host, r.User) |
| 123 | if err != nil { |
| 124 | Errlog.Errorf("write filed attempt: %v", err) |
| 125 | return ResponseFailure |
| 126 | } |
| 127 | p.WriteStat(true, r.Service, r.Host, r.User, "e") |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | return nil |
| 132 | } |
func easyjsonD587a15Decode12
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 266 | func easyjsonD587a15Decode12(in *jlexer.Lexer, out *License) { |
| 267 | isTopLevel := in.IsStart() |
| 268 | if in.IsNull() { |
| 269 | if isTopLevel { |
| 270 | in.Consumed() |
| 271 | } |
| 272 | in.Skip() |
| 273 | return |
| 274 | } |
| 275 | in.Delim('{') |
| 276 | for !in.IsDelim('}') { |
| 277 | key := in.UnsafeFieldName(false) |
| 278 | in.WantColon() |
| 279 | if in.IsNull() { |
| 280 | in.Skip() |
| 281 | in.WantComma() |
| 282 | continue |
| 283 | } |
| 284 | switch key { |
| 285 | case "group": |
| 286 | out.Group = string(in.String()) |
| 287 | case "id": |
| 288 | out.ID = string(in.String()) |
| 289 | case "limit": |
| 290 | out.Limit = int(in.Int()) |
| 291 | case "message": |
| 292 | out.Message = string(in.String()) |
| 293 | case "sign": |
| 294 | out.Sign = string(in.String()) |
| 295 | case "signatures": |
| 296 | if in.IsNull() { |
| 297 | in.Skip() |
| 298 | out.Signatures = nil |
| 299 | } else { |
| 300 | in.Delim('[') |
| 301 | if out.Signatures == nil { |
| 302 | if !in.IsDelim(']') { |
| 303 | out.Signatures = make([]string, 0, 4) |
| 304 | } else { |
| 305 | out.Signatures = []string{} |
| 306 | } |
| 307 | } else { |
| 308 | out.Signatures = (out.Signatures)[:0] |
| 309 | } |
| 310 | for !in.IsDelim(']') { |
| 311 | var v4 string |
| 312 | v4 = string(in.String()) |
| 313 | out.Signatures = append(out.Signatures, v4) |
| 314 | in.WantComma() |
| 315 | } |
| 316 | in.Delim(']') |
| 317 | } |
| 318 | case "status": |
| 319 | out.Status = string(in.String()) |
| 320 | case "token_created_utc": |
| 321 | out.TokenCreatedUTC = int(in.Int()) |
| 322 | case "token_expire_utc": |
| 323 | out.TokenExpireUTC = int(in.Int()) |
| 324 | case "upgrade_url": |
| 325 | out.UpgradeURL = string(in.String()) |
| 326 | default: |
| 327 | in.SkipRecursive() |
| 328 | } |
| 329 | in.WantComma() |
| 330 | } |
| 331 | in.Delim('}') |
| 332 | if isTopLevel { |
| 333 | in.Consumed() |
| 334 | } |
| 335 | } |
func easyjson2c6259e0Encode1
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license_proto_easyjson.go:
| 90 | func easyjson2c6259e0Encode1(out *jwriter.Writer, in License) { |
| 91 | out.RawByte('{') |
| 92 | first := true |
| 93 | _ = first |
| 94 | { |
| 95 | const prefix string = ",\"group\":" |
| 96 | out.RawString(prefix[1:]) |
| 97 | out.String(string(in.Group)) |
| 98 | } |
| 99 | { |
| 100 | const prefix string = ",\"id\":" |
| 101 | out.RawString(prefix) |
| 102 | out.String(string(in.ID)) |
| 103 | } |
| 104 | { |
| 105 | const prefix string = ",\"limit\":" |
| 106 | out.RawString(prefix) |
| 107 | out.Int(int(in.Limit)) |
| 108 | } |
| 109 | { |
| 110 | const prefix string = ",\"message\":" |
| 111 | out.RawString(prefix) |
| 112 | out.String(string(in.Message)) |
| 113 | } |
| 114 | { |
| 115 | const prefix string = ",\"sign\":" |
| 116 | out.RawString(prefix) |
| 117 | out.String(string(in.Sign)) |
| 118 | } |
| 119 | { |
| 120 | const prefix string = ",\"signatures\":" |
| 121 | out.RawString(prefix) |
| 122 | if in.Signatures == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { |
| 123 | out.RawString("null") |
| 124 | } else { |
| 125 | out.RawByte('[') |
| 126 | for v2, v3 := range in.Signatures { |
| 127 | if v2 > 0 { |
| 128 | out.RawByte(',') |
| 129 | } |
| 130 | out.String(string(v3)) |
| 131 | } |
| 132 | out.RawByte(']') |
| 133 | } |
| 134 | } |
| 135 | { |
| 136 | const prefix string = ",\"status\":" |
| 137 | out.RawString(prefix) |
| 138 | out.String(string(in.Status)) |
| 139 | } |
| 140 | { |
| 141 | const prefix string = ",\"token_created_utc\":" |
| 142 | out.RawString(prefix) |
| 143 | out.Int(int(in.TokenCreatedUTC)) |
| 144 | } |
| 145 | { |
| 146 | const prefix string = ",\"token_expire_utc\":" |
| 147 | out.RawString(prefix) |
| 148 | out.Int(int(in.TokenExpireUTC)) |
| 149 | } |
| 150 | { |
| 151 | const prefix string = ",\"upgrade_url\":" |
| 152 | out.RawString(prefix) |
| 153 | out.String(string(in.UpgradeURL)) |
| 154 | } |
| 155 | out.RawByte('}') |
| 156 | } |
func easyjsonD587a15Encode12
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 336 | func easyjsonD587a15Encode12(out *jwriter.Writer, in License) { |
| 337 | out.RawByte('{') |
| 338 | first := true |
| 339 | _ = first |
| 340 | { |
| 341 | const prefix string = ",\"group\":" |
| 342 | out.RawString(prefix[1:]) |
| 343 | out.String(string(in.Group)) |
| 344 | } |
| 345 | { |
| 346 | const prefix string = ",\"id\":" |
| 347 | out.RawString(prefix) |
| 348 | out.String(string(in.ID)) |
| 349 | } |
| 350 | { |
| 351 | const prefix string = ",\"limit\":" |
| 352 | out.RawString(prefix) |
| 353 | out.Int(int(in.Limit)) |
| 354 | } |
| 355 | { |
| 356 | const prefix string = ",\"message\":" |
| 357 | out.RawString(prefix) |
| 358 | out.String(string(in.Message)) |
| 359 | } |
| 360 | { |
| 361 | const prefix string = ",\"sign\":" |
| 362 | out.RawString(prefix) |
| 363 | out.String(string(in.Sign)) |
| 364 | } |
| 365 | { |
| 366 | const prefix string = ",\"signatures\":" |
| 367 | out.RawString(prefix) |
| 368 | if in.Signatures == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { |
| 369 | out.RawString("null") |
| 370 | } else { |
| 371 | out.RawByte('[') |
| 372 | for v5, v6 := range in.Signatures { |
| 373 | if v5 > 0 { |
| 374 | out.RawByte(',') |
| 375 | } |
| 376 | out.String(string(v6)) |
| 377 | } |
| 378 | out.RawByte(']') |
| 379 | } |
| 380 | } |
| 381 | { |
| 382 | const prefix string = ",\"status\":" |
| 383 | out.RawString(prefix) |
| 384 | out.String(string(in.Status)) |
| 385 | } |
| 386 | { |
| 387 | const prefix string = ",\"token_created_utc\":" |
| 388 | out.RawString(prefix) |
| 389 | out.Int(int(in.TokenCreatedUTC)) |
| 390 | } |
| 391 | { |
| 392 | const prefix string = ",\"token_expire_utc\":" |
| 393 | out.RawString(prefix) |
| 394 | out.Int(int(in.TokenExpireUTC)) |
| 395 | } |
| 396 | { |
| 397 | const prefix string = ",\"upgrade_url\":" |
| 398 | out.RawString(prefix) |
| 399 | out.String(string(in.UpgradeURL)) |
| 400 | } |
| 401 | out.RawByte('}') |
| 402 | } |
func easyjsonD587a15Decode11
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 135 | func easyjsonD587a15Decode11(in *jlexer.Lexer, out *SendMessagesApiRequest) { |
| 136 | isTopLevel := in.IsStart() |
| 137 | if in.IsNull() { |
| 138 | if isTopLevel { |
| 139 | in.Consumed() |
| 140 | } |
| 141 | in.Skip() |
| 142 | return |
| 143 | } |
| 144 | in.Delim('{') |
| 145 | for !in.IsDelim('}') { |
| 146 | key := in.UnsafeFieldName(false) |
| 147 | in.WantColon() |
| 148 | if in.IsNull() { |
| 149 | in.Skip() |
| 150 | in.WantComma() |
| 151 | continue |
| 152 | } |
| 153 | switch key { |
| 154 | case "rpm_ver": |
| 155 | out.AgentVersion = string(in.String()) |
| 156 | case "license": |
| 157 | easyjsonD587a15Decode12(in, &out.License) |
| 158 | case "method": |
| 159 | out.Method = string(in.String()) |
| 160 | case "ver": |
| 161 | out.ProtocolVersion = string(in.String()) |
| 162 | case "server_id": |
| 163 | out.ServerID = string(in.String()) |
| 164 | case "payload": |
| 165 | if in.IsNull() { |
| 166 | in.Skip() |
| 167 | out.Payload = nil |
| 168 | } else { |
| 169 | in.Delim('[') |
| 170 | if out.Payload == nil { |
| 171 | if !in.IsDelim(']') { |
| 172 | out.Payload = make([]StatRecord, 0, 0) |
| 173 | } else { |
| 174 | out.Payload = []StatRecord{} |
| 175 | } |
| 176 | } else { |
| 177 | out.Payload = (out.Payload)[:0] |
| 178 | } |
| 179 | for !in.IsDelim(']') { |
| 180 | var v1 StatRecord |
| 181 | (v1).UnmarshalEasyJSON(in) |
| 182 | out.Payload = append(out.Payload, v1) |
| 183 | in.WantComma() |
| 184 | } |
| 185 | in.Delim(']') |
| 186 | } |
| 187 | default: |
| 188 | in.SkipRecursive() |
| 189 | } |
| 190 | in.WantComma() |
| 191 | } |
| 192 | in.Delim('}') |
| 193 | if isTopLevel { |
| 194 | in.Consumed() |
| 195 | } |
| 196 | } |
func easyjson3c9d2b01Decode11
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 99 | func easyjson3c9d2b01Decode11(in *jlexer.Lexer, out *Request) { |
| 100 | isTopLevel := in.IsStart() |
| 101 | if in.IsNull() { |
| 102 | if isTopLevel { |
| 103 | in.Consumed() |
| 104 | } |
| 105 | in.Skip() |
| 106 | return |
| 107 | } |
| 108 | in.Delim('{') |
| 109 | for !in.IsDelim('}') { |
| 110 | key := in.UnsafeFieldName(false) |
| 111 | in.WantColon() |
| 112 | if in.IsNull() { |
| 113 | in.Skip() |
| 114 | in.WantComma() |
| 115 | continue |
| 116 | } |
| 117 | switch key { |
| 118 | case "type": |
| 119 | out.Type = string(in.String()) |
| 120 | case "service": |
| 121 | out.Service = string(in.String()) |
| 122 | case "user": |
| 123 | out.User = string(in.String()) |
| 124 | case "host": |
| 125 | out.Host = string(in.String()) |
| 126 | case "hash": |
| 127 | if in.IsNull() { |
| 128 | in.Skip() |
| 129 | out.Hash = nil |
| 130 | } else { |
| 131 | in.Delim('[') |
| 132 | if out.Hash == nil { |
| 133 | if !in.IsDelim(']') { |
| 134 | out.Hash = make([]string, 0, 4) |
| 135 | } else { |
| 136 | out.Hash = []string{} |
| 137 | } |
| 138 | } else { |
| 139 | out.Hash = (out.Hash)[:0] |
| 140 | } |
| 141 | for !in.IsDelim(']') { |
| 142 | var v1 string |
| 143 | v1 = string(in.String()) |
| 144 | out.Hash = append(out.Hash, v1) |
| 145 | in.WantComma() |
| 146 | } |
| 147 | in.Delim(']') |
| 148 | } |
| 149 | case "sign": |
| 150 | out.Sign = string(in.String()) |
| 151 | default: |
| 152 | in.SkipRecursive() |
| 153 | } |
| 154 | in.WantComma() |
| 155 | } |
| 156 | in.Delim('}') |
| 157 | if isTopLevel { |
| 158 | in.Consumed() |
| 159 | } |
| 160 | } |
func easyjsonD587a15Encode11
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 197 | func easyjsonD587a15Encode11(out *jwriter.Writer, in SendMessagesApiRequest) { |
| 198 | out.RawByte('{') |
| 199 | first := true |
| 200 | _ = first |
| 201 | { |
| 202 | const prefix string = ",\"rpm_ver\":" |
| 203 | out.RawString(prefix[1:]) |
| 204 | out.String(string(in.AgentVersion)) |
| 205 | } |
| 206 | if true { |
| 207 | const prefix string = ",\"license\":" |
| 208 | out.RawString(prefix) |
| 209 | easyjsonD587a15Encode12(out, in.License) |
| 210 | } |
| 211 | if in.Method != "" { |
| 212 | const prefix string = ",\"method\":" |
| 213 | out.RawString(prefix) |
| 214 | out.String(string(in.Method)) |
| 215 | } |
| 216 | { |
| 217 | const prefix string = ",\"ver\":" |
| 218 | out.RawString(prefix) |
| 219 | out.String(string(in.ProtocolVersion)) |
| 220 | } |
| 221 | if in.ServerID != "" { |
| 222 | const prefix string = ",\"server_id\":" |
| 223 | out.RawString(prefix) |
| 224 | out.String(string(in.ServerID)) |
| 225 | } |
| 226 | if len(in.Payload) != 0 { |
| 227 | const prefix string = ",\"payload\":" |
| 228 | out.RawString(prefix) |
| 229 | { |
| 230 | out.RawByte('[') |
| 231 | for v2, v3 := range in.Payload { |
| 232 | if v2 > 0 { |
| 233 | out.RawByte(',') |
| 234 | } |
| 235 | (v3).MarshalEasyJSON(out) |
| 236 | } |
| 237 | out.RawByte(']') |
| 238 | } |
| 239 | } |
| 240 | out.RawByte('}') |
| 241 | } |
func easyjsonD587a15Encode1
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 65 | func easyjsonD587a15Encode1(out *jwriter.Writer, in StatRecord) { |
| 66 | out.RawByte('{') |
| 67 | first := true |
| 68 | _ = first |
| 69 | { |
| 70 | const prefix string = ",\"name\":" |
| 71 | out.RawString(prefix[1:]) |
| 72 | out.String(string(in.Name)) |
| 73 | } |
| 74 | { |
| 75 | const prefix string = ",\"attackers_ip\":" |
| 76 | out.RawString(prefix) |
| 77 | out.String(string(in.AttackersIP)) |
| 78 | } |
| 79 | { |
| 80 | const prefix string = ",\"rule\":" |
| 81 | out.RawString(prefix) |
| 82 | out.Int(int(in.Rule)) |
| 83 | } |
| 84 | { |
| 85 | const prefix string = ",\"message\":" |
| 86 | out.RawString(prefix) |
| 87 | out.String(string(in.Message)) |
| 88 | } |
| 89 | { |
| 90 | const prefix string = ",\"severity\":" |
| 91 | out.RawString(prefix) |
| 92 | out.Int(int(in.Severity)) |
| 93 | } |
| 94 | { |
| 95 | const prefix string = ",\"retries\":" |
| 96 | out.RawString(prefix) |
| 97 | out.Int(int(in.Retries)) |
| 98 | } |
| 99 | { |
| 100 | const prefix string = ",\"timestamp\":" |
| 101 | out.RawString(prefix) |
| 102 | out.Int64(int64(in.Timestamp)) |
| 103 | } |
| 104 | { |
| 105 | const prefix string = ",\"plugin_id\":" |
| 106 | out.RawString(prefix) |
| 107 | out.String(string(in.PluginId)) |
| 108 | } |
| 109 | out.RawByte('}') |
| 110 | } |
func easyjsonD587a15Decode1
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 20 | func easyjsonD587a15Decode1(in *jlexer.Lexer, out *StatRecord) { |
| 21 | isTopLevel := in.IsStart() |
| 22 | if in.IsNull() { |
| 23 | if isTopLevel { |
| 24 | in.Consumed() |
| 25 | } |
| 26 | in.Skip() |
| 27 | return |
| 28 | } |
| 29 | in.Delim('{') |
| 30 | for !in.IsDelim('}') { |
| 31 | key := in.UnsafeFieldName(false) |
| 32 | in.WantColon() |
| 33 | if in.IsNull() { |
| 34 | in.Skip() |
| 35 | in.WantComma() |
| 36 | continue |
| 37 | } |
| 38 | switch key { |
| 39 | case "name": |
| 40 | out.Name = string(in.String()) |
| 41 | case "attackers_ip": |
| 42 | out.AttackersIP = string(in.String()) |
| 43 | case "rule": |
| 44 | out.Rule = int(in.Int()) |
| 45 | case "message": |
| 46 | out.Message = string(in.String()) |
| 47 | case "severity": |
| 48 | out.Severity = int(in.Int()) |
| 49 | case "retries": |
| 50 | out.Retries = int(in.Int()) |
| 51 | case "timestamp": |
| 52 | out.Timestamp = int64(in.Int64()) |
| 53 | case "plugin_id": |
| 54 | out.PluginId = string(in.String()) |
| 55 | default: |
| 56 | in.SkipRecursive() |
| 57 | } |
| 58 | in.WantComma() |
| 59 | } |
| 60 | in.Delim('}') |
| 61 | if isTopLevel { |
| 62 | in.Consumed() |
| 63 | } |
| 64 | } |
func Process.WriteStat
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 203 | func (p *Process) WriteStat(success bool, service, ip, username, password string) { |
| 204 | if p.cfg.SendStats == false || ip == "127.0.0.1" { |
| 205 | return |
| 206 | } |
| 207 | |
| 208 | now := time.Now() |
| 209 | p.statLock.Lock() |
| 210 | if success { |
| 211 | message := fmt.Sprintf("%s s_ip %s - %s:e res:true", service, ip, username) |
| 212 | record, ok := p.statSuccessfulRecords[message] |
| 213 | if !ok { |
| 214 | p.statSuccessfulRecords[message] = &StatRecord{ |
| 215 | Name: "pam_imunify info", |
| 216 | AttackersIP: ip, |
| 217 | Rule: 77777, |
| 218 | Message: message, |
| 219 | Severity: 1, |
| 220 | Retries: 1, |
| 221 | Timestamp: now.Unix(), |
| 222 | PluginId: "pam_imunify", |
| 223 | } |
| 224 | } else { |
| 225 | record.Retries++ |
| 226 | } |
| 227 | |
| 228 | if p.statSuccessfulTime.IsZero() { |
| 229 | p.statSuccessfulTime = now |
| 230 | } else if p.statSuccessfulTime.Add(time.Duration(p.cfg.SendStatsSuccessfulAggTime) * time.Second).Before(now) { |
| 231 | p.statSuccessfulTime = time.Time{} |
| 232 | p.statCh <- p.statSuccessfulRecords |
| 233 | p.statSuccessfulRecords = make(map[string]*StatRecord) |
| 234 | } |
| 235 | } else { |
| 236 | message := fmt.Sprintf("%s s_ip %s - %s:%s res:false", service, ip, username, password) |
| 237 | record, ok := p.statUnsuccessfulRecords[message] |
| 238 | if !ok { |
| 239 | p.statUnsuccessfulRecords[message] = &StatRecord{ |
| 240 | Name: "pam_imunify info", |
| 241 | AttackersIP: ip, |
| 242 | Rule: 77777, |
| 243 | Message: message, |
| 244 | Severity: 1, |
| 245 | Retries: 1, |
| 246 | Timestamp: now.Unix(), |
| 247 | PluginId: "pam_imunify", |
| 248 | } |
| 249 | } else { |
| 250 | record.Retries++ |
| 251 | } |
| 252 | |
| 253 | if p.statUnsuccessfulTime.IsZero() { |
| 254 | p.statUnsuccessfulTime = now |
| 255 | } else if p.statUnsuccessfulTime.Add(time.Duration(p.cfg.SendStatsUnsuccessfulAggTime) * time.Second).Before(now) { |
| 256 | p.statUnsuccessfulTime = time.Time{} |
| 257 | p.statCh <- p.statUnsuccessfulRecords |
| 258 | p.statUnsuccessfulRecords = make(map[string]*StatRecord) |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | p.statLock.Unlock() |
| 263 | |
| 264 | } |
func Process.Stop
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 317 | func (p *Process) Stop() { |
| 318 | // Stop accepting new connections |
| 319 | for listener := range p.acceptList { |
| 320 | _ = listener.Close() |
| 321 | delete(p.acceptList, listener) |
| 322 | } |
| 323 | p.acceptRoutineWait.Wait() |
| 324 | |
| 325 | // Close all opened connections |
| 326 | p.connListLock.Lock() |
| 327 | for conn := range p.connList { |
| 328 | _ = conn.Close() |
| 329 | delete(p.connList, conn) |
| 330 | } |
| 331 | p.connListLock.Unlock() |
| 332 | p.connRoutinesWait.Wait() |
| 333 | |
| 334 | if p.cfg.SendStats { |
| 335 | p.statLock.Lock() |
| 336 | p.statCh <- p.statSuccessfulRecords |
| 337 | p.statCh <- p.statUnsuccessfulRecords |
| 338 | p.statLock.Unlock() |
| 339 | close(p.statCh) |
| 340 | p.statWait.Wait() |
| 341 | p.lw.Stop() |
| 342 | } |
| 343 | |
| 344 | err := p.db.Close() |
| 345 | if err != nil { |
| 346 | Errlog.Fatalf("database close: %v", err) |
| 347 | } |
| 348 | |
| 349 | p.syslog.Close() |
| 350 | |
| 351 | if p.sentryLogger != nil { |
| 352 | p.sentryLogger.Flush() |
| 353 | } |
| 354 | |
| 355 | log.SetLevel(log.InfoLevel) |
| 356 | log.SetOutput(os.Stderr) |
| 357 | } |
func easyjson3c9d2b01Decode1
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 20 | func easyjson3c9d2b01Decode1(in *jlexer.Lexer, out *Response) { |
| 21 | isTopLevel := in.IsStart() |
| 22 | if in.IsNull() { |
| 23 | if isTopLevel { |
| 24 | in.Consumed() |
| 25 | } |
| 26 | in.Skip() |
| 27 | return |
| 28 | } |
| 29 | in.Delim('{') |
| 30 | for !in.IsDelim('}') { |
| 31 | key := in.UnsafeFieldName(false) |
| 32 | in.WantColon() |
| 33 | if in.IsNull() { |
| 34 | in.Skip() |
| 35 | in.WantComma() |
| 36 | continue |
| 37 | } |
| 38 | switch key { |
| 39 | case "action": |
| 40 | out.Action = string(in.String()) |
| 41 | case "message": |
| 42 | out.Message = string(in.String()) |
| 43 | default: |
| 44 | in.SkipRecursive() |
| 45 | } |
| 46 | in.WantComma() |
| 47 | } |
| 48 | in.Delim('}') |
| 49 | if isTopLevel { |
| 50 | in.Consumed() |
| 51 | } |
| 52 | } |
func Process.ProcessModuleConn
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/module.go:
| 10 | func (p *Process) ProcessModuleConn(c net.Conn) { |
| 11 | b := make([]byte, 2048) |
| 12 | for { |
| 13 | n, err := c.Read(b) |
| 14 | if err != nil { |
| 15 | if shouldLogError(err) { |
| 16 | Errlog.Errorf("read: %v", err) |
| 17 | } |
| 18 | break |
| 19 | } |
| 20 | |
| 21 | requestId := p.RequestId() |
| 22 | |
| 23 | log.Debugf("--[svc:%d]->> %v", requestId, string(b[:n])) |
| 24 | |
| 25 | resp := p.ProcessModuleRequest(b[:n]) |
| 26 | if resp == nil { |
| 27 | break |
| 28 | } |
| 29 | |
| 30 | log.Debugf("<-[svc:%d]--- %v", requestId, string(resp)) |
| 31 | |
| 32 | _, err = c.Write(resp) |
| 33 | if err != nil { |
| 34 | Errlog.Errorf("connection serve: %v", err) |
| 35 | break |
| 36 | } |
| 37 | } |
| 38 | } |
func NewSentryLogger
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/sentry_logger.go:
| 93 | func NewSentryLogger(package_name string, package_version string) (s *SentryLogger, |
| 94 | err error) { |
| 95 | s = new(SentryLogger) |
| 96 | s.dsn = SENTRY_DSN |
| 97 | |
| 98 | httpsync_transport := sentry.NewHTTPSyncTransport() |
| 99 | httpsync_transport.Configure(sentry.ClientOptions{ |
| 100 | Dsn: SENTRY_DSN, |
| 101 | }) |
| 102 | sentry.Init(sentry.ClientOptions{ |
| 103 | Dsn: SENTRY_DSN, |
| 104 | Transport: httpsync_transport, |
| 105 | }) |
| 106 | |
| 107 | server_ip, err := getOwnIP() |
| 108 | if err != nil { |
| 109 | Errlog.Errorf("failed to retrieve server IP: %v", err) |
| 110 | } |
| 111 | server_id, err := getServerId() |
| 112 | if err != nil { |
| 113 | return nil, fmt.Errorf("failed to retrieve server ID: %v", err) |
| 114 | } |
| 115 | os_release, err := getOsRelease() |
| 116 | if err != nil { |
| 117 | Errlog.Errorf("failed to retrieve OS release: %v", err) |
| 118 | } |
| 119 | |
| 120 | sentry.ConfigureScope(func(scope *sentry.Scope) { |
| 121 | scope.SetTag("name", package_name) |
| 122 | scope.SetTag("version", package_version) |
| 123 | if server_ip != nil { |
| 124 | scope.SetTag("server_ip", server_ip.String()) |
| 125 | } |
| 126 | if server_id != "" { |
| 127 | scope.SetUser(sentry.User{ |
| 128 | ID: server_id, |
| 129 | }) |
| 130 | } |
| 131 | if os_release != "" { |
| 132 | scope.SetTag("os.version", os_release) |
| 133 | } |
| 134 | }) |
| 135 | |
| 136 | return s, nil |
| 137 | } |
func main
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 372 | func main() { |
| 373 | var ( |
| 374 | done bool |
| 375 | cfgPath string |
| 376 | err error |
| 377 | ) |
| 378 | |
| 379 | flag.StringVar(&cfgPath, "f", DefaultIniPath, "ini file path") |
| 380 | flag.Parse() |
| 381 | |
| 382 | sigs := make(chan os.Signal, 1) |
| 383 | signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) |
| 384 | |
| 385 | for !done { |
| 386 | p := new(Process) |
| 387 | |
| 388 | err = p.Start(cfgPath) |
| 389 | if err != nil { |
| 390 | Errlog.Fatalf("start: %v", err) |
| 391 | } |
| 392 | |
| 393 | switch <-sigs { |
| 394 | case syscall.SIGINT, syscall.SIGTERM: |
| 395 | done = true |
| 396 | break |
| 397 | case syscall.SIGHUP: |
| 398 | } |
| 399 | |
| 400 | p.Stop() |
| 401 | |
| 402 | p = nil |
| 403 | runtime.GC() |
| 404 | } |
| 405 | } |
func getOwnIP
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/sentry_logger.go:
| 28 | func getOwnIP() (ip net.IP, err error) { |
| 29 | var ifaces []net.Interface |
| 30 | ifaces, err = net.Interfaces() |
| 31 | |
| 32 | for _, i := range ifaces { |
| 33 | if i.Flags&net.FlagUp == 0 { |
| 34 | continue |
| 35 | } |
| 36 | |
| 37 | var addrs []net.Addr |
| 38 | addrs, err = i.Addrs() |
| 39 | |
| 40 | for _, addr := range addrs { |
| 41 | switch v := addr.(type) { |
| 42 | case *net.IPNet: |
| 43 | ip = v.IP |
| 44 | case *net.IPAddr: |
| 45 | ip = v.IP |
| 46 | } |
| 47 | |
| 48 | if ip == nil || ip.To4() == nil || ip.IsLoopback() { |
| 49 | ip = nil |
| 50 | } else { |
| 51 | break |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | return |
| 56 | } |
func Database.RemoveSuccess
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 174 | func (db *Database) RemoveSuccess(ip string, user string) error { |
| 175 | batch := new(leveldb.Batch) |
| 176 | |
| 177 | if user != "" { |
| 178 | batch.Delete([]byte(user)) |
| 179 | log.Tracef("---[db]->> del %v", user) |
| 180 | } |
| 181 | if user != "" && ip != "" { |
| 182 | batch.Delete([]byte(ip + "/" + user)) |
| 183 | log.Tracef("---[db]->> del %v", ip+"/"+user) |
| 184 | } |
| 185 | |
| 186 | if batch.Len() == 0 { |
| 187 | return nil |
| 188 | } |
| 189 | |
| 190 | db.lock.Lock() |
| 191 | defer db.lock.Unlock() |
| 192 | |
| 193 | err := db.db.Write(batch, nil) |
| 194 | if err != nil { |
| 195 | return fmt.Errorf("batch write: %v", err) |
| 196 | } |
| 197 | |
| 198 | return nil |
| 199 | } |
func query
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/rbl.go:
| 71 | func query(ctx context.Context, nameserver string, rbl string, host string, r *Result) { |
| 72 | r.Listed = false |
| 73 | |
| 74 | resolver := net.Resolver{ |
| 75 | PreferGo: true, |
| 76 | } |
| 77 | if nameserver != "" { |
| 78 | resolver.Dial = func(ctx context.Context, network, address string) (net.Conn, error) { |
| 79 | d := net.Dialer{} |
| 80 | return d.DialContext(ctx, "udp", nameserver) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | lookup := fmt.Sprintf("%s.%s", host, rbl) |
| 85 | |
| 86 | res, err := resolver.LookupHost(ctx, lookup) |
| 87 | if len(res) > 0 { |
| 88 | r.Listed = true |
| 89 | txt, _ := resolver.LookupTXT(ctx, lookup) |
| 90 | if len(txt) > 0 { |
| 91 | r.Text = txt[0] |
| 92 | } |
| 93 | } |
| 94 | if err != nil { |
| 95 | r.Error = true |
| 96 | r.ErrorType = err |
| 97 | } |
| 98 | |
| 99 | return |
| 100 | } |
func Process.ProcessCPanelFtpAuthConn
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/cpanel.go:
| 31 | func (p *Process) ProcessCPanelFtpAuthConn(c net.Conn) { |
| 32 | b, err := CPanelFtpAuthRecv(c) |
| 33 | if err != nil { |
| 34 | if shouldLogError(err) { |
| 35 | Errlog.Errorf("read: %v", err) |
| 36 | } |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | requestId := p.RequestId() |
| 41 | |
| 42 | log.Debugf("--[svc:%d]->>\n%v", requestId, string(b)) |
| 43 | |
| 44 | resp := p.ProcessCPanelFtpAuthRequest(b) |
| 45 | if resp == nil { |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | log.Debugf("<-[svc:%d]---\n%v", requestId, string(resp)) |
| 50 | |
| 51 | _, err = c.Write(resp) |
| 52 | if err != nil { |
| 53 | Errlog.Errorf("connection serve: %v", err) |
| 54 | return |
| 55 | } |
| 56 | } |
func CPanelAuthMsg.Unmarshal
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/cpanel.go:
| 170 | func (r *CPanelAuthMsg) Unmarshal(b []byte) *CPanelAuthMsg { |
| 171 | lines := bytes.Split(b, []byte{'\n'}) |
| 172 | for _, line := range lines { |
| 173 | i := bytes.IndexByte(line, ':') |
| 174 | if i == -1 { |
| 175 | continue |
| 176 | } |
| 177 | key := line[:i] |
| 178 | value := line[i+1:] |
| 179 | switch string(key) { |
| 180 | case "account": |
| 181 | r.Account = string(value) |
| 182 | case "password": |
| 183 | r.Password = string(value) |
| 184 | case "peer": |
| 185 | r.Peer = string(value) |
| 186 | case "auth_ok": |
| 187 | r.AuthOk = string(value) |
| 188 | } |
| 189 | } |
| 190 | return r |
| 191 | } |
func Request.CheckSign
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request.go:
| 27 | func (r Request) CheckSign(secret, key string) bool { |
| 28 | hash := sha256.New() |
| 29 | hash.Write([]byte(secret)) |
| 30 | hash.Write([]byte(r.Type)) |
| 31 | hash.Write([]byte(r.Service)) |
| 32 | hash.Write([]byte(r.User)) |
| 33 | hash.Write([]byte(r.Host)) |
| 34 | for _, v := range r.Hash { |
| 35 | hash.Write([]byte(v)) |
| 36 | } |
| 37 | hash.Write([]byte(key)) |
| 38 | sign, err := hex.DecodeString(r.Sign) |
| 39 | if err != nil { |
| 40 | return false |
| 41 | } |
| 42 | return bytes.Equal(hash.Sum(nil), sign) |
| 43 | } |
func Process.ServeListener
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 278 | func (p *Process) ServeListener(l net.Listener, connCallback func(c net.Conn)) { |
| 279 | for { |
| 280 | c, err := l.Accept() |
| 281 | if err != nil { |
| 282 | if shouldLogError(err) { |
| 283 | Errlog.Errorf("accept: %v", err) |
| 284 | } |
| 285 | break |
| 286 | } |
| 287 | |
| 288 | p.connListLock.Lock() |
| 289 | p.connList[c] = struct{}{} |
| 290 | p.connListLock.Unlock() |
| 291 | |
| 292 | p.connRoutinesWait.Add(1) |
| 293 | //go p.ServeConn(c, connCallback) |
| 294 | go func(c net.Conn, connCallback func(c net.Conn)) { |
| 295 | connCallback(c) |
| 296 | |
| 297 | p.connListLock.Lock() |
| 298 | if _, ok := p.connList[c]; ok { |
| 299 | delete(p.connList, c) |
| 300 | err := c.Close() |
| 301 | if err != nil { |
| 302 | Errlog.Errorf("connection close: %v", err) |
| 303 | } |
| 304 | } |
| 305 | p.connListLock.Unlock() |
| 306 | |
| 307 | p.connRoutinesWait.Done() |
| 308 | }(c, connCallback) |
| 309 | } |
| 310 | p.acceptRoutineWait.Done() |
| 311 | } |
func CheckRBL
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/rbl.go:
| 126 | func CheckRBL(r string, rbl []string, ip string, timeout time.Duration) (bool, error) { |
| 127 | if ip == "" || ip == "127.0.0.1" { |
| 128 | return false, nil |
| 129 | } |
| 130 | |
| 131 | ctx, cancel := context.WithTimeout(context.Background(), timeout) |
| 132 | defer cancel() |
| 133 | |
| 134 | var e error = nil |
| 135 | for _, server := range rbl { |
| 136 | r := rblLookupIP(ctx, r, server, ip) |
| 137 | for _, res := range r.Results { |
| 138 | if res.Error == false { |
| 139 | return true, nil |
| 140 | } else { |
| 141 | e = res.ErrorType |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | return false, e |
| 147 | } |
func Process.ServeSendStat
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 184 | func (p *Process) ServeSendStat() { |
| 185 | for statsMap := range p.statCh { |
| 186 | stats := make([]StatRecord, 0, len(statsMap)) |
| 187 | for _, v := range statsMap { |
| 188 | stats = append(stats, *v) |
| 189 | } |
| 190 | |
| 191 | license := (*License)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&p.license)))) |
| 192 | err := p.sendMessageAPI.SendStats(license, stats) |
| 193 | if err != nil { |
| 194 | Errlog.Errorf("Send stats for %d records error: %v", len(stats), err) |
| 195 | continue |
| 196 | } |
| 197 | log.Infof("Send stats for %d records success", len(stats)) |
| 198 | log.WithField("Records", stats).Debug("Send stats records") |
| 199 | } |
| 200 | p.statWait.Done() |
| 201 | } |
func rblLookupIP
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/rbl.go:
| 105 | func rblLookupIP(ctx context.Context, resolver string, rblList string, targetIP string) (r RBLResults) { |
| 106 | r.List = rblList |
| 107 | r.Host = targetIP |
| 108 | |
| 109 | res := Result{} |
| 110 | res.Address = targetIP |
| 111 | |
| 112 | ip := net.ParseIP(targetIP) |
| 113 | if ip == nil { |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | addr := ReverseIP(ip) |
| 118 | |
| 119 | query(ctx, resolver, rblList, addr, &res) |
| 120 | |
| 121 | r.Results = append(r.Results, res) |
| 122 | |
| 123 | return |
| 124 | } |
func getServerId
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/sentry_logger.go:
| 58 | func getServerId() (id string, err error) { |
| 59 | var f *os.File |
| 60 | f, err = os.Open("/var/imunify360/license.json") |
| 61 | if err != nil { |
| 62 | return |
| 63 | } |
| 64 | defer f.Close() |
| 65 | |
| 66 | data, _ := ioutil.ReadAll(f) |
| 67 | |
| 68 | var license Im360License |
| 69 | json.Unmarshal(data, &license) |
| 70 | |
| 71 | id = license.Id |
| 72 | return |
| 73 | } |
func @63:25
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api.go:
| 63 | func() (interface{}, error) { |
| 64 | res, err := ca.client.Post(ca.baseURL+sendMessageURL, sendMessageContentTypeJSON, bytes.NewReader(b)) |
| 65 | if err != nil { |
| 66 | return nil, err |
| 67 | } |
| 68 | defer res.Body.Close() |
| 69 | |
| 70 | body, err := ioutil.ReadAll(res.Body) |
| 71 | if err != nil { |
| 72 | return nil, err |
| 73 | } |
| 74 | |
| 75 | if res.StatusCode != http.StatusOK { |
| 76 | return body, fmt.Errorf("error response: %d, %s", res.StatusCode, string(body)) |
| 77 | } |
| 78 | |
| 79 | return body, nil |
| 80 | } |
func @191:14
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/rbl.go:
| 191 | func(key interface{}) (interface{}, error) { |
| 192 | s, ok := key.(string) |
| 193 | if !ok { |
| 194 | return nil, fmt.Errorf("LRU Cache: Bad key value type") |
| 195 | } |
| 196 | value, err := CheckRBL(r.resolverAddr, r.rblServers, s, r.requestTimeout) |
| 197 | if value || err == nil { |
| 198 | return value, nil |
| 199 | } |
| 200 | noSuchHost := strings.HasSuffix(err.Error(), "no such host") |
| 201 | if _, ok := err.(*net.DNSError); !ok || err.(*net.DNSError).IsTimeout || !noSuchHost { |
| 202 | return nil, err |
| 203 | } |
| 204 | return value, nil |
| 205 | } |
func getOsRelease
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/sentry_logger.go:
| 75 | func getOsRelease() (os_release string, err error) { |
| 76 | var f *os.File |
| 77 | f, err = os.Open("/etc/os-release") |
| 78 | if err != nil { |
| 79 | return |
| 80 | } |
| 81 | defer f.Close() |
| 82 | |
| 83 | data, _ := ioutil.ReadAll(f) |
| 84 | |
| 85 | matches := regexp.MustCompile(`PRETTY_NAME=(.+)`).FindSubmatch(data) |
| 86 | if len(matches) > 1 { |
| 87 | os_release = strings.Trim(string(matches[1]), "\"") |
| 88 | } |
| 89 | |
| 90 | return |
| 91 | } |
func @294:6
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 294 | func(c net.Conn, connCallback func(c net.Conn)) { |
| 295 | connCallback(c) |
| 296 | |
| 297 | p.connListLock.Lock() |
| 298 | if _, ok := p.connList[c]; ok { |
| 299 | delete(p.connList, c) |
| 300 | err := c.Close() |
| 301 | if err != nil { |
| 302 | Errlog.Errorf("connection close: %v", err) |
| 303 | } |
| 304 | } |
| 305 | p.connListLock.Unlock() |
| 306 | |
| 307 | p.connRoutinesWait.Done() |
| 308 | } |
func CPanelFtpAuthRecv
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/cpanel.go:
| 14 | func CPanelFtpAuthRecv(conn net.Conn) ([]byte, error) { |
| 15 | var rb []byte |
| 16 | reader := bufio.NewReader(conn) |
| 17 | for { |
| 18 | b, err := reader.ReadBytes('\n') |
| 19 | if err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | |
| 23 | rb = append(rb, b...) |
| 24 | |
| 25 | if bytes.Equal([]byte("end\n"), b) { |
| 26 | return rb, nil |
| 27 | } |
| 28 | } |
| 29 | } |
func LicenseWatcher.watcher
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 110 | func (lw *LicenseWatcher) watcher() { |
| 111 | defer lw.wg.Done() |
| 112 | |
| 113 | ticker := time.NewTicker(lw.interval) |
| 114 | defer ticker.Stop() |
| 115 | |
| 116 | lw.readLicenseAndNotify() |
| 117 | for { |
| 118 | select { |
| 119 | case <-lw.done: |
| 120 | return |
| 121 | case <-ticker.C: |
| 122 | lw.readLicenseAndNotify() |
| 123 | } |
| 124 | } |
| 125 | } |
func WhiteList.isNeedUpdate
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/whitelist.go:
| 69 | func (wl *WhiteList) isNeedUpdate() bool { |
| 70 | for fileName, fileModTime := range wl.file { |
| 71 | info, err := os.Stat(fileName) |
| 72 | if err != nil || info == nil { |
| 73 | if !fileModTime.IsZero() { |
| 74 | return true |
| 75 | } |
| 76 | } else if !info.ModTime().Equal(fileModTime) { |
| 77 | return true |
| 78 | } |
| 79 | } |
| 80 | return false |
| 81 | } |
func @120:24
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/sentry_logger.go:
| 120 | func(scope *sentry.Scope) { |
| 121 | scope.SetTag("name", package_name) |
| 122 | scope.SetTag("version", package_version) |
| 123 | if server_ip != nil { |
| 124 | scope.SetTag("server_ip", server_ip.String()) |
| 125 | } |
| 126 | if server_id != "" { |
| 127 | scope.SetUser(sentry.User{ |
| 128 | ID: server_id, |
| 129 | }) |
| 130 | } |
| 131 | if os_release != "" { |
| 132 | scope.SetTag("os.version", os_release) |
| 133 | } |
| 134 | } |
func Database.Close
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 106 | func (db *Database) Close() error { |
| 107 | db.lock.Lock() |
| 108 | defer db.lock.Unlock() |
| 109 | |
| 110 | if atomic.LoadInt64(&db.closed) == 0 { |
| 111 | atomic.SwapInt64(&db.closed, 1) |
| 112 | db.stopExpireOld <- true |
| 113 | db.waitExpireOld.Wait() |
| 114 | return db.db.Close() |
| 115 | } |
| 116 | return nil |
| 117 | } |
func shouldLogError
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 59 | func shouldLogError(err error) bool { |
| 60 | if err == nil { |
| 61 | return false |
| 62 | } |
| 63 | |
| 64 | if err == io.EOF { |
| 65 | return false |
| 66 | } |
| 67 | |
| 68 | str := err.Error() |
| 69 | if strings.Contains(str, "use of closed network connection") { |
| 70 | return false |
| 71 | } |
| 72 | |
| 73 | return true |
| 74 | } |
func rbl.Check
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/rbl.go:
| 168 | func (r rbl) Check(ip string) (bool, error) { |
| 169 | if r.cache == nil { |
| 170 | return CheckRBL(r.resolverAddr, r.rblServers, ip, r.requestTimeout) |
| 171 | } |
| 172 | v, err := r.cache.Get(ip) |
| 173 | value, ok := v.(bool) |
| 174 | if !ok { |
| 175 | return false, err |
| 176 | } |
| 177 | return value, err |
| 178 | } |
func Process.Serve
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 266 | func (p *Process) Serve(network, address string, connCallback func(c net.Conn)) error { |
| 267 | l, err := net.Listen(network, address) |
| 268 | if err != nil { |
| 269 | return err |
| 270 | } |
| 271 | |
| 272 | p.acceptList[l] = struct{}{} |
| 273 | p.acceptRoutineWait.Add(1) |
| 274 | go p.ServeListener(l, connCallback) |
| 275 | return nil |
| 276 | } |
func ToIP
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 359 | func ToIP(host string) string { |
| 360 | if host == "" || net.ParseIP(host) != nil { |
| 361 | return host |
| 362 | } |
| 363 | |
| 364 | ips, err := net.LookupIP(host) |
| 365 | if err != nil || len(ips) == 0 { |
| 366 | return "" |
| 367 | } |
| 368 | |
| 369 | return ips[0].String() |
| 370 | } |
func DatabaseDrop
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 59 | func DatabaseDrop(cfg *Config) error { |
| 60 | path := filepath.Join(cfg.Database, "/leveldb") |
| 61 | |
| 62 | err := os.RemoveAll(path) |
| 63 | if err != nil { |
| 64 | return fmt.Errorf("rm -rf %s: %v", path, err) |
| 65 | } |
| 66 | |
| 67 | return nil |
| 68 | } |
func SendMessageAPI.send
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api.go:
| 57 | func (ca *SendMessageAPI) send(requestBody MarshalJSON) error { |
| 58 | b, err := requestBody.MarshalJSON() |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | |
| 63 | _, err = ca.cb.Execute(func() (interface{}, error) { |
| 64 | res, err := ca.client.Post(ca.baseURL+sendMessageURL, sendMessageContentTypeJSON, bytes.NewReader(b)) |
| 65 | if err != nil { |
| 66 | return nil, err |
| 67 | } |
| 68 | defer res.Body.Close() |
| 69 | |
| 70 | body, err := ioutil.ReadAll(res.Body) |
| 71 | if err != nil { |
| 72 | return nil, err |
| 73 | } |
| 74 | |
| 75 | if res.StatusCode != http.StatusOK { |
| 76 | return body, fmt.Errorf("error response: %d, %s", res.StatusCode, string(body)) |
| 77 | } |
| 78 | |
| 79 | return body, nil |
| 80 | }) |
| 81 | |
| 82 | return err |
| 83 | } |
func NewRBL
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/rbl.go:
| 180 | func NewRBL(config RBLConfig) RBL { |
| 181 | r := &rbl{ |
| 182 | resolverAddr: config.ResolverAddr, |
| 183 | rblServers: config.RBLServers, |
| 184 | requestTimeout: config.RequestTimeout, |
| 185 | } |
| 186 | if config.CacheSize <= 0 || config.CacheTimeout <= 0 { |
| 187 | return r |
| 188 | } |
| 189 | r.cache = gcache.New(config.CacheSize). |
| 190 | Expiration(config.CacheTimeout).ARC(). |
| 191 | LoaderFunc(func(key interface{}) (interface{}, error) { |
| 192 | s, ok := key.(string) |
| 193 | if !ok { |
| 194 | return nil, fmt.Errorf("LRU Cache: Bad key value type") |
| 195 | } |
| 196 | value, err := CheckRBL(r.resolverAddr, r.rblServers, s, r.requestTimeout) |
| 197 | if value || err == nil { |
| 198 | return value, nil |
| 199 | } |
| 200 | noSuchHost := strings.HasSuffix(err.Error(), "no such host") |
| 201 | if _, ok := err.(*net.DNSError); !ok || err.(*net.DNSError).IsTimeout || !noSuchHost { |
| 202 | return nil, err |
| 203 | } |
| 204 | return value, nil |
| 205 | }). |
| 206 | Build() |
| 207 | return r |
| 208 | } |
func SendMessageAPI.SendStats
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api.go:
| 86 | func (ca *SendMessageAPI) SendStats(license *License, messages []StatRecord) error { |
| 87 | if license == nil { |
| 88 | return errInvalidLicense |
| 89 | } |
| 90 | |
| 91 | r := SendMessagesApiRequest{ |
| 92 | AgentVersion: ca.agentVersion, |
| 93 | ServerID: license.ID, |
| 94 | Method: sendMessageMethod, |
| 95 | License: *license, |
| 96 | Payload: messages, |
| 97 | ProtocolVersion: sendMessageProtocolVersion, |
| 98 | } |
| 99 | |
| 100 | return ca.send(r) |
| 101 | } |
func @138:18
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 138 | func(l License, valid bool) { |
| 139 | var lic *License |
| 140 | if valid { |
| 141 | lic = &l |
| 142 | } |
| 143 | atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&p.license)), unsafe.Pointer(lic)) |
| 144 | } |
func packageVersion
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/pkg_version.go:
| 27 | func packageVersion(name string) (string, error) { |
| 28 | v, err := getRPMVersion(name) |
| 29 | if err != nil { |
| 30 | v, err = getDEBVersion(name) |
| 31 | } |
| 32 | return v, err |
| 33 | } |
func collectOutput
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/pkg_version.go:
| 7 | func collectOutput(name string, args ...string) (string, error) { |
| 8 | out, err := exec.Command(name, args...).Output() |
| 9 | if err != nil { |
| 10 | return "", err |
| 11 | } |
| 12 | return string(out), nil |
| 13 | } |
func Request.MarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 234 | func (v Request) MarshalJSON() ([]byte, error) { |
| 235 | w := jwriter.Writer{} |
| 236 | easyjson3c9d2b01Encode11(&w, v) |
| 237 | return w.Buffer.BuildBytes(), w.Error |
| 238 | } |
func Request.UnmarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 246 | func (v *Request) UnmarshalJSON(data []byte) error { |
| 247 | r := jlexer.Lexer{Data: data} |
| 248 | easyjson3c9d2b01Decode11(&r, v) |
| 249 | return r.Error() |
| 250 | } |
func StatRecord.MarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 113 | func (v StatRecord) MarshalJSON() ([]byte, error) { |
| 114 | w := jwriter.Writer{} |
| 115 | easyjsonD587a15Encode1(&w, v) |
| 116 | return w.Buffer.BuildBytes(), w.Error |
| 117 | } |
func Response.UnmarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 89 | func (v *Response) UnmarshalJSON(data []byte) error { |
| 90 | r := jlexer.Lexer{Data: data} |
| 91 | easyjson3c9d2b01Decode1(&r, v) |
| 92 | return r.Error() |
| 93 | } |
func License.MarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license_proto_easyjson.go:
| 159 | func (v License) MarshalJSON() ([]byte, error) { |
| 160 | w := jwriter.Writer{} |
| 161 | easyjson2c6259e0Encode1(&w, v) |
| 162 | return w.Buffer.BuildBytes(), w.Error |
| 163 | } |
func SendMessagesApiRequest.MarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 244 | func (v SendMessagesApiRequest) MarshalJSON() ([]byte, error) { |
| 245 | w := jwriter.Writer{} |
| 246 | easyjsonD587a15Encode11(&w, v) |
| 247 | return w.Buffer.BuildBytes(), w.Error |
| 248 | } |
func SendMessagesApiRequest.UnmarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 256 | func (v *SendMessagesApiRequest) UnmarshalJSON(data []byte) error { |
| 257 | r := jlexer.Lexer{Data: data} |
| 258 | easyjsonD587a15Decode11(&r, v) |
| 259 | return r.Error() |
| 260 | } |
func StatRecord.UnmarshalJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 125 | func (v *StatRecord) UnmarshalJSON(data []byte) error { |
| 126 | r := jlexer.Lexer{Data: data} |
| 127 | easyjsonD587a15Decode1(&r, v) |
| 128 | return r.Error() |
| 129 | } |
func @78:19
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/rbl.go:
| 78 | func(ctx context.Context, network, address string) (net.Conn, error) { |
| 79 | d := net.Dialer{} |
| 80 | return d.DialContext(ctx, "udp", nameserver) |
| 81 | } |
func errlog.Fatalf
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/errlog.go:
| 30 | func (*errlog) Fatalf(format string, args ...interface{}) { |
| 31 | log.Fatalf(format, args...) |
| 32 | sentrySend(format, args...) |
| 33 | } |
func Database.WithUserWhitelist
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 70 | func (db *Database) WithUserWhitelist(wl *UserWhiteList) *Database { |
| 71 | db.usersWhitelist = wl |
| 72 | return db |
| 73 | } |
func Database.WithUserIPWhitelist
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/database.go:
| 75 | func (db *Database) WithUserIPWhitelist(wl *UserIPWhiteList) *Database { |
| 76 | db.userIPWhitelist = wl |
| 77 | return db |
| 78 | } |
func SentryLogger.Write
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/sentry_logger.go:
| 139 | func (s *SentryLogger) Write(data []byte) (n int, err error) { |
| 140 | sentry.CaptureMessage(string(data)) |
| 141 | return len(data), nil |
| 142 | } |
func LicenseWatcher.Stop
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 188 | func (lw *LicenseWatcher) Stop() { |
| 189 | close(lw.done) |
| 190 | lw.wg.Wait() |
| 191 | } |
func LicenseWatcher.Start
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 103 | func (lw *LicenseWatcher) Start() { |
| 104 | lw.wg.Add(1) |
| 105 | go func() { |
| 106 | lw.watcher() |
| 107 | }() |
| 108 | } |
func NewSendMessageAPI
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api.go:
| 35 | func NewSendMessageAPI(apiURL string, agentVersion string, timeout time.Duration) *SendMessageAPI { |
| 36 | return &SendMessageAPI{ |
| 37 | agentVersion: agentVersion, |
| 38 | client: &http.Client{Timeout: timeout}, |
| 39 | baseURL: apiURL, |
| 40 | cb: gobreaker.NewCircuitBreaker(gobreaker.Settings{ |
| 41 | Name: "SendMessageAPIBreaker", |
| 42 | Interval: timeout * 5, |
| 43 | Timeout: timeout * 2, |
| 44 | ReadyToTrip: func(counts gobreaker.Counts) bool { |
| 45 | return counts.ConsecutiveFailures >= 3 |
| 46 | }, |
| 47 | }), |
| 48 | } |
| 49 | } |
func Request.UnmarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 253 | func (v *Request) UnmarshalEasyJSON(l *jlexer.Lexer) { |
| 254 | easyjson3c9d2b01Decode11(l, v) |
| 255 | } |
func Request.MarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 241 | func (v Request) MarshalEasyJSON(w *jwriter.Writer) { |
| 242 | easyjson3c9d2b01Encode11(w, v) |
| 243 | } |
func getRPMVersion
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/pkg_version.go:
| 21 | func getRPMVersion(name string) (string, error) { |
| 22 | return collectOutput("rpm", "-q", "--queryformat=%{VERSION}-%{RELEASE}", name) |
| 23 | } |
func @44:17
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api.go:
| 44 | func(counts gobreaker.Counts) bool { |
| 45 | return counts.ConsecutiveFailures >= 3 |
| 46 | } |
func SentryLogger.Flush
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/sentry_logger.go:
| 144 | func (s *SentryLogger) Flush() { |
| 145 | sentry.Flush(time.Second * 5) |
| 146 | } |
func Config.IsVerboseLoggingMode
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 48 | func (cfg *Config) IsVerboseLoggingMode() bool { |
| 49 | return cfg.IsLogfileEnabled() |
| 50 | } |
func Config.IsSentryEnabled
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 44 | func (cfg *Config) IsSentryEnabled() bool { |
| 45 | return cfg.Sentry != "" && cfg.Sentry != "off" |
| 46 | } |
func Response.UnmarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 96 | func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer) { |
| 97 | easyjson3c9d2b01Decode1(l, v) |
| 98 | } |
func Config.IsLogfileEnabled
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 40 | func (cfg *Config) IsLogfileEnabled() bool { |
| 41 | return cfg.LogFilename != "" |
| 42 | } |
func SendMessagesApiRequest.UnmarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 263 | func (v *SendMessagesApiRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { |
| 264 | easyjsonD587a15Decode11(l, v) |
| 265 | } |
func @105:5
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go:
| 105 | func() { |
| 106 | lw.watcher() |
| 107 | } |
func SendMessagesApiRequest.MarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 251 | func (v SendMessagesApiRequest) MarshalEasyJSON(w *jwriter.Writer) { |
| 252 | easyjsonD587a15Encode11(w, v) |
| 253 | } |
func Response.MarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/request_easyjson.go:
| 84 | func (v Response) MarshalEasyJSON(w *jwriter.Writer) { |
| 85 | easyjson3c9d2b01Encode1(w, v) |
| 86 | } |
func StatRecord.UnmarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 132 | func (v *StatRecord) UnmarshalEasyJSON(l *jlexer.Lexer) { |
| 133 | easyjsonD587a15Decode1(l, v) |
| 134 | } |
func getDEBVersion
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/pkg_version.go:
| 16 | func getDEBVersion(name string) (string, error) { |
| 17 | return collectOutput("dpkg-query", "--showformat=${Version}", "--show", name) |
| 18 | } |
func StatRecord.MarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/api_proto_easyjson.go:
| 120 | func (v StatRecord) MarshalEasyJSON(w *jwriter.Writer) { |
| 121 | easyjsonD587a15Encode1(w, v) |
| 122 | } |
func errlog.Configure
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/errlog.go:
| 16 | func (*errlog) Configure(isSentryEnabled bool) { |
| 17 | Errlog.isSentryEnabled = isSentryEnabled |
| 18 | } |
func License.MarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license_proto_easyjson.go:
| 166 | func (v License) MarshalEasyJSON(w *jwriter.Writer) { |
| 167 | easyjson2c6259e0Encode1(w, v) |
| 168 | } |
func License.UnmarshalEasyJSON
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license_proto_easyjson.go:
| 178 | func (v *License) UnmarshalEasyJSON(l *jlexer.Lexer) { |
| 179 | easyjson2c6259e0Decode1(l, v) |
| 180 | } |
func Process.RequestId
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/main.go:
| 313 | func (p *Process) RequestId() uint { |
| 314 | return uint(atomic.AddUint32(&p.requestId, 1)) |
| 315 | } |
func loadLockConfig
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/config.go:
| 167 | func loadLockConfig(s *ini.Section, defaultWhitelist string) LockConfig { |
| 168 | return LockConfig{ |
| 169 | Timeout: rangeInt64(s.Key("timeout"), 300, 0, 9999999), |
| 170 | Attempts: rangeInt(s.Key("attempts"), 10, 0, 100), |
| 171 | Period: rangeInt64(s.Key("period"), 300, 0, 9999999), |
| 172 | WhitelistFileName: s.Key("whitelist").MustString(defaultWhitelist), |
| 173 | } |
| 174 | } |
func @128:32
BackIn /builddir/build/BUILD/imunify360-pam-5.3.0/src/agent/license.go: