-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.go
73 lines (61 loc) · 2.25 KB
/
lookup.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
65
66
67
68
69
70
71
72
73
package commands
import (
"fmt"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/malice-plugins/pkgs/database/elasticsearch"
"github.com/malice-plugins/pkgs/utils"
"github.com/maliceio/malice/config"
"github.com/maliceio/malice/malice/database"
"github.com/maliceio/malice/malice/docker/client"
"github.com/maliceio/malice/malice/docker/client/container"
"github.com/maliceio/malice/plugins"
"github.com/pkg/errors"
)
func cmdLookUp(hash string, logs bool) error {
docker := client.NewDockerClient()
elasticsearchInDocker := false
es := elasticsearch.Database{
Index: utils.Getopt("MALICE_ELASTICSEARCH_INDEX", "malice"),
Type: utils.Getopt("MALICE_ELASTICSEARCH_TYPE", "samples"),
URL: utils.Getopt("MALICE_ELASTICSEARCH_URL", config.Conf.DB.URL),
Username: utils.Getopt("MALICE_ELASTICSEARCH_USERNAME", config.Conf.DB.Username),
Password: utils.Getopt("MALICE_ELASTICSEARCH_PASSWORD", config.Conf.DB.Password),
}
// This assumes you haven't set up an elasticsearch instance and that malice should create one
if strings.EqualFold(es.URL, "http://localhost:9200") {
elasticsearchInDocker = true
// Check that database is running
if _, running, _ := container.Running(docker, config.Conf.DB.Name); !running {
log.Error("database is NOT running, starting now...")
err := database.Start(docker, es, logs)
if err != nil {
return errors.Wrap(err, "failed to start to database")
}
}
}
// Initialize the malice database
es.Init()
if plugins.InstalledPluginsCheck(docker) {
log.Debug("All enabled plugins are installed.")
} else {
// Prompt user to install all plugins?
fmt.Println("All enabled plugins not installed would you like to install them now? (yes/no)")
fmt.Println("[Warning] This can take a while if it is the first time you have ran Malice.")
if utils.AskForConfirmation() {
plugins.UpdateAllPlugins(docker)
}
}
/////////////////////////////
// Write hash to the Database
resp, err := es.StoreHash(hash)
if err != nil {
return errors.Wrap(err, "cmd lookup failed to store hash")
}
plugins.RunIntelPlugins(docker, hash, resp.Id, true, elasticsearchInDocker)
return nil
}
// APILookUp is an API wrapper for cmdLookUp
func APILookUp(hash string) error {
return cmdLookUp(hash, false)
}