Common

package
v0.0.0-...-12ecdd1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Config/types.go

Index

Constants

View Source
const (
	LogLevelAll     = "ALL"     // 显示所有级别日志
	LogLevelError   = "ERROR"   // 仅显示错误日志
	LogLevelBase    = "BASE"    // 仅显示信息日志
	LogLevelInfo    = "INFO"    // 仅显示信息日志
	LogLevelSuccess = "SUCCESS" // 仅显示成功日志
	LogLevelDebug   = "DEBUG"   // 仅显示调试日志
)

定义系统支持的日志级别常量

View Source
const (
	PluginTypeService = "service" // 服务类型插件
	PluginTypeWeb     = "web"     // Web类型插件
	PluginTypeLocal   = "local"   // 本地类型插件
)

在 Common/const.go 中添加 插件类型常量

View Source
const (
	LangZH = "zh" // 中文
	LangEN = "en" // 英文
	LangJA = "ja" // 日文
	LangRU = "ru" // 俄文
)

支持的语言类型

Variables

View Source
var (
	Outputfile   string // 输出文件路径
	OutputFormat string // 输出格式
)
View Source
var (
	// =========================================================
	// 扫描目标配置
	// =========================================================
	Ports        string   // 要扫描的端口列表,如"80,443,8080"
	ExcludePorts string   // 要排除的端口列表
	ExcludeHosts string   // 要排除的主机列表
	AddPorts     string   // 额外添加的端口列表
	HostPort     []string // 主机:端口格式的目标列表

	// =========================================================
	// 认证与凭据配置
	// =========================================================
	Username     string // 用于认证的用户名
	Password     string // 用于认证的密码
	AddUsers     string // 额外添加的用户名列表
	AddPasswords string // 额外添加的密码列表

	// 特定服务认证
	Domain     string   // Active Directory/SMB域名
	HashValue  string   // 用于哈希认证的单个哈希值
	HashValues []string // 哈希值列表
	HashBytes  [][]byte // 二进制格式的哈希值列表
	HashFile   string   // 包含哈希值的文件路径
	SshKeyPath string   // SSH私钥文件路径

	// =========================================================
	// 扫描控制配置
	// =========================================================
	ScanMode          string // 扫描模式或指定的插件列表
	ThreadNum         int    // 并发扫描线程数
	ModuleThreadNum   int    // 模块内部线程数
	Timeout           int64  // 单个扫描操作超时时间(秒)
	GlobalTimeout     int64  // 整体扫描超时时间(秒)
	LiveTop           int    // 显示的存活主机排名数量
	DisablePing       bool   // 是否禁用主机存活性检测
	UsePing           bool   // 是否使用ICMP Ping检测主机存活
	EnableFingerprint bool   // 是否跳过服务指纹识别
	LocalMode         bool   // 是否启用本地信息收集模式

	// =========================================================
	// 输入文件配置
	// =========================================================
	HostsFile     string // 包含目标主机的文件路径
	UsersFile     string // 包含用户名列表的文件路径
	PasswordsFile string // 包含密码列表的文件路径
	PortsFile     string // 包含端口列表的文件路径

	// =========================================================
	// Web扫描配置
	// =========================================================
	TargetURL   string   // 单个目标URL
	URLsFile    string   // 包含URL列表的文件路径
	URLs        []string // 解析后的URL目标列表
	WebTimeout  int64    // Web请求超时时间(秒),默认5秒
	HttpProxy   string   // HTTP代理地址
	Socks5Proxy string   // SOCKS5代理地址

	// =========================================================
	// POC与漏洞利用配置
	// =========================================================
	// POC配置
	PocPath       string  // POC脚本路径
	Pocinfo       PocInfo // POC详细信息结构
	EnablePocScan bool    //nopoc, default to true to disable POC scans

	// Redis利用
	RedisFile         string        // Redis利用目标文件
	RedisShell        string        // Redis反弹Shell命令
	DisableRedis      bool   = true // 是否禁用Redis利用测试,默认禁用
	RedisWritePath    string        // Redis文件写入路径
	RedisWriteContent string        // Redis文件写入内容
	RedisWriteFile    string        // Redis写入的源文件

	// 其他漏洞利用
	Shellcode string // 用于MS17010等漏洞利用的Shellcode

	// =========================================================
	// 暴力破解控制
	// =========================================================
	DisableBrute bool // 是否禁用暴力破解模块
	MaxRetries   int  // 连接失败最大重试次数

	// =========================================================
	// 输出与显示配置
	// =========================================================
	DisableSave   bool          // 是否禁止保存扫描结果
	Silent        bool          // 是否启用静默模式
	NoColor       bool          // 是否禁用彩色输出
	LogLevel      string        // Log output level
	DebugMode     bool          // Debug mode shortcut
	ShowProgress  bool          // 是否显示进度条
	ShowScanPlan  bool          // 是否显示扫描计划详情
	SlowLogOutput bool          // 是否启用慢速日志输出
	Language      string = "en" // 界面语言设置
	ApiAddr       string        // API地址
	SecretKey     string        // 加密密钥
)
View Source
var (
	UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
	Accept    = "" /* 135-byte string literal not displayed */
	DnsLog    bool
	PocNum    int
	PocFull   bool
	Cookie    string
)
View Source
var (

	// Num 表示待处理的总任务数量
	Num int64
	// End 表示已经完成的任务数量
	End int64
)

