host

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DisplayFields = map[string]func(h *pb.Host) string{

	"ID": func(h *pb.Host) string {
		if h.Status != nil && h.Status.State == "up" {
			return color.HiGreenString(display.FormatSmallID(h.Id))
		}
		return display.FormatSmallID(h.Id)
	},
	"Hostnames": func(h *pb.Host) string {
		var hostnames []string
		for _, hn := range h.Hostnames {
			hostnames = append(hostnames, hn.Name)
		}
		return strings.Join(hostnames, "\n")
	},
	"OS Name": func(h *pb.Host) string {
		osName, _ := GetOperatingSystem(h)
		return osName
	},
	"OS Family": func(h *pb.Host) string {
		_, fam := GetOperatingSystem(h)
		return fam
	},
	"Addresses": func(h *pb.Host) string {
		var addresses []string
		for _, hn := range h.Addresses {
			addresses = append(addresses, hn.Addr)
		}
		return strings.Join(addresses, "\n")
	},
	"Status": func(h *pb.Host) string {
		if h.Status == nil {
			return ""
		}
		switch h.Status.State {
		case "up":
			return color.HiGreenString(h.Status.State)
		case "down":
			return color.HiRedString(h.Status.State)
		default:
			return h.Status.State
		}
	},
	"Hops": func(h *pb.Host) string {
		if h.Trace == nil {
			return ""
		}

		return fmt.Sprint(len(h.Trace.Hops))
	},
	"Extra Ports": func(h *pb.Host) string {
		ports := ""
		for _, port := range h.ExtraPorts {
			ports += printExtraPorts(port, 1)
		}

		return ports
	},
	"Arch": getProbableCPU,
	"MAC":  func(h *pb.Host) string { return h.MAC },
	"Purpose": func(h *pb.Host) string {
		if h.OS == nil {
			return ""
		}

		if h.Purpose != "" {
			return h.Purpose
		}

		times := map[string]int{}

		for _, m := range h.OS.Matches {
			for _, c := range m.Classes {
				if c.Type != "" {
					times[c.Type]++
				}
			}
		}

		var purposes []string
		for name, times := range times {
			typeStr := name + display.Dim + fmt.Sprintf("(%d)", times)
			purposes = append(purposes, typeStr)
		}

		return strings.Join(purposes, " | ")
	},

	"Route": func(h *pb.Host) string {
		if h.Trace == nil {
			return ""
		}

		routes := "\n" + display.Reset

		for i := len(h.Trace.Hops) - 1; i >= 0; i-- {
			hop := h.Trace.Hops[i]
			line := display.Dim + "  |_ "
			rtt := display.Dim + fmt.Sprintf("%*s", 6, hop.RTT) + display.Reset
			ipPad := fmt.Sprintf("%*s  ", 18, hop.IPAddr)
			line += rtt + ipPad + display.Bold + display.FgYellow + hop.Host + display.Reset
			routes += line + "\n"
		}

		return strings.TrimSuffix(routes, "\n")
	},
	"Scripts": func(h *pb.Host) string {
		return ""
	},
	"Sources": func(h *pb.Host) string {
		return provenance.Tools(h.GetSources())
	},
	"Virtual Host": func(h *pb.Host) string {
		return h.VirtualHost
	},
	"Comment": func(h *pb.Host) string {
		return h.Comment
	},
}

Fields maps field names to their value generators.

Functions

func Completions

func Completions() []display.Options

Completions returns some columns to be combined into completion candidates and/or their descriptions.

func Detail

func Detail(h *pb.Host, showRoute bool) display.Detail

Detail assembles the full `info` view for a single host: the identity banner, the side-by-side info panes, the derived insights, and any trailing sections (open ports, extra ports, comment and — when showRoute is set — the full traceroute). It hands these to the shared display.Detail renderer, so a host's detail view is laid out identically to every other domain's. showRoute mirrors the `hosts show --traceroute` flag: the route can be long, so it prints only on request.

func DisplayDetails

func DisplayDetails() []display.Options

DetailHeaders returns the headers for a detailed host view.

func DisplayHeaders

func DisplayHeaders() []display.Options

DisplayHeaders returns all weighted table headers for a table of hosts.

func FilterIdenticalPort

func FilterIdenticalPort(raw []host.PortORM, dbHosts []*host.PortORM) (filtered []host.PortORM)

FilterIdenticalPort returns a list of portsfrom which have been removed all ports that are already in the database, with a very high degree of certitude. This avoids redundance when manipulating new ports/services.

func GetOperatingSystem

func GetOperatingSystem(h *pb.Host) (osName, osFamily string)

GetOperatingSystem returns the operating system of the host based on potential OS guess matches, or if none and the information is known without any guessing.

func InfoPanes

func InfoPanes(h *pb.Host) []display.Pane

InfoPanes groups a host's detail into titled panes (System / Network / Status) for side-by-side layout via display.Columns, mirroring the credential and service info views. Empty panes are dropped, so a host with no OS/network data never prints a bare title.

func Insights

func Insights(h *pb.Host) (lines []string)

Insights returns cross-cutting observations about a single host for the info view: a down/stale warning, exposed cleartext services, a large-attack-surface note, and a flag when the OS is only an nmap guess.

func MergeHost

func MergeHost(dst, src *host.Host) (changed bool)

MergeHost folds src into dst in place, by field class, without losing data. It assumes the two already match (SameHost); callers do the matching and scoping.

func SameHost

func SameHost(a, b *host.Host) bool

SameHost reports whether two in-memory hosts denote the same machine, using natural keys only (DEDUP.md §2, keyed-first): MAC is definitive, otherwise a shared address is decisive. A shared hostname alone is deliberately NOT enough to merge — virtual hosts share names — so per the no-false-merge asymmetry we would rather split than wrongly collapse two hosts.

func SamePort

func SamePort(a, b *host.Port) bool

SamePort keys a port by (protocol, number) — its natural key within a host.

Types

type Group

type Group host.Group

Group - A computer group of users. This type will be closely related to the various aims/credential types.

func (*Group) ToORM

func (g *Group) ToORM(ctx context.Context) (host.GroupORM, error)

ToORM - Get the SQL object for the Group.

func (*Group) ToPB

func (g *Group) ToPB() *host.Group

ToPB - Get the Protobuf object for the Group.

type Host

type Host pb.Host

Host - A physical or virtual computer host. The type has several categories of fields: general information, and Nmap-compliant fields (ports, status, route, scripts etc).

type Port

type Port host.Port

Port - A port on a Host. The type has several categories of fields: general information, and Nmap-compliant fields (status, owner, service, scripts etc).

func (*Port) ToORM

func (p *Port) ToORM(ctx context.Context) (host.PortORM, error)

ToORM - Get the SQL object for the Port.

func (*Port) ToPB

func (p *Port) ToPB() *host.Port

ToPB - Get the Protobuf object for the Port.

type User

type User host.User

User - A computer (login) user. This type will be closely related to the various aims/credential types.

func (*User) ToORM

func (u *User) ToORM(ctx context.Context) (host.UserORM, error)

ToORM - Get the SQL object for the User.

func (*User) ToPB

func (u *User) ToPB() *host.User

ToPB - Get the Protobuf object for the User.

Directories

Path Synopsis
pb
os
rpc

Jump to

Keyboard shortcuts

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