hackcheck

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MIT Imports: 10 Imported by: 0

README

HackCheck-go

GoDoc

Official go library for the hackcheck.io API

Installation

go get -u github.com/hackcheckio/hackcheck-go

Quick start

Example usage

import (
	"fmt"

	"github.com/hackcheckio/hackcheck-go"
)

func main() {
	hc := hackcheck.New("MY_API_KEY")

	resp, err := hc.Search(
		&SearchOptions{
			Field: hackcheck.SearchFieldEmail,
			Query: "example@example.com",
		},
	)

	if err != nil {
		panic(err)
	}

	fmt.Println(resp.Results)
}

Getting your api key

  1. Visit https://hackcheck.io/profile
  2. Add your IP address in the "Authorized IP Addresses" text area and click Update
  3. Copy your API key

Other examples

Breach Monitors
import (
	"fmt"

	"github.com/hackcheckio/hackcheck-go"
)

func main() {
	hc := hackcheck.New("MY_API_KEY")

	// Listing breach monitors
	monitors, err := hc.GetMonitors()
	if err != nil {
		panic(err)
	}


	fmt.Println(monitors.AssetMonitors)
	fmt.Println(monitors.DomainMonitors)

	// Getting a monitor
	myAssetMonitor, err := hc.GetAssetMonitor("...") // or hc.GetDomainMonitor
	if err != nil {
		panic(err)
	}

	fmt.Println(myAssetMonitor.Status)
	fmt.Println(myAssetMonitor.Asset)

	// Updating a monitor
	domainMonitor, err := hc.UpdateDomainMonitor("id123123123", &hackcheck.UpdateDomainMonitorParams{
		Domain: "example.com",
		NotificationEmail: "notifications@example.com",
	})
	if err != nil {
		panic(err)
	}

	fmt.Println(domainMonitor.Domain)
}
Filtering databases
import (
	"fmt"

	"github.com/hackcheckio/hackcheck-go"
)

func main() {
	hc := hackcheck.New("MY_API_KEY")

	// This will only yield results from "website.com" and "website.org"
	// Use hackcheck.SearchFilterTypeIgnore if you want to ignore the databases
	resp, err := hc.Search(
		&SearchOptions{
			Field: hackcheck.SearchFieldEmail,
			Query: "example@example.com",
			Filter: &SearchFilterOptions{
				Type: hackcheck.SearchFilterTypeUse,
				Databases: []string{"website.com", "website.org"},
			},
		},
	)

	if err != nil {
		panic(err)
	}

	fmt.Println(resp.Results)
}
Checking if a query exists
import (
	"fmt"

	"github.com/hackcheckio/hackcheck-go"
)

func main() {
	hc := hackcheck.New("MY_API_KEY")

	// Returns true if the query is found
	exists, err := hc.Check(
		&CheckOptions{
			Field: hackcheck.SearchFieldEmail,
			Query: "example@example.com",
		},
	)

	if err != nil {
		panic(err)
	}

	fmt.Println(exists)
}
Custom http client & context
import (
	"fmt"

	"github.com/hackcheckio/hackcheck-go"
)

func main() {
	customCtx := context.Background()
	customHttpClient := &http.Client{}

	hc := hackcheck.New("MY_API_KEY", hackcheck.WithContext(customCtx), hackcheck.WithHTTP(customHttpClient))
	// ...
}

Documentation

Index

Constants

View Source
const (
	MonitorStatusRunning = iota
	MonitorStatusPaused
	MonitorStatusExpired
)
View Source
const (
	SearchFilterTypeUse    = "use"
	SearchFilterTypeIgnore = "ignore"
)

Variables