全局变量定义

View Source
var AllPorts = "1-65535"
View Source
var DbPorts = "1433,1521,3306,5432,5672,6379,7687,9042,9093,9200,11211,27017,61616"
View Source
var DefaultMap = []string{
	"GenericLines",
	"GetRequest",
	"TLSSessionReq",
	"SSLSessionReq",
	"ms-sql-s",
	"JavaRMI",
	"LDAPSearchReq",
	"LDAPBindReq",
	"oracle-tns",
	"Socks5",
}
View Source
var (
	ErrParseIP = errors.New(GetText("parse_ip_error")) // IP解析失败的统一错误
)

IP解析相关错误

View Source
var MainPorts = "" +

	"21,22,23,25,53,80,81,88,110,111,135,139,143,161,389,443,445,465,502,512,513,514,515,548,554,587,623,636,873,902,993,995," +

	"1080,1099,1194,1433,1434,1521,1522,1525,1723,1883," +

	"2049,2121,2181,2200,2222,2375,2376,2379,2380,3000,3128,3268,3269,3306,3389,3690," +

	"4369,4444,4848,5000,5005,5044,5060,5432,5601,5631,5632,5671,5672,5900,5984,5985,5986," +

	"6000,6379,6380,6443,6666,6667," +

	"7001,7002,7474,7687,8000,8005,8008,8009,8080,8081,8086,8088,8089,8090,8161,8180,8443,8500,8834,8848,8880,8888,9000,9001,9042,9080,9090,9092,9093,9160,9200,9300,9418,9443,9999," +

	"10000,10051,10250,10255,11211,15672,22222,26379,27017,27018,50000,50070,50075,61613,61614,61616"
View Source
var OutputMutex sync.Mutex

添加一个全局互斥锁来控制输出

View Source
var Passwords = []string{"123456", "admin", "admin123", "root", "", "pass123", "pass@123", "password", "Password", "P@ssword123", "123123", "654321", "111111", "123", "1", "admin@123", "Admin@123", "admin123!@#", "{user}", "{user}1", "{user}111", "{user}123", "{user}@123", "{user}_123", "{user}#123", "{user}@111", "{user}@2019", "{user}@123#4", "P@ssw0rd!", "P@ssw0rd", "Passw0rd", "qwe123", "12345678", "test", "test123", "123qwe", "123qwe!@#", "123456789", "123321", "666666", "a123456.", "123456~a", "123456!a", "000000", "1234567890", "8888888", "!QAZ2wsx", "1qaz2wsx", "abc123", "abc123456", "1qaz@WSX", "a11111", "a12345", "Aa1234", "Aa1234.", "Aa12345", "a123456", "a123123", "Aa123123", "Aa123456", "Aa12345.", "sysadmin", "system", "1qaz!QAZ", "2wsx@WSX", "qwe123!@#", "Aa123456!", "A123456s!", "sa123456", "1q2w3e", "Charge123", "Aa123456789", "elastic123"}
View Source
var PluginManager = make(map[string]ScanPlugin)

