Documentation ¶
Index ¶
- Variables
- func ExtractBlockFromMatch(raw string) []string
- func FetchBannerFromHostPort(baseCtx context.Context, packet2 []byte, host string, port interface{}, ...) (bool, []*lowhttp.RedirectFlow, error)
- func FileOrDirToWebRules(dir string) []*rule.FingerPrintRule
- func GetDefaultNmapServiceProbeRules() (map[*NmapProbe][]*NmapMatch, error)
- func GetDefaultTCPServiceName(port int) string
- func GetDefaultUDPServiceName(port int) string
- func GetDefaultWebFingerprintRules() ([]*rule.FingerPrintRule, error)
- func GetRuleBlockByConfig(currentPort int, config *Config) (emptyBlock *RuleBlock, blocks []*RuleBlock, ok bool)
- func ParseNmapServiceProbeToRuleMap(raw []byte) (result map[*NmapProbe][]*NmapMatch, err error)
- func ParseNmapServiceProbesTxt(raw string) ([]*NmapProbe, []*NmapMatch, []string)
- func SetMatchResultCache(addr string, result *MatchResult)
- func SetMatchResultDatabaseCache(addr string, result *MatchResult)
- func UnquoteCStyleString(raw string) (string, error)
- type Config
- func (c *Config) CanOnlyScanTCP() bool
- func (c *Config) CanScanTCP() bool
- func (c *Config) CanScanUDP() bool
- func (c *Config) Configure(ops ...ConfigOption)
- func (c *Config) GetFingerprintRules() map[*NmapProbe][]*NmapMatch
- func (c *Config) GetWebFingerprintRules() []*rule.FingerPrintRule
- func (c *Config) IsFiltered(host string, port int) bool
- type ConfigOption
- func WithActiveMode(raw bool) ConfigOption
- func WithCache(b bool) ConfigOption
- func WithCtx(ctx context.Context) ConfigOption
- func WithDatabaseCache(b bool) ConfigOption
- func WithDisableIotWebFingerprint(t bool) ConfigOption
- func WithDisableWebFingerprint(t bool) ConfigOption
- func WithExcludeHosts(hosts string) ConfigOption
- func WithExcludePorts(ports string) ConfigOption
- func WithFingerprintDataSize(size int) ConfigOption
- func WithFingerprintRule(rules map[*NmapProbe][]*NmapMatch) ConfigOption
- func WithForceEnableAllFingerprint(b bool) ConfigOption
- func WithNmapRule(i interface{}) ConfigOption
- func WithOnlyEnableWebFingerprint(b bool) ConfigOption
- func WithPoolSize(size int) ConfigOption
- func WithProbeTimeout(timeout time.Duration) ConfigOption
- func WithProbeTimeoutHumanRead(f float64) ConfigOption
- func WithProbesConcurrentMax(m int) ConfigOption
- func WithProbesMax(m int) ConfigOption
- func WithProxy(proxies ...string) ConfigOption
- func WithRarityMax(rarity int) ConfigOption
- func WithRuntimeId(id string) ConfigOption
- func WithTransportProtos(protos ...TransportProto) ConfigOption
- func WithWebFingerprintRule(i any) ConfigOption
- func WithWebFingerprintUseAllRules(b bool) ConfigOption
- type DataBlock
- type FingerprintInfo
- type HTTPFlow
- type MatchResult
- func (m *MatchResult) GetBanner() string
- func (m *MatchResult) GetCPEs() []string
- func (m *MatchResult) GetDomains() []string
- func (m *MatchResult) GetFuzzRequest() *mutate.FuzzHTTPRequest
- func (m *MatchResult) GetHtmlTitle() string
- func (m *MatchResult) GetProto() TransportProto
- func (m *MatchResult) GetRequestRaw() (bool, []byte)
- func (m *MatchResult) GetResponseRaw() []byte
- func (m *MatchResult) GetServiceName() string
- func (m *MatchResult) HaveDialFailed() bool
- func (m *MatchResult) IsOpen() bool
- func (m *MatchResult) Merge(f *MatchResult)
- func (m *MatchResult) String(schemaForce ...string) string
- func (m *MatchResult) Tidy()
- type Matcher
- type MatcherResultAnalysis
- type NmapMatch
- type NmapProbe
- type Pool
- type PoolCallback
- type PoolTask
- type PortState
- type Rule
- type RuleBlock
- type TransportProto
Constants ¶
This section is empty.
Variables ¶
var ( DefaultNmapServiceProbeRules map[*NmapProbe][]*NmapMatch DefaultNmapServiceProbeRulesOnce sync.Once DefaultWebFingerprintRules []*rule.FingerPrintRule DefaultWebFingerprintRulesOnce sync.Once )
var FpMatchResultTTLCache = utils.NewTTLCache[*MatchResult](3 * time.Minute)
var TCPDefault = make(map[int][]defaultPort)
var UDPDefault = make(map[int][]defaultPort)
Functions ¶
func ExtractBlockFromMatch ¶
func FetchBannerFromHostPort ¶
func FileOrDirToWebRules ¶
func FileOrDirToWebRules(dir string) []*rule.FingerPrintRule
func GetDefaultWebFingerprintRules ¶
func GetDefaultWebFingerprintRules() ([]*rule.FingerPrintRule, error)
func GetRuleBlockByConfig ¶
func SetMatchResultCache ¶
func SetMatchResultCache(addr string, result *MatchResult)
func SetMatchResultDatabaseCache ¶
func SetMatchResultDatabaseCache(addr string, result *MatchResult)
func UnquoteCStyleString ¶
Types ¶
type Config ¶
type Config struct { // 针对那种传输层协议进行指纹识别? TransportProtos []TransportProto // 在主动模式发包的基础上进行探测控制 // 稀有度越大,表示这个服务在现实存在的可能性越小 // 取值范围为1-9 // 默认值为 5 RarityMax int /* Probe 为主动发送一些数据包来检测指纹信息的机制,以下选项可以控制 Probe 的使用 */ // 主动模式,这个模式下,会主动发包进行探测指纹,(启用 Probe) // 默认值为 false ActiveMode bool // 默认每一个 Probe 的超时时间 ProbeTimeout time.Duration // 发送 Probe 的数量限制,默认值为 5 ProbesMax int // 发送 Probe 的并发量,默认值为 5 ProbesConcurrentMax int // 指定规则 FingerprintRules map[*NmapProbe][]*NmapMatch // 指纹检测时候取的数据大小,意味着多大的数据会参与到指纹识别中 // 2048 为默认值 // 主机指纹识别的时间与这个值成正比 FingerprintDataSize int // // ForceEnableAllFingerprint 表示强制检测 Web 指纹 ForceEnableAllFingerprint bool // OnlyEnableWebFingerprint 表示值进行 Web 指纹识别 // 这个选项为 True 的时候,行为将会覆盖 ForceEnableAllFingerprint OnlyEnableWebFingerprint bool // 禁用专门的 Web 指纹扫描 DisableWebFingerprint bool // 这个选项标志着,如果 Web 指纹检测中途已经检测出了某些指纹,也应该继续检测其他指纹 WebFingerprintUseAllRules bool // 爬虫发现的最大 URL 数量,默认是 5 个 CrawlerMaxUrlCount int // 使用指定的 WebRule 来测试 Web 指纹,默认为使用默认指纹 WebFingerprintRules []*rule.FingerPrintRule // 并发池的大小配置(单体不生效) PoolSize int // 为端口扫描设置代理 Proxies []string // 在同一个引擎进程内,可以缓存 EnableCache bool // 设置数据库缓存,可以跨进程 EnableDatabaseCache bool // Exclude ExcludeHostsFilter *hostsparser.HostsParser ExcludePortsFilter *utils.PortsFilter // Runtime id RuntimeId string // ctx Ctx context.Context // Disable default fingerprint DisableDefaultFingerprint bool DisableDefaultIotFingerprint bool // contains filtered or unexported fields }
func NewConfig ¶
func NewConfig(options ...ConfigOption) *Config
func (*Config) CanOnlyScanTCP ¶ added in v1.2.3
func (*Config) CanScanTCP ¶
func (*Config) CanScanUDP ¶
func (*Config) Configure ¶
func (c *Config) Configure(ops ...ConfigOption)
func (*Config) GetFingerprintRules ¶
func (*Config) GetWebFingerprintRules ¶
func (c *Config) GetWebFingerprintRules() []*rule.FingerPrintRule
type ConfigOption ¶
type ConfigOption func(config *Config)
func WithActiveMode ¶
func WithActiveMode(raw bool) ConfigOption
func WithCache ¶
func WithCache(b bool) ConfigOption
cache servicescan 的配置选项,设置本次扫描是否使用缓存 @param {bool} b 是否使用缓存 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.cache(true)) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithCtx ¶ added in v1.3.3
func WithCtx(ctx context.Context) ConfigOption
func WithDatabaseCache ¶
func WithDatabaseCache(b bool) ConfigOption
databaseCache servicescan 的配置选项,设置本次扫描是否使用数据库缓存 @param {bool} b 是否使用数据库缓存 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.databaseCache(true)) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithDisableIotWebFingerprint ¶
func WithDisableIotWebFingerprint(t bool) ConfigOption
func WithDisableWebFingerprint ¶
func WithDisableWebFingerprint(t bool) ConfigOption
func WithExcludeHosts ¶
func WithExcludeHosts(hosts string) ConfigOption
excludeHosts servicescan 的配置选项,设置本次扫描排除的主机 @param {string} hosts 主机,支持逗号分割、CIDR、-的格式 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("192.168.1.1/24", "22-80,443,3389", servicescan.excludeHosts("192.168.1.1")) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithExcludePorts ¶
func WithExcludePorts(ports string) ConfigOption
excludePorts servicescan 的配置选项,设置本次扫描排除的端口 @param {string} ports 端口,支持逗号分割、-的格式 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.excludePorts("22,80")) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithFingerprintDataSize ¶
func WithFingerprintDataSize(size int) ConfigOption
func WithFingerprintRule ¶
func WithFingerprintRule(rules map[*NmapProbe][]*NmapMatch) ConfigOption
func WithForceEnableAllFingerprint ¶ added in v1.3.1
func WithForceEnableAllFingerprint(b bool) ConfigOption
func WithNmapRule ¶
func WithNmapRule(i interface{}) ConfigOption
nmapRule servicescan 的配置选项,设置本次扫描使用的 Nmap 指纹规则 @param {interface{}} i Nmap 指纹规则
func WithOnlyEnableWebFingerprint ¶
func WithOnlyEnableWebFingerprint(b bool) ConfigOption
func WithPoolSize ¶
func WithPoolSize(size int) ConfigOption
concurrent servicescan 的配置选项,用于设置整体扫描并发 @param {int} size 并发数量 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.concurrent(100)) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithProbeTimeout ¶
func WithProbeTimeout(timeout time.Duration) ConfigOption
func WithProbeTimeoutHumanRead ¶
func WithProbeTimeoutHumanRead(f float64) ConfigOption
probeTimeout servicescan 的配置选项,设置每一个探测包的超时时间 @param {float64} f 超时时间,单位为秒 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.probeTimeout(5)) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithProbesConcurrentMax ¶
func WithProbesConcurrentMax(m int) ConfigOption
maxProbesConcurrent servicescan 的配置选项,设置本次扫描发送 Probe 的并发量,默认值为 5 @param {int} m 并发量 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.active(true), // 需要在主动发包的基础上 servicescan.maxProbes(50), // 设置本次扫描使用的最大探测包数量 servicescan.maxProbesConcurrent(10) // 设置本次扫描发送 Probe 的并发量 ) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithProbesMax ¶
func WithProbesMax(m int) ConfigOption
maxProbes servicescan 的配置选项,在主动模式发包的基础上设置本次扫描使用的最大探测包数量,默认值为 5 @param {int} m 最大探测包数量 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.active(true), // 需要在主动发包的基础上 servicescan.maxProbes(10) ) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithProxy ¶
func WithProxy(proxies ...string) ConfigOption
proxy servicescan 的配置选项,设置本次扫描使用的代理 @param {string} proxies 代理地址,支持 http 和 socks5 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.proxy("http://127.0.0.1:1080")) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithRarityMax ¶
func WithRarityMax(rarity int) ConfigOption
nmapRarityMax servicescan 的配置选项,设置本次扫描使用的 Nmap 指纹稀有度,在主动模式发包的基础上进行探测控制 稀有度越大,表示这个服务在现实存在的可能性越小,取值范围为 1-9,默认值为 5 @param {int} rarity 稀有度,取值范围为 1-9 @return {ConfigOption} 返回配置项 Example: ``` result, err = servicescan.Scan("127.0.0.1", "22-80,443,3389,161", servicescan.active(true), // 需要在主动发包的基础上通过稀有度进行筛选 servicescan.nmapRarityMax(9), ) die(err)
for v := range result { fmt.Println(v.String()) }
```
func WithRuntimeId ¶ added in v1.3.3
func WithRuntimeId(id string) ConfigOption
func WithTransportProtos ¶
func WithTransportProtos(protos ...TransportProto) ConfigOption
func WithWebFingerprintRule ¶
func WithWebFingerprintRule(i any) ConfigOption
webRule servicescan 的配置选项,设置本次扫描使用的 Web 指纹规则 @param {interface{}} i Web 指纹规则
func WithWebFingerprintUseAllRules ¶
func WithWebFingerprintUseAllRules(b bool) ConfigOption
type FingerprintInfo ¶
type FingerprintInfo struct { IP string `json:"ip"` Port int `json:"port"` Proto TransportProto `json:"proto"` ServiceName string `json:"service_name"` ProductVerbose string `json:"product_verbose"` Info string `json:"info"` Version string `json:"version"` Hostname string `json:"hostname"` OperationVerbose string `json:"operation_verbose"` DeviceType string `json:"device_type"` CPEs []string `json:"cpes"` Raw string `json:"raw"` Banner string `json:"banner"` CPEFromUrls map[string][]*rule.CPE `json:"cpe_from_urls"` HttpFlows []*HTTPFlow `json:"http_flows"` // tls info for fill... TLSInspectResults []*netx.TLSInspectResult }
func ToFingerprintInfo ¶
func ToFingerprintInfo(rule *NmapMatch, match *regexp2.Match) *FingerprintInfo
func (*FingerprintInfo) FromRegexp2Match ¶
func (f *FingerprintInfo) FromRegexp2Match(match *regexp2.Match)
type MatchResult ¶
type MatchResult struct { Target string `json:"target"` Port int `json:"port"` State PortState `json:"state"` Reason string `json:"reason"` Fingerprint *FingerprintInfo `json:"fingerprint"` }
func GetMatchResultCache ¶
func GetMatchResultCache(addr string) *MatchResult
func GetMatchResultDatabaseCache ¶
func GetMatchResultDatabaseCache(addr string) *MatchResult
func (*MatchResult) GetBanner ¶
func (m *MatchResult) GetBanner() string
func (*MatchResult) GetCPEs ¶
func (m *MatchResult) GetCPEs() []string
func (*MatchResult) GetDomains ¶
func (m *MatchResult) GetDomains() []string
func (*MatchResult) GetFuzzRequest ¶ added in v1.2.4
func (m *MatchResult) GetFuzzRequest() *mutate.FuzzHTTPRequest
func (*MatchResult) GetHtmlTitle ¶
func (m *MatchResult) GetHtmlTitle() string
func (*MatchResult) GetProto ¶
func (m *MatchResult) GetProto() TransportProto
func (*MatchResult) GetRequestRaw ¶ added in v1.2.4
func (m *MatchResult) GetRequestRaw() (bool, []byte)
func (*MatchResult) GetResponseRaw ¶ added in v1.2.4
func (m *MatchResult) GetResponseRaw() []byte
func (*MatchResult) GetServiceName ¶
func (m *MatchResult) GetServiceName() string
func (*MatchResult) HaveDialFailed ¶
func (m *MatchResult) HaveDialFailed() bool
func (*MatchResult) IsOpen ¶
func (m *MatchResult) IsOpen() bool
func (*MatchResult) Merge ¶
func (m *MatchResult) Merge(f *MatchResult)
func (*MatchResult) String ¶
func (m *MatchResult) String(schemaForce ...string) string
func (*MatchResult) Tidy ¶
func (m *MatchResult) Tidy()
type Matcher ¶
type Matcher struct { Config *Config // contains filtered or unexported fields }
func NewFingerprintMatcher ¶
func (*Matcher) Match ¶
func (f *Matcher) Match(host string, port int, options ...ConfigOption) (result *MatchResult, err error)
func (*Matcher) MatchWithContext ¶
func (f *Matcher) MatchWithContext(ctx context.Context, host string, port int, options ...ConfigOption) (result *MatchResult, err error)
type MatcherResultAnalysis ¶
type MatcherResultAnalysis struct { TotalScannedPort int `json:"total_scaned_port"` TotalOpenPort int `json:"total_open_port"` TargetOpenPortCountMap map[string]int `json:"target_open_port_count_map"` TargetClosedPortCountMap map[string]int `json:"target_closed_port_count_map"` ClosedPort []string `json:"closed_port"` OpenPortCPEMap map[string][]string `json:"open_port_cpe_map"` OpenPortServiceMap map[string]string `json:"open_port_service_map"` }
func MatcherResultsToAnalysis ¶
func MatcherResultsToAnalysis(res []*MatchResult) *MatcherResultAnalysis
func (*MatcherResultAnalysis) Show ¶
func (s *MatcherResultAnalysis) Show()
func (*MatcherResultAnalysis) ToJson ¶
func (s *MatcherResultAnalysis) ToJson(file string)
type NmapMatch ¶
type NmapMatch struct { ServiceName string `json:"service_name"` // m// MatchRule lazyRegexpInterface `json:"match_rule"` // p// ProductVerbose string `json:"product_verbose"` // i// Info string `json:"info"` // v// Version string `json:"version_verbose"` // h Hostname string `json:"hostname"` // o OperationVerbose string `json:"operation_verbose"` // d DeviceType string `json:"device_type"` // From CPE CPEs []string `json:"cpes"` Raw string `json:"raw"` }
func ParseNmapMatch ¶
type NmapProbe ¶
type NmapProbe struct { Index int `json:"index"` Rarity int `json:"rarity"` DefaultPorts []int `json:"default_ports"` Proto TransportProto `json:"proto"` Name string `json:"probe_name"` Payload string `json:"payload"` Raw string `json:"raw"` }
func ParseNmapProbe ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func NewExecutingPool ¶
func (*Pool) AddCallback ¶
func (p *Pool) AddCallback(cb PoolCallback)
type PoolCallback ¶
type PoolCallback func(matcherResult *MatchResult, err error)
type PoolTask ¶
type PoolTask struct { Host string Port int Urls []string Options []ConfigOption // contains filtered or unexported fields }
type RuleBlock ¶
func GetRuleBlockByServiceName ¶ added in v1.2.3
type TransportProto ¶
type TransportProto string
var ( TCP TransportProto = "tcp" UDP TransportProto = "udp" )
func ParseStringToProto ¶
func ParseStringToProto(protos ...interface{}) []TransportProto