mirror of
https://github.com/yunginnanet/HellPot
synced 2024-06-24 06:48:02 +00:00
gofmt and refine logging
This commit is contained in:
parent
3f75a2c7de
commit
db7f5d7103
18
README.md
18
README.md
@ -32,3 +32,21 @@ Live example: <a href="https://vx-underground.org/wp-login.php" rel="nofollow">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",
|
||||
]
|
||||
```
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
title = "HellPot"
|
||||
|
||||
[logger]
|
||||
debug = false
|
||||
debug = true
|
||||
log_directory = "./logs/"
|
||||
|
||||
[http]
|
||||
|
10
http.go
10
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, "<HTML>\n<BODY>\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")
|
||||
}
|
||||
}
|
||||
|
2
main.go
2
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
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -26,4 +26,3 @@ func LogInit() {
|
||||
multi := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr}, logFile)
|
||||
GlobalLogger = zerolog.New(multi).With().Timestamp().Logger()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user