-
Notifications
You must be signed in to change notification settings - Fork 0
/
ioc_converter_stix.go
62 lines (54 loc) · 1.31 KB
/
ioc_converter_stix.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
// tie-threatbus-bridge
// Copyright (c) 2021, DCSO GmbH
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/TcM1911/stix2"
)
func mapTIEtoSTIX2(iocType string) (string, error) {
switch iocType {
case "DomainName":
return "[domain-name:value = '%s']", nil
case "URLVerbatim":
return "[url:value = '%s']", nil
case "IPv4":
return "[ipv4-addr:value = '%s']", nil
case "IPv6":
return "[ipv6-addr:value = '%s']", nil
case "FileName":
return "[file:name = '%s']", nil
case "EMail":
return "[email-addr:value = '%s']", nil
default:
return "", fmt.Errorf("unsupported data type: %s", iocType)
}
}
type IOCConverterSTIX2 struct{}
func MakeIOCConverterSTIX2() *IOCConverterSTIX2 {
return &IOCConverterSTIX2{}
}
func (c *IOCConverterSTIX2) Topic() string {
return "stix2/indicator"
}
func (c *IOCConverterSTIX2) FromIOC(ioc *IOC) ([]byte, error) {
t, err := mapTIEtoSTIX2(ioc.DataType)
if err != nil {
return nil, err
}
tsNow := &stix2.Timestamp{
Time: time.Now().UTC(),
}
i, err := stix2.NewIndicator(fmt.Sprintf(t, ioc.Value), "stix", tsNow,
stix2.OptionCreated(tsNow), stix2.OptionModified(tsNow))
if err != nil {
return nil, err
}
i.Types = append(i.Types, stix2.IndicatorTypeMaliciousActivity)
data, err := json.Marshal(i)
if err != nil {
return nil, err
}
return data, nil
}