Documentation
¶
Overview ¶
Package gofofa fofa client in Go
env settings: - FOFA_CLIENT_URL full fofa connection string, format: <url>/?key=<key>&version=<v2> - FOFA_SERVER fofa server - FOFA_EMAIL optional legacy account email - FOFA_KEY fofa account key
Index ¶
- Constants
- Variables
- func Category(configFile, inputFile string, options ...CategoryOptions) (string, error)
- func ExtractIconFromHtml(data []byte) string
- func FofaURLFromEnv() string
- func IconHash(iconUrl string) (hash string, err error)
- func NewFixUrl(rowURL string) string
- func NewRequestConfig(fullURL string) *http.Client
- func ValidateFieldsAll(fields []string) error
- func ValidateFieldsNext(fields []string) error
- type AccountInfo
- type Cate
- type CategoryOptions
- type Client
- func (c *Client) AccountInfo() (ac AccountInfo, err error)
- func (c *Client) DumpSearch(query string, allSize int, batchSize int, fields []string, ...) (err error)
- func (c *Client) Fetch(apiURI string, params map[string]string, v interface{}) (err error)
- func (c *Client) GetContext() context.Context
- func (c *Client) HostSearch(query string, size int, fields []string, options ...SearchOptions) (res [][]string, err error)
- func (c *Client) HostSize(query string) (count int, err error)
- func (c *Client) HostStats(host string) (data HostStatsData, err error)
- func (c *Client) SetContext(ctx context.Context)
- func (c *Client) Stats(query string, size int, fields []string) (res []StatsObject, err error)
- func (c *Client) URL() string
- func (c *Client) Update(configURL string) error
- type ClientOption
- func WithAccountDebug(v bool) ClientOption
- func WithLogger(logger *logrus.Logger) ClientOption
- func WithOnResults(onResults func(results [][]string)) ClientOption
- func WithRateLimitRetry(maxRetries int, retryDelay time.Duration) ClientOption
- func WithSharedRateLimit(enabled bool) ClientOption
- func WithURL(configURL string) ClientOption
- type Config
- type CusFields
- type DeductMode
- type HostResults
- type HostStatsData
- type HttpResponse
- type SearchOptions
- type StatsItem
- type StatsObject
- type StatsResults
- type VipLevel
- type WorkerBrowser
Constants ¶
const (
NoHostWithFixURL = "host field must included when fixUrl option set"
)
Variables ¶
var ValidFieldsAll = map[string]bool{ "ip": true, "port": true, "protocol": true, "country": true, "country_name": true, "region": true, "city": true, "longitude": true, "latitude": true, "asn": true, "org": true, "host": true, "domain": true, "os": true, "server": true, "icp": true, "title": true, "jarm": true, "header": true, "banner": true, "cert": true, "base_protocol": true, "link": true, "cert.issuer.org": true, "cert.issuer.cn": true, "cert.subject.org": true, "cert.subject.cn": true, "tls.ja3s": true, "tls.version": true, "cert.sn": true, "cert.not_before": true, "cert.not_after": true, "cert.domain": true, "header_hash": true, "banner_hash": true, "banner_fid": true, "cname": true, "lastupdatetime": true, "product": true, "product_category": true, "product.version": true, "icon_hash": true, "cert.is_valid": true, "cname_domain": true, "body": true, "cert.is_match": true, "cert.is_equal": true, "icon": true, "fid": true, "structinfo": true, }
ValidFieldsAll is the whitelist of fields for the /search/all API endpoint. Based on https://fofa.info/api
var ValidFieldsNext = map[string]bool{ "ip": true, "port": true, "protocol": true, "country": true, "country_name": true, "region": true, "city": true, "longitude": true, "latitude": true, "asn": true, "org": true, "host": true, "domain": true, "os": true, "server": true, "icp": true, "title": true, "jarm": true, "header": true, "banner": true, "cert": true, "base_protocol": true, "link": true, "cert.issuer.org": true, "cert.issuer.cn": true, "cert.subject.org": true, "cert.subject.cn": true, "tls.ja3s": true, "tls.version": true, "cert.sn": true, "cert.not_before": true, "cert.not_after": true, "cert.domain": true, "header_hash": true, "banner_hash": true, "banner_fid": true, "cname": true, "lastupdatetime": true, "product": true, "product_category": true, "product.version": true, "icon_hash": true, "cert.is_valid": true, "cname_domain": true, "body": true, "cert.is_match": true, "cert.is_equal": true, "icon": true, "fid": true, "structinfo": true, }
ValidFieldsNext is the whitelist of fields for the /search/next API endpoint. Based on https://fofa.info/api/batches_pages
Functions ¶
func Category ¶
func Category(configFile, inputFile string, options ...CategoryOptions) (string, error)
func ExtractIconFromHtml ¶
ExtractIconFromHtml extract link icon from html
func FofaURLFromEnv ¶
func FofaURLFromEnv() string
FofaURLFromEnv parse fofa connection url from env, then generate url string
func IconHash ¶
IconHash if url is a local icon file, then calc the hash if url is remote icon url, the download and calc the hash if url is web homepage, then try to parse favicon url and download it, then calc the hash
func NewRequestConfig ¶
func ValidateFieldsAll ¶ added in v0.2.29
ValidateFieldsAll checks that all fields are in the ValidFieldsAll whitelist. Returns an error immediately if an unsupported field is detected.
func ValidateFieldsNext ¶ added in v0.2.29
ValidateFieldsNext checks that all fields are in the ValidFieldsNext whitelist. Returns an error immediately if an unsupported field is detected.
Types ¶
type AccountInfo ¶
type AccountInfo struct {
Error bool `json:"error"` // error or not
ErrMsg string `json:"errmsg,omitempty"` // error string message
FCoin int `json:"fcoin"` // fcoin count
FofaPoint int64 `json:"fofa_point"` // fofa point
IsVIP bool `json:"isvip"` // is vip
VIPLevel VipLevel `json:"vip_level"` // vip level
RemainApiQuery int `json:"remain_api_query"` // available query
RemainApiData int `json:"remain_api_data"` // available data amount
}
AccountInfo fofa account info
func (AccountInfo) String ¶
func (ai AccountInfo) String() string
type CategoryOptions ¶
type Client ¶
type Client struct {
Server string // can set local server for debugging, format: <scheme>://<host>
APIVersion string // api version
Email string // fofa email
Key string // fofa key
Account AccountInfo // fofa account info
DeductMode DeductMode // Deduct Mode
// contains filtered or unexported fields
}
Client of fofa connection
func NewClient ¶
func NewClient(options ...ClientOption) (*Client, error)
NewClient from fofa connection string to config and with env config merge
func (*Client) AccountInfo ¶
func (c *Client) AccountInfo() (ac AccountInfo, err error)
AccountInfo fetch account info from fofa
func (*Client) DumpSearch ¶
func (c *Client) DumpSearch(query string, allSize int, batchSize int, fields []string, onResults func([][]string, int) error, options ...SearchOptions) (err error)
DumpSearch search fofa host data query fofa query string size data size: -1 means all,0 means just data total info, >0 means actual size fields of fofa host search options for search
func (*Client) GetContext ¶
GetContext 获取context,用于中止任务
func (*Client) HostSearch ¶
func (c *Client) HostSearch(query string, size int, fields []string, options ...SearchOptions) (res [][]string, err error)
HostSearch search fofa host data query fofa query string size data size: -1 means all,0 means just data total info, >0 means actual size fields of fofa host search options for search
func (*Client) HostStats ¶
func (c *Client) HostStats(host string) (data HostStatsData, err error)
HostStats fetch query matched host count
func (*Client) SetContext ¶
SetContext 设置context,用于中止任务
type ClientOption ¶
func WithAccountDebug ¶
func WithAccountDebug(v bool) ClientOption
WithAccountDebug 是否错误里面显示账号密码原始信息
func WithOnResults ¶
func WithOnResults(onResults func(results [][]string)) ClientOption
WithOnResults set on results callback
func WithRateLimitRetry ¶ added in v0.2.29
func WithRateLimitRetry(maxRetries int, retryDelay time.Duration) ClientOption
WithRateLimitRetry configures retries for FOFA rate-limit responses. maxRetries is the number of attempts after the initial request.
func WithSharedRateLimit ¶ added in v0.2.29
func WithSharedRateLimit(enabled bool) ClientOption
WithSharedRateLimit enables a process-shared query rate limit for CLI-style clients. The state file contains only the next send time, not credentials.
func WithURL ¶
func WithURL(configURL string) ClientOption
WithURL configURL format: <url>/?key=<key>&version=<v2>&tlsdisabled=false&debuglevel=0 The legacy email parameter is optional.
type Config ¶ added in v0.2.27
type Config struct {
Categories []Cate `yaml:"categories"`
CustomFields []CusFields `yaml:"custom_fields"`
}
func LoadConfig ¶ added in v0.2.27
type DeductMode ¶
type DeductMode int
DeductMode should deduct fcoin automatically or just use free limit
const ( // DeductModeFree only use free limit size DeductModeFree DeductMode = 0 // DeductModeFCoin deduct fcoin automatically if account has fcoin DeductModeFCoin DeductMode = 1 )
func ParseDeductMode ¶
func ParseDeductMode(v string) DeductMode
ParseDeductMode parse string to DeductMode
type HostResults ¶
type HostResults struct {
Mode string `json:"mode"`
Error bool `json:"error"`
Errmsg string `json:"errmsg"`
Query string `json:"query"`
Page int `json:"page"`
Size int `json:"size"` // 总数
Results interface{} `json:"results"`
Next string `json:"next"`
}
HostResults /search/all api results
type HostStatsData ¶
type HostStatsData struct {
Error bool `json:"error"`
Errmsg string `json:"errmsg"`
Host string `json:"host"`
IP string `json:"ip"`
ASN int `json:"asn"`
ORG string `json:"org"`
Country string `json:"country_name"`
CountryCode string `json:"country_code"`
Protocols []string `json:"protocol"`
Ports []int `json:"port"`
Categories []string `json:"category"`
Products []string `json:"product"`
UpdateTime string `json:"update_time"`
}
HostStatsData /host api results
type HttpResponse ¶
func DoHttpCheck ¶
func DoHttpCheck(rowURL string, retry int) HttpResponse
type SearchOptions ¶
type SearchOptions struct {
FixUrl bool // each host fix as url, like 1.1.1.1,80 will change to http://1.1.1.1, https://1.1.1.1:8443 will no change
UrlPrefix string // default is http://
Full bool // search result for over a year
UniqByIP bool // uniq by ip
CheckActive int // probe website is existed, add isActive field
DeWildcard int // number of wildcard domains retained
Filter string // filter data by rules
DedupHost bool // prioritize subdomain data retention
}
SearchOptions options of search, for post processors
type StatsObject ¶
StatsObject one stats object
type StatsResults ¶
type StatsResults struct {
Error bool `json:"error"`
Errmsg string `json:"errmsg"`
Distinct map[string]interface{} `json:"distinct"`
Aggs map[string]interface{} `json:"aggs"`
LastUpdateTime string `json:"lastupdatetime"`
}
StatsResults /search/stats api results
type WorkerBrowser ¶
func NewWorkerBrowser ¶
func NewWorkerBrowser(url string, retry int) *WorkerBrowser
func (*WorkerBrowser) ParseHTML ¶
func (wp *WorkerBrowser) ParseHTML(htmlStr string, tag string) string
func (*WorkerBrowser) Run ¶
func (wp *WorkerBrowser) Run() (response map[string]interface{}, err error)