pkg

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 34 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// MaxReadSize 是从网络读取的最大字节数
	MaxReadSize = 4096
	// ReadTimeout 是网络读取的超时时间
	ReadTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVResult added in v0.11.5

type CSVResult struct {
	Timestamp    time.Time `json:"timestamp"`
	ScanID       string    `json:"scan_id"`
	Protocol     string    `json:"protocol"`
	Host         string    `json:"host"`
	Port         int       `json:"port"`
	Status       string    `json:"status"`
	ResponseTime string    `json:"response_time"`
	ErrorMessage string    `json:"error_message"`
}

CSVResult represents a single scan result for CSV output

type CSVWriter added in v0.11.5

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

CSVWriter handles thread-safe CSV file writing with buffering

func NewCSVWriter added in v0.11.5

func NewCSVWriter(filePath string) (*CSVWriter, error)

NewCSVWriter creates a new CSV writer for the specified file path

func (*CSVWriter) Close added in v0.11.5

func (w *CSVWriter) Close() error

Close closes the CSV writer and flushes remaining data

func (*CSVWriter) Flush added in v0.11.5

func (w *CSVWriter) Flush() error

Flush flushes any buffered data to disk

func (*CSVWriter) GetPath added in v0.11.5

func (w *CSVWriter) GetPath() string

GetPath returns the file path of the CSV writer

func (*CSVWriter) IsClosed added in v0.11.5

func (w *CSVWriter) IsClosed() bool

IsClosed returns whether the writer is closed

func (*CSVWriter) WriteResult added in v0.11.5

func (w *CSVWriter) WriteResult(result CSVResult) error

WriteResult writes a single scan result to the CSV file

type CheckResult

type CheckResult struct {
	Success      bool
	ProtocolType ProtocolType
	Host         string
	Port         string
	Timestamp    time.Time
	ResponseTime time.Duration
	ErrorMessage string
}

type DeliveryInfo

type DeliveryInfo struct {
	ProtocolType       ProtocolType
	Host               string
	Port               string
	User               string
	Password           string
	PrivateKeyFullPath string
	Detector           *Detector
	CheckResultChan    chan CheckResult
	Wg                 *sync.WaitGroup
	ProgressManager    *ProgressManager // Added for progress tracking
	ScanContext        *ScanContext     // Added for cancellation support
}

type Detector

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

func NewDetector

func NewDetector(timeOut time.Duration) *Detector

func (Detector) CommonPortCheck

func (d Detector) CommonPortCheck(host, port string) error

func (Detector) FTPCheck

func (d Detector) FTPCheck(host, port string) error

func (Detector) HBBRCheck added in v0.13.0

func (d Detector) HBBRCheck(host, port string) error

func (Detector) HBBS21116Check added in v0.13.0

func (d Detector) HBBS21116Check(host, port string) error

func (Detector) HBBSCheck added in v0.13.0

func (d Detector) HBBSCheck(host, port string) error

func (Detector) RDPCheck

func (d Detector) RDPCheck(host, port string) error

func (Detector) SFTPCheck

func (d Detector) SFTPCheck(host, port, user, password, privateKeyFullPath string) error

func (Detector) SFTPCheckWithAuth added in v0.12.0

func (d Detector) SFTPCheckWithAuth(host, port, user, password, privateKeyFullPath string) error

保留原有的认证式SFTP检测方法(向后兼容)

func (Detector) SSHCheck

func (d Detector) SSHCheck(host, port string) error

func (Detector) TelnetCheck

func (d Detector) TelnetCheck(host, port string) error

func (Detector) VNCCheck

func (d Detector) VNCCheck(host, port string) error

type IPRangeInfo

type IPRangeInfo struct {
	Begin         net.IP
	CountNextTime int
	CICR          *cidr.CIDR
}

type InputInfo

type InputInfo struct {
	Host               string // 192.168.50.123-200
	Port               string // 80,90,100,101-120
	User               string
	Password           string
	PrivateKeyFullPath string
}

type OutputInfo

type OutputInfo struct {
	ProtocolType     ProtocolType
	SuccessMapString map[string][]string
	FailedMapString  map[string][]string
}

type ProgressManager added in v0.14.1

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

ProgressManager manages dual progress bars for IP and port scanning

func NewProgressManager added in v0.14.1

func NewProgressManager(totalIPs, totalPorts int) *ProgressManager

NewProgressManager creates a new progress manager with dual progress bars

func (*ProgressManager) Finish added in v0.14.1

