Core

package
v0.0.0-...-fb99b47 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const WrTimeout = 5 // 默认读写超时时间(秒)

Variables

View Source
var (
	AliveHosts []string                    // 存活主机列表
	ExistHosts = make(map[string]struct{}) // 已发现主机记录

)
View Source
var ProbeString string

Functions

func ArrayCountValueTop

func ArrayCountValueTop(arrInit []string, length int, flag bool) (arrTop []string, arrLen []int)

ArrayCountValueTop 统计IP地址段存活数量并返回TOP N结果

func CheckLive

func CheckLive(hostslist []string, Ping bool) []string

CheckLive 检测主机存活状态

func DecodeData

func DecodeData(s string) ([]byte, error)

func DecodePattern

func DecodePattern(s string) ([]byte, error)

解码模式字符串,处理转义序列

func EnhancedPortScan

func EnhancedPortScan(hosts []string, ports string, timeout int64) []string

EnhancedPortScan 高性能端口扫描函数

func ExecCommandPing

func ExecCommandPing(ip string) bool

ExecCommandPing 执行系统Ping命令检测主机存活

func ExecuteScanTasks

func ExecuteScanTasks(targets []Common.HostInfo, strategy ScanStrategy, ch *chan struct{}, wg *sync.WaitGroup)

任务执行通用框架

func GetAllPlugins

func GetAllPlugins() []string

GetAllPlugins 返回所有已注册插件的名称列表

func IsContain

func IsContain(items []string, item string) bool

IsContain 检查切片中是否包含指定元素

func RunIcmp1

func RunIcmp1(hostslist []string, conn *icmp.PacketConn, chanHosts chan string)

RunIcmp1 使用ICMP批量探测主机存活(监听模式)

func RunIcmp2

func RunIcmp2(hostslist []string, chanHosts chan string)

RunIcmp2 使用ICMP并发探测主机存活(无监听模式)

func RunPing

func RunPing(hostslist []string, chanHosts chan string)

RunPing 使用系统Ping命令并发探测主机存活

func Scan

func Scan(info Common.HostInfo)

入口函数,向后兼容旧的调用方式

Types

type Directive

type Directive struct {
	DirectiveName string
	Flag          string
	Delimiter     string
	DirectiveStr  string
}

type Extras

type Extras struct {
	VendorProduct   string
	Version         string
	Info            string
	Hostname        string
	OperatingSystem string
	DeviceType      string
	CPE             string
}

func (*Extras) ToMap

func (e *Extras) ToMap() map[string]string

ToMap 将 Extras 转换为 map[string]string

type Info

type Info struct {
	Address string   // 目标IP地址
	Port    int      // 目标端口
	Conn    net.Conn // 网络连接
	Result  Result   // 探测结果
	Found   bool     // 是否成功识别服务
}

Info 定义单个端口探测的上下文信息

func (*Info) Connect

func (i *Info) Connect(msg []byte) []byte

Connect 发送数据并获取响应

func (*Info) GetInfo

func (i *Info) GetInfo(response []byte, probe *Probe)

GetInfo 分析响应数据并提取服务信息

func (*Info) PortInfo

func (i *Info) PortInfo()

PortInfo 执行端口服务识别的主要逻辑

func (*Info) Read

func (i *Info) Read() ([]byte, error)

Read 从连接读取响应

func (*Info) Write

func (i *Info) Write(msg []byte) error

Write 写入数据到连接

type LocalScanStrategy

type LocalScanStrategy struct{}

LocalScanStrategy 本地扫描策略

func NewLocalScanStrategy

func NewLocalScanStrategy() *LocalScanStrategy

NewLocalScanStrategy 创建新的本地扫描策略

func (*LocalScanStrategy) Description

func (s *LocalScanStrategy) Description() string

Description 返回策略描述

func (*LocalScanStrategy) Execute

func (s *LocalScanStrategy) Execute(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup)

Execute 执行本地扫描策略

func (*LocalScanStrategy) GetPlugins

func (s *LocalScanStrategy) GetPlugins() ([]string, bool)

GetPlugins 获取本地扫描插件列表

func (*LocalScanStrategy) IsPluginApplicable

