forked from by2waysprojects/shellcode-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploit_db_service.go
64 lines (49 loc) Β· 1.58 KB
/
exploit_db_service.go
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
package services
import (
"fmt"
"io"
"net/http"
"shellcode-db/model"
services "shellcode-db/services/model"
"github.com/gocarina/gocsv"
)
type APIService struct{}
func NewExploitDbService() *APIService {
return &APIService{}
}
func (api *APIService) FetchArchitectures() ([]model.Architecture, error) {
url := "https://gitlab.com/exploit-database/exploitdb/-/raw/main/files_shellcodes.csv"
response, err := http.Get(url)
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode)
}
var shellcodesExploitDB []services.Shellcode
body, _ := io.ReadAll(response.Body)
if err := gocsv.UnmarshalBytes(body, &shellcodesExploitDB); err != nil {
return nil, err
}
var shellcodes []model.Architecture
mapArchitectureShell := map[string][]model.Shellcode{}
for _, shell := range shellcodesExploitDB {
fileUrl := fmt.Sprintf("https://gitlab.com/exploit-database/exploitdb/-/raw/main/%s", shell.File)
response, err := http.Get(fileUrl)
if err != nil {
continue
}
if response.StatusCode != http.StatusOK {
continue
}
body, _ := io.ReadAll(response.Body)
response.Body.Close()
mapArchitectureShell[shell.Platform] = append(mapArchitectureShell[shell.Platform],
model.Shellcode{ID: shell.Id, Name: shell.Description, DatePublished: shell.DatePublished, Data: string(body)})
}
for key, value := range mapArchitectureShell {
shellcodes = append(shellcodes, model.Architecture{ID: key, Name: key, Shellcodes: value})
}
return shellcodes, nil
}