summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnderByEndera <[email protected]>2020-12-19 17:07:13 +0800
committerEnderByEndera <[email protected]>2020-12-19 17:07:13 +0800
commitc70c7a0425593ae1fa58987c108c7a931a900271 (patch)
tree9552bac1def1ebd37fc230cf4682ca3f5beeedc8
parent91f35a667cd0e714180c102dea1aef453d311397 (diff)
Added command line command and flags by using
cobra, a usefule command-line development tool. Added logger by using logrus development tool
-rw-r--r--.vscode/launch.json3
-rw-r--r--cmd/root.go115
-rw-r--r--cmd/version.go29
-rw-r--r--comm/commflush.go (renamed from preprocessing/commflush.go)15
-rw-r--r--comm/commflush_test.go (renamed from preprocessing/commflush_test.go)4
-rw-r--r--comm/commget.go (renamed from preprocessing/commget.go)13
-rw-r--r--comm/commget_test.go (renamed from preprocessing/commget_test.go)4
-rw-r--r--go.mod7
-rw-r--r--go.sum301
-rw-r--r--logger/commlog.go45
-rw-r--r--main.go14
-rw-r--r--main_test.go10
-rw-r--r--rules/commscore.go31
-rw-r--r--rules/commscore_test.go10
-rw-r--r--rules/marshalling.go115
-rw-r--r--rules/marshalling_test.go100
-rw-r--r--rules/rules.go63
-rw-r--r--rules/rules_test.go36
-rw-r--r--rules/rulestype_test.go110
-rw-r--r--rules/ruletypes.go70
-rw-r--r--yaml/yaml.go29
-rw-r--r--yaml/yaml_test.go2
22 files changed, 879 insertions, 247 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 8e09abe..fc0c2a3 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -9,7 +9,8 @@
"type": "go",
"request": "launch",
"mode": "debug",
- "program": "${workspaceFolder}"
+ "program": "${workspaceFolder}",
+ "args": ["-e=path,command"]
},
{
"name": "Launch",
diff --git a/cmd/root.go b/cmd/root.go
new file mode 100644
index 0000000..c377e3e
--- /dev/null
+++ b/cmd/root.go
@@ -0,0 +1,115 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2020-12-19 11:59:02
+ * @LastEditTime: 2020-12-19 17:05:53
+ * @LastEditors: Please set LastEditors
+ * @Description: root of the commdetection cmd
+ * @FilePath: /commdetection/cmd/root.go
+ */
+
+package cmd
+
+import (
+ "commdetection/comm"
+ "commdetection/logger"
+ "commdetection/rules"
+ "commdetection/yaml"
+ "encoding/json"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/cobra"
+)
+
+var rootCmd = &cobra.Command{
+ Use: "commdetection",
+ Short: "commdetection is the command-line tool for detecting harmful commands",
+ Long: "A fast and precise command-line tool for detecting harmful commands",
+ Run: func(cmd *cobra.Command, args []string) {
+ root()
+ },
+}
+
+var (
+ filterStr string = "which"
+ evaluations []string
+ file string = "/root/.bash_history"
+ logLevel uint32 = 5
+
+ filters = []comm.Filter{}
+ rs = rules.Rules{}
+ buf []byte
+)
+
+// Execute executes the command
+func Execute() {
+ // 初始化
+ initialize()
+ rootCmd.Execute()
+}
+
+func initialize() {
+ rootCmd.PersistentFlags().StringVar(&filterStr, "filter", "which", "choose one filter to filt the data from the file")
+ rootCmd.PersistentFlags().StringSliceVarP(&evaluations, "evaluations", "e", []string{}, "choose one or more evaluations to evaluate commands")
+ 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)
+
+ logger.Init(logrus.Level(logLevel), &logrus.TextFormatter{
+ FullTimestamp: true,
+ TimestampFormat: "2006-01-02 15:07:05",
+ })
+
+ if err := yaml.InitYamlSetting(); err != nil {
+ logger.Fatalln(err)
+ }
+}
+
+func root() {
+ for _, ev := range evaluations {
+ switch ev {
+ case "command":
+ rs = rules.AddRule(rs, rules.Rule{
+ Name: "Command",
+ RuleFunc: "EvaluateCommandRule",
+ })
+ case "path":
+ rs = rules.AddRule(rs, rules.Rule{
+ Name: "Path",
+ RuleFunc: "EvaluatePathRule",
+ })
+ default:
+ logger.Warnln("invalid rule name: " + ev)
+ }
+ }
+
+ switch filterStr {
+ case "which":
+ filters = append(filters, comm.WhichCommandFilter)
+ case "simple":
+ filters = append(filters, comm.SimpleCommandFilter)
+ case "help":
+ filters = append(filters, comm.HelpCommandFilter)
+ case "man":
+ filters = append(filters, comm.ManCommandFilter)
+ }
+
+ // 从文件中获取路径,默认获取路径为/root/.bash_history
+ logger.Debugln("Start getting commmands from " + file)
+ commands := comm.GetCommands(file, "")
+ // 清理无效命令,利用filter函数保留有效命令以便提供分析
+ logger.Debugln("Start flushing commands using", filterStr)
+ commands = comm.FlushCommands(commands, filters)
+ // 初始化命令得分
+ logger.Debugln("Initializing commands' scores")
+ css := rules.InitCommScores(commands)
+ // 评估命令,利用rs中保留的规则进行评估
+ logger.Debugln("Evaluating commands' scores using ", evaluations)
+ css = rules.EvaluateCommScore(css, rs)
+ // 将命令得分保存到json文件中
+ logger.Debugln("Storing result to output.json file")
+ jsonBuf, _ := json.Marshal(css)
+ ioutil.WriteFile(filepath.Join(os.Getenv("COMMDEPATH"), "output.json"), jsonBuf, os.ModeAppend)
+}
diff --git a/cmd/version.go b/cmd/version.go
new file mode 100644
index 0000000..b615fe8
--- /dev/null
+++ b/cmd/version.go
@@ -0,0 +1,29 @@
+/*
+ * @Author: your name
+ * @Date: 2020-12-19 11:49:14
+ * @LastEditTime: 2020-12-19 11:52:50
+ * @LastEditors: Please set LastEditors
+ * @Description: In User Settings Edit
+ * @FilePath: /commdetection/cmd/version.go
+ */
+
+package cmd
+
+import (
+ "commdetection/logger"
+
+ "github.com/spf13/cobra"
+)
+
+var verCmd = &cobra.Command{
+ Use: "version",
+ Short: "show version",
+ Long: "show version of the application",
+ Run: func(cmd *cobra.Command, args []string) {
+ version()
+ },
+}
+
+func version() {
+ logger.Debugln("Version 0.01")
+}
diff --git a/preprocessing/commflush.go b/comm/commflush.go
index ac4a220..c5ef60b 100644
--- a/preprocessing/commflush.go
+++ b/comm/commflush.go
@@ -1,13 +1,13 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-07 09:22:53
- * @LastEditTime: 2020-12-07 14:59:59
+ * @LastEditTime: 2020-12-19 10:42:51
* @LastEditors: Please set LastEditors
* @Description: this file flushes invalid commands using various types of filters
* @FilePath: /commdetection/commflush.go
*/
-package preprocessing
+package comm
import (
"bytes"
@@ -74,9 +74,7 @@ func SimpleCommandFilter(commands []Command) []Command {
// HelpCommandFilter tries to use "`Command` --help", "`Command` -h" and "`Command` help" to judge `Command` is valid or not
func HelpCommandFilter(commands []Command) []Command {
return cmdFilter(commands, func(command string) error {
- if commandChecker(command, "--help", NOTFOUNDREG) != nil &&
- commandChecker(command, "help", NOTFOUNDREG) != nil &&
- commandChecker(command, "-h", NOTFOUNDREG) != nil {
+ if commandChecker(command, "--help", NOTFOUNDREG) != nil {
return errors.New("command not found or not in $PATH or directory")
}
return nil
@@ -90,6 +88,13 @@ func ManCommandFilter(commands []Command) []Command {
})
}
+// WhichCommandFilter tries to use "which `Command`" cmd to judge `Command` is valid or not
+func WhichCommandFilter(commands []Command) []Command {
+ return cmdFilter(commands, func(command string) error {
+ return commandChecker("which", command, "")
+ })
+}
+
func commandChecker(command, flag, reg string) error {
compile, _ := regexp.Compile(reg)
var (
diff --git a/preprocessing/commflush_test.go b/comm/commflush_test.go
index a704c0b..baf6bbe 100644
--- a/preprocessing/commflush_test.go
+++ b/comm/commflush_test.go
@@ -1,4 +1,4 @@
-package preprocessing
+package comm
import (
"fmt"
@@ -175,7 +175,7 @@ func TestFlushCommands(t *testing.T) {
func BenchmarkFlushCommands(b *testing.B) {
b.Run("FlushCommands BenchMark Test", func(b *testing.B) {
- filters := []Filter{SimpleCommandFilter, HelpCommandFilter, ManCommandFilter}
+ filters := []Filter{WhichCommandFilter}
commands := GetCommands("/root/.bash_history", "")
b.ResetTimer()
commands = FlushCommands(commands, filters)
diff --git a/preprocessing/commget.go b/comm/commget.go
index eda07cc..920ec2d 100644
--- a/preprocessing/commget.go
+++ b/comm/commget.go
@@ -1,18 +1,17 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-02 17:08:59
- * @LastEditTime: 2020-12-09 10:27:45
+ * @LastEditTime: 2020-12-19 10:47:41
* @LastEditors: Please set LastEditors
* @Description: Get commands from file or network
* @FilePath: /commdetection/preprocessing/commget.go
*/
-package preprocessing
+package comm
import (
- "fmt"
+ "commdetection/logger"
"io/ioutil"
- "log"
"reflect"
"strings"
)
@@ -30,16 +29,16 @@ func GetCommands(file string, url string) []Command {
if err == nil {
return commands
}
- log.Print(err)
+ logger.Warnln(err)
}
if url != "" {
commands, err := getCommandsFromNet(url)
if err == nil {
return commands
}
- log.Print(err)
+ logger.Warnln(err)
}
- log.Print(fmt.Errorf("cannot get commands from any file or net"))
+ logger.Warnln("cannot get commands from any file or net")
return []Command{}
}
diff --git a/preprocessing/commget_test.go b/comm/commget_test.go
index bd7a9bb..9651a56 100644
--- a/preprocessing/commget_test.go
+++ b/comm/commget_test.go
@@ -1,12 +1,12 @@
/*
* @Author: your name
* @Date: 2020-12-02 17:09:14
- * @LastEditTime: 2020-12-09 10:26:20
+ * @LastEditTime: 2020-12-19 10:42:59
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /commdetection/preprocessing/commget_test.go
*/
-package preprocessing
+package comm
import (
"testing"
diff --git a/go.mod b/go.mod
index 1c51936..80e0e1f 100644
--- a/go.mod
+++ b/go.mod
@@ -2,4 +2,9 @@ module commdetection
go 1.15
-require gopkg.in/yaml.v2 v2.4.0
+require (
+ github.com/sirupsen/logrus v1.7.0
+ github.com/spf13/cobra v1.1.1
+ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
+ gopkg.in/yaml.v2 v2.4.0
+)
diff --git a/go.sum b/go.sum
index 0e02cb7..41ff5d4 100644
--- a/go.sum
+++ b/go.sum
@@ -1,9 +1,298 @@
-github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
-github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
-github.com/sevlyar/go-daemon v0.1.5 h1:Zy/6jLbM8CfqJ4x4RPr7MJlSKt90f00kNM1D401C+Qk=
-github.com/sevlyar/go-daemon v0.1.5/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE=
-golang.org/x/sys v0.0.0-20201204225414-ed752295db88 h1:KmZPnMocC93w341XZp26yTJg8Za7lhb2KhkYmixoeso=
-golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
+cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
+cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
+cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
+cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
+cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
+cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
+cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk=
+cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
+cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
+dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
+github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
+github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
+github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
+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/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=
+github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
+github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
+github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
+github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
+github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
+github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
+github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
+github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
+github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
+github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
+github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
+github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
+github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
+github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
+github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
+github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
+github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
+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=
+github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+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=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
+github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
+github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
+github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
+github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
+github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
+github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
+github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
+github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
+github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
+github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
+github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
+github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
+github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
+github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
+github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
+github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
+github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
+github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
+github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
+github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
+github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
+github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
+github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
+github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
+github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
+github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
+github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
+github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
+github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
+github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
+github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
+github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+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/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
+github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
+github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
+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/konsorten/go-windows-terminal-sequences v1.0.1/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/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
+github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
+github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
+github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
+github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
+github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
+github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
+github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
+github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
+github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
+github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
+github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
+github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
+github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
+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/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/errors v0.8.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=
+github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
+github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
+github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
+github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
+github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
+github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
+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.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=
+github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
+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.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/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
+github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
+github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
+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 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=
+github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
+github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
+github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
+github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
+github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
+go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
+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=
+go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
+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-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
+golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
+golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
+golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
+golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
+golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
+golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
+golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
+golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
+golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
+golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+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/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
+golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+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-20190423024810-112230192c58/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=
+golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+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-20190412213103-97732733099d/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-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-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
+golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+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-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-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=
+golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
+google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
+google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
+google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
+google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
+google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
+google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
+google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
+google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
+google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
+gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
+gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
+gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
+gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
+rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
diff --git a/logger/commlog.go b/logger/commlog.go
new file mode 100644
index 0000000..9a4ebc4
--- /dev/null
+++ b/logger/commlog.go
@@ -0,0 +1,45 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2020-12-18 16:16:09
+ * @LastEditTime: 2020-12-19 10:47:01
+ * @LastEditors: Please set LastEditors
+ * @Description: In User Settings Edit
+ * @FilePath: /commdetection/commlog/commlog.go
+ */
+
+package logger
+
+import (
+ "os"
+
+ "github.com/sirupsen/logrus"
+)
+
+var logger = logrus.New()
+
+// Init initializes
+func Init(logLevel logrus.Level, formatter logrus.Formatter) {
+ logger.SetFormatter(formatter)
+ logger.SetLevel(logLevel)
+ logger.SetOutput(os.Stdout)
+}
+
+// Warnln uses logrus.Warnln to set warn info
+func Warnln(args ...interface{}) {
+ logger.Warnln(args)
+}
+
+// Debugln uses logrus.Debugln to set debug info
+func Debugln(args ...interface{}) {
+ logger.Debugln(args)
+}
+
+// Fatalln uses logrus.Fatalln to set fatal info
+func Fatalln(args ...interface{}) {
+ logger.Fatalln(args)
+}
+
+// Warnf uses logrus.Warnf to set warning formatted info
+func Warnf(format string, args ...interface{}) {
+ logger.Warnf(format, args)
+}
diff --git a/main.go b/main.go
index 76dcd7d..fb5252d 100644
--- a/main.go
+++ b/main.go
@@ -1,18 +1,16 @@
/*
- * @Author: your name
+ * @Author: EnderByEndera
* @Date: 2020-12-04 15:03:24
- * @LastEditTime: 2020-12-15 11:46:55
+ * @LastEditTime: 2020-12-19 11:41:28
* @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
+ * @Description: Main Func Entry, use flags to give help
* @FilePath: /commdetection/main.go
*/
+
package main
-import (
- "commdetection/yaml"
- "fmt"
-)
+import "commdetection/cmd"
func main() {
- fmt.Println(yaml.GetYamlSetting("commrule"))
+ cmd.Execute()
}
diff --git a/main_test.go b/main_test.go
index 52166b9..bffd420 100644
--- a/main_test.go
+++ b/main_test.go
@@ -1,19 +1,15 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-04 15:03:42
- * @LastEditTime: 2020-12-15 11:51:34
+ * @LastEditTime: 2020-12-19 13:13:53
* @LastEditors: Please set LastEditors
* @Description: Test main.go
* @FilePath: /commdetection/main_test.go
*/
package main
-import (
- "commdetection/yaml"
- "fmt"
- "testing"
-)
+import "testing"
func TestMain(t *testing.T) {
- fmt.Println(yaml.GetYamlSetting("commrule"))
+ main()
}
diff --git a/rules/commscore.go b/rules/commscore.go
new file mode 100644
index 0000000..b343f98
--- /dev/null
+++ b/rules/commscore.go
@@ -0,0 +1,31 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2020-12-16 13:59:51
+ * @LastEditTime: 2020-12-19 10:43:36
+ * @LastEditors: Please set LastEditors
+ * @Description: Includes CommScore definition
+ * @FilePath: /commdetection/rules/commscore.go
+ */
+
+package rules
+
+import (
+ "commdetection/comm"
+)
+
+// CommScore includes command name and its score
+type CommScore struct {
+ Command comm.Command `json:"command"`
+ Score float64 `json:"score"`
+}
+
+// InitCommScores initialize commscores from []Command
+func InitCommScores(commands []comm.Command) (commScores []CommScore) {
+ for _, command := range commands {
+ commScores = append(commScores, CommScore{
+ Command: command,
+ Score: 100,
+ })
+ }
+ return
+}
diff --git a/rules/commscore_test.go b/rules/commscore_test.go
new file mode 100644
index 0000000..caee64b
--- /dev/null
+++ b/rules/commscore_test.go
@@ -0,0 +1,10 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2020-12-16 14:33:02
+ * @LastEditTime: 2020-12-16 14:34:40
+ * @LastEditors: Please set LastEditors
+ * @Description: In User Settings Edit
+ * @FilePath: /commdetection/rules/commscore_test.go
+ */
+
+package rules
diff --git a/rules/marshalling.go b/rules/marshalling.go
new file mode 100644
index 0000000..a6452fd
--- /dev/null
+++ b/rules/marshalling.go
@@ -0,0 +1,115 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2020-12-16 13:57:06
+ * @LastEditTime: 2020-12-19 10:48:00
+ * @LastEditors: Please set LastEditors
+ * @Description: Includes various marshalling ways
+ * @FilePath: /commdetection/rules/marshalling.go
+ */
+
+package rules
+
+import (
+ "commdetection/logger"
+ "commdetection/yaml"
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "strings"
+)
+
+//TODO: Temporarily use the funcMap to map the stringVal and the funcRule, will use a func to map later
+var (
+ ruleFuncMap = map[string]evaluation{
+ "EvaluateCommandRule": EvaluateCommandRule,
+ "EvaluatePathRule": EvaluatePathRule,
+ }
+)
+
+// GetFuncName returns a function's name
+func GetFuncName(i interface{}, seps ...rune) string {
+ fn := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
+ fields := strings.FieldsFunc(fn, func(sep rune) bool {
+ for _, s := range seps {
+ if sep == s {
+ return true
+ }
+ }
+ return false
+ })
+ if size := len(fields); size > 0 {
+ return fields[size-1]
+ }
+ return ""
+}
+
+func marshalRules(rs Rules) (err error) {
+ fileName := yaml.GetYamlSetting("multirules")
+ if fileName == "" {
+ fileName = filepath.Join(os.Getenv("COMMDEPATH"), "rules", "rulesjson", "rules.json")
+ }
+ err = marshalSetting(rs, fileName)
+ return
+}
+
+// unmarshalRules unmarshal rules from a json file
+func unmarshalRules() (r Rules, err error) {
+ fileName := yaml.GetYamlSetting("rules")
+ if fileName == "" {
+ fileName = filepath.Join(os.Getenv("COMMDEPATH"), "rules", "rulesjson", "rules.json")
+ }
+ err = unmarshalSetting(fileName, r)
+ if err != nil {
+ fmt.Printf("json file settings conversion to %s failed, please check json file %s is correct or not", reflect.TypeOf(r).Name(), fileName)
+ }
+ return
+}
+
+func marshalSensitivePathSetting(spaths SPaths, fileName string) error {
+ return marshalSetting(spaths, fileName)
+}
+
+func unmarshalSensitivePathSetting(fileName string) (spaths SPaths, err error) {
+ err = unmarshalSetting(fileName, &spaths)
+ if err != nil {
+ logger.Warnf("json file settings conversion to %s failed, please check json file %s is correct or not\n", reflect.TypeOf(spaths).Name(), fileName)
+ }
+ return
+}
+
+func marshalSensitiveCommSetting(scomms []SComm, fileName string) error {
+ return marshalSetting(scomms, fileName)
+}
+
+func unmarshalSensitiveCommSetting(fileName string) (scomms SComms, err error) {
+ err = unmarshalSetting(fileName, &scomms)
+ if err != nil {
+ logger.Warnf("json file settings conversion to %s failed, please check json file %s is correct or not\n", reflect.TypeOf(scomms).Name(), fileName)
+ }
+ return
+}
+
+func marshalSetting(settings interface{}, fileName string) error {
+ buf, err := json.Marshal(settings)
+ if err != nil {
+ return err
+ }
+ ioutil.WriteFile(fileName, buf, os.ModeAppend)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func unmarshalSetting(fileName string, settings interface{}) error {
+ buf, err := ioutil.ReadFile(fileName)
+ if err != nil {
+ return err
+ }
+ err = json.Unmarshal(buf, settings)
+ return err
+}
diff --git a/rules/marshalling_test.go b/rules/marshalling_test.go
new file mode 100644
index 0000000..16a2cb9
--- /dev/null
+++ b/rules/marshalling_test.go
@@ -0,0 +1,100 @@
+/*
+ * @Author: EnderByEndera
+ * @Date: 2020-12-16 14:31:00
+ * @LastEditTime: 2020-12-16 14:32:44
+ * @LastEditors: Please set LastEditors
+ * @Description: Test marshalling.go
+ * @FilePath: /commdetection/rules/marshalling_test.go
+ */
+
+package rules
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "reflect"
+ "testing"
+)
+
+func TestMarshalSensitiveCommSetting(t *testing.T) {
+ fileName := "rulesjson/commrules.json"
+ scomms := SComms{
+ {
+ Comm: "wget",
+ Coefficient: 0.8,
+ },
+ {
+ Comm: "apt",
+ Coefficient: 1.0,
+ },
+ }
+ err := marshalSensitiveCommSetting(scomms, fileName)
+ if err != nil {
+ t.Error(err)
+ }
+ jsonBuf, _ := json.Marshal(scomms)
+ readBuf, err := ioutil.ReadFile(fileName)
+ if !reflect.DeepEqual(readBuf, jsonBuf) {
+ fmt.Println(readBuf)
+ t.Errorf("results are not as predicted")
+ }
+}
+
+func TestUnmarshalSensitiveCommSetting(t *testing.T) {
+ fileName := "rulesjson/commrules.json"
+ scomms, err := unmarshalSensitiveCommSetting(fileName)
+ if err != nil {
+ t.Error(err)
+ }
+ predict := SComms{
+ {
+ Comm: "wget",
+ Coefficient: 0.8,
+ },
+ {
+ Comm: "apt",
+ Coefficient: 1.0,
+ },
+ }
+ if !reflect.DeepEqual(scomms, predict) {
+ t.Errorf("results are not as predicted")
+ }
+}
+
+func TestMarshalSensitivePathSetting(t *testing.T) {
+ fileName := "rulesjson/pathrules.json"
+ spaths := SPaths{
+ {
+ Path: "/root/go/src/commdetection/rules",
+ Coefficient: 0.7,
+ },
+ }
+ err := marshalSensitivePathSetting(spaths, fileName)
+ if err != nil {
+ t.Error(err)
+ }
+ jsonBuf, _ := json.Marshal(spaths)
+ readBuf, err := ioutil.ReadFile(fileName)
+ if !reflect.DeepEqual(readBuf, jsonBuf) {
+ fmt.Println(readBuf)
+ t.Errorf("results are not as predicted")
+ }
+}
+
+func TestUnmarshalSensitivePathSetting(t *testing.T) {
+ fileName := "rulesjson/pathrules.json"
+ spaths, err := unmarshalSensitivePathSetting(fileName)
+ if err != nil {
+ t.Error(err)
+ }
+ predict := SPaths{
+ {
+ Path: "/root/go/src/commdetection/rules",
+ Coefficient: 0.7,
+ },
+ }
+ if !reflect.DeepEqual(spaths, predict) {
+ t.Errorf("results are not as predicted")
+ }
+}
diff --git a/rules/rules.go b/rules/rules.go
index 8c97a8f..0066543 100644
--- a/rules/rules.go
+++ b/rules/rules.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-04 15:03:00
- * @LastEditTime: 2020-12-15 10:05:33
+ * @LastEditTime: 2020-12-19 16:47:09
* @LastEditors: Please set LastEditors
* @Description: rules provide all the rules to check the commands' availability and set score of every command
* @FilePath: /commdetection/rules/commcheck.go
@@ -10,19 +10,9 @@
package rules
import (
- prep "commdetection/preprocessing"
- "commdetection/yaml"
- "fmt"
- "log"
- "reflect"
+ "commdetection/logger"
)
-// CommScore includes command name and its score
-type CommScore struct {
- Command prep.Command `json:"command"`
- Score float64 `json:"score"`
-}
-
// Rule defines a rule's func and its name
type Rule struct {
Name string `json:"name"`
@@ -32,19 +22,13 @@ type Rule struct {
// Rules is the slice of Rule
type Rules []Rule
-//TODO: Temporarily use the funcMap to map the stringVal and the funcRule, will use a func to map later
-var (
- ruleFuncMap = map[string]func(CommScore) CommScore{
- "EvaluateCommandRule": EvaluateCommandRule,
- "EvaluatePathRule": EvaluatePathRule,
- }
-)
+type evaluation func(CommScore) CommScore
// AddRule adds one rule to the rules
func AddRule(rs Rules, rule Rule) Rules {
for _, r := range rs {
if r.Name == rule.Name {
- log.Printf("%s already existed", rule.Name)
+ logger.Warnf("%s already existed", rule.Name)
return rs
}
}
@@ -62,31 +46,34 @@ func DeleteRuleByName(r Rules, ruleName string) Rules {
}
}
if !existed {
- log.Printf("rule %s not existed in the rules", ruleName)
+ logger.Warnf("rule %s not existed in the rules", ruleName)
}
return r
}
-// MarshalRules marshal rules to a json file
-func MarshalRules(rs Rules) (err error) {
- fileName := "rulesjson/rules.json"
- err = marshalSetting(rs, fileName)
- return
-}
-
-// UnmarshalRules unmarshal rules from a json file
-func UnmarshalRules() (r Rules, err error) {
- fileName := yaml.GetYamlSetting("rules")
- err = unmarshalSetting(fileName, r)
- if err != nil {
- fmt.Printf("json file settings conversion to %s failed, please check json file %s is correct or not", reflect.TypeOf(r).Name(), fileName)
- }
- return
-}
-
// CreateRule creates one rule with name and rule func and return a Rule
func CreateRule(name string, rule string) (r Rule) {
r.Name = name
r.RuleFunc = rule
return
}
+
+// EvaluateCommScore evaluates scores of the commands in the css
+func EvaluateCommScore(css []CommScore, rs Rules) []CommScore {
+ defer func() {
+ err := recover()
+ if err != nil {
+ logger.Fatalln("Unexpected error happened, RuleFunc conversion failed, please check the ruleFuncMap")
+ }
+ }()
+ if len(rs) == 0 {
+ logger.Warnln("There are no rules in the evaluation")
+ return css
+ }
+ for index := 0; index < len(css); index++ {
+ for _, r := range rs {
+ css[index] = ruleFuncMap[r.RuleFunc](css[index])
+ }
+ }
+ return css
+}
diff --git a/rules/rules_test.go b/rules/rules_test.go
index 4e8030a..1c3ef32 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: 2020-12-15 15:57:32
+ * @LastEditTime: 2020-12-19 10:44:44
* @LastEditors: Please set LastEditors
* @Description: Test commrules.go
* @FilePath: /commdetection/rules/commrules_test.go
@@ -9,7 +9,7 @@
package rules
import (
- "commdetection/preprocessing"
+ "commdetection/comm"
"fmt"
"testing"
)
@@ -57,7 +57,7 @@ func TestRule(t *testing.T) {
}
}
cs := CommScore{
- Command: preprocessing.Command{CommName: "wget"},
+ Command: comm.Command{CommName: "wget"},
Score: 100,
}
for _, rule := range r {
@@ -118,9 +118,37 @@ func TestRule(t *testing.T) {
RuleFunc: "EvaluateCommandRule",
},
}
- err := MarshalRules(rs)
+ err := marshalRules(rs)
if err != nil {
t.Error(err)
}
})
}
+
+func TestInitCommScores(t *testing.T) {
+ comms := comm.GetCommands("/root/.bash_history", "")
+ comms = comm.FlushCommands(comms, []comm.Filter{comm.ManCommandFilter})
+ css := InitCommScores(comms)
+ fmt.Println(css)
+}
+
+func TestEvaluateCommScore(t *testing.T) {
+ css := EvaluateCommScore([]CommScore{
+ {
+ Command: comm.Command{
+ CommName: "wget",
+ Flags: []string{""},
+ },
+ Score: 100,
+ },
+ },
+ Rules{
+ Rule{
+ Name: "RuleA",
+ RuleFunc: "EvaluateCommandRule",
+ },
+ })
+ if css[0].Score != 80.0 {
+ t.Errorf("Wrong Score")
+ }
+}
diff --git a/rules/rulestype_test.go b/rules/rulestype_test.go
index 8e5f3a3..5222996 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: 2020-12-15 17:36:38
+ * @LastEditTime: 2020-12-19 10:45:05
* @LastEditors: Please set LastEditors
* @Description: Test UnmarshalSetting and MarshalSetting
* @FilePath: /commdetection/rules/rulestype_test.go
@@ -10,100 +10,15 @@
package rules
import (
- prep "commdetection/preprocessing"
- "encoding/json"
- "fmt"
- "io/ioutil"
- "reflect"
+ "commdetection/comm"
+ "log"
"testing"
)
-func TestMarshalSensitiveCommSetting(t *testing.T) {
- fileName := "rulesjson/commrules.json"
- scomms := SComms{
- {
- Comm: "wget",
- Coefficient: 0.8,
- },
- {
- Comm: "apt",
- Coefficient: 1.0,
- },
- }
- err := marshalSensitiveCommSetting(scomms, fileName)
- if err != nil {
- t.Error(err)
- }
- jsonBuf, _ := json.Marshal(scomms)
- readBuf, err := ioutil.ReadFile(fileName)
- if !reflect.DeepEqual(readBuf, jsonBuf) {
- fmt.Println(readBuf)
- t.Errorf("results are not as predicted")
- }
-}
-
-func TestUnmarshalSensitiveCommSetting(t *testing.T) {
- fileName := "rulesjson/commrules.json"
- scomms, err := unmarshalSensitiveCommSetting(fileName)
- if err != nil {
- t.Error(err)
- }
- predict := SComms{
- {
- Comm: "wget",
- Coefficient: 0.8,
- },
- {
- Comm: "apt",
- Coefficient: 1.0,
- },
- }
- if !reflect.DeepEqual(scomms, predict) {
- t.Errorf("results are not as predicted")
- }
-}
-
-func TestMarshalSensitivePathSetting(t *testing.T) {
- fileName := "rulesjson/pathrules.json"
- spaths := SPaths{
- {
- Path: "/root/go/src/commdetection/rules",
- Coefficient: 0.7,
- },
- }
- err := marshalSensitivePathSetting(spaths, fileName)
- if err != nil {
- t.Error(err)
- }
- jsonBuf, _ := json.Marshal(spaths)
- readBuf, err := ioutil.ReadFile(fileName)
- if !reflect.DeepEqual(readBuf, jsonBuf) {
- fmt.Println(readBuf)
- t.Errorf("results are not as predicted")
- }
-}
-
-func TestUnmarshalSensitivePathSetting(t *testing.T) {
- fileName := "rulesjson/pathrules.json"
- spaths, err := unmarshalSensitivePathSetting(fileName)
- if err != nil {
- t.Error(err)
- }
- predict := SPaths{
- {
- Path: "/root/go/src/commdetection/rules",
- Coefficient: 0.7,
- },
- }
- if !reflect.DeepEqual(spaths, predict) {
- t.Errorf("results are not as predicted")
- }
-}
-
func TestEvaluateCommandRule(t *testing.T) {
t.Run("Test Normal Command Rule Evaluation", func(t *testing.T) {
cs := CommScore{
- Command: prep.Command{
+ Command: comm.Command{
CommName: "wget",
Flags: []string{"https://127.0.0.1:8080"},
},
@@ -119,15 +34,15 @@ func TestEvaluateCommandRule(t *testing.T) {
func TestEvaluatePathRule(t *testing.T) {
t.Run("Test Normal Path Rule Evaluation", func(t *testing.T) {
cs := CommScore{
- Command: prep.Command{
+ Command: comm.Command{
CommName: "wget",
- Flags: []string{},
+ Flags: []string{"/root/go/src/commdetection/rules/rulesjson/rules.json"},
},
Score: 100,
}
cs = EvaluatePathRule(cs)
if cs.Score >= 0 {
- fmt.Printf("result score is %f", cs.Score)
+ log.Printf("result score is %f", cs.Score)
} else {
t.Errorf("score is not as predicted")
}
@@ -136,16 +51,21 @@ func TestEvaluatePathRule(t *testing.T) {
func BenchmarkEvaluateCommandRule(b *testing.B) {
cs := CommScore{
- Command: prep.Command{
+ Command: comm.Command{
CommName: "wget",
Flags: []string{"https://127.0.0.1:8080"},
},
Score: 100,
}
cs = EvaluateCommandRule(cs)
- cs = EvaluateCommandRule(cs)
}
func BenchmarkEvaluatePathRule(b *testing.B) {
- //TODO: will finish after the EvaluatePathRule is finished
+ comms := comm.GetCommands("/root/.bash_history", "")
+ comms = comm.FlushCommands(comms, []comm.Filter{comm.ManCommandFilter})
+ css := InitCommScores(comms)
+ b.ResetTimer()
+ for _, cs := range css {
+ cs = EvaluatePathRule(cs)
+ }
}
diff --git a/rules/ruletypes.go b/rules/ruletypes.go
index 2dd77ec..067ec17 100644
--- a/rules/ruletypes.go
+++ b/rules/ruletypes.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-08 10:59:19
- * @LastEditTime: 2020-12-15 17:30:21
+ * @LastEditTime: 2020-12-19 10:48:21
* @LastEditors: Please set LastEditors
* @Description: Unmarshal and marshal various types of settings and rules
* @FilePath: /commdetection/rules/ruletypes.go
@@ -10,14 +10,10 @@
package rules
import (
+ "commdetection/logger"
"commdetection/yaml"
- "encoding/json"
- "fmt"
- "io/ioutil"
- "log"
"os"
"path/filepath"
- "reflect"
)
// SPath includes sensitive path dir and its sensitive coefficient
@@ -47,7 +43,7 @@ func EvaluatePathRule(cs CommScore) CommScore {
}
spaths, err := unmarshalSensitivePathSetting(fileName)
if err != nil {
- log.Printf("cannot get sensitive paths from file %s, please check the file path", fileName)
+ logger.Warnf("cannot get sensitive paths from file %s, please check the file path", fileName)
return cs
}
for _, spath := range spaths {
@@ -67,12 +63,15 @@ func EvaluatePathRule(cs CommScore) CommScore {
break
}
}
- cs.Score *= 1.0 - float64(similar)/float64(len(spath.Path))*(1.0-spath.Coefficient)
+ ratio := float64(similar) / float64(len(spath.Path))
+ if ratio > 0.1 {
+ cs.Score *= 1.0 - ratio*(1.0-spath.Coefficient)
+ }
}
return nil
})
if err != nil {
- log.Print(err)
+ logger.Warnf("Error occured during EvaluatePathRule, error is %s", err)
}
}
return cs
@@ -87,7 +86,7 @@ func EvaluateCommandRule(cs CommScore) CommScore {
}
scomms, err := unmarshalSensitiveCommSetting(fileName)
if err != nil {
- log.Printf("cannot get sensitive paths from file %s, please check the file path", fileName)
+ logger.Warnf("cannot get sensitive paths from file %s, please check the file path", fileName)
return cs
}
for _, scomm := range scomms {
@@ -97,54 +96,3 @@ func EvaluateCommandRule(cs CommScore) CommScore {
}
return cs
}
-
-func marshalSensitivePathSetting(spaths SPaths, fileName string) error {
- return marshalSetting(spaths, fileName)
-}
-
-func marshalSensitiveCommSetting(scomms []SComm, fileName string) error {
- return marshalSetting(scomms, fileName)
-}
-
-func unmarshalSensitivePathSetting(fileName string) (spaths SPaths, err error) {
-
- err = unmarshalSetting(fileName, &spaths)
- if err != nil {
- log.Printf("json file settings conversion to %s failed, please check json file %s is correct or not\n", reflect.TypeOf(spaths).Name(), fileName)
- }
- return
-}
-
-func unmarshalSensitiveCommSetting(fileName string) (scomms SComms, err error) {
- err = unmarshalSetting(fileName, &scomms)
- if err != nil {
- log.Printf("json file settings conversion to %s failed, please check json file %s is correct or not\n", reflect.TypeOf(scomms).Name(), fileName)
- }
- return
-}
-
-func marshalSetting(settings interface{}, fileName string) error {
- buf, err := json.Marshal(settings)
- if err != nil {
- return err
- }
- ioutil.WriteFile(fileName, buf, os.ModeAppend)
- if err != nil {
- return err
- }
- return nil
-}
-
-func unmarshalSetting(fileName string, settings interface{}) error {
- dir, err := os.Getwd()
- fmt.Println(dir)
- buf, err := ioutil.ReadFile(fileName)
- if err != nil {
- return err
- }
- err = json.Unmarshal(buf, settings)
- if err != nil {
- log.Println("Unmarshal Settings from json file failed, please check your json file")
- }
- return err
-}
diff --git a/yaml/yaml.go b/yaml/yaml.go
index a345872..b0a6e80 100644
--- a/yaml/yaml.go
+++ b/yaml/yaml.go
@@ -1,7 +1,7 @@
/*
* @Author: EnderByEndera
* @Date: 2020-12-09 16:44:44
- * @LastEditTime: 2020-12-15 11:52:42
+ * @LastEditTime: 2020-12-19 10:48:31
* @LastEditors: Please set LastEditors
* @Description: Init settings from yaml file
* @FilePath: /commdetection/init/init.go
@@ -10,8 +10,8 @@
package yaml
import (
+ "commdetection/logger"
"io/ioutil"
- "log"
"os"
"path/filepath"
@@ -27,18 +27,28 @@ type Conf struct {
}
}
-// GetYamlSetting gets the yaml settings from conf.yaml
-func GetYamlSetting(settingName string) (c string) {
- conf := new(Conf)
+var conf *Conf
+
+// InitYamlSetting initializes the yaml setting configuration
+func InitYamlSetting() error {
+ conf = new(Conf)
buf, err := ioutil.ReadFile(filepath.Join(os.Getenv("COMMDEPATH"), "conf.yaml"))
if err != nil {
- log.Println("read yaml file failed, return NULL string")
- return ""
+ logger.Warnln("read yaml file failed, return NULL string")
+ return err
}
err = yaml.Unmarshal(buf, conf)
if err != nil {
- log.Println("Unmarshal yaml file failed, please check conf.yaml, return NULL string")
- return ""
+ logger.Warnln("Unmarshal yaml file failed, please check conf.yaml, return NULL string")
+ return err
+ }
+ return nil
+}
+
+// GetYamlSetting gets the yaml settings from conf.yaml
+func GetYamlSetting(settingName string) (c string) {
+ if conf == nil {
+ InitYamlSetting()
}
switch settingName {
case "commrules":
@@ -49,6 +59,7 @@ func GetYamlSetting(settingName string) (c string) {
c = filepath.Join(os.Getenv("COMMDEPATH"), conf.Paths.MultiRulesPath)
default:
c = os.Getenv("COMMDEPATH")
+ logger.Warnln("Didn't get any setting, use default value: " + os.Getenv("COMMDEPATH"))
}
return
}
diff --git a/yaml/yaml_test.go b/yaml/yaml_test.go
index 9dfda4e..59ca084 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: 2020-12-15 10:22:26
+ * @LastEditTime: 2020-12-17 10:02:22
* @LastEditors: Please set LastEditors
* @Description: test yaml.go
* @FilePath: /commdetection/yaml/yaml_test.go