2020-01-14 09:43:12 +01:00
|
|
|
package main
|
|
|
|
|
2020-01-14 14:49:14 +01:00
|
|
|
import (
|
2020-01-30 17:43:10 +01:00
|
|
|
"os"
|
|
|
|
"sync"
|
2020-01-15 16:46:13 +01:00
|
|
|
|
2020-01-16 15:56:57 +01:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-02-10 16:11:25 +01:00
|
|
|
"github.com/spf13/viper"
|
2020-07-06 12:14:59 +02:00
|
|
|
"gitlab.dcso.lolcat/LABS/styx/broker"
|
2020-03-02 17:06:28 +01:00
|
|
|
"gitlab.dcso.lolcat/LABS/styx/graph"
|
2020-05-27 12:05:53 +02:00
|
|
|
"gitlab.dcso.lolcat/LABS/styx/matcher"
|
2020-02-25 10:05:31 +01:00
|
|
|
"gitlab.dcso.lolcat/LABS/styx/plugins"
|
2020-01-14 14:49:14 +01:00
|
|
|
)
|
|
|
|
|
2020-02-07 14:52:29 +01:00
|
|
|
func init() {
|
|
|
|
// Setting up logging.
|
|
|
|
logrus.SetFormatter(&logrus.TextFormatter{
|
|
|
|
FullTimestamp: true,
|
|
|
|
})
|
|
|
|
logrus.SetReportCaller(true)
|
2020-02-10 16:11:25 +01:00
|
|
|
viper.SetConfigName("config")
|
|
|
|
viper.SetConfigType("yaml")
|
|
|
|
viper.AddConfigPath(".")
|
2020-02-07 14:52:29 +01:00
|
|
|
}
|
|
|
|
|
2020-01-14 09:43:12 +01:00
|
|
|
func main() {
|
2020-02-10 16:11:25 +01:00
|
|
|
err := viper.ReadInConfig()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Setenv("SHODAN_KEY", viper.GetString("shodan.key"))
|
2020-03-02 17:06:28 +01:00
|
|
|
logrus.Info("Starting to get data from the Internet...")
|
2020-02-06 17:01:37 +01:00
|
|
|
|
2020-07-06 12:14:59 +02:00
|
|
|
logrus.Info("Initializing Kafka...")
|
|
|
|
_, err = broker.SetUpKafkaConnecter()
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithField("err", err).Error("error initialising kafka")
|
|
|
|
}
|
|
|
|
logrus.Info("done")
|
2020-01-30 17:43:10 +01:00
|
|
|
|
2020-06-08 10:49:19 +02:00
|
|
|
logrus.Info("Initializing Dgraph...")
|
2020-03-04 15:16:59 +01:00
|
|
|
dgraphClient, err := graph.ConnectToDgraph()
|
2020-03-02 16:27:51 +01:00
|
|
|
if err != nil {
|
|
|
|
logrus.WithField("err", err).Error("error initialising the graph database")
|
|
|
|
}
|
2020-06-08 10:49:19 +02:00
|
|
|
logrus.Info("done")
|
2020-03-02 16:27:51 +01:00
|
|
|
|
2020-01-30 17:43:10 +01:00
|
|
|
// stop channel
|
|
|
|
stopChan := make(chan os.Signal)
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
2020-02-25 10:05:31 +01:00
|
|
|
// go broker.ReadEventFromKafka()
|
2020-02-04 10:35:18 +01:00
|
|
|
|
2020-01-29 11:05:05 +01:00
|
|
|
// certstream
|
2020-02-25 10:05:31 +01:00
|
|
|
c := plugins.CertStreamPlugin{}
|
|
|
|
if ok := c.Initialize(); !ok {
|
2020-03-02 17:06:28 +01:00
|
|
|
logrus.Info("certstream plugin not activated")
|
2020-03-19 09:27:15 +01:00
|
|
|
} else {
|
|
|
|
c.Run(&wg, dgraphClient)
|
2020-02-14 11:36:47 +01:00
|
|
|
}
|
2020-01-29 11:05:05 +01:00
|
|
|
|
2020-02-07 17:39:33 +01:00
|
|
|
// pastebin
|
2020-02-25 10:05:31 +01:00
|
|
|
p := plugins.PastebinPlugin{}
|
|
|
|
if ok := p.Initialize(); !ok {
|
2020-03-02 17:06:28 +01:00
|
|
|
logrus.Info("pastebin plugin not activated")
|
2020-03-19 09:27:15 +01:00
|
|
|
} else {
|
2020-05-19 10:10:42 +02:00
|
|
|
p.Run(&wg, dgraphClient)
|
2020-02-14 11:36:47 +01:00
|
|
|
}
|
2020-02-05 14:46:52 +01:00
|
|
|
|
|
|
|
// shodan
|
2020-02-25 10:05:31 +01:00
|
|
|
s := plugins.ShodanPlugin{}
|
|
|
|
if ok := s.Initialize(); !ok {
|
2020-03-02 16:27:51 +01:00
|
|
|
logrus.Info("shodan plugin not activated")
|
2020-03-19 09:27:15 +01:00
|
|
|
} else {
|
2020-05-18 16:09:04 +02:00
|
|
|
s.Run(&wg, dgraphClient)
|
2020-02-06 17:01:37 +01:00
|
|
|
}
|
2020-02-05 14:46:52 +01:00
|
|
|
|
2020-05-27 12:05:53 +02:00
|
|
|
// main matcher
|
|
|
|
m := matcher.Matcher{}
|
|
|
|
if ok := m.Initialize(); !ok {
|
|
|
|
logrus.Info("matcher is not activated")
|
|
|
|
} else {
|
|
|
|
m.Run(&wg, dgraphClient)
|
|
|
|
}
|
|
|
|
|
2020-02-25 10:05:31 +01:00
|
|
|
go func() {
|
|
|
|
<-stopChan
|
2020-03-02 17:06:28 +01:00
|
|
|
logrus.Info("Shutting down...")
|
2020-02-25 10:05:31 +01:00
|
|
|
c.Stop(&wg)
|
|
|
|
p.Stop(&wg)
|
|
|
|
s.Stop(&wg)
|
2020-05-27 12:05:53 +02:00
|
|
|
m.Stop(&wg)
|
2020-02-25 10:05:31 +01:00
|
|
|
}()
|
2020-02-14 11:36:47 +01:00
|
|
|
|
|
|
|
wg.Wait()
|
2020-03-02 17:06:28 +01:00
|
|
|
logrus.Info("done")
|
2020-02-14 11:36:47 +01:00
|
|
|
|
|
|
|
}
|