-
-
Notifications
You must be signed in to change notification settings - Fork 573
feat: first implementation of honeypot logic #1342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ade8505
feat: first implementation of honeypot logic
Xe e0f4468
fix(honeypot/naive): optimize hilariously
Xe 958daba
feat(honeypot/naive): attempt to automatically filter out based on cr…
Xe 83c8c36
fix(lib): use mazeGen instead of bsGen
Xe 82fca3e
docs: add honeypot docs
Xe 9ccd5db
chore(test): go mod tidy
Xe 5e69031
chore: fix spelling metadata
Xe 15b0927
chore: spelling
Xe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package honeypot | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/promauto" | ||
| ) | ||
|
|
||
| var Timings = promauto.NewHistogramVec(prometheus.HistogramOpts{ | ||
| Namespace: "anubis", | ||
| Subsystem: "honeypot", | ||
| Name: "pagegen_timings", | ||
| Help: "The amount of time honeypot page generation takes per method", | ||
| Buckets: prometheus.ExponentialBuckets(0.5, 2, 32), | ||
| }, []string{"method"}) | ||
|
|
||
| type Info struct { | ||
| CreatedAt time.Time `json:"createdAt"` | ||
| UserAgent string `json:"userAgent"` | ||
| IPAddress string `json:"ipAddress"` | ||
| HitCount int `json:"hitCount"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| html { | ||
| max-width: 70ch; | ||
| padding: 3em 1em; | ||
| margin: auto; | ||
| line-height: 1.75; | ||
| font-size: 1.25em; | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package naive | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "log/slog" | ||
| "math/rand/v2" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/TecharoHQ/anubis/internal/honeypot" | ||
| "github.com/TecharoHQ/anubis/lib/store" | ||
| "github.com/a-h/templ" | ||
| "github.com/google/uuid" | ||
| "github.com/m1/gospin" | ||
|
|
||
| ) | ||
|
|
||
| //go:generate go tool github.com/a-h/templ/cmd/templ generate | ||
|
|
||
| // XXX(Xe): All of this was generated by ChatGPT, GLM 4.6, and GPT-OSS 120b. This is pseudoprofound bullshit in spintax[1] format so that the bullshit generator can emit plausibly human-authored text while being very computationally cheap. | ||
|
|
||
| // | ||
| // It feels somewhat poetic to use spammer technology in Anubis. | ||
|
|
||
| // | ||
| // [1]: https://outboundly.ai/blogs/what-is-spintax-and-how-to-use-it/ | ||
| // | ||
| //go:embed spintext.txt | ||
| var spintext string | ||
|
|
||
| //go:embed titles.txt | ||
| var titles string | ||
|
|
||
| //go:embed affirmations.txt | ||
| var affirmations string | ||
|
|
||
| func New(st store.Interface, lg *slog.Logger) *Impl { | ||
| spin := gospin.New(nil) | ||
|
|
||
|
|
||
| return &Impl{ | ||
| st: st, | ||
| infos: store.JSON[honeypot.Info]{Underlying: st, Prefix: "honeypot-infos"}, | ||
| spin: spin, | ||
| lg: lg.With("component", "honeypot/naive"), | ||
| } | ||
| } | ||
|
|
||
| type Impl struct { | ||
| st store.Interface | ||
| infos store.JSON[honeypot.Info] | ||
| spin *gospin.Spinner | ||
|
|
||
| lg *slog.Logger | ||
| } | ||
|
|
||
| func (i *Impl) makeAffirmations() []string { | ||
| result, err := i.spin.SpinN(affirmations, rand.IntN(5)+1) | ||
| if err != nil { | ||
| i.lg.Debug("can't spin affirmations, using fallback", "err", err) | ||
| return []string{uuid.NewString()} | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| func (i *Impl) makeSpins() []string { | ||
| result, err := i.spin.SpinN(spintext, rand.IntN(8)+8) | ||
| if err != nil { | ||
| i.lg.Debug("can't spin text, using fallback", "err", err) | ||
| return []string{uuid.NewString()} | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| func (i *Impl) makeTitle() string { | ||
| result, err := i.spin.Spin(titles) | ||
| if err != nil { | ||
| i.lg.Debug("can't spin titles, using fallback", "err", err) | ||
| return uuid.NewString() | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| func (i *Impl) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
| t0 := time.Now() | ||
|
|
||
| id := r.PathValue("id") | ||
| if id == "" { | ||
| id = uuid.NewString() | ||
| } | ||
|
|
||
| stage := r.PathValue("stage") | ||
| if stage == "init" { | ||
| i.lg.Debug("found new entrance point", "id", id, "userAgent", r.UserAgent(), "ip", r.Header.Get("X-Real-Ip")) | ||
| } | ||
|
|
||
| spins := i.makeSpins() | ||
| affirmations := i.makeAffirmations() | ||
| title := i.makeTitle() | ||
|
|
||
| var links []link | ||
| for _, affirmation := range affirmations { | ||
| links = append(links, link{ | ||
| href: uuid.NewString(), | ||
| body: affirmation, | ||
| }) | ||
| } | ||
|
|
||
| templ.Handler( | ||
| base(title, i.maze(spins, links)), | ||
| templ.WithStreaming(), | ||
| templ.WithStatus(http.StatusOK), | ||
| ).ServeHTTP(w, r) | ||
|
|
||
| t1 := time.Since(t0) | ||
| honeypot.Timings.WithLabelValues("naive").Observe(float64(t1.Milliseconds())) | ||
| } | ||
|
|
||
| type link struct { | ||
| href string | ||
| body string | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package naive | ||
|
|
||
| import "fmt" | ||
|
|
||
| templ base(title string, body templ.Component) { | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <style> | ||
| html { | ||
| max-width: 70ch; | ||
| padding: 3em 1em; | ||
| margin: auto; | ||
| line-height: 1.75; | ||
| font-size: 1.25em; | ||
| } | ||
| </style> | ||
| <title>{ title }</title> | ||
| </head> | ||
| <body> | ||
| <h1>{ title }</h1> | ||
| @body | ||
| </body> | ||
| </html> | ||
| } | ||
|
|
||
| templ (i Impl) maze(body []string, links []link) { | ||
| for _, paragraph := range body { | ||
| <p>{ paragraph }</p> | ||
| } | ||
| <ul> | ||
| for _, link := range links { | ||
| <li><a href={ templ.SafeURL(fmt.Sprintf("./%s", link.href)) }></a>{ link.body }</li> | ||
| } | ||
| </ul> | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.