Documentation
¶
Overview ¶
Package importer converts the files other security tools export into CTIS 1.4 reports: Nessus v2 XML, Qualys host detection XML (joined with the Qualys KnowledgeBase), CycloneDX and SPDX SBOMs, OSV records, CSAF 2.0 and OpenVEX documents, DefectDojo Generic Findings JSON, SARIF 2.1.0, and the native JSON of trivy, nuclei, semgrep, betterleaks and vuls, nmap XML, testssl.sh JSON, ffuf JSON, S3Scanner JSON lines, arjun JSON, line lists (FormatLines) and CTIS reports (FormatCTIS, passed through without the receiver profile's extensions). It is the one conversion entry point: a receiver's upload and CI endpoints and a sensor's parser tool all call Parse.
A code report (SARIF, semgrep, betterleaks, a trivy file-system scan) is filed on Options.Repository when it is set; a receiver that knows the repository from a verified identity sets it, so a file can never move its findings onto another asset.
Detect names the format of a file from its first bytes; Parse converts it. A Result carries the CTIS report, the VEX statements of a VEX document (which describe products, not findings, and so are not findings of the report), counts, problems with their line numbers, and the source fields the file held that the format's mapping spec does not know.
Bundles ¶
Some tools write a directory of files that only make sense together. A bundle is read with ParseBundle (not Parse): the caller lists the files (OpenBundleZip for an archive, NewArchiveFile for any other source) and the layout, not a file name, decides the format. FormatReconFTW reads a reconFTW results directory, v3 and v4 layouts: subdomains, addresses, httpx results, URLs, takeover, bucket and WAF candidates, and the nuclei result files (through the nuclei importer). BundleLimits bound the files listed and read, bytes, line length and path depth. Files that hold people data or credentials are never opened; files the spec does not know are listed in Result.Unmapped and the ones skipped on purpose in Result.Skipped.
Mapping discipline ¶
Every format has a mapping spec (Specs): one row per source field, saying which CTIS member holds it, or why it is deliberately not kept. The package tests walk every fixture and fail when a fixture holds a field the spec does not list, so an importer can never drop a field silently. The spec tables are rendered to docs/importers/, with the coverage of each format, and a test keeps the documents in step with the code.
The native value always travels next to the normalized one: the source's severity, status, ids and scores go to finding.native and finding.scores, and fields without a CTIS member go to finding.source_extra (bounded).
Hostile input ¶
Every file is treated as hostile. The limits (Limits) bound the input size, nesting depth, element and attribute counts, text sizes and the number of findings, assets and statements. XML is read with document type declarations limited to an external identifier (an internal subset, and so any entity declaration, is refused, and no external resource is ever read), only the predefined entities, and only UTF-8, US-ASCII or ISO-8859-1 input. JSON must be valid UTF-8 and is depth-checked before it is decoded. Archives (OpenZip) refuse path traversal, absolute paths, links, nested archives and decompression bombs.
Credentials and scan operator details are never copied into a report: the Nessus and Qualys mapping specs list the policy, preference and user fields as ignored, and the parsers skip them.
Index ¶
- Constants
- Variables
- func AdapterModule(f Format) (string, bool)
- func IsLocalFamily(family string) bool
- func IsZip(head []byte) bool
- func LinesAsValues() []string
- func Register(f Format, a Adapter)
- func Registered(f Format) bool
- func SafeXMLTokenReader(r io.Reader, lim Limits) xml.TokenReader
- type Adapter
- type ArchiveFile
- type ArchiveLimits
- type Builder
- func (b *Builder) Asset(a ctis.Asset) (string, error)
- func (b *Builder) AssetByID(id string) *ctis.Asset
- func (b *Builder) CodeAsset(fromFile *ctis.Asset) ctis.Asset
- func (b *Builder) Dependency(d ctis.Dependency) error
- func (b *Builder) Finding(f ctis.Finding) error
- func (b *Builder) FoldPaths(fold func(string) string)
- func (b *Builder) Format() Format
- func (b *Builder) Issue(is Issue)
- func (b *Builder) Limits() Limits
- func (b *Builder) Options() Options
- func (b *Builder) ReadAll(r io.Reader) ([]byte, error)
- func (b *Builder) Result() *Result
- func (b *Builder) ScanJSON(data []byte, index ...string) (*JSONDoc, error)
- func (b *Builder) Statement(s VEXStatement) error
- func (b *Builder) Tick() error
- func (b *Builder) TooMany(what string, limit int) error
- type BundleLimits
- type Coverage
- type Field
- type Format
- type HostCoverage
- type ImportCoverage
- type Issue
- type JSONDoc
- type Limits
- type Options
- type ParseError
- type Product
- type Result
- type SkippedPath
- type Spec
- type Stats
- type VEXStatement
Constants ¶
const ( // The file holds no plugin selection (no Policy element, as in some // exports): which checks ran is unknown. CoverageNoPolicy = "no_policy" // The plugin results carry no plugin details. CoverageNoPluginDetails = "no_plugin_details" // The file holds no host. CoverageNoHosts = "no_hosts" )
Coverage reason codes.
const ( LinesAsAuto = "auto" LinesAsHost = "host" LinesAsDomain = "domain" LinesAsIP = "ip" LinesAsURL = "url" )
What each line of a line list names (Options.LinesAs).
const ( ComplianceOutcomeKey = "compliance_outcome" ComplianceOutcomeError = "error" ComplianceOutcomeSkipped = "skipped" )
The outcomes of a compliance result that was not evaluated, in extensions["io.openctem"].compliance_outcome.
const Container = "(container)"
Container is the Target of a field that only groups other fields.
const NessusNoDetailsMessage = "export lacks plugin details; re-export with full plugin attributes"
NessusNoDetailsMessage is the issue of a file whose plugin results carry no plugin details (an export without plugin attributes): no CVE, score or description can be imported from it.
const SniffLen = 64 << 10
SniffLen is how many leading bytes Detect needs at most.
Variables ¶
var ( // ErrUnknownFormat: Detect does not recognize the input, or the format // named is not one this package reads. ErrUnknownFormat = errors.New("unknown import format") // ErrTooLarge: the input or one of its parts is over a limit. ErrTooLarge = errors.New("import input over a limit") // ErrUnsafe: the input uses a construct this package never reads (an // XML internal subset or entity declaration, an unsupported charset, // a link or traversal in an archive). ErrUnsafe = errors.New("import input uses a refused construct") // ErrMalformed: the input is not well-formed for its format. ErrMalformed = errors.New("malformed import input") )
Errors a caller can test with errors.Is.
Functions ¶
func AdapterModule ¶
AdapterModule returns the Go module whose adapter reads format, and false for a format this package reads itself.
func IsLocalFamily ¶ added in v2.0.2
IsLocalFamily reports whether a Nessus plugin family holds local (credentialed) checks: the "<OS> Local Security Checks" families and the families of checks that read the host from inside.
func LinesAsValues ¶ added in v2.0.2
func LinesAsValues() []string
LinesAsValues lists the values of Options.LinesAs.
func Register ¶
Register makes Parse read format f with a. Only the formats an adapter module reads (AdapterModule) can be registered, each once; anything else panics, because it is a programming error in the adapter.
func Registered ¶
Registered reports whether Parse can read f: a format of this package, or one whose adapter is linked into the program.
func SafeXMLTokenReader ¶
func SafeXMLTokenReader(r io.Reader, lim Limits) xml.TokenReader
SafeXMLTokenReader returns the hardened XML token reader this package parses with, for other readers of untrusted XML (the declarative mappings of importer/mapping). It is stricter than the format parsers: it refuses every document type declaration, so no DTD of any kind is accepted, and it knows only the five predefined entities. Depth, element count, attributes per element, text size and input size are bounded by lim (zero fields take DefaultLimits). Errors are *ParseError wrapping ErrTooLarge, ErrUnsafe or ErrMalformed. Comments and processing instructions are dropped.
Types ¶
type Adapter ¶
type Adapter struct {
// Parse converts one input. It reads the input through the Builder
// (ReadAll, ScanJSON) so the size, depth and UTF-8 limits apply, and
// adds what it converts through the Builder (Asset, Finding,
// Dependency, Statement), so the record limits, the minimum severity
// and the secret masking apply.
Parse func(b *Builder, r io.Reader) error
// Tool is the format's default tool (tool.name of the report).
Tool ctis.Tool
// Spec lists every source field the adapter knows (Result.Unmapped,
// docs/importers).
Spec Spec
}
Adapter is what an adapter registers for one format.
type ArchiveFile ¶
type ArchiveFile struct {
// The file's path inside the archive, cleaned. It is only a label: it is
// never used to create a file.
Name string
// Uncompressed size as the archive declares it (the reader enforces the
// limits on the real size).
DeclaredSize int64
// contains filtered or unexported fields
}
ArchiveFile is one file of an archive.
func NewArchiveFile ¶
func NewArchiveFile(name string, size int64, open func() (io.ReadCloser, error)) ArchiveFile
NewArchiveFile describes a file that is not read from a ZIP archive (a task directory on a sensor, a test fixture) so ParseBundle can read it like one. The name is checked by ParseBundle as an archive entry name is; open is called at most once per read and its reader is bounded by the bundle limits.
func OpenBundleZip ¶
func OpenBundleZip(r io.ReaderAt, size int64, lim BundleLimits) ([]ArchiveFile, error)
OpenBundleZip lists the files of a ZIP archive that holds a bundle, with the guards of OpenZip (traversal, absolute and backslash paths, links, encrypted and nested archives, bombs) at the bundle limits.
func OpenZip ¶
func OpenZip(r io.ReaderAt, size int64, lim ArchiveLimits) ([]ArchiveFile, error)
OpenZip lists the regular files of a ZIP archive. It refuses the whole archive when an entry has an absolute path, a ".." element, a backslash, a drive letter or a control character in its name, is a link or another non-regular file, is encrypted, or is itself an archive, and when there are more than MaxEntries files. Nothing is ever written to disk.
func (ArchiveFile) Open ¶
func (a ArchiveFile) Open() (io.ReadCloser, error)
Open returns the file's content. The reader fails with ErrTooLarge as soon as the file passes MaxEntryBytes, the archive passes MaxTotalBytes, or the file decompresses at more than MaxRatio.
type ArchiveLimits ¶
type ArchiveLimits struct {
// Most files in the archive (directories are not counted).
MaxEntries int
// Largest uncompressed file.
MaxEntryBytes int64
// Largest sum of the uncompressed files.
MaxTotalBytes int64
// Largest ratio of uncompressed to compressed size of one file, checked
// as the file is read, once it is past 1 MiB.
MaxRatio int64
}
ArchiveLimits bound what OpenZip accepts. Zero fields take the defaults of DefaultArchiveLimits.
func DefaultArchiveLimits ¶
func DefaultArchiveLimits() ArchiveLimits
DefaultArchiveLimits returns the limits a zero ArchiveLimits stands for.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
builder collects one Result within the limits.
func (*Builder) Asset ¶
Asset adds an asset (value made canonical, deduplicated by type and canonical value) and returns its id; "" with no error when the value has no canonical form (an issue says why).
func (*Builder) CodeAsset ¶
CodeAsset is the asset a code report is filed on: Options.Repository, else fromFile (what the file names), else Options.DefaultAsset, else an unclassified asset named after the tool.
func (*Builder) Dependency ¶
func (b *Builder) Dependency(d ctis.Dependency) error
Dependency adds a component of the scanned asset.
func (*Builder) Finding ¶
Finding adds a finding unless it is below Options.MinSeverity; a secret finding is masked (ctis.RedactSecretFinding).
func (*Builder) FoldPaths ¶
FoldPaths sets a function that folds each source path before it is recorded (a recursive structure listed once in the spec). Call it before ScanJSON.
func (*Builder) Issue ¶
Issue records a problem that does not stop the parse (at most Limits.MaxIssues are kept).
func (*Builder) ReadAll ¶
ReadAll reads the whole input within Limits.MaxInputBytes and drops a UTF-8 byte order mark.
func (*Builder) Result ¶
Result is the result being built: the report, the VEX statements and the counts. An adapter sets the report's tool and metadata and counts Stats.Records and Stats.Skipped; it adds records only through the Builder.
func (*Builder) ScanJSON ¶
ScanJSON checks a JSON input (UTF-8, syntax, depth, string length) in one streaming pass before anything is decoded, records the source field paths for Result.Unmapped, and the offsets of the elements of the arrays named in index ("/runs[]/results[]") for the line numbers of issues.
func (*Builder) Statement ¶
func (b *Builder) Statement(s VEXStatement) error
Statement adds a VEX statement.
type BundleLimits ¶
type BundleLimits struct {
// Most files listed in the archive.
MaxFilesListed int
// Most files whose content is read.
MaxFilesRead int
// Largest uncompressed file.
MaxFileBytes int64
// Largest sum of the files that are read.
MaxTotalBytes int64
// Longest line of a list file; a longer line is skipped.
MaxLineBytes int
// Most lines read from one file.
MaxLines int
// Deepest directory nesting of a file name.
MaxPathDepth int
// Largest ratio of uncompressed to compressed size of one file.
MaxRatio int64
}
BundleLimits bound what ParseBundle accepts. A zero field takes its default (DefaultBundleLimits). A recon directory is large, so these differ from the single-file defaults of ArchiveLimits.
func DefaultBundleLimits ¶
func DefaultBundleLimits() BundleLimits
DefaultBundleLimits returns the limits a zero BundleLimits stands for.
type Field ¶
Field is one row of a mapping spec.
Path is the field's path in the source: XML as "/Root/Child/@attr" (elements keyed by an attribute as "tag[name]"), JSON as "/member/array[]/ member". A "*" matches any run of characters inside one path segment; a "**" segment matches zero or more segments (a trailing "/**" matches everything below).
Exactly one of Target and Ignored is set: Target names the CTIS member or members the value goes to; Ignored says why the value is deliberately not kept. A container element whose children are listed has Target "(container)".
type Format ¶
type Format string
Format names a file format this package reads.
const ( // Nessus v2 XML (.nessus), written by Nessus and Tenable.sc. FormatNessus Format = "nessus" // Qualys VM host list detection XML (HOST_LIST_VM_DETECTION_OUTPUT). FormatQualys Format = "qualys" // Qualys KnowledgeBase XML (KNOWLEDGE_BASE_VULN_LIST_OUTPUT). Read only // as the companion of a detection file (Options.QualysKnowledgeBase). FormatQualysKB Format = "qualys_kb" // CycloneDX 1.4 to 1.6 JSON: an SBOM, a VDR or a VEX. FormatCycloneDX Format = "cyclonedx" // SPDX 2.2 / 2.3 JSON. FormatSPDX Format = "spdx" // osv-scanner JSON results (packages with their OSV records). FormatOSV Format = "osv" // CSAF 2.0 JSON (the VEX profile and the security advisory profile). FormatCSAF Format = "csaf" // OpenVEX JSON. FormatOpenVEX Format = "openvex" // DefectDojo Generic Findings Import JSON. FormatDefectDojo Format = "defectdojo" // SARIF 2.1.0 (any static analysis tool that writes SARIF). FormatSARIF Format = "sarif" // trivy JSON (image, file-system, repository and config scans). FormatTrivy Format = "trivy" // nuclei JSON lines (-jsonl) or a JSON array (-json-export). FormatNuclei Format = "nuclei" // semgrep JSON (--json). FormatSemgrep Format = "semgrep" // opengrep JSON (--json): the semgrep JSON shape; Detect names that // shape semgrep, so choose opengrep with Options.Format. FormatOpengrep Format = "opengrep" // betterleaks JSON report (the gitleaks-compatible array). FormatBetterleaks Format = "betterleaks" // vuls JSON scan result (one server). FormatVuls Format = "vuls" // gitleaks JSON report (an array of leaks). Every gitleaks-compatible // scanner writes the same shape; Options.ToolName names the tool. FormatGitleaks Format = "gitleaks" // grype JSON output. FormatGrype Format = "grype" // ZAP traditional JSON or XML report. FormatZAP Format = "zap" // Generic bug-bounty / disclosure reports: {"bounty_reports": [...]} as // JSON, or one report per CSV row. Detect names the JSON shape only; CSV // is read when Options.Format forces this format. FormatBountyReport Format = "bounty_report" // nmap XML output (-oX), also written by masscan -oX and other // nmap-compatible scanners: hosts, addresses, names and open ports // with their services. No findings. FormatNmap Format = "nmap" // testssl.sh JSON (--jsonfile, flat, or --jsonfile-pretty): TLS and // HTTP header checks of each endpoint. FormatTestssl Format = "testssl" // A line list: one name, address, CIDR block or URL per line // (Options.LinesAs). Never detected: choose it with Options.Format. FormatLines Format = "lines" // A CTIS 2.0 report, read strictly and passed through. The receiver // profile's extensions (io.openctem) are removed: a document cannot // say it is in scope. FormatCTIS Format = "ctis" // ffuf JSON output (-of json): the URLs that answered, as endpoints. // No findings; the command line and configuration are never read. FormatFfuf Format = "ffuf" // S3Scanner JSON lines (-json): storage buckets and the permissions // they grant to everyone or to every authenticated user. FormatS3Scanner Format = "s3scanner" // arjun JSON output (-oJ): URLs and the parameter names found on them. // No findings; the request headers are never read. FormatArjun Format = "arjun" )
const ( // FormatReconFTW is a reconFTW results directory. It is read with // ParseBundle, never with Parse. FormatReconFTW Format = "reconftw" )
func Detect ¶
Detect names the format of an input from its leading bytes (at most SniffLen are read). It recognizes the formats of AllFormats and FormatQualysKB. It never errors on hostile input; it returns false.
func DetectBundle ¶
DetectBundle names the format of a bundle from the file names alone: it recognizes a reconFTW results directory by its layout. It never reads a file and never errors on hostile names.
type HostCoverage ¶ added in v2.0.2
type HostCoverage struct {
// The asset of the report the host is.
AssetRef string `json:"asset_ref"`
// When the host's scan ended (HOST_END), else when it started. Nil
// when the file gives neither: such a host proves nothing (Finished
// false).
ObservedAt *time.Time `json:"observed_at,omitempty"`
// Finished is true when the file records the end of the host's scan.
// An unfinished host (a stopped scan) proves nothing.
Finished bool `json:"finished"`
// Credentialed is true when the scan logged in to the host.
Credentialed bool `json:"credentialed"`
// LocalChecks is true when the local checks (credentialed patch and
// configuration checks) ran on the host: credentialed and no
// authentication failure or "local checks not available" result. When
// false, only network-level findings of the host may close.
LocalChecks bool `json:"local_checks"`
// The plugin id that showed the authentication failure or the missing
// local checks, when there was one.
AuthIssue string `json:"auth_issue,omitempty"`
}
HostCoverage is one scanned host of an import.
type ImportCoverage ¶ added in v2.0.2
type ImportCoverage struct {
// Complete is false when the file cannot prove an absence (Reasons
// says why): no plugin selection in the file, plugin results without
// plugin details. Hosts are still listed.
Complete bool `json:"complete"`
// Why the file proves nothing, or narrows what it proves: stable codes
// (CoverageNoPolicy, CoverageNoPluginDetails, CoverageNoHosts).
Reasons []string `json:"reasons,omitempty"`
// Plugin families the scan ran whole.
Families []string `json:"families,omitempty"`
// Plugins the scan ran outside those families (the policy's plugin
// set and the individually enabled plugins of a mixed family).
Plugins []string `json:"plugins,omitempty"`
// The hosts the file holds, in file order.
Hosts []HostCoverage `json:"hosts"`
}
ImportCoverage is what a scan export proves about the findings it does not hold: on which hosts, for which checks, an absent finding means the check ran and did not find it. A receiver that closes findings missing from an import closes only what Covers answers true for. A nil ImportCoverage, or one that is not Complete, proves nothing: nothing may close.
Only the Nessus importer fills it today.
func (*ImportCoverage) Covers ¶ added in v2.0.2
func (c *ImportCoverage) Covers(assetRef, pluginID, family string, local, compliance bool, observedLater *time.Time) bool
Covers reports whether a finding absent from the import may be closed: the file is complete, the host is in it and finished, the plugin ran (its family whole, or the plugin itself), and a local check is closed only on a host where local checks ran. Compliance results are never closed by absence (only a PASSED result of the same check resolves a FAILED one). observedLater is the receiver's last sighting of the finding: a finding seen after the host's scan is never closed by it.
func (*ImportCoverage) Host ¶ added in v2.0.2
func (c *ImportCoverage) Host(assetRef string) (HostCoverage, bool)
Host returns the coverage of the host whose asset is assetRef.
type Issue ¶
type Issue struct {
// 1-based line and column of the place in the input, when known.
Line int `json:"line,omitempty"`
Column int `json:"column,omitempty"`
// The record the problem is in: an XML element path or a JSON pointer.
Path string `json:"path,omitempty"`
Message string `json:"message"`
}
Issue is a problem at a place in the input.
type JSONDoc ¶
type JSONDoc struct {
// contains filtered or unexported fields
}
JSONDoc is a JSON input that passed Builder.ScanJSON.
type Limits ¶
type Limits struct {
// Largest input, in bytes.
MaxInputBytes int64
// Deepest nesting of XML elements or JSON objects and arrays.
MaxDepth int
// Most XML elements in one document.
MaxElements int
// Most attributes on one XML element.
MaxAttributes int
// Largest text of one XML element or one JSON string, in bytes. Longer
// values are refused, not truncated, so a file that needs them is seen
// as what it is.
MaxTextBytes int
// Most findings, assets, dependencies and VEX statements in one result.
MaxFindings int
MaxAssets int
MaxComponents int
MaxStatements int
// Most web endpoints in one result.
MaxEndpoints int
// Most distinct source field paths recorded for the coverage check.
MaxObservedPaths int
// Most problems reported in Result.Issues.
MaxIssues int
}
Limits bound what a parser accepts. A zero field takes its default (DefaultLimits). The defaults are sized for a real export of a large estate; a receiver that accepts uploads from people should pass smaller values.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits returns the limits a zero Limits stands for.
type Options ¶
type Options struct {
// Format of the input. Empty: Detect decides from the first bytes.
Format Format
// Limits on the input; zero fields take DefaultLimits.
Limits Limits
// metadata.generated_at of the report. Zero: the time of the parse
// (UTC).
Now time.Time
// metadata.id of the report: a lowercase UUIDv7 (ctis.NewReportID).
// Empty: a new one. Anything else fails the parse.
ReportID string
// metadata.channel of the report. Empty: ChannelManual (a file someone
// imports).
Channel ctis.Channel
// Key of the HMAC the secret fingerprint recipe needs
// (fingerprint.NewSecretDigest), at least 16 bytes. With a key, a secret
// finding the importer sees the raw secret of gets a recipe v2
// fingerprint over its digest. Without one the fingerprint is left empty
// and the receiver computes its own. The key and the secret never enter
// the report.
SecretKey []byte
// tool.name of the report. Empty: the format's tool (nessus, qualys,
// cyclonedx, ...).
ToolName string
// Findings below this severity are counted in Stats.Skipped and left
// out. Empty keeps every finding.
MinSeverity ctis.Severity
// The asset of records that name none (a DefectDojo finding without an
// endpoint). Nil: an unclassified asset named after the tool.
DefaultAsset *ctis.Asset
// The repository a code report (SARIF, semgrep, betterleaks, a trivy
// file-system scan) is filed on, with its branch and commit. It wins
// over what the file names (a SARIF versionControlProvenance, a trivy
// artifact). A receiver that knows the repository from a verified
// identity (a CI workload token) sets it from there and never from the
// file; the importer only records the file's claim.
Repository string
Branch string
CommitSHA string
// SourceRoot is the absolute directory the scanned tree was at when
// the tool ran (a sensor's checkout). A data flow step's absolute path
// under it is made relative to it; without it, an absolute step path is
// kept only when another path of the flow reveals the root.
SourceRoot string
// SARIF only. ToolType is the kind of tool that wrote the log: "sast",
// "sca", "secret", "iac" or "web3". It decides the type of every finding
// and the tool's techniques instead of the rule tags and the tool name
// (a scanner runtime that knows what it ran sets it). Other values are
// ignored. DefaultConfidence (1 to 100) is the confidence of a result
// whose rule states no precision; zero or out of range: 90.
ToolType string
DefaultConfidence int
// bounty_report only. The intake of records that carry none (the program
// or platform the reports came from). Lower-cased; 1 to 64 characters of
// a-z, 0-9, '.', '_' and '-', starting with a letter or digit. Empty:
// "import". An invalid value fails the parse.
BountyIntake string
// ParseBundle only. Limits of a multi-file bundle; zero fields take
// DefaultBundleLimits.
Bundle BundleLimits
// Domains the importing organization treats as its own. A host of a
// bundle or of a network format (nmap, testssl, lines, ctis) at or below
// one of them is marked import_scope=in_target, any other name
// outside_target, and an address unknown. Empty: a bundle uses the
// target domain it names; a network format marks every host unknown.
// The verdict is a hint: a receiver judges scope itself.
ScopeDomains []string
// FormatLines only: what each line names. One of LinesAsAuto (the
// default: a URL, an address, a CIDR block or a DNS name, by its form),
// LinesAsHost (a DNS name or an address), LinesAsDomain, LinesAsIP (an
// address or a CIDR block) or LinesAsURL.
LinesAs string
// NoPassthrough: the standard-format adapters leave out the members
// their mapping does not list. By default they keep them under
// extensions["org.ctis.interop.<format>"] (docs/interop.md).
NoPassthrough bool
// Observe lists the source field paths the input held in
// Result.Fields (a mapping editor shows them next to Result.Unmapped).
Observe bool
// The Qualys KnowledgeBase XML for a Qualys detection file. Optional:
// without it, detections keep their QID and results but have no title
// beyond the QID, CVEs or CVSS.
QualysKnowledgeBase io.Reader
}
Options configure Parse. The zero value detects the format and uses the default limits.
type ParseError ¶
ParseError is the error of an input that could not be read. Line and Column point into the input when known.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type Product ¶
type Product struct {
// Package URL.
PURL string `json:"purl,omitempty"`
// CPE 2.3 name.
CPE string `json:"cpe,omitempty"`
// Name and version as the document states them, when it gives no
// identifier.
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
// When set, the statement is about these components inside the
// product only (an OpenVEX subcomponent, a CSAF relationship's
// component), not about the product as a whole or about the components
// anywhere else. A receiver matches a finding on a subcomponent's PURL
// or CPE only when the finding's asset is the product.
Subcomponents []Product `json:"subcomponents,omitempty"`
}
Product is a product of a VEX statement.
type Result ¶
type Result struct {
// Format of the file.
Format Format `json:"format"`
// The CTIS report: assets, findings and dependencies. Never nil; a VEX
// document gives a report without findings.
Report *ctis.Report `json:"report"`
// The statements of a VEX document (CSAF VEX, OpenVEX, the analysis
// members of a CycloneDX VEX). A receiver applies them to its own
// findings that match a statement's vulnerability and product.
VEX []VEXStatement `json:"vex,omitempty"`
// Counts of what the file held and what was kept.
Stats Stats `json:"stats"`
// Problems that did not stop the import (an item without a required
// field, a value out of range), at most Limits.MaxIssues.
Issues []Issue `json:"issues,omitempty"`
// Source field paths the file held that the format's mapping spec does
// not list, sorted. Their values are not in the report; a receiver can
// show them so the spec is extended.
Unmapped []string `json:"unmapped,omitempty"`
// Source field paths the file held, sorted; only with Options.Observe.
Fields []string `json:"fields,omitempty"`
// Layout of a multi-file bundle ("v3", "v4" for reconftw); empty for a
// single file.
Layout string `json:"layout,omitempty"`
// What the file proves about the findings it does not hold (which
// hosts and checks ran); nil when the format declares nothing, and
// then nothing may be closed by absence. See ImportCoverage.
Coverage *ImportCoverage `json:"coverage,omitempty"`
// Files of a bundle that were deliberately not opened or not read, each
// with the reason (people and credential data, images, files over the
// read limit). Every other file the importer did not read is in
// Unmapped.
Skipped []SkippedPath `json:"skipped,omitempty"`
}
Result is what Parse returns for one file.
func Parse ¶
Parse reads one exported file and converts it to CTIS.
It returns a *ParseError (wrapping ErrUnknownFormat, ErrTooLarge, ErrUnsafe or ErrMalformed) when the input cannot be read at all. Problems with single records do not fail the parse; they are in Result.Issues and the record is skipped.
func ParseBundle ¶
ParseBundle joins the files of one tool run into one CTIS report. Only FormatReconFTW is a bundle format; opts.Format may name it or be empty.
It returns a *ParseError (wrapping ErrUnknownFormat, ErrTooLarge, ErrUnsafe or ErrMalformed) when the bundle cannot be read at all: an unsafe path, a decompression bomb, more files or bytes than the limits allow, or no recognizable layout. Problems with single lines or files do not fail the parse; they are in Result.Issues. Files that are not read are in Result.Skipped (on purpose) or Result.Unmapped (not known).
type SkippedPath ¶
SkippedPath is a file of a bundle that was not read on purpose.
type Spec ¶
type Spec struct {
Format Format
// Human name of the source format and the versions the spec was written
// against.
Title string
SourceVersion string
// Notes on normalization rules that are not per field (severity tables,
// status tables, asset identity, deduplication).
Rules []string
// The fields, in document order.
Fields []Field
// Origin is where the spec is kept and how its document is
// regenerated; empty for the importers of this package
// (importer/spec_<format>.go).
Origin string
}
Spec is the mapping spec of one format: every source field the importer knows, and what becomes of it.
func SpecFromMapping ¶
SpecFromMapping is the spec of an interoperability import mapping (v2/interop/<format>/<version>/import.json): its fields with their targets and reasons, its notes as rules.
func Specs ¶
func Specs() []Spec
Specs returns the mapping spec of every format Parse reads (plus the Qualys KnowledgeBase), sorted by format.
func (Spec) Coverage ¶
Coverage counts the spec's mapped and ignored fields (containers are not counted).
type Stats ¶
type Stats struct {
// Records of the source: Nessus ReportItems, Qualys detections, CycloneDX
// vulnerabilities, OSV affected packages, DefectDojo findings.
Records int `json:"records"`
Assets int `json:"assets"`
Findings int `json:"findings"`
Components int `json:"components"`
Statements int `json:"statements"`
Endpoints int `json:"endpoints,omitempty"`
// Records skipped (below the minimum severity, or unusable; the reason
// of an unusable record is in Issues).
Skipped int `json:"skipped"`
// Findings per CTIS severity.
BySeverity map[ctis.Severity]int `json:"by_severity,omitempty"`
}
Stats counts what an import read and produced.
type VEXStatement ¶
type VEXStatement struct {
// The vulnerability, under every id the document gives it.
VulnerabilityIDs []ctis.VulnerabilityID `json:"vulnerability_ids"`
// The products the statement is about. A receiver matches a finding
// on a shared PURL (version-less when the statement's PURL has no
// version) or CPE.
Products []Product `json:"products"`
// The statement.
VEX ctis.VEX `json:"vex"`
}
VEXStatement is one exploitability statement of a VEX document: the status of the products below for the vulnerability below.
Source Files
¶
- adapter.go
- archive.go
- arjun.go
- betterleaks.go
- bounty_report.go
- bundle.go
- codeasset.go
- coverage.go
- ctisdoc.go
- defectdojo.go
- doc.go
- ffuf.go
- format.go
- gitleaks.go
- grype.go
- guard.go
- jsonsafe.go
- kit.go
- leaks.go
- limits.go
- lines.go
- nessus.go
- nessus_compliance.go
- nessus_coverage.go
- nessus_inventory.go
- nmap.go
- nuclei.go
- opengrep.go
- osv.go
- parse.go
- qualys.go
- refs.go
- result.go
- s3scanner.go
- sbom_shared.go
- scope.go
- semgrep.go
- shared.go
- spec.go
- spec_arjun.go
- spec_betterleaks.go
- spec_bounty_report.go
- spec_ctis.go
- spec_defectdojo.go
- spec_ffuf.go
- spec_gitleaks.go
- spec_grype.go
- spec_lines.go
- spec_nessus.go
- spec_nmap.go
- spec_nuclei.go
- spec_opengrep.go
- spec_osv.go
- spec_qualys.go
- spec_qualys_kb.go
- spec_reconftw.go
- spec_s3scanner.go
- spec_semgrep.go
- spec_testssl.go
- spec_trivy.go
- spec_vuls.go
- spec_zap.go
- testssl.go
- trivy.go
- trivy_graph.go
- vuls.go
- xmlsafe.go
- zap.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mapping turns the JSON, JSON Lines, CSV or XML output of any tool into a CTIS report through a declarative mapping file, so a tool or an export needs no parser code.
|
Package mapping turns the JSON, JSON Lines, CSV or XML output of any tool into a CTIS report through a declarative mapping file, so a tool or an export needs no parser code. |