Class ::nsmcp::SystemLogPeers (public)
::nx::Class ::nsmcp::SystemLogPeers
Defined in /usr/local/ns/tcl/nsmcp/log-summary.tcl
- Testcases:
- No testcase defined.
Source code: :public object method add {statsVar message includeAddresses {timestamp {}} {offset 0}} { # # Count one selected physical record before grouping and sampling. # # @param statsVar Caller-owned bounded peer accumulator. # @param message Original logical record before redaction. # @param includeAddresses Whether the caller requested authorized addresses. # @param timestamp Parsed warning time for optional context sampling. # @param offset Original warning byte offset. # upvar 1 $statsVar stats dict incr stats recordCount set peer {} if {[regexp {from peer ([^ \t\r\n]+)} $message -> value]} { if {![ns_ip valid $value]} {set value [string trimright $value :]} if {[ns_ip valid $value]} {set peer $value} } if {$peer eq {}} {dict incr stats unknownPeerRecords; return} set key [expr {$includeAddresses ? $peer : [ns_crypto::md string -digest sha256 -- $peer]}] if {![dict exists $stats counts $key] && [dict size [dict get $stats counts]]>=65536} { dict incr stats capacityOmittedRecords return } dict incr stats knownPeerRecords set count 0 if {[dict exists $stats counts $key]} {set count [dict get $stats counts $key]} dict set stats counts $key [expr {$count+1}] if {$includeAddresses && $timestamp ne {}} { set kind other if {[string match {*received TLS handshake on a non-TLS connection*} $message]} { set kind tls-on-http } elseif {[string match {*received HTTP/2 connection preface on an HTTP/1 connection*} $message]} { set kind http2-preface } set sample [dict create timestamp $timestamp offset $offset peerKey [ns_crypto::md string -digest sha256 -- $peer] kind $kind] set retained {} if {[dict exists $stats samples $peer]} {set retained [dict get $stats samples $peer]} if {![llength $retained]} { set retained [list $sample] } elseif {[llength $retained]==1} { lappend retained $sample } else { lset retained 1 $sample } dict set stats samples $peer $retained } } :public object method candidates {stats} { # # Select bounded exact-peer samples from the full warning ranking. # # @param stats Full-window authorized peer accumulator. # @return Up to five ranked peers, each with at most two warning samples. # set rows {} dict for {peer count} [dict get $stats counts] {lappend rows [list $peer $count]} set rows [lsort -integer -decreasing -index 1 [lsort -index 0 $rows]] set result {} foreach row [lrange $rows 0 4] { set peer [lindex $row 0] if {[dict exists $stats samples $peer]} { lappend result [dict create peer $peer count [lindex $row 1] samples [dict get $stats samples $peer]] } } return $result } :public object method assessmentFields {candidate sequences available {scope nearby-warning-window}} { # # Classify observed behavior using bounded same-peer access context. # # @param candidate One exact peer and its warning samples. # @param sequences Nearby access records in sample order. # @param available Whether the access correlation completed. # @return Typed JSON fields with behavior, confidence and evidence limits. # set samples [dict get $candidate samples] set kinds [lsort -unique [lmap sample $samples {dict get $sample kind}]] set statuses {}; set paths {}; set agents {}; set sensitivePaths {}; set sensitiveRecords 0 set records 0; set misses 0; set clipped 0 foreach sequence $sequences { if {[dict get $sequence returnedRecords]==0} {incr misses} if {[dict get $sequence recordsTruncated]} {incr clipped} foreach row [dict get $sequence records] { incr records lappend statuses [dict get $row status] if {[dict get $row path] ne {}} { set path [dict get $row path] lappend paths $path set lower [string tolower [lindex [split $path ?] 0]] if {[regexp {(^|/)\.env($|[./_-])|(^|/)\.aws/credentials($|/)|(^|/)\.git/config($|/)|(^|/)phpinfo\.php$} $lower]} { lappend sensitivePaths $path incr sensitiveRecords } } if {[dict get $row userAgent] ne {}} {lappend agents [dict get $row userAgent]} } } set kindFields {} set kindIndex 0 foreach kind $kinds {lappend kindFields $kindIndex string $kind; incr kindIndex} set successful 0; set unavailable 0 foreach status $statuses { if {$status>=200 && $status<400} {incr successful} if {$status==503} {incr unavailable} } set distinctPaths [llength [lsort -unique $paths]] set distinctSensitivePaths [llength [lsort -unique $sensitivePaths]] set distinctAgents [llength [lsort -unique $agents]] set behavior undetermined; set confidence insufficient if {$available && $distinctSensitivePaths>=2} { set behavior sensitive-file-probing; set confidence moderate } elseif {$available && [llength $kinds]>=2 && "tls-on-http" in $kinds && "http2-preface" in $kinds} { set behavior protocol-probing; set confidence moderate } elseif {$available && (($distinctPaths>=3 && $records>=4 && $distinctAgents>=2) || ($distinctPaths>=5 && $records>=6))} { set behavior multi-path-activity; set confidence moderate } set pathFields {} set pathIndex 0 foreach path [lrange [lsort -unique $paths] 0 7] { lappend pathFields $pathIndex string $path incr pathIndex } set sensitiveFields {} set sensitiveIndex 0 foreach path [lrange [lsort -unique $sensitivePaths] 0 7] { lappend sensitiveFields $sensitiveIndex string $path incr sensitiveIndex } return [list peer string [dict get $candidate peer] behavior string $behavior confidence string $confidence evidenceScope string $scope warningRecords number [dict get $candidate count] sampledWarnings number [llength $samples] omittedWarnings number [expr {[dict get $candidate count]-[llength $samples]}] warningKinds array $kindFields nearbyRecords number $records nearbySuccessfulResponses number $successful nearby503Responses number $unavailable nearbyDistinctPaths number $distinctPaths nearbyPathExamples array $pathFields sensitiveFileRequestRecords number $sensitiveRecords distinctSensitiveFilePaths number $distinctSensitivePaths sensitiveFilePathExamples array $sensitiveFields nearbyDistinctUserAgentClaims number $distinctAgents missingContextSamples number $misses truncatedContextSamples number $clipped assessmentAvailable boolean $available limitations string {Behavior is a heuristic candidate from at most two warning times and bounded committed access records, not a client or operator identity. Sensitive-file probing describes requests for conventional secret or diagnostic paths; it does not establish access to such files or hostile intent by one identified client. Same peer does not establish one TCP connection. User-Agent values are claims. Query strings are not retained; activity outside the bounded history is invisible. Missing access data or truncated context reduces confidence.}] } :public object method fields {stats limit includeAddresses scanComplete} { # Serialize all-window source counts and bounded authorized rankings. # @return Typed JSON fields with explicit unknown and omission counts. set rows {} dict for {peer count} [dict get $stats counts] {lappend rows [list $peer $count]} set rows [lsort -integer -decreasing -index 1 [lsort -index 0 $rows]] set peers {}; set index 0; set displayed 0 if {$includeAddresses} { foreach row [lrange $rows 0 [expr {$limit-1}]] { lassign $row peer count lappend peers $index object [list peer string $peer count number $count] incr index incr displayed $count } } set concentration {} foreach n {1 10 100} { set total 0 foreach row [lrange $rows 0 [expr {$n-1}]] {incr total [lindex $row 1]} lappend concentration top${n}Records number $total } set omitted [dict get $stats capacityOmittedRecords] return [list recordCount number [dict get $stats recordCount] knownPeerRecords number [dict get $stats knownPeerRecords] unknownPeerRecords number [dict get $stats unknownPeerRecords] observedDistinctPeers number [llength $rows] capacity number 65536 capacityOmittedRecords number $omitted aggregationComplete boolean [expr {$scanComplete && $omitted==0}] addressesIncluded boolean $includeAddresses peers array $peers rankedOmittedPeers number [expr {$includeAddresses ? [llength $rows]-$index : 0}] rankedOmittedRecords number [expr {$includeAddresses ? [dict get $stats knownPeerRecords]-$displayed : 0}] concentration object $concentration limitations string {Counts cover selected physical log records before grouping/sampling limits. Missing or invalid logged peers are unknown. Address rankings require diagnostics.logs.peers.read. Cardinality overflow makes distinct counts and concentration lower bounds. Ranking omissions remain counted. Coverage and clipped-record limits of the enclosing summary apply; logged peers do not identify people or organizations.}] }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)