diff --git a/README.md b/README.md index 165fe1b..46bbad6 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,21 @@ Live example: D If the configuration file is missing, the default settings will automatically drop itself in the current working directory as `config.toml`. +``` +title = "HellPot" + +[logger] +debug = false +log_directory = "./logs/" + +[http] +bind_addr = "127.0.0.1" +bind_port = "8080" +# paths to be added to robots.txt that we will respond to +paths = [ + "wp-login.php", + "wp-login", +] +``` + + \ No newline at end of file diff --git a/config.toml b/config.toml index 3e18570..e6d06d7 100644 --- a/config.toml +++ b/config.toml @@ -1,7 +1,7 @@ title = "HellPot" [logger] -debug = false +debug = true log_directory = "./logs/" [http] diff --git a/http.go b/http.go index fc656fe..e71d055 100644 --- a/http.go +++ b/http.go @@ -39,6 +39,12 @@ func NewHoneypot(mm MarkovMap, buffsize int) http.HandlerFunc { paths = paths + "Disallow: " + p + "\r\n" } + log.Debug(). + Str("UserAgent", r.UserAgent()). + Strs("REMOTE_ADDR", r.Header.Values("X-Real-IP")). + Strs("PATHS", config.Paths). + Msg("SERVE_ROBOTS") + if _, err := io.WriteString(w, robotsTxt+paths+"\r\n"); err != nil { log.Error().Err(err).Msg("SERVE_ROBOTS_ERROR") } @@ -69,13 +75,13 @@ func NewHoneypot(mm MarkovMap, buffsize int) http.HandlerFunc { buf := getBuffer() defer putBuffer(buf) io.WriteString(w, "\n\n") - n, err := io.CopyBuffer(w, mm, buf) + n, _ := io.CopyBuffer(w, mm, buf) log.Info(). Str("UserAgent", r.UserAgent()). Interface("URL", r.URL.RequestURI()). Strs("REMOTE_ADDR", r.Header.Values("X-Real-IP")). Int64("BYTES", n). Dur("DURATION", time.Since(s)). - Err(err).Msg("FINISH") + Msg("FINISH") } } diff --git a/main.go b/main.go index 318ba0d..fe66fb5 100644 --- a/main.go +++ b/main.go @@ -10,10 +10,8 @@ import ( // ascii banners and other aesthetic shit "HellPot/src/decorate" - // bitcask embedded key/value database //"HellPot/src/casket" - ) var log zerolog.Logger diff --git a/src/config/config.go b/src/config/config.go index 2a4e19e..3d19301 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -47,15 +47,15 @@ var appLabel string = Title + " " + Version */ var ( - Debug bool = false - LogDir string - Banner string - DataDir string + Debug bool = false + LogDir string + Banner string + DataDir string Databases []string //Color bool - BindAddr string - BindPort string - Paths []string + BindAddr string + BindPort string + Paths []string ) // ----------------------------------------------------------------- @@ -69,11 +69,11 @@ var ( customconfig bool /*Config (for viper) - this is an exported variable that merely points to the underlying viper config instance - This will allow us to reference the viper type from any other package if we need to */ + this is an exported variable that merely points to the underlying viper config instance + This will allow us to reference the viper type from any other package if we need to */ Config *viper.Viper - log zerolog.Logger + log zerolog.Logger configLocations []string home string @@ -141,8 +141,8 @@ func preLog() zerolog.Logger { } /*PrintConfigLog (for debug) - here we implement a buffer for the log lines generated by our configuration engine - We use this to assure that our log output appears _after_ the banner output instead of before it */ + here we implement a buffer for the log lines generated by our configuration engine + We use this to assure that our log output appears _after_ the banner output instead of before it */ func PrintConfigLog() { for _, line := range logBuffer.lines { print(line) @@ -169,7 +169,7 @@ func Blueprint() { buf, err := ioutil.ReadAll(f) err2 := Config.ReadConfig(bytes.NewBuffer(buf)) - if (err != nil || err2 != nil) { + if err != nil || err2 != nil { println("Error reading specified config file: " + os.Args[i+1]) if err != nil { panic("config file read fatal error: " + err.Error()) @@ -212,20 +212,20 @@ func Blueprint() { }, } -/* - defData := map[string]interface{}{ - "directory": "./.data/", - } + /* + defData := map[string]interface{}{ + "directory": "./.data/", + } - // here we are defining a generic category as an example - defCategory := map[string]interface{}{ - "shouldistay": true, - "shouldigo": false, - "optics": "ironsights", - "fucksgiven": 0, - "admins": []string{"Satan", "Yahweh", "FuckholeJones"}, - } -*/ + // here we are defining a generic category as an example + defCategory := map[string]interface{}{ + "shouldistay": true, + "shouldigo": false, + "optics": "ironsights", + "fucksgiven": 0, + "admins": []string{"Satan", "Yahweh", "FuckholeJones"}, + } + */ Config.SetDefault("name", defName) Config.SetDefault("logger", defLogger) @@ -274,7 +274,6 @@ func associate() { zerolog.SetGlobalLevel(zerolog.DebugLevel) } - for _, key := range Config.AllKeys() { log.Debug().Str("key", key).Msg("LOAD_CONFIG_DIRECTIVE") } @@ -287,7 +286,7 @@ func associate() { //Databases = Config.GetStringSlice("database.databases") // HellPot specific directives - BindAddr = Config.GetString("http.bind_addr") - BindPort = Config.GetString("http.bind_port") - Paths = Config.GetStringSlice("http.paths") + BindAddr = Config.GetString("http.bind_addr") + BindPort = Config.GetString("http.bind_port") + Paths = Config.GetStringSlice("http.paths") } diff --git a/src/decorate/decorate.go b/src/decorate/decorate.go index cbae965..6279418 100644 --- a/src/decorate/decorate.go +++ b/src/decorate/decorate.go @@ -12,13 +12,13 @@ const banner = "ChtbOTc7NDBtIBtbOTc7NDNt4paEG1szMzs0MG3ilojilpIbWzk3OzQwbSAbWzMz /*Banner (print banner) - load the base64 data which contains the banner - then after decoding the banner we will iterate through the resulting string line by line + load the base64 data which contains the banner + then after decoding the banner we will iterate through the resulting string line by line - we do this so that in the future we can add effects like a gradient to the banner if desired + we do this so that in the future we can add effects like a gradient to the banner if desired - if we didn't want to worry about that we could nix the strings and bufio imports - and just fmt.Println(dec) to print the banner without additional styling + if we didn't want to worry about that we could nix the strings and bufio imports + and just fmt.Println(dec) to print the banner without additional styling */ func Banner() { if len(banner) < 1 { diff --git a/src/logger/logger.go b/src/logger/logger.go index 685c8fe..f7c69ab 100644 --- a/src/logger/logger.go +++ b/src/logger/logger.go @@ -26,4 +26,3 @@ func LogInit() { multi := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr}, logFile) GlobalLogger = zerolog.New(multi).With().Timestamp().Logger() } -