PluginManager 管理插件注册

View Source
var PortMap = map[int][]string{}/* 798 elements not displayed */

添加一个全局的进度条变量

View Source
var ServicePorts = "" /* 189-byte string literal not displayed */
View Source
var StartTime = time.Now()
View Source
var Userdict = map[string][]string{
	"ftp":        {"ftp", "admin", "www", "web", "root", "db", "wwwroot", "data"},
	"mysql":      {"root", "mysql"},
	"mssql":      {"sa", "sql"},
	"smb":        {"administrator", "admin", "guest"},
	"rdp":        {"administrator", "admin", "guest"},
	"postgresql": {"postgres", "admin"},
	"ssh":        {"root", "admin"},
	"mongodb":    {"root", "admin"},
	"oracle":     {"sys", "system", "admin", "test", "web", "orcl"},
	"telnet":     {"root", "admin", "test"},
	"elastic":    {"elastic", "admin", "kibana"},
	"rabbitmq":   {"guest", "admin", "administrator", "rabbit", "rabbitmq", "root"},
	"kafka":      {"admin", "kafka", "root", "test"},
	"activemq":   {"admin", "root", "activemq", "system", "user"},
	"ldap":       {"admin", "administrator", "root", "cn=admin", "cn=administrator", "cn=manager"},
	"smtp":       {"admin", "root", "postmaster", "mail", "smtp", "administrator"},
	"imap":       {"admin", "mail", "postmaster", "root", "user", "test"},
	"pop3":       {"admin", "root", "mail", "user", "test", "postmaster"},
	"zabbix":     {"Admin", "admin", "guest", "user"},
	"rsync":      {"rsync", "root", "admin", "backup"},
	"cassandra":  {"cassandra", "admin", "root", "system"},
	"neo4j":      {"neo4j", "admin", "root", "test"},
}
View Source
var WebPorts = "" /* 1044-byte string literal not displayed */

Functions

func Banner()

func CheckErrs

func CheckErrs(err error) error

CheckErrs 检查是否为需要重试的错误

func CloseOutput

func CloseOutput() error

CloseOutput 关闭输出系统

func Flag

func Flag(Info *HostInfo)

Flag 解析命令行参数并配置扫描选项

func FlagFromRemote

func FlagFromRemote(info *HostInfo, argString string) error

FlagFormRemote 解析远程扫描的命令行参数

func FormatHostPort

func FormatHostPort(host string, port int) string

FormatHostPort 根据IP版本格式化 host:port 字符串 IPv6使用 [host]:port 格式,IPv4使用 host:port 格式

func GetText

func GetText(key string, args ...interface{}) string

GetText 获取指定key的当前语言文本

func InitLogger

func InitLogger()

InitLogger 初始化日志系统

func InitOutput

func InitOutput() error

InitOutput 初始化输出系统

func IsIPv6

func IsIPv6(s string) bool

IsIPv6 检测字符串是否为IPv6地址 IPv6地址至少包含2个冒号(如 ::1, 2a0d:d6c0::1)

func LogBase

func LogBase(msg string)

LogBase 记录进度信息

func LogDebug

func LogDebug(msg string)

LogDebug 记录调试日志

func LogError

func LogError(errMsg string)

LogError 记录错误日志,自动包含文件名和行号信息

func LogInfo

func LogInfo(msg string)

LogInfo 记录信息日志 [*]

func LogSuccess

func LogSuccess(result string)

LogSuccess 记录成功日志,并更新最后成功时间 [+]

func Parse

func Parse(Info *HostInfo) error

Parse 配置解析的总入口函数 协调调用各解析子函数,完成完整的配置处理流程

func ParseIP

func ParseIP(host string, filename string, nohosts ...string) (hosts []string, err error)