func (pm *ProgressManager) Finish()

Finish marks all progress bars as complete

func (*ProgressManager) IncrementIP added in v0.14.1

func (pm *ProgressManager) IncrementIP(ip string)

IncrementIP advances the IP progress bar by one

func (*ProgressManager) IncrementPort added in v0.14.1

func (pm *ProgressManager) IncrementPort(port int)

IncrementPort advances the port progress bar by one

func (*ProgressManager) StartNewIP added in v0.14.1

func (pm *ProgressManager) StartNewIP(ip string)

StartNewIP creates a new port progress bar for the current IP

func (*ProgressManager) Wait added in v0.14.1

func (pm *ProgressManager) Wait()

Wait waits for all progress bars to complete their rendering

type ProtocolType

type ProtocolType int
const (
	RDP ProtocolType = iota + 1
	SSH
	FTP
	SFTP
	Telnet
	VNC
	Common
	RustDeskHBBS
	RustDeskHBBR
	RustDeskHBBS21116
)

func String2ProtocolType added in v0.11.5

func String2ProtocolType(input string) ProtocolType

func (ProtocolType) String

func (p ProtocolType) String() string

type ResumeManager added in v0.11.5

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

ResumeManager handles the persistence and loading of scan states

func NewResumeManager added in v0.11.5

func NewResumeManager(storageDir string) *ResumeManager

NewResumeManager creates a new resume manager

func (*ResumeManager) CleanupOldStates added in v0.11.5

func (rm *ResumeManager) CleanupOldStates(maxAge time.Duration) error

CleanupOldStates removes scan state files older than the specified duration

func (*ResumeManager) ListIncompleteScans added in v0.11.5

func (rm *ResumeManager) ListIncompleteScans() ([]*ScanState, error)

ListIncompleteScans returns a list of all incomplete scans

func (*ResumeManager) LoadScanState added in v0.11.5

func (rm *ResumeManager) LoadScanState(scanID string) (*ScanState, error)

LoadScanState loads a previously saved scan state

func (*ResumeManager) RemoveIncompleteScan added in v0.11.5

func (rm *ResumeManager) RemoveIncompleteScan(scanID string) error

RemoveIncompleteScan removes a scan from the incomplete scans index

func (*ResumeManager) SaveScanState added in v0.11.5

func (rm *ResumeManager) SaveScanState(scanContext *ScanContext, inputInfo InputInfo, csvFilePath string) error

SaveScanState saves the current state of a scan

type ScanContext added in v0.11.5