View Source
var (
	EndpointBase = "https://api.hackcheck.io/"

	EndpointSearch = func(apiKey, field, query string) string {
		return EndpointBase + "search/" + apiKey + "/" + field + "/" + query
	}
	EndpointCheck = func(apiKey, field, query string) string {
		return EndpointBase + "search/check/" + apiKey + "/" + field + "/" + query
	}

	EndpointGetMonitors = func(apiKey string) string {
		return EndpointBase + "monitors/" + apiKey + "/list"
	}
	EndpointGetAssetMonitor = func(apiKey, monitorID string) string {
		return EndpointBase + "monitors/" + apiKey + "/list/asset/" + monitorID
	}
	EndpointGetDomainMonitor = func(apiKey, monitorID string) string {
		return EndpointBase + "monitors/" + apiKey + "/list/domain/" + monitorID
	}

	EndpointGetAssetMonitorSources = func(apiKey, monitorID string) string {
		return EndpointBase + "monitors/" + apiKey + "/sources/asset/" + monitorID
	}
	EndpointGetDomainMonitorSources = func(apiKey, monitorID string) string {
		return EndpointBase + "monitors/" + apiKey + "/sources/domain/" + monitorID
	}

	EndpointUpdateAssetMonitor = func(apiKey, monitorID string) string {
		return EndpointBase + "monitors/" + apiKey + "/update/asset/" + monitorID
	}
	EndpointUpdateDomainMonitor = func(apiKey, monitorID string) string {
		return EndpointBase + "monitors/" + apiKey + "/update/domain/" + monitorID
	}

	EndpointTogglePauseAssetMonitor = func(apiKey, monitorID string) string {
		return EndpointBase + "monitors/" + apiKey + "/pause/asset/" + monitorID
	}
	EndpointTogglePauseDomainMonitor = func(apiKey, monitorID string) string {
		return EndpointBase + "monitors/" + apiKey + "/pause/domain/" + monitorID
	}
)
View Source
var (
	ErrUnauthorizedIPAddress = errors.New("unauthorized ip address")
	ErrInvalidAPIKey         = errors.New("invalid api key")

	ErrServerError = errors.New("server returned an error")
)

Functions

func WithContext

func WithContext(ctx context.Context) func(hc *HackCheckClient)

WithHttp will set the HackCheckClients context

func WithHTTP

func WithHTTP(client *http.Client) func(hc *HackCheckClient)

WithHttp will set the HackCheckClients http client

Types

type AssetMonitor

type AssetMonitor struct {
	ID                string        `json:"id"`
	Status            MonitorStatus `json:"status"`
	Type              SearchField   `json:"type"`
	Asset             string        `json:"asset"`
	NotificationEmail string        `json:"notification_email"`
	ExpiresSoon       bool          `json:"expires_soon"`
	CreatedAt         time.Time     `json:"created_at"`
	EndsAt            time.Time     `json:"ends_at"`
}

type CheckOptions

type CheckOptions struct {
	Field SearchField
	Query string
}

type CheckResponse

type CheckResponse struct {
	Found bool `json:"found"`
}

type DomainMonitor

type DomainMonitor struct {
	ID                string        `json:"id"`
	Status            MonitorStatus `json:"status"`
	Domain            string        `json:"domain"`
	NotificationEmail string        `json:"notification_email"`
	ExpiresSoon       bool          `json:"expires_soon"`
	CreatedAt         time.Time     `json:"created_at"`
	EndsAt            time.Time     `json:"ends_at"`
}

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type GetMonitorsResponse

type GetMonitorsResponse struct {
	AssetMonitors  []AssetMonitor  `json:"asset_monitors"`
	DomainMonitors []DomainMonitor `json:"domain_monitors"`
}

type HackCheckClient

type HackCheckClient struct {
	Apikey string
	// contains filtered or unexported fields
}

func New

func New(apikey string, options ...HackCheckClientOption) *HackCheckClient

func (*HackCheckClient) Check

func (h *HackCheckClient) Check(options *CheckOptions) (bool, error)

func (*HackCheckClient) GetAssetMonitor

func (h *HackCheckClient) GetAssetMonitor(monitorID string) (*AssetMonitor, error)

func (*HackCheckClient) GetAssetMonitorSources

func (h *HackCheckClient) GetAssetMonitorSources(monitorID string) ([]Source, error)

func (*HackCheckClient) GetDomainMonitor