ParseIP 解析各种格式的IP地址 参数:

  • host: 主机地址(可以是单个IP、IP范围、CIDR或常用网段简写)
  • filename: 包含主机地址的文件名
  • nohosts: 需要排除的主机地址列表

返回:

  • []string: 解析后的IP地址列表
  • error: 解析过程中的错误

func ParseInput

func ParseInput(Info *HostInfo) error

ParseInput 解析和验证输入参数配置 处理多种配置的冲突检查、格式验证和参数处理

func ParsePass

func ParsePass(Info *HostInfo) error

ParsePass 解析密码、URL、主机和端口等目标配置 处理多种输入源的配置,并更新全局目标信息

func ParsePort

func ParsePort(ports string) []int

ParsePort 解析端口配置字符串为端口号列表

func ParsePortsFromString

func ParsePortsFromString(portsStr string) []int

func ParseUser

func ParseUser() error

ParseUser 解析用户名配置 处理直接指定的用户名和从文件加载的用户名,更新全局用户字典

func ReadFileLines

func ReadFileLines(filename string) ([]string, error)

ReadFileLines 读取文件内容并返回非空行的切片 通用的文件读取函数,处理文件打开、读取和错误报告

func RegisterPlugin

func RegisterPlugin(name string, plugin ScanPlugin)

RegisterPlugin 注册插件

func RemoveDuplicate

func RemoveDuplicate(old []string) []string

RemoveDuplicate 对字符串切片进行去重

func SaveResult

func SaveResult(result *ScanResult) error

SaveResult 保存扫描结果

func SetLanguage

func SetLanguage()

func Socks5Dialer

func Socks5Dialer(forward *net.Dialer) (proxy.Dialer, error)

Socks5Dialer 创建Socks5代理拨号器

func WrapperTCP

func WrapperTCP(network, address string, forward *net.Dialer) (net.Conn, error)

WrapperTCP 根据配置创建TCP连接

func WrapperTcpWithTimeout

func WrapperTcpWithTimeout(network, address string, timeout time.Duration) (net.Conn, error)

WrapperTcpWithTimeout 创建一个带超时的TCP连接

Types

type HostInfo

type HostInfo struct {
	Host    string
	Ports   string
	Url     string
	Infostr []string
}

type LogEntry

type LogEntry struct {
	Level   string    // 日志级别: ERROR/INFO/SUCCESS/DEBUG
	Time    time.Time // 日志时间
	Content string    // 日志内容
}

LogEntry 定义单条日志的结构

type OutputManager

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

OutputManager 输出管理器结构体

var ResultOutput *OutputManager

全局输出管理器

type PocInfo

type PocInfo struct {
	Target  string
	PocName string
}

type ResultType

type ResultType string

ResultType 定义结果类型

const (
	HOST    ResultType = "HOST"    // 主机存活
	PORT    ResultType = "PORT"    // 端口开放
	SERVICE ResultType = "SERVICE" // 服务识别
	VULN    ResultType = "VULN"    // 漏洞发现
)

type ScanPlugin

type ScanPlugin struct {
	Name     string                // 插件名称
	Ports    []int                 // 适用端口
	Types    []string              // 插件类型标签,一个插件可以有多个类型
	ScanFunc func(*HostInfo) error // 扫描函数
}

ScanPlugin 定义扫描插件的结构

func (*ScanPlugin) HasPort

func (p *ScanPlugin) HasPort(port int) bool

HasPort 检查插件是否支持指定端口

func (ScanPlugin) HasType

func (p ScanPlugin) HasType(typeName string) bool

添加一个用于检查插件类型的辅助方法

type ScanResult

type ScanResult struct {
	Time    time.Time              `json:"time"`    // 发现时间
	Type    ResultType             `json:"type"`    // 结果类型
	Target  string                 `json:"target"`  // 目标(IP/域名/URL)
	Status  string                 `json:"status"`  // 状态描述
	Details map[string]interface{} `json:"details"` // 详细信息
}

ScanResult 扫描结果结构

func GetResults

func GetResults() ([]*ScanResult, error)

type ScanStatus

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

ScanStatus 用于记录和管理扫描状态的结构体

Jump to

Keyboard shortcuts

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