func (s *LocalScanStrategy) IsPluginApplicable(plugin Common.ScanPlugin, targetPort int, isCustomMode bool) bool

IsPluginApplicable 判断插件是否适用于本地扫描

func (*LocalScanStrategy) LogPluginInfo

func (s *LocalScanStrategy) LogPluginInfo()

LogPluginInfo 输出本地扫描插件信息

func (*LocalScanStrategy) Name

func (s *LocalScanStrategy) Name() string

Name 返回策略名称

func (*LocalScanStrategy) PrepareTargets

func (s *LocalScanStrategy) PrepareTargets(info Common.HostInfo) []Common.HostInfo

PrepareTargets 准备本地扫描目标

type Match

type Match struct {
	IsSoft          bool           // 是否为软匹配
	Service         string         // 服务名称
	Pattern         string         // 匹配模式
	VersionInfo     string         // 版本信息格式
	FoundItems      []string       // 找到的项目
	PatternCompiled *regexp.Regexp // 编译后的正则表达式
}

func (*Match) MatchPattern

func (m *Match) MatchPattern(response []byte) bool

MatchPattern 使用正则表达式匹配响应内容

func (*Match) ParseVersionInfo

func (m *Match) ParseVersionInfo(response []byte) Extras

ParseVersionInfo 解析版本信息并返回额外信息结构

type PortInfoScanner

type PortInfoScanner struct {
	Address string        // 目标IP地址
	Port    int           // 目标端口
	Conn    net.Conn      // 网络连接
	Timeout time.Duration // 超时时间
	// contains filtered or unexported fields
}

PortInfoScanner 定义端口服务识别器

func NewPortInfoScanner

func NewPortInfoScanner(addr string, port int, conn net.Conn, timeout time.Duration) *PortInfoScanner

NewPortInfoScanner 创建新的端口服务识别器实例

func (*PortInfoScanner) Identify

func (s *PortInfoScanner) Identify() (*ServiceInfo, error)

Identify 执行服务识别,返回识别结果

type Probe

type Probe struct {
	Name     string // 探测器名称
	Data     string // 探测数据
	Protocol string // 协议
	Ports    string // 端口范围
	SSLPorts string // SSL端口范围

	TotalWaitMS  int    // 总等待时间
	TCPWrappedMS int    // TCP包装等待时间
	Rarity       int    // 稀有度
	Fallback     string // 回退探测器名称

	Matchs *[]Match // 匹配规则列表
}

func (*Probe) ContainsPort

func (p *Probe) ContainsPort(testPort int) bool

ContainsPort 检查指定端口是否在探测器的端口范围内

type ProbesRarity

type ProbesRarity []Probe

ProbesRarity 用于按稀有度排序的探测器切片

func (ProbesRarity) Len

func (ps ProbesRarity) Len() int

Len 返回切片长度,实现 sort.Interface 接口

func (ProbesRarity) Less

func (ps ProbesRarity) Less(i, j int) bool

Less 比较函数,按稀有度升序排序,实现 sort.Interface 接口

func (ProbesRarity) Swap

func (ps ProbesRarity) Swap(i, j int)

Swap 交换切片中的两个元素,实现 sort.Interface 接口

type Result

type Result struct {
	Service Service           // 识别出的服务信息
	Banner  string            // 服务横幅
	Extras  map[string]string // 额外信息
	Send    []byte            // 发送的探测数据
	Recv    []byte            // 接收到的响应数据
}

Result 定义单次探测的结果

type ScanStrategy

type ScanStrategy interface {
	// 名称和描述
	Name() string
	Description() string

	// 执行扫描的主要方法
	Execute(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup)

	// 插件管理方法
	GetPlugins() ([]string, bool)
	LogPluginInfo()

	// 任务准备方法
	PrepareTargets(info Common.HostInfo) []Common.HostInfo
	IsPluginApplicable(plugin Common.ScanPlugin, targetPort int, isCustomMode bool) bool
}

ScanStrategy 定义扫描策略接口

type ScanTask

type ScanTask struct {
	// contains filtered or unexported fields
}

ScanTask 表示单个扫描任务

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner 扫描器结构体

func NewScanner

func NewScanner(info Common.HostInfo) *Scanner

NewScanner 创建新的扫描器并选择合适的策略

