Fix: config bug

This commit is contained in:
kayos@tcp.direct 2021-10-17 10:09:28 -07:00
parent e92e71b7e0
commit 5593a54da4
11 changed files with 70 additions and 40 deletions

View File

@ -11,15 +11,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Build
run: go build -v ./...
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
- name: Test
run: go test -v ./...

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
go.sum
/dist/

View File

@ -1,12 +1,12 @@
# HellPot
[![GoDoc](https://godoc.org/github.com/yunginnanet/HellPot?status.svg)](https://godoc.org/github.com/yunginnanet/HellPot) [![Go Report Card](https://goreportcard.com/badge/github.com/yunginnanet/HellPot)](https://goreportcard.com/report/github.com/yunginnanet/HellPot) [![IRC](https://img.shields.io/badge/ircd.chat-%23tcpdirect-blue.svg)](ircs://ircd.chat:6697/#tcpdirect)
## Summary
HellPot is an endless honeypot based on [Heffalump](https://github.com/carlmjohnson/heffalump) that sends unruly HTTP bots to hell.
Notably it implements a [toml configuration file](https://github.com/spf13/viper), has [JSON logging](https://github.com/rs/zerolog), and comes with significant performance gains.
[![GoDoc](https://godoc.org/github.com/yunginnanet/HellPot?status.svg)](https://godoc.org/github.com/yunginnanet/HellPot) [![Go Report Card](https://goreportcard.com/badge/github.com/yunginnanet/HellPot)](https://goreportcard.com/report/github.com/yunginnanet/HellPot) [![IRC](https://img.shields.io/badge/ircd.chat-%23tcpdirect-blue.svg)](ircs://ircd.chat:6697/#tcpdirect)
![Exploding Heffalump](hellgif.gif)

View File

@ -21,30 +21,31 @@ func init() {
}
func writeConfig() {
if runtime.GOOS != "windows" {
if _, err := os.Stat(prefConfigLocation); os.IsNotExist(err) {
if err = os.Mkdir(prefConfigLocation, 0755); err != nil {
println("error writing new config: " + err.Error())
if runtime.GOOS == "windows" {
newconfig := "hellpot-config"
snek.SetConfigName(newconfig)
if err = snek.MergeInConfig(); err != nil {
if err = snek.SafeWriteConfigAs(newconfig + ".toml"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
newconfig := prefConfigLocation + "/" + "config.toml"
if err = snek.SafeWriteConfigAs(newconfig); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
Filename = newconfig
return
}
newconfig := "hellpot-config"
snek.SetConfigName(newconfig)
if err = snek.MergeInConfig(); err != nil {
if err = snek.SafeWriteConfigAs(newconfig + ".toml"); err != nil {
fmt.Println(err.Error())
if _, err := os.Stat(prefConfigLocation); os.IsNotExist(err) {
if err = os.MkdirAll(prefConfigLocation, 0755); err != nil {
println("error writing new config: " + err.Error())
os.Exit(1)
}
}
newconfig := prefConfigLocation + "/" + "config.toml"
if err = snek.SafeWriteConfigAs(newconfig); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
Filename = newconfig
}
@ -207,18 +208,17 @@ func processOpts() {
"http.paths": &Paths,
}
// bool options and their exported variables
boolOpt := map[string]*bool {
"http.use_unix_socket": &UseUnixSocket,
"logger.debug": &Debug,
boolOpt := map[string]*bool{
"http.use_unix_socket": &UseUnixSocket,
"logger.debug": &Debug,
"performance.restrict_concurrency": &RestrictConcurrency,
"logger.nocolor": &NoColor,
"logger.nocolor": &NoColor,
}
// integer options and their exported variables
intOpt := map[string]*int {
intOpt := map[string]*int{
"performance.max_workers": &MaxWorkers,
}
for key, opt := range stringOpt {
*opt = snek.GetString(key)
}

View File

@ -9,6 +9,7 @@ import (
)
var (
// CurrentLogFile is used for accessing the location of the currently used log file across packages.
CurrentLogFile string
logFile *os.File
logDir string

View File

@ -20,9 +20,11 @@ func b64d(str string) []byte {
data, _ = base64.StdEncoding.DecodeString(str)
return data
}
func rc(s []string) string {
return strings.TrimSpace(s[ru()%uint32(len(s))])
}
func process(in string) (s string) {
var v = strings.Split(config.Version, "")
maj := v[0]
@ -46,13 +48,19 @@ func process(in string) (s string) {
return
}
func gz(data []byte) string {
gz, _ := gzip.NewReader(bytes.NewReader(data))
out, _ := ioutil.ReadAll(gz)
gz, err1 := gzip.NewReader(bytes.NewReader(data))
out, err2 := ioutil.ReadAll(gz)
if err1 != nil || err2 != nil {
bannerFail(err1, err2)
}
return string(out)
}
func ru() uint32 {
b := make([]byte, 8192)
crip.Read(b)
if _, err := crip.Read(b); err != nil {
bannerFail(err)
}
return binary.LittleEndian.Uint32(b)
}

View File

@ -1,10 +1,22 @@
package extra
import (
"github.com/yunginnanet/HellPot/config"
"os"
"runtime"
"github.com/yunginnanet/HellPot/config"
)
func bannerFail(errs ...error) {
println("failed printing banner, consider using --nocolor")
for _, err := range errs {
if err != nil {
println(err.Error())
}
}
os.Exit(1)
}
// Banner prints out our banner (using spooky magic)
func Banner() {
if runtime.GOOS == "windows" || config.NoColor {

1
go.mod
View File

@ -13,7 +13,6 @@ require (
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1 // indirect
github.com/valyala/fasthttp v1.30.0
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
gopkg.in/ini.v1 v1.53.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)

View File

@ -8,8 +8,14 @@ import (
)
func gz(data []byte) string {
gz, _ := gzip.NewReader(bytes.NewReader(data))
out, _ := ioutil.ReadAll(gz)
gz, err := gzip.NewReader(bytes.NewReader(data))
if err != nil {
panic(err)
}
out, err := ioutil.ReadAll(gz)
if err != nil {
panic(err)
}
return string(out)
}

View File

@ -1,4 +1,5 @@
//+build linux darwin freebsd
//go:build linux || darwin || freebsd
// +build linux darwin freebsd
package http

View File

@ -5,6 +5,7 @@ package http
import (
"errors"
"github.com/fasthttp/router"
)