type ScanContext struct {
	// Basic scan information
	ScanID     string
	Protocol   ProtocolType
	StartTime  time.Time
	UpdateTime time.Time

	// Scan parameters
	HostRange string
	PortRange string
	Threads   int
	Timeout   int

	// Progress tracking
	TotalTargets   int
	ScannedTargets int
	SuccessCount   int
	FailureCount   int

	// Statistics
	ResponseTimeSum time.Duration
	MinResponseTime time.Duration
	MaxResponseTime time.Duration

	// Context for cancellation
	Ctx    context.Context
	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

ScanContext tracks the state and progress of a scan operation

func NewScanContext added in v0.11.5

func NewScanContext(protocol ProtocolType, hostRange, portRange string, threads, timeout int) *ScanContext

NewScanContext creates a new scan context with the given parameters

func (*ScanContext) EstimateRemainingTime added in v0.11.5

func (sc *ScanContext) EstimateRemainingTime() time.Duration

EstimateRemainingTime estimates the remaining time based on current progress

func (*ScanContext) GetCompletedTargets added in v0.11.5

func (sc *ScanContext) GetCompletedTargets() map[string]bool

GetCompletedTargets returns a copy of completed targets

func (*ScanContext) GetElapsedDuration added in v0.11.5

func (sc *ScanContext) GetElapsedDuration() time.Duration

GetElapsedDuration returns the time elapsed since the scan started

func (*ScanContext) GetFailedTargets added in v0.11.5

func (sc *ScanContext) GetFailedTargets() map[string]bool

GetFailedTargets returns a copy of failed targets

func (*ScanContext) GetPendingTargets added in v0.11.5

func (sc *ScanContext) GetPendingTargets() []string

GetPendingTargets returns a copy of the pending targets

func (*ScanContext) GetProgress added in v0.11.5

func (sc *ScanContext) GetProgress() float64

GetProgress returns the current progress as a percentage

func (*ScanContext) GetStats added in v0.11.5

func (sc *ScanContext) GetStats() ScanStats

GetStats returns current scan statistics

func (*ScanContext) IsComplete added in v0.11.5

func (sc *ScanContext) IsComplete() bool

IsComplete returns true if all targets have been scanned

func (*ScanContext) IsCompleted added in v0.11.5

func (sc *ScanContext) IsCompleted(host string, port int) bool

IsCompleted checks if a target has been completed (successfully or failed)

func (*ScanContext) MarkCompleted added in v0.11.5

func (sc *ScanContext) MarkCompleted(host string, port int, responseTime time.Duration)

MarkCompleted marks a target as successfully scanned

func (*ScanContext) MarkFailed added in v0.11.5

func (sc *ScanContext) MarkFailed(host string, port int)

MarkFailed marks a target as failed

func (*ScanContext) SetTargets added in v0.11.5

func (sc *ScanContext) SetTargets(targets []string)

SetTargets sets the total targets and initializes the pending list

type ScanState added in v0.11.5

type ScanState struct {
	ScanID       string    `json:"scan_id"`
	Protocol     string    `json:"protocol"`
	HostRange    string    `json:"host_range"`
	PortRange    string    `json:"port_range"`
	Threads      int       `json:"threads"`
	Timeout      int       `json:"timeout"`
	User         string    `json:"user,omitempty"`
	Password     string    `json:"password,omitempty"`
	PrivateKey   string    `json:"private_key,omitempty"`
	StartTime    time.Time `json:"start_time"`
	LastUpdate   time.Time `json:"last_update"`
	TotalTargets int       `json:"total_targets"`
	ScannedCount int       `json:"scanned_count"`
	SuccessCount int       `json:"success_count"`
	FailureCount int       `json:"failure_count"`

	// Target tracking
	CompletedTargets []string `json:"completed_targets"`
	FailedTargets    []string `json:"failed_targets"`
	PendingTargets   []string `json:"pending_targets"`

	// File locations
	CSVFilePath string `json:"csv_file_path"`
	StatePath   string `json:"state_path"`
}

ScanState represents the persisted state of a scan

func (*ScanState) ConvertToInputInfo added in v0.11.5

func (state *ScanState) ConvertToInputInfo() InputInfo

ConvertToInputInfo converts a ScanState back to InputInfo

func (*ScanState) ConvertToProtocolType added in v0.11.5

func (state *ScanState) ConvertToProtocolType() ProtocolType

ConvertToProtocolType converts protocol string back to ProtocolType

func (*ScanState) GetElapsedTime added in v0.11.5

func (state *ScanState) GetElapsedTime() time.Duration

GetElapsedTime returns the time elapsed since the scan started

func (*ScanState) GetProgress added in v0.11.5

func (state *ScanState) GetProgress() float64

GetProgress returns the scan progress as a percentage

func (*ScanState) IsComplete added in v0.11.5

func (state *ScanState) IsComplete() bool

IsComplete returns true if the scan is complete (no pending targets)

type ScanStats added in v0.11.5

type ScanStats struct {
	ScanID          string
	Protocol        ProtocolType
	StartTime       time.Time
	UpdateTime      time.Time
	TotalTargets    int
	ScannedTargets  int
	SuccessCount    int
	FailureCount    int
	PendingCount    int
	ProgressPercent float64
	AvgResponseTime time.Duration
	MinResponseTime time.Duration
	MaxResponseTime time.Duration
	ScanDuration    time.Duration
}

ScanStats provides a snapshot of scan statistics

type ScanTools

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

func NewScanTools

func NewScanTools(threads int, timeOut time.Duration) *ScanTools

func (ScanTools) ResumeScan added in v0.11.5

func (s ScanTools) ResumeScan(scanID string, showProgressStep bool) (*OutputInfo, *ScanContext, error)

ResumeScan resumes a previously interrupted scan TODO: Implement this method to avoid circular imports

func (ScanTools) Scan

func (s ScanTools) Scan(protocolType ProtocolType, inputInfo InputInfo, showProgressStep bool) (*OutputInfo, error)

func (ScanTools) ScanWithOutput added in v0.11.5

func (s ScanTools) ScanWithOutput(protocolType ProtocolType, inputInfo InputInfo, showProgressStep bool, csvOutputPath string, enableProgress bool) (*OutputInfo, *ScanContext, error)

ScanWithOutput scans with enhanced CSV logging and progress tracking

Directories

Path Synopsis
backup

Jump to

Keyboard shortcuts

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