Skip to content

Add optional Cleanuper interface for post-exploit artifact undo - #596

Open
vlobstein-vc wants to merge 3 commits into
mainfrom
feat/cleanup-registry
Open

vlobstein-vc wants to merge 3 commits into
mainfrom
feat/cleanup-registry

Conversation

@vlobstein-vc

@vlobstein-vc vlobstein-vc commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds an optional Cleanuper interface. Modules opt in by implementing Cleanup(conf *config.Config) bool alongside ValidateTarget, CheckVersion, and RunExploit. The framework calls Cleanup after RunExploit returns, regardless of success or failure. A panic in RunExploit is recovered, surfaced at framework error level, and Cleanup still fires before the scan moves on, so a single misbehaving target does not take down the whole run. Operators can pass -no-cleanup to skip the call.

Usage

type MyExploit struct {
    token     string
    rulesetID int64
}

func (s *MyExploit) RunExploit(conf *config.Config) bool {
    s.token, s.rulesetID = "", 0   // reset; the Exploit value is reused across targets
    // ... run the chain, stashing artifact ids on s ...
    return true
}

func (s *MyExploit) Cleanup(conf *config.Config) bool {
    ok := true
    if s.rulesetID != 0 {
        ok = deleteRuleset(conf, s.token, s.rulesetID) && ok
    }
    if s.token != "" {
        ok = revokeToken(conf, s.token) && ok
    }
    return ok
}

Notes

  • Backwards compatible. Modules that do not implement Cleanup are unchanged; the framework's deferred type assertion is hoisted out of the defer so the no-op path costs nothing.
  • The framework reuses the same Exploit value across targets, so modules with cross-method state must reset it at the top of RunExploit. Documented on the interface and in docs/getting-started.md.
  • A panic in RunExploit is recovered inside the cleanup defer: the value is logged via output.PrintfFrameworkError("RunExploit panicked: %v", r), Cleanup still runs, the scan continues onto the next target.
  • -no-cleanup wired in cli.exploitFunctionality; the framework prints a warning when the call is skipped.

Signed-off-by: Valentin Lobstein <281638514+vlobstein-vc@users.noreply.github.com>
@vlobstein-vc
vlobstein-vc marked this pull request as ready for review May 14, 2026 14:13
@vlobstein-vc
vlobstein-vc requested a review from j-baines May 14, 2026 14:13
Comment thread cli/commandline.go
Comment on lines +409 to +410
flag.BoolVar(&conf.NoCleanup, "no-cleanup", false,
"Skip the optional Cleanup method after RunExploit (any artifact created on the target will remain)")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the programmer implements a cleanup function, don't you think it should always just be called after -e usage?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default is cleanup-on; the flag is the operator-side escape hatch for inspecting a dropper, leaving the artifact for blue-team analysis, or diffing a clean run vs a failed one. Happy to drop it if you still think it's not worth the surface.

Comment thread docs/getting-started.md
return true
}

func (s *MyExploit) Cleanup(conf *config.Config) bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think very often people will want to use the shell the acquired to do cleanup. Can this support that in some way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I see what you mean, shell-driven cleanup is genuinely useful but it's a different surface (channel-side state + post-session dispatch hook) so I'd rather open it as a follow-up PR than balloon this one.

Signed-off-by: Valentin Lobstein <281638514+vlobstein-vc@users.noreply.github.com>
Signed-off-by: Valentin Lobstein <281638514+vlobstein-vc@users.noreply.github.com>
@vlobstein-vc vlobstein-vc self-assigned this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants