summaryrefslogtreecommitdiffstats
path: root/internal/client/osint.go
blob: 95e3550686931540b9e5fd2c2ca43d0308967fde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package client

import (
	"encoding/json"
	"fmt"
	"git.db.org.ai/dborg/internal/models"
	"net/url"
)

func (c *Client) LookupBSSID(params *models.BSSIDParams) (*models.BSSIDLookupResponse, error) {
	path := fmt.Sprintf("/osint/bssid/%s", url.PathEscape(params.BSSID))

	queryParams := url.Values{}
	if params.All {
		queryParams.Add("all", "true")
	}
	if params.Google {
		queryParams.Add("google", "true")
	}
	if params.OSM {
		queryParams.Add("osm", "true")
	}

	data, err := c.Get(path, queryParams)
	if err != nil {
		return nil, err
	}

	var response models.BSSIDLookupResponse
	if err := json.Unmarshal(data, &response); err != nil {
		return nil, fmt.Errorf("failed to parse BSSID lookup response: %w", err)
	}

	return &response, nil
}

func (c *Client) SearchBreachForum(params *models.BreachForumSearchParams) (*models.BreachForumSearchResponse, error) {
	path := "/osint/breachforum/search"

	queryParams := url.Values{}
	queryParams.Add("search", params.Search)
	if params.MaxHits > 0 {
		queryParams.Add("max_hits", fmt.Sprintf("%d", params.MaxHits))
	}

	data, err := c.Get(path, queryParams)
	if err != nil {
		return nil, err
	}

	var response models.BreachForumSearchResponse
	if err := json.Unmarshal(data, &response); err != nil {
		return nil, fmt.Errorf("failed to parse BreachForum search response: %w", err)
	}

	return &response, nil
}

func (c *Client) SearchOpenDirectoryFiles(params *models.OpenDirectorySearchParams) (*models.OpenDirectorySearchResponse, error) {
	path := fmt.Sprintf("/osint/files/%s", url.PathEscape(params.URL))

	queryParams := url.Values{}
	if params.Filename != "" {
		queryParams.Add("filename", params.Filename)
	}
	if params.Extension != "" {
		queryParams.Add("extension", params.Extension)
	}
	if params.Exclude != "" {
		queryParams.Add("exclude", params.Exclude)
	}
	if params.Size > 0 {
		queryParams.Add("size", fmt.Sprintf("%d", params.Size))
	}
	if params.From > 0 {
		queryParams.Add("from", fmt.Sprintf("%d", params.From))
	}

	data, err := c.Get(path, queryParams)
	if err != nil {
		return nil, err
	}

	var response models.OpenDirectorySearchResponse
	if err := json.Unmarshal(data, &response); err != nil {
		return nil, fmt.Errorf("failed to parse open directory search response: %w", err)
	}

	return &response, nil
}