func (*Scanner) Scan

func (s *Scanner) Scan(info Common.HostInfo)

Scan 执行整体扫描流程

type Service

type Service struct {
	Name   string            // 服务名称
	Extras map[string]string // 服务的额外属性
}

Service 定义服务的基本信息

type ServiceInfo

type ServiceInfo struct {
	Name    string            // 服务名称,如 http、ssh 等
	Banner  string            // 服务返回的横幅信息
	Version string            // 服务版本号
	Extras  map[string]string // 其他额外信息,如操作系统、产品名等
}

ServiceInfo 定义服务识别的结果信息

type ServiceScanStrategy

type ServiceScanStrategy struct{}

ServiceScanStrategy 服务扫描策略

func NewServiceScanStrategy

func NewServiceScanStrategy() *ServiceScanStrategy

NewServiceScanStrategy 创建新的服务扫描策略

func (*ServiceScanStrategy) Description

func (s *ServiceScanStrategy) Description() string

Description 返回策略描述

func (*ServiceScanStrategy) Execute

func (s *ServiceScanStrategy) Execute(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup)

Execute 执行服务扫描策略

func (*ServiceScanStrategy) GetPlugins

func (s *ServiceScanStrategy) GetPlugins() ([]string, bool)

GetPlugins 获取服务扫描插件列表

func (*ServiceScanStrategy) IsPluginApplicable

func (s *ServiceScanStrategy) IsPluginApplicable(plugin Common.ScanPlugin, targetPort int, isCustomMode bool) bool

IsPluginApplicable 判断插件是否适用于服务扫描

func (*ServiceScanStrategy) LogPluginInfo

func (s *ServiceScanStrategy) LogPluginInfo()

LogPluginInfo 输出服务扫描插件信息

func (*ServiceScanStrategy) Name

func (s *ServiceScanStrategy) Name() string

Name 返回策略名称

func (*ServiceScanStrategy) PrepareTargets

func (s *ServiceScanStrategy) PrepareTargets(info Common.HostInfo) []Common.HostInfo

PrepareTargets 准备目标信息

type Target

type Target struct {
	IP       string // 目标IP地址
	Port     int    // 目标端口
	Protocol string // 协议类型
}

Target 定义目标结构体

func (*Target) GetAddress

func (t *Target) GetAddress() string

GetAddress 获取目标的完整地址(IP:端口)

type VScan

type VScan struct {
	Exclude        string
	AllProbes      []Probe
	UdpProbes      []Probe
	Probes         []Probe
	ProbesMapKName map[string]Probe
}

func (*VScan) Init

func (v *VScan) Init()

Init 初始化VScan对象

func (*VScan) SetusedProbes

func (v *VScan) SetusedProbes()

设置使用的探测器

type WebScanStrategy

type WebScanStrategy struct{}

WebScanStrategy Web扫描策略

func NewWebScanStrategy

func NewWebScanStrategy() *WebScanStrategy

NewWebScanStrategy 创建新的Web扫描策略

func (*WebScanStrategy) Description

func (s *WebScanStrategy) Description() string

Description 返回策略描述

func (*WebScanStrategy) Execute

func (s *WebScanStrategy) Execute(info Common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup)

Execute 执行Web扫描策略

func (*WebScanStrategy) GetPlugins

func (s *WebScanStrategy) GetPlugins() ([]string, bool)

GetPlugins 获取Web扫描插件列表

func (*WebScanStrategy) IsPluginApplicable

func (s *WebScanStrategy) IsPluginApplicable(plugin Common.ScanPlugin, targetPort int, isCustomMode bool) bool

IsPluginApplicable 判断插件是否适用于Web扫描

func (*WebScanStrategy) LogPluginInfo

func (s *WebScanStrategy) LogPluginInfo()

LogPluginInfo 输出Web扫描插件信息

func (*WebScanStrategy) Name

func (s *WebScanStrategy) Name() string

Name 返回策略名称

func (*WebScanStrategy) PrepareTargets

func (s *WebScanStrategy) PrepareTargets(baseInfo Common.HostInfo) []Common.HostInfo

PrepareTargets 准备URL目标列表

Jump to

Keyboard shortcuts

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