func (h *HackCheckClient) GetDomainMonitor(monitorID string) (*DomainMonitor, error)

func (*HackCheckClient) GetDomainMonitorSources

func (h *HackCheckClient) GetDomainMonitorSources(monitorID string) ([]Source, error)

func (*HackCheckClient) GetMonitors

func (h *HackCheckClient) GetMonitors() (*GetMonitorsResponse, error)

func (*HackCheckClient) Search

func (h *HackCheckClient) Search(options *SearchOptions) (*SearchResponse, error)

func (*HackCheckClient) TogglePauseAssetMonitor

func (h *HackCheckClient) TogglePauseAssetMonitor(monitorID string) (*AssetMonitor, error)

func (*HackCheckClient) TogglePauseDomainMonitor

func (h *HackCheckClient) TogglePauseDomainMonitor(monitorID string) (*DomainMonitor, error)

func (*HackCheckClient) UpdateAssetMonitor

func (h *HackCheckClient) UpdateAssetMonitor(monitorID string, updateParams *UpdateAssetMonitorParams) (*AssetMonitor, error)

func (*HackCheckClient) UpdateDomainMonitor

func (h *HackCheckClient) UpdateDomainMonitor(monitorID string, updateParams *UpdateDomainMonitorParams) (*DomainMonitor, error)

type HackCheckClientOption

type HackCheckClientOption func(*HackCheckClient)

type MonitorStatus

type MonitorStatus int

type RateLimitError

type RateLimitError struct {
	Limit             int
	RemainingRequests int
	// contains filtered or unexported fields
}

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type SearchField

type SearchField = string
const (
	SearchFieldEmail       SearchField = "email"
	SearchFieldUsername    SearchField = "username"
	SearchFieldFullName    SearchField = "full_name"
	SearchFieldPassword    SearchField = "password"
	SearchFieldIPAddress   SearchField = "ip_address"
	SearchFieldPhoneNumber SearchField = "phone_number"
	SearchFieldDomain      SearchField = "domain"
	SearchFieldHash        SearchField = "hash"
)

type SearchFilterOptions

type SearchFilterOptions struct {
	Type      SearchFilterType
	Databases []string
}

type SearchFilterType

type SearchFilterType = string

type SearchOptions

type SearchOptions struct {
	Field      SearchField
	Query      string
	Filter     *SearchFilterOptions
	Pagination *SearchPaginationOptions
}

type SearchPaginationOptions

type SearchPaginationOptions struct {
	Offset int
	Limit  int
}

type SearchResponse

type SearchResponse struct {
	Databases  int                       `json:"databases"`
	FirstSeen  string                    `json:"first_seen"`
	LastSeen   string                    `json:"last_seen"`
	Results    []SearchResult            `json:"results"`
	Pagination *SearchResponsePagination `json:"pagination"`
}

type SearchResponsePagination

type SearchResponsePagination struct {
	DocumentCount int `json:"document_count"`
	Next          *struct {
		Offset int `json:"offset"`
		Limit  int `json:"limit"`
	} `json:"next"`
	Prev *struct {
		Offset int `json:"offset"`
		Limit  int `json:"limit"`
	} `json:"prev"`
}

type SearchResult

type SearchResult struct {
	Email       string `json:"email"`
	Password    string `json:"password"`
	Username    string `json:"username"`
	FullName    string `json:"full_name"`
	IPAddress   string `json:"ip_address"`
	PhoneNumber string `json:"phone_number"`
	Hash        string `json:"hash"`
	Source      Source `json:"source"`
}

type Source

type Source struct {
	Name string `json:"name"`
	Date string `json:"date"`
}

type UpdateAssetMonitorParams

type UpdateAssetMonitorParams struct {
	Asset             string `json:"asset"`
	Type              string `json:"asset_type"`
	NotificationEmail string `json:"notification_email"`
}

type UpdateDomainMonitorParams

type UpdateDomainMonitorParams struct {
	Domain            string
	NotificationEmail string `json:"notification_email"`
}

Jump to

Keyboard shortcuts

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