summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnderByEndera <[email protected]>2021-01-10 17:37:12 +0800
committerEnderByEndera <[email protected]>2021-01-10 17:37:12 +0800
commit9b94af59b7af6d0f8910b458d0ebc18c5b708be0 (patch)
treeb91cbb5c3ad57dc8ea8d966964d11246649760c9
parentff5e63a5c277b9fe2284fd2d9ed988cec177431a (diff)
1. in root.go, delete GetLogLevel and GetFileName func
2. move Command struct to model package 3. let getCommandsFromHist not exported 4. let Commands type can be sorted by using sort.Sort 5. created mongo_conn.go and comm_mongo.go, connecting to mongo database 6. changed marshal_and_unmarshal.go to json_marshal.go 7. in yaml.go, added MongoSet struct to let user define the connection type for the mongodb 8. clean the structure of the pakcages, let the import structure be cleaned
-rw-r--r--README.en.md7
-rw-r--r--README.md11
-rw-r--r--cmd/root.go13
-rw-r--r--comm/commflush.go19
-rw-r--r--comm/commflush_test.go11
-rw-r--r--comm/commget.go77
-rw-r--r--comm/commget_test.go7
-rw-r--r--conf.yaml7
-rw-r--r--go.mod1
-rw-r--r--go.sum74
-rwxr-xr-xhistory.sh4
-rw-r--r--main.go8
-rw-r--r--model/comm_model.go52
-rw-r--r--model/comm_mongo.go159
-rw-r--r--model/comm_mongo_test.go112
-rw-r--r--model/json_marshal.go (renamed from model/marshal_and_unmarshal.go)16
-rw-r--r--model/json_marshal_test.go (renamed from model/marshal_and_unmarshal_test.go)0
-rw-r--r--model/mongo_conn.go47
-rw-r--r--model/rule_model.go8
-rw-r--r--rules/commscore.go5
-rw-r--r--rules/rules_test.go6
-rw-r--r--rules/rulestype_test.go8
-rw-r--r--static/rules/commrules.json2
-rw-r--r--static/rules/pathrules.json2
-rw-r--r--static/rules/rules.json2
-rw-r--r--yaml/yaml.go61
-rw-r--r--yaml/yaml_test.go2
27 files changed, 595 insertions, 126 deletions
diff --git a/README.en.md b/README.en.md
index 9c5d784..fce7547 100644
--- a/README.en.md
+++ b/README.en.md
@@ -1,7 +1,7 @@
<!--
* @Author: EnderByEndera
* @Date: 2020-12-23 14:42:44
- * @LastEditTime: 2020-12-23 15:04:02
+ * @LastEditTime: 2021-01-05 18:18:37
* @LastEditors: Please set LastEditors
* @Description: Describe the project by English
* @FilePath: /commdetection/README.en.md
@@ -17,8 +17,9 @@ Commdetection contains the following modules
2. The comm module includes Command Get and Command Flush functions to obtain all commands and clear invalid commands
3. logger module, based on logrus custom logger and middleware, middleware is conveniently provided to the gin back-end framework to customize log analysis
4. The router module, based on the gin-gonic framework, customizes the martini-like API and provides a variety of API interfaces for users to facilitate command analysis and monitoring
-5. The rules module is the core of the instruction detection system. Based on user-defined rules, two modes can be selected for instruction evaluation
-6. yaml module, parsing system yaml configuration file
+5. model module is the base of the models
+6. The rules module is the core of the instruction detection system. Based on user-defined rules, two modes can be selected for instruction evaluation
+7. yaml module, parsing system yaml configuration file
#### Installation
diff --git a/README.md b/README.md
index 72ab7b0..cc729ee 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
<!--
* @Author: your name
* @Date: 2020-12-23 14:42:44
- * @LastEditTime: 2020-12-23 14:50:52
+ * @LastEditTime: 2021-01-05 18:18:06
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /commdetection/README.md
@@ -17,15 +17,16 @@ commdetection包含以下几个模块
1. cmd模块,使用了cobra作为命令行生成工具,提供了几类子命令和flags以方便用户自定义模式
2. comm模块,包含Command Get和Command Flush功能,以获得和清除无效指令
3. logger模块,基于logrus自定义logger和middleware,middleware方便提供给gin后端框架以自定义日志分析
-4. router模块,基于gin-gonic框架,自定义martini-like API,提供多种API接口给用户,方便用户进行命令分析和监控
-5. rules模块,指令检测系统核心,基于用户自定义规则,可选择两种模式进行指令评估
-6. yaml模块,解析系统yaml配置文件
+4. model模块,存放各类model
+5. router模块,基于gin-gonic框架,自定义martini-like API,提供多种API接口给用户,方便用户进行命令分析和监控
+6. rules模块,指令检测系统核心,基于用户自定义规则,可选择两种模式进行指令评估
+7. yaml模块,解析系统yaml配置文件
#### 安装教程
1. 使用`git clone https://gitee.com/EnderByEndera/commdetection`下载本项目
-2. 定义环境变量`export set COMMDEPATH=本机克隆地址`
+2. 定义环境变量`export set COMMDEPATH=本机克隆地址`(最好能够放置于.bashrc或/etc/profile中并source)
3. 使用`go build`命令
#### 使用说明
diff --git a/cmd/root.go b/cmd/root.go
index a81d8fe..5612915 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-19 11:59:02
- * @LastEditTime: 2021-01-05 18:04:44
+ * @LastEditTime: 2021-01-06 09:51:43
* @LastEditors: Please set LastEditors
* @Description: root of the commdetection cmd
* @FilePath: /commdetection/cmd/root.go
@@ -55,16 +55,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&file, "file", "/root/.bash_history", "choose one file storing data of the commands")
rootCmd.PersistentFlags().Uint32Var(&logLevel, "loglevel", uint32(logrus.DebugLevel), "choose log level")
rootCmd.AddCommand(verCmd) // add version as a subcommand
-}
-
-// GetLogLevel returns loglevel sent by rootCmd
-func GetLogLevel() uint32 {
- return logLevel
-}
-
-// GetFileName returns filename passed by the command line value
-func GetFileName() string {
- return file
+ logger.LogLevel = logrus.Level(logLevel)
}
func root() {
diff --git a/comm/commflush.go b/comm/commflush.go
index d0b79e8..cf88d8f 100644
--- a/comm/commflush.go
+++ b/comm/commflush.go
@@ -11,6 +11,7 @@ package comm
import (
"bytes"
+ "commdetection/model"
"errors"
"os/exec"
"regexp"
@@ -25,7 +26,7 @@ const NOTFOUNDREG = "((.*)[Cc]ommand(.*)not found(.*))|((.*)No such file or dire
const MANENTRYREG = "No manual entry for (.*)"
// Filter defines filter function to clean invalid commadns or ops given by file or net
-type Filter func([]Command) []Command
+type Filter func([]model.Command) []model.Command
//IntSlice includes a list of n array in order to use sort.Sort() method to sort n
type IntSlice []int
@@ -40,7 +41,7 @@ type errorNum struct {
}
// FlushCommands erase all the invalid commands through various filters
-func FlushCommands(commands []Command, filters []Filter) []Command {
+func FlushCommands(commands []model.Command, filters []Filter) []model.Command {
for _, filter := range filters {
commands = filter(commands)
}
@@ -48,12 +49,12 @@ func FlushCommands(commands []Command, filters []Filter) []Command {
}
// removeOneCommand removes only one command from the list given the index
-func removeOneCommand(commands []Command, n int) []Command {
+func removeOneCommand(commands []model.Command, n int) []model.Command {
return append(commands[:n], commands[n+1:]...)
}
// removeCommands removes a list of commands using index
-func removeCommands(commands []Command, n IntSlice) []Command {
+func removeCommands(commands []model.Command, n IntSlice) []model.Command {
if len(n) == 0 {
return commands
}
@@ -66,7 +67,7 @@ func removeCommands(commands []Command, n IntSlice) []Command {
// SimpleCommandFilter tries to run command without any flag to see whether this command can be run properly
// Deprecated: use WhichCommandFilter instead
-func SimpleCommandFilter(commands []Command) []Command {
+func SimpleCommandFilter(commands []model.Command) []model.Command {
return cmdsFilter(commands, func(command string) error {
return checkOneCmd(command, "", NOTFOUNDREG)
})
@@ -74,7 +75,7 @@ func SimpleCommandFilter(commands []Command) []Command {
// HelpCommandFilter tries to use "`Command` --help", "`Command` -h" and "`Command` help" to judge `Command` is valid or not
// Deprecated: use WhichCommandFilter instead
-func HelpCommandFilter(commands []Command) []Command {
+func HelpCommandFilter(commands []model.Command) []model.Command {
return cmdsFilter(commands, func(command string) error {
if checkOneCmd(command, "--help", NOTFOUNDREG) != nil {
return errors.New("command not found or not in $PATH or directory")
@@ -85,14 +86,14 @@ func HelpCommandFilter(commands []Command) []Command {
// ManCommandFilter tries to use "man `Command`" cmd to judge `Command` is valid or not
// Deprecated: use WhichCommandFilter instead
-func ManCommandFilter(commands []Command) []Command {
+func ManCommandFilter(commands []model.Command) []model.Command {
return cmdsFilter(commands, func(command string) error {
return checkOneCmd("man", command, MANENTRYREG)
})
}
// WhichCommandFilter tries to use "which `Command`" cmd to judge `Command` is valid or not
-func WhichCommandFilter(commands []Command) []Command {
+func WhichCommandFilter(commands []model.Command) []model.Command {
return cmdsFilter(commands, func(command string) error {
return checkOneCmd("which", command, "")
})
@@ -130,7 +131,7 @@ func checkOneCmd(command, arg, reg string) error {
return nil
}
-func cmdsFilter(commands []Command, execute func(string) error) []Command {
+func cmdsFilter(commands []model.Command, execute func(string) error) []model.Command {
var invalidNum []int
ec := make(chan errorNum, 1)
for commNum, command := range commands {
diff --git a/comm/commflush_test.go b/comm/commflush_test.go
index c1d3344..fea14f8 100644
--- a/comm/commflush_test.go
+++ b/comm/commflush_test.go
@@ -1,7 +1,7 @@
/*
* @Author: your name
* @Date: 2020-12-03 12:51:28
- * @LastEditTime: 2021-01-05 17:10:16
+ * @LastEditTime: 2021-01-06 10:01:49
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /commdetection/comm/commflush_test.go
@@ -9,6 +9,7 @@
package comm
import (
+ "commdetection/model"
"fmt"
"reflect"
"testing"
@@ -16,7 +17,7 @@ import (
func TestFlushCommands(t *testing.T) {
t.Run("FlushCommands Test Using WhichCommandFilter", func(t *testing.T) {
- commands := []Command{
+ commands := []model.Command{
{
CommName: "wget",
Args: []string{},
@@ -46,7 +47,7 @@ func TestFlushCommands(t *testing.T) {
Args: []string{},
},
}
- predict := []Command{
+ predict := []model.Command{
{
CommName: "wget",
Args: []string{},
@@ -72,9 +73,9 @@ func TestFlushCommands(t *testing.T) {
})
t.Run("FlushCommands with no commands", func(t *testing.T) {
- commands := []Command{}
+ commands := []model.Command{}
commands = FlushCommands(commands, []Filter{WhichCommandFilter})
- if !reflect.DeepEqual(commands, []Command{}) {
+ if !reflect.DeepEqual(commands, []model.Command{}) {
fmt.Println(commands)
t.Errorf("results are not as predicted")
}
diff --git a/comm/commget.go b/comm/commget.go
index 22ee6f7..f2e4d26 100644
--- a/comm/commget.go
+++ b/comm/commget.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-02 17:08:59
- * @LastEditTime: 2021-01-05 17:19:16
+ * @LastEditTime: 2021-01-10 09:49:55
* @LastEditors: Please set LastEditors
* @Description: Get commands from file or network
* @FilePath: /commdetection/preprocessing/commget.go
@@ -12,25 +12,28 @@ package comm
import (
"bytes"
"commdetection/logger"
+ "commdetection/model"
"io/ioutil"
"os/exec"
+ "sort"
"strconv"
"strings"
"time"
)
-// Command contains command and its flags or symbols
-type Command struct {
- CommName string `json:"commName"`
- Args []string `json:"args"`
- Flags []string `json:"flags"`
- TimeStamp time.Time `json:"timestamp"`
- User string `json:"user"`
- Mac string `json:"mac"`
+// GetCommands returns a list of commands preprocessed which first get commands from file then net
+func GetCommands() []model.Command {
+ commands, err := getCommandsFromHist()
+ if err != nil {
+ logger.Warnln(err)
+ return []model.Command{}
+ }
+ sort.Sort(commands)
+ return commands
}
-// GetCommandsFromHist gets the commands by using `history` bash command
-func GetCommandsFromHist() ([]Command, error) {
+// getCommandsFromHist gets the commands by using `history` bash command
+func getCommandsFromHist() (model.Commands, error) {
var (
stderr bytes.Buffer
stdout bytes.Buffer
@@ -39,15 +42,18 @@ func GetCommandsFromHist() ([]Command, error) {
hist.Stderr = &stderr
hist.Stdout = &stdout
err := hist.Run()
+ if err != nil {
+ return nil, err
+ }
commands := commandsFromString(stdout.String())
- return commands, err
+ return commands, nil
}
-func commandsFromString(s string) []Command {
- var commands []Command
+func commandsFromString(s string) model.Commands {
+ var commands model.Commands
commLines := strings.Split(s, "\n")
for _, comm := range commLines {
- newComm := Command{}
+ newComm := model.Command{}
var timestamp string
for num, commArg := range strings.Fields(comm) {
if _, err := strconv.Atoi(commArg); err != nil && num == 0 {
@@ -59,18 +65,18 @@ func commandsFromString(s string) []Command {
case num == 1:
timestamp = commArg
case num == 2:
- timestamp += " " + commArg
+ timestamp += " " + commArg // create the timestamp string to parse
var err error
newComm.TimeStamp, err = time.Parse("2006-01-02 15:04:05", timestamp)
if err != nil {
newComm.TimeStamp = time.Time{}
}
case num == 3:
- newComm.Mac = commArg
+ newComm.Mac = commArg // comm[3] arg is Mac Address
case num == 4:
- newComm.User = commArg
+ newComm.User = commArg // comm[4] arg is Username
case num == 5:
- newComm.CommName = commArg
+ newComm.CommName = commArg // comm[5] arg is command name
default:
if commArg[0] != '-' { // comm is a flag
newComm.Args = append(newComm.Args, commArg)
@@ -86,21 +92,15 @@ func commandsFromString(s string) []Command {
return commands
}
-// GetCommands returns a list of commands preprocessed which first get commands from file then net
-//
-// If file and url is set to null, GetCommands will call getCommandsFromHistory func automatically
-//TODO: Will temporarily use GetCommandsFromHist to replace GetCommands, will put commands in the mongo db later
-func GetCommands() []Command {
- commands, err := GetCommandsFromHist()
- if err != nil {
- logger.Warnln(err)
- return []Command{}
- }
- return commands
+// TODO: will promote it later
+func getCommandsFromDB() (model.Commands, error) {
+ commands := new(model.Commands)
+ commands.GetCommandsFrom("test", "commands")
+ return *commands, nil
}
-func getCommandsFromFile(f string) ([]Command, error) {
- var commands []Command
+func getCommandsFromFile(f string) ([]model.Command, error) {
+ var commands []model.Command
buf, err := ioutil.ReadFile(f)
if err != nil {
return nil, err
@@ -112,9 +112,9 @@ func getCommandsFromFile(f string) ([]Command, error) {
return commands, nil
}
-func splitCommandsInLine(tComm []string) []Command {
- commands := []Command{}
- newComm := Command{}
+func splitCommandsInLine(tComm []string) []model.Command {
+ commands := []model.Command{}
+ newComm := model.Command{}
for commNum, comm := range tComm {
if commNum == 0 {
newComm.CommName = comm
@@ -128,12 +128,7 @@ func splitCommandsInLine(tComm []string) []Command {
}
}
if newComm.CommName != "" {
- commands = append([]Command{newComm}, commands...)
+ commands = append([]model.Command{newComm}, commands...)
}
return commands
}
-
-// TODO: ready to develop until API is given
-func getCommandsFromNet(url string) ([]Command, error) {
- return nil, nil
-}
diff --git a/comm/commget_test.go b/comm/commget_test.go
index 0845fb9..86ea987 100644
--- a/comm/commget_test.go
+++ b/comm/commget_test.go
@@ -9,6 +9,7 @@
package comm
import (
+ "commdetection/model"
"fmt"
"reflect"
"strings"
@@ -17,7 +18,7 @@ import (
func TestGetCommands(t *testing.T) {
t.Run("Get Commands From history Test", func(t *testing.T) {
- commands, err := GetCommandsFromHist()
+ commands, err := getCommandsFromHist()
if err != nil {
t.Error(err)
}
@@ -29,7 +30,7 @@ func TestSplitCommandsInLine(t *testing.T) {
t.Run("split large command test", func(t *testing.T) {
str := "ls && cp -s abc && goc"
commands := splitCommandsInLine(strings.Fields(str))
- predict := []Command{
+ predict := []model.Command{
{
CommName: "ls",
Args: []string{},
@@ -54,7 +55,7 @@ func TestSplitCommandsInLine(t *testing.T) {
})
}
-func checkCommands(commands []Command, t *testing.T) {
+func checkCommands(commands []model.Command, t *testing.T) {
for commNum, command := range commands {
if command.CommName == "" {
t.Errorf("command %d is empty", commNum)
diff --git a/conf.yaml b/conf.yaml
index 2e30593..b51f367 100644
--- a/conf.yaml
+++ b/conf.yaml
@@ -1,2 +1,5 @@
-ginmode: release
-port: 8060 \ No newline at end of file
+gin:
+ ginmode: release
+ port: 8060
+mongo:
+ timeout: 10s \ No newline at end of file
diff --git a/go.mod b/go.mod
index 0c2aa9f..4cdf96e 100644
--- a/go.mod
+++ b/go.mod
@@ -37,6 +37,7 @@ require (
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
+ go.mongodb.org/mongo-driver v1.4.4
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 // indirect
diff --git a/go.sum b/go.sum
index 32d10d4..9c5c889 100644
--- a/go.sum
+++ b/go.sum
@@ -25,6 +25,8 @@ github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
+github.com/aws/aws-sdk-go v1.34.28 h1:sscPpn/Ns3i0F4HPEWAVcwdIRaZZCuL7llJ2/60yPIk=
+github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
@@ -75,7 +77,33 @@ github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
+github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
+github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
+github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
+github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
+github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
+github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
+github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
+github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs=
+github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
+github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
+github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk=
+github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28=
+github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo=
+github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk=
+github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw=
+github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360=
+github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg=
+github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE=
+github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8=
+github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
+github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
+github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
+github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
+github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
+github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
+github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -98,6 +126,8 @@ github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
+github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -106,6 +136,7 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
@@ -151,6 +182,11 @@ github.com/imkira/go-interpol v1.1.0 h1:KIiKr0VSG2CUW1hl1jpiyuzuJeKUUpC8iM1AIE7N
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
+github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
+github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
@@ -163,13 +199,17 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
+github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
+github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
+github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg=
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.4 h1:kz40R/YWls3iqT9zX9AHN3WoVsrAWVyui5sxuLqiXqU=
github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
+github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
@@ -184,6 +224,8 @@ github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgx
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
+github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
+github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
@@ -208,6 +250,7 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLD
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
@@ -226,8 +269,11 @@ github.com/onsi/gomega v1.10.4 h1:NiTx7EEvBzu9sFOD1zORteLSt3o8gnlvZZwSE9TnY9U=
github.com/onsi/gomega v1.10.4/go.mod h1:g/HbgYopi++010VEqkFgJHKC09uJiW9UkXvMUuKHUCQ=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
+github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
@@ -242,6 +288,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
+github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
+github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
@@ -250,6 +298,9 @@ github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
+github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
+github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
+github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
@@ -262,6 +313,7 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
+github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4=
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
@@ -278,6 +330,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
+github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
+github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
@@ -292,6 +346,10 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasthttp v1.19.0 h1:PfTS4PeH3xDr3WomrDS2ID8lU2GskK1xS3YG6gIpibU=
github.com/valyala/fasthttp v1.19.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
+github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk=
+github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
+github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc h1:n+nNi93yXLkJvKwXNP9d55HC7lGK4H/SRcwB5IaUZLo=
+github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
@@ -310,6 +368,8 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDf
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
+go.mongodb.org/mongo-driver v1.4.4 h1:bsPHfODES+/yx2PCWzUYMH8xj6PVniPI8DQrsJuSXSs=
+go.mongodb.org/mongo-driver v1.4.4/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
@@ -318,7 +378,9 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -357,6 +419,7 @@ golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
@@ -369,7 +432,10 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
+golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -379,9 +445,13 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -416,9 +486,13 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
+golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
diff --git a/history.sh b/history.sh
index 5f8c9cf..a74716e 100755
--- a/history.sh
+++ b/history.sh
@@ -1,9 +1,9 @@
###
# @Author: EnderbyEndera
# @Date: 2021-01-05 15:36:26
- # @LastEditTime: 2021-01-05 17:23:34
+ # @LastEditTime: 2021-01-05 18:15:26
# @LastEditors: Please set LastEditors
- # @Description: In User Settings Edit
+ # @Description: history.sh is used in the commget.go to get history commands in the host with the defined format
# @FilePath: /commdetection/history.sh
###
diff --git a/main.go b/main.go
index 6f06a72..e832d86 100644
--- a/main.go
+++ b/main.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-04 15:03:24
- * @LastEditTime: 2020-12-23 16:11:29
+ * @LastEditTime: 2021-01-06 09:50:51
* @LastEditors: Please set LastEditors
* @Description: Main Func Entry, use flags to give help
* @FilePath: /commdetection/main.go
@@ -12,14 +12,8 @@ package main
import (
"commdetection/cmd"
"commdetection/logger"
-
- "github.com/sirupsen/logrus"
)
-func init() {
- logger.LogLevel = logrus.Level(cmd.GetLogLevel())
-}
-
func main() {
if err := cmd.Execute(); err != nil {
logger.Fatalln(err)
diff --git a/model/comm_model.go b/model/comm_model.go
new file mode 100644
index 0000000..6d9ea60
--- /dev/null
+++ b/model/comm_model.go
@@ -0,0 +1,52 @@
+/*
+ * @Author: your name
+ * @Date: 2021-01-06 09:56:18
+ * @LastEditTime: 2021-01-10 09:45:28
+ * @LastEditors: Please set LastEditors
+ * @Description: In User Settings Edit
+ * @FilePath: /commdetection/model/comm_model.go
+ */
+
+package model
+
+import (
+ "reflect"
+ "sort"
+ "time"
+)
+
+// Command contains command and its flags or symbols
+type Command struct {
+ CommName string `json:"commname" bson:"commname"`
+ Args []string `json:"args" bson:"args,omitempty"`
+ Flags []string `json:"flags" bson:"flags,omitempty"`
+ TimeStamp time.Time `json:"timestamp" bson:"timestamp"`
+ User string `json:"user" bson:"user"`
+ Mac string `json:"mac" bson:"mac"`
+}
+
+// Commands is the multi type of Command
+type Commands []Command
+
+func (c Commands) Len() int {
+ return len(c)
+}
+
+func (c Commands) Swap(i, j int) {
+ c[i], c[j] = c[j], c[i]
+}
+
+func (c Commands) Less(i, j int) bool {
+ return c[j].TimeStamp.After(c[i].TimeStamp)
+}
+
+// Has returns whether c has the command
+func (c Commands) Has(command Command) bool {
+ sort.Sort(c)
+ if sort.Search(c.Len(), func(i int) bool {
+ return reflect.DeepEqual(c[i], command)
+ }) == c.Len() {
+ return false
+ }
+ return true
+}
diff --git a/model/comm_mongo.go b/model/comm_mongo.go
new file mode 100644
index 0000000..4e0227a
--- /dev/null
+++ b/model/comm_mongo.go
@@ -0,0 +1,159 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2021-01-09 16:46:53
+ * @LastEditTime: 2021-01-10 16:31:17
+ * @LastEditors: Please set LastEditors
+ * @Description: comm_mongo.go tries to get connection with mongodb lib
+ * @FilePath: /commdetection/model/command_mongo.go
+ */
+
+package model
+
+import (
+ "commdetection/logger"
+ "context"
+ "fmt"
+ "sort"
+
+ "go.mongodb.org/mongo-driver/bson"
+ "go.mongodb.org/mongo-driver/mongo"
+ "go.mongodb.org/mongo-driver/mongo/options"
+)
+
+// GetCommandsFrom gets all the commands in the mongodb collections
+func (c *Commands) GetCommandsFrom(dbName string, cName string) error {
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
+ defer cancel()
+ client, err := connect(ctx)
+ if err != nil {
+ return err
+ }
+ defer closeClient(ctx, client)
+ return client.UseSession(ctx, func(sc mongo.SessionContext) error {
+ client := sc.Client()
+ collection := client.Database(dbName).Collection(cName)
+ cur, err := collection.Find(ctx, bson.D{})
+ defer cur.Close(ctx)
+ if err != nil {
+ return err
+ }
+ for cur.Next(ctx) {
+ var next Command
+ err := cur.Decode(&next)
+ if err != nil {
+ logger.Warnln(err)
+ }
+ *c = append(*c, next)
+ }
+ return nil
+ })
+}
+
+// InsertAllTo insert the given commands to the specified database and collection
+func (c *Commands) InsertAllTo(dbName string, cName string) error {
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
+ defer cancel()
+ client, err := connect(ctx)
+ if err != nil {
+ return err
+ }
+ if !sort.IsSorted(c) {
+ sort.Sort(c)
+ }
+ defer closeClient(ctx, client)
+ return client.UseSession(ctx, func(sc mongo.SessionContext) error {
+ client := sc.Client()
+ collections := client.Database(dbName).Collection(cName)
+ var documents []interface{}
+ for _, command := range *c {
+ documents = append(documents, command)
+ }
+ res, err := collections.InsertMany(sc, documents, options.InsertMany().SetOrdered(true))
+ if err != nil {
+ sc.AbortTransaction(ctx)
+ return err
+ }
+ sc.CommitTransaction(ctx)
+ logger.Debugln("Insert succeeded, Ids are ", res)
+ return nil
+ })
+}
+
+// InsertAnyTo inserts one command to the dbName.cName
+func (c *Commands) InsertAnyTo(dbName, cName string, index uint) error {
+ if index >= uint(c.Len()) {
+ return fmt.Errorf("Index %d out of range", index)
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
+ defer cancel()
+ client, err := connect(ctx)
+ if err != nil {
+ return err
+ }
+ defer closeClient(ctx, client)
+ return client.UseSession(ctx, func(sc mongo.SessionContext) error {
+ client := sc.Client()
+ collections := client.Database(dbName).Collection(cName)
+ res, err := collections.InsertOne(sc, (*c)[index])
+ if err != nil {
+ sc.AbortTransaction(sc)
+ return err
+ }
+ sc.CommitTransaction(sc)
+ logger.Debugln("Insert succeeded, Id is ", res)
+ return nil
+ })
+}
+
+// DeleteOneFrom deletes one command from the dbName.cName
+func (c *Commands) DeleteOneFrom(dbName, cName string, index uint) error {
+ if index >= uint(c.Len()) {
+ return fmt.Errorf("index %d out of range", index)
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
+ defer cancel()
+ client, err := connect(ctx)
+ if err != nil {
+ return err
+ }
+ defer closeClient(ctx, client)
+ return client.UseSession(ctx, func(sc mongo.SessionContext) error {
+ client := sc.Client()
+ collections := client.Database(dbName).Collection(cName)
+ res, err := collections.DeleteOne(sc, (*c)[index])
+ if err != nil {
+ sc.AbortTransaction(ctx)
+ return err
+ }
+ sc.CommitTransaction(ctx)
+ logger.Debugln("Delete succeeded, Id is ", res)
+ return nil
+ })
+}
+
+// DeleteAllFrom deletes many commands from dbName.cName
+func (c *Commands) DeleteAllFrom(dbName, cName string) error {
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
+ defer cancel()
+ client, err := connect(ctx)
+ if err != nil {
+ return err
+ }
+ defer closeClient(ctx, client)
+ return client.UseSession(ctx, func(sc mongo.SessionContext) error {
+ client := sc.Client()
+ collections := client.Database(dbName).Collection(cName)
+ var deleteResults []*mongo.DeleteResult
+ for _, command := range *c {
+ res, err := collections.DeleteOne(ctx, command)
+ if err != nil {
+ sc.AbortTransaction(ctx)
+ return err
+ }
+ deleteResults = append(deleteResults, res)
+ }
+ sc.CommitTransaction(ctx)
+ logger.Debugln("Delete succeeded, ids are ", deleteResults)
+ return nil
+ })
+}
diff --git a/model/comm_mongo_test.go b/model/comm_mongo_test.go
new file mode 100644
index 0000000..80413c5
--- /dev/null
+++ b/model/comm_mongo_test.go
@@ -0,0 +1,112 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2021-01-06 15:26:48
+ * @LastEditTime: 2021-01-10 16:26:32
+ * @LastEditors: Please set LastEditors
+ * @Description: test mongo.go
+ * @FilePath: /commdetection/model/mongo_test.go
+ */
+
+package model
+
+import (
+ "sort"
+ "testing"
+ "time"
+)
+
+func TestGetCommandsFromMongo(t *testing.T) {
+ commands := new(Commands)
+ err := commands.GetCommandsFrom("test", "commands")
+ if err != nil {
+ t.Error(err)
+ }
+ if commands == nil || commands.Len() == 0 {
+ t.Error("Commands are nil commands")
+ }
+ if !sort.IsSorted(commands) {
+ t.Error("Commands are not sorted")
+ }
+}
+
+func TestInsertCommandsToMongo(t *testing.T) {
+ t.Run("Test InsertManyTo func", func(t *testing.T) {
+ commands := Commands{}
+ for i := 0; i < 10; i++ {
+ commands = append(commands, Command{
+ CommName: "wget",
+ Args: []string{},
+ Flags: []string{},
+ TimeStamp: time.Now(),
+ User: "root",
+ })
+ }
+ err := commands.InsertAllTo("test", "commands")
+ if err != nil {
+ t.Error(err)
+ }
+ })
+
+ t.Run("Test InsertAnyTo func", func(t *testing.T) {
+ commands := Commands{
+ {
+ CommName: "wget",
+ Args: []string{},
+ Flags: []string{},
+ TimeStamp: time.Now(),
+ User: "root",
+ },
+ }
+ err := commands.InsertAnyTo("test", "commands", 1)
+ if err == nil {
+ t.Errorf("No IndexOutOfRange error appeared")
+ }
+ err = commands.InsertAnyTo("test", "commands", 0)
+ if err != nil {
+ t.Error(err)
+ }
+ })
+}
+
+func TestDeleteCommandsFromMongo(t *testing.T) {
+ t.Run("Test DeleteOne func", func(t *testing.T) {
+ commands := Commands{
+ {
+ CommName: "wget",
+ Args: []string{},
+ Flags: []string{},
+ TimeStamp: time.Now(),
+ User: "root",
+ },
+ }
+ err := commands.InsertAnyTo("test", "commands", 0)
+ if err != nil {
+ t.Error(err)
+ }
+ err = commands.DeleteOneFrom("test", "commands", 0)
+ if err != nil {
+ t.Error(err)
+ }
+ })
+
+ t.Run("Test DeleteAll func", func(t *testing.T) {
+ commands := Commands{}
+ for i := 0; i < 10; i++ {
+ commands = append(commands, Command{
+ CommName: "wget",
+ Args: []string{},
+ Flags: []string{},
+ TimeStamp: time.Now(),
+ User: "root",
+ })
+ }
+ err := commands.InsertAllTo("test", "commands")
+ if err != nil {
+ t.Error(err)
+ }
+ err = commands.DeleteAllFrom("test", "commands")
+ if err != nil {
+ t.Error(err)
+ }
+ })
+}
diff --git a/model/marshal_and_unmarshal.go b/model/json_marshal.go
index 710a0d7..6fd4590 100644
--- a/model/marshal_and_unmarshal.go
+++ b/model/json_marshal.go
@@ -1,7 +1,15 @@
/*
+ * @Author: your name
+ * @Date: 2021-01-05 10:37:28
+ * @LastEditTime: 2021-01-10 09:39:58
+ * @LastEditors: Please set LastEditors
+ * @Description: In User Settings Edit
+ * @FilePath: /commdetection/model/marshal_and_unmarshal.go
+ */
+/*
* @Author: EnderByEndera
* @Date: 2020-12-16 13:57:06
- * @LastEditTime: 2021-01-04 17:27:49
+ * @LastEditTime: 2021-01-06 09:56:56
* @LastEditors: Please set LastEditors
* @Description: Includes various marshalling ways
* @FilePath: /commdetection/rules/marshalling.go
@@ -71,7 +79,7 @@ func MarshalSensitivePathSetting(spaths SPaths) error {
return marshalSetting(fileName, spaths)
}
-// UnmarshalSensitivePathSetting unmarshals spaths setting json file to spaths variable
+// UnmarshalSensitivePathSetting unmarshal spaths setting json file to spaths variable
func UnmarshalSensitivePathSetting() (spaths SPaths, err error) {
fileName := yaml.GetPathRulesSetting()
if fileName == "" {
@@ -93,7 +101,7 @@ func MarshalSensitiveCommSetting(scomms []SComm) error {
return marshalSetting(fileName, scomms)
}
-// UnmarshalSensitiveCommSetting unmarshals scomms setting json file to scomms variable
+// UnmarshalSensitiveCommSetting unmarshal scomms setting json file to scomms variable
func UnmarshalSensitiveCommSetting() (scomms SComms, err error) {
fileName := yaml.GetCommRulesSetting()
if fileName == "" {
@@ -115,7 +123,7 @@ func MarshalUnsensitiveWebsiteSetting(ussites Ussites) error {
return marshalSetting(fileName, ussites)
}
-// UnMarshalUnsensitiveWebsiteSetting unmarshals ussites setting json file to ussites variable
+// UnMarshalUnsensitiveWebsiteSetting unmarshal ussites setting json file to ussites variable
func UnMarshalUnsensitiveWebsiteSetting() (ussites Ussites, err error) {
fileName := yaml.GetWebsiteRulesSetting()
if fileName == "" {
diff --git a/model/marshal_and_unmarshal_test.go b/model/json_marshal_test.go
index 0bd8266..0bd8266 100644
--- a/model/marshal_and_unmarshal_test.go
+++ b/model/json_marshal_test.go
diff --git a/model/mongo_conn.go b/model/mongo_conn.go
new file mode 100644
index 0000000..1b9db06
--- /dev/null
+++ b/model/mongo_conn.go
@@ -0,0 +1,47 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2021-01-06 11:12:49
+ * @LastEditTime: 2021-01-10 15:33:10
+ * @LastEditors: Please set LastEditors
+ * @Description: In User Settings Edit
+ * @FilePath: /commdetection/model/db.go
+ */
+
+package model
+
+import (
+ "commdetection/logger"
+ "commdetection/yaml"
+ "context"
+ "fmt"
+ "time"
+
+ "go.mongodb.org/mongo-driver/mongo"
+ "go.mongodb.org/mongo-driver/mongo/options"
+)
+
+var (
+ dbset yaml.MongoSet
+ timeout time.Duration
+)
+
+func init() {
+ dbset = yaml.GetMongoSetting()
+ var err error
+ timeout, err = time.ParseDuration(dbset.Timeout)
+ if err != nil {
+ logger.Warnln(err)
+ }
+}
+
+func closeClient(ctx context.Context, client *mongo.Client) {
+ err := client.Disconnect(ctx)
+ if err != nil {
+ logger.Warnln(err)
+ }
+}
+
+func connect(ctx context.Context) (*mongo.Client, error) {
+ return mongo.Connect(ctx, options.Client().
+ ApplyURI(fmt.Sprintf("mongodb://%s:%d", dbset.Host, dbset.Port)))
+}
diff --git a/model/rule_model.go b/model/rule_model.go
index 81414a5..d530d22 100644
--- a/model/rule_model.go
+++ b/model/rule_model.go
@@ -9,10 +9,6 @@
package model
-import (
- "commdetection/comm"
-)
-
// Rule defines a rule's func and its name
type Rule struct {
Name string `json:"name"`
@@ -27,8 +23,8 @@ type Evaluation func(CommScore) CommScore
// CommScore includes command name and its score
type CommScore struct {
- Command comm.Command `json:"command"`
- Score float64 `json:"score"`
+ Command Command `json:"command"`
+ Score float64 `json:"score"`
}
// SPath includes sensitive path dir and its sensitive coefficient
diff --git a/rules/commscore.go b/rules/commscore.go
index f94c693..082548e 100644
--- a/rules/commscore.go
+++ b/rules/commscore.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-16 13:59:51
- * @LastEditTime: 2021-01-04 16:41:41
+ * @LastEditTime: 2021-01-06 09:58:52
* @LastEditors: Please set LastEditors
* @Description: Includes CommScore definition
* @FilePath: /commdetection/rules/commscore.go
@@ -10,12 +10,11 @@
package rules
import (
- "commdetection/comm"
"commdetection/model"
)
// InitCommScores initialize commscores from []Command
-func InitCommScores(commands []comm.Command) (commScores []model.CommScore) {
+func InitCommScores(commands []model.Command) (commScores []model.CommScore) {
for _, command := range commands {
commScores = append(commScores, model.CommScore{
Command: command,
diff --git a/rules/rules_test.go b/rules/rules_test.go
index 41eb131..468a5f6 100644
--- a/rules/rules_test.go
+++ b/rules/rules_test.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-04 15:03:09
- * @LastEditTime: 2021-01-05 17:19:26
+ * @LastEditTime: 2021-01-06 09:59:08
* @LastEditors: Please set LastEditors
* @Description: Test commrules.go
* @FilePath: /commdetection/rules/commrules_test.go
@@ -58,7 +58,7 @@ func TestRule(t *testing.T) {
}
}
cs := model.CommScore{
- Command: comm.Command{CommName: "wget"},
+ Command: model.Command{CommName: "wget"},
Score: 100,
}
for _, rule := range r {
@@ -136,7 +136,7 @@ func TestInitCommScores(t *testing.T) {
func TestEvaluateCommScore(t *testing.T) {
css := EvaluateCommScore([]model.CommScore{
{
- Command: comm.Command{
+ Command: model.Command{
CommName: "wget",
Args: []string{""},
},
diff --git a/rules/rulestype_test.go b/rules/rulestype_test.go
index d92d0c3..dcc70ba 100644
--- a/rules/rulestype_test.go
+++ b/rules/rulestype_test.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-08 11:28:49
- * @LastEditTime: 2021-01-05 17:19:57
+ * @LastEditTime: 2021-01-06 09:59:40
* @LastEditors: Please set LastEditors
* @Description: Test UnmarshalSetting and MarshalSetting
* @FilePath: /commdetection/rules/rulestype_test.go
@@ -19,7 +19,7 @@ import (
func TestEvaluateCommandRule(t *testing.T) {
t.Run("Test Normal Command Rule Evaluation", func(t *testing.T) {
cs := model.CommScore{
- Command: comm.Command{
+ Command: model.Command{
CommName: "wget",
Args: []string{"https://127.0.0.1:8080"},
},
@@ -35,7 +35,7 @@ func TestEvaluateCommandRule(t *testing.T) {
func TestEvaluatePathRule(t *testing.T) {
t.Run("Test Normal Path Rule Evaluation", func(t *testing.T) {
cs := model.CommScore{
- Command: comm.Command{
+ Command: model.Command{
CommName: "wget",
Args: []string{"rules.json"},
},
@@ -53,7 +53,7 @@ func TestEvaluatePathRule(t *testing.T) {
func TestEvaluateWebsiteRule(t *testing.T) {
t.Run("Test Evaluating Website Rule", func(t *testing.T) {
cs := model.CommScore{
- Command: comm.Command{
+ Command: model.Command{
CommName: "wget",
Args: []string{"https://golang.org/"},
Flags: []string{},
diff --git a/static/rules/commrules.json b/static/rules/commrules.json
index 959b475..519cba1 100644
--- a/static/rules/commrules.json
+++ b/static/rules/commrules.json
@@ -1 +1 @@
-[{"command":"sudo","coefficient":0.1},{"command":"wget","coefficient":0.8},{"command":"apt","coefficient":0.2}] \ No newline at end of file
+[{"command":"wget","coefficient":0.8},{"command":"apt","coefficient":1}] \ No newline at end of file
diff --git a/static/rules/pathrules.json b/static/rules/pathrules.json
index 4f8c9f0..a73d2f0 100644
--- a/static/rules/pathrules.json
+++ b/static/rules/pathrules.json
@@ -1 +1 @@
-[{"Path":"/root/go/src/commdetection","Coefficient":0.5}] \ No newline at end of file
+[{"Path":"/root/go/src/commdetection","Coefficient":0.7}] \ No newline at end of file
diff --git a/static/rules/rules.json b/static/rules/rules.json
index 3339112..3a3c234 100644
--- a/static/rules/rules.json
+++ b/static/rules/rules.json
@@ -1 +1 @@
-[{"name":"pathrule","rulefunc":"EvaluatePathRule"}] \ No newline at end of file
+[{"name":"RuleA","rulefunc":"EvaluateCommandRule"}] \ No newline at end of file
diff --git a/yaml/yaml.go b/yaml/yaml.go
index 2b4cc3a..002a7ef 100644
--- a/yaml/yaml.go
+++ b/yaml/yaml.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-09 16:44:44
- * @LastEditTime: 2021-01-04 19:11:44
+ * @LastEditTime: 2021-01-06 12:40:04
* @LastEditors: Please set LastEditors
* @Description: Init settings from yaml file
* @FilePath: /commdetection/init/init.go
@@ -20,16 +20,34 @@ import (
"gopkg.in/yaml.v2"
)
+// MongoSet is the setting for the mongo db connection
+type MongoSet struct {
+ Host string `yaml:"host"`
+ Port uint16 `yaml:"port"`
+ User string `yaml:"user"`
+ Pwd string `yaml:"password"`
+ Timeout string `yaml:"timeout"`
+}
+
+// RulePaths is the rule paths
+type RulePaths struct {
+ MultiRulesPath string `yaml:"multirulepath"`
+ CommRulePath string `yaml:"commrulepath"`
+ PathRulePath string `yaml:"pathrulepath"`
+ WebsiteRulesPath string `yaml:"webrulepath"`
+}
+
+// GinSet is the setting for the gin-gonic router
+type GinSet struct {
+ GinMode string `yaml:"ginmode"`
+ GinPort uint16 `yaml:"port"`
+}
+
// Conf defines the configuration from the yaml file
type Conf struct {
- Paths struct {
- MultiRulesPath string `yaml:"multirulepath"`
- CommRulePath string `yaml:"commrulepath"`
- PathRulePath string `yaml:"pathrulepath"`
- WebsiteRulesPath string `yaml:"webrulepath"`
- } `yaml:"path"`
- GinMode string `yaml:"ginmode"`
- Port uint16 `yaml:"port"`
+ Paths RulePaths `yaml:"path"`
+ Gin GinSet `yaml:"gin"`
+ Mongo MongoSet `yaml:"mongo"`
}
var conf *Conf
@@ -39,6 +57,7 @@ func init() {
buf, err := ioutil.ReadFile(filepath.Join(os.Getenv("COMMDEPATH"), "conf.yaml"))
if err != nil {
logger.Warnln("read yaml file failed, return NULL string")
+ return
}
err = yaml.Unmarshal(buf, conf)
if err != nil {
@@ -46,10 +65,24 @@ func init() {
}
}
+// GetMongoSetting returns the mongo db settings
+func GetMongoSetting() MongoSet {
+ if conf.Mongo.Host == "" {
+ conf.Mongo.Host = "localhost"
+ }
+ if conf.Mongo.Port == 0 {
+ conf.Mongo.Port = 27017
+ }
+ if conf.Mongo.Timeout == "" {
+ conf.Mongo.Timeout = "30s"
+ }
+ return conf.Mongo
+}
+
// GetPort returns port of the server, if port is undefined, then return :8080
func GetPort() string {
- if conf.Port != 0 {
- return ":" + strconv.Itoa(int(conf.Port))
+ if conf.Gin.GinPort != 0 {
+ return ":" + strconv.Itoa(int(conf.Gin.GinPort))
}
return ":8080"
@@ -57,10 +90,10 @@ func GetPort() string {
// GetGinMode returns ginmode(release, debug, test)
func GetGinMode() (string, error) {
- if conf.GinMode == "debug" || conf.GinMode == "release" || conf.GinMode == "test" {
- return conf.GinMode, nil
+ if conf.Gin.GinMode == "debug" || conf.Gin.GinMode == "release" || conf.Gin.GinMode == "test" {
+ return conf.Gin.GinMode, nil
}
- return "debug", fmt.Errorf("GinMode reads failed. Cannot find %s in any of gin modes", conf.GinMode)
+ return "debug", fmt.Errorf("GinMode reads failed. Cannot find %s in any of gin modes", conf.Gin.GinMode)
}
// GetCommRulesSetting returns the path storing sensitive command rules
diff --git a/yaml/yaml_test.go b/yaml/yaml_test.go
index d8b58ad..148ee38 100644
--- a/yaml/yaml_test.go
+++ b/yaml/yaml_test.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-14 14:57:47
- * @LastEditTime: 2021-01-04 15:34:16
+ * @LastEditTime: 2021-01-06 17:14:32
* @LastEditors: Please set LastEditors
* @Description: test yaml.go
* @FilePath: /commdetection/yaml/yaml_test.go