leakkill 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- leakkill/__init__.py +2 -0
- leakkill/__main__.py +3 -0
- leakkill/aws.py +30 -0
- leakkill/cli.py +202 -0
- leakkill/guard.py +97 -0
- leakkill/providers.py +282 -0
- leakkill/report.py +90 -0
- leakkill/scanner.py +183 -0
- leakkill-0.3.0.dist-info/METADATA +188 -0
- leakkill-0.3.0.dist-info/RECORD +14 -0
- leakkill-0.3.0.dist-info/WHEEL +5 -0
- leakkill-0.3.0.dist-info/entry_points.txt +2 -0
- leakkill-0.3.0.dist-info/licenses/LICENSE +16 -0
- leakkill-0.3.0.dist-info/top_level.txt +1 -0
leakkill/__init__.py
ADDED
leakkill/__main__.py
ADDED
leakkill/aws.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Minimal AWS Signature Version 4 signer (stdlib only)."""
|
|
2
|
+
import hashlib, hmac, urllib.parse
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _hmac(key, msg):
|
|
7
|
+
return hmac.new(key, msg.encode(), hashlib.sha256).digest()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def sign(method, url, region, service, body, key_id, secret, headers=None, now=None):
|
|
11
|
+
"""Return the headers (incl. Authorization) for a SigV4-signed request."""
|
|
12
|
+
t = now or datetime.now(timezone.utc)
|
|
13
|
+
amzdate, datestamp = t.strftime("%Y%m%dT%H%M%SZ"), t.strftime("%Y%m%d")
|
|
14
|
+
u = urllib.parse.urlsplit(url)
|
|
15
|
+
q = sorted(urllib.parse.parse_qsl(u.query, keep_blank_values=True))
|
|
16
|
+
canonical_qs = "&".join(f"{urllib.parse.quote(k, safe='-_.~')}={urllib.parse.quote(v, safe='-_.~')}" for k, v in q)
|
|
17
|
+
hdrs = {"host": u.netloc, "x-amz-date": amzdate, **{k.lower(): v for k, v in (headers or {}).items()}}
|
|
18
|
+
signed = ";".join(sorted(hdrs))
|
|
19
|
+
canonical_headers = "".join(f"{k}:{hdrs[k].strip()}\n" for k in sorted(hdrs))
|
|
20
|
+
creq = "\n".join([method, u.path or "/", canonical_qs, canonical_headers, signed,
|
|
21
|
+
hashlib.sha256(body).hexdigest()])
|
|
22
|
+
scope = f"{datestamp}/{region}/{service}/aws4_request"
|
|
23
|
+
to_sign = "\n".join(["AWS4-HMAC-SHA256", amzdate, scope, hashlib.sha256(creq.encode()).hexdigest()])
|
|
24
|
+
k = _hmac(("AWS4" + secret).encode(), datestamp)
|
|
25
|
+
for part in (region, service, "aws4_request"):
|
|
26
|
+
k = _hmac(k, part)
|
|
27
|
+
sig = hmac.new(k, to_sign.encode(), hashlib.sha256).hexdigest()
|
|
28
|
+
out = {k: v for k, v in hdrs.items() if k != "host"}
|
|
29
|
+
out["Authorization"] = f"AWS4-HMAC-SHA256 Credential={key_id}/{scope}, SignedHeaders={signed}, Signature={sig}"
|
|
30
|
+
return out
|
leakkill/cli.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""leakkill: find leaked secrets, check if they're live, revoke them, and guard AI coding agents.
|
|
2
|
+
|
|
3
|
+
leakkill [scan] [PATH ...] find secrets (offline; exit 1 if any)
|
|
4
|
+
leakkill verify [PATH ...] ...and check which are live and whose they are (exit 1 if any live)
|
|
5
|
+
leakkill revoke [PATH ...] plan revocation of live secrets; add --yes to do it
|
|
6
|
+
leakkill report [PATH ...] write an incident report with step-by-step cleanup
|
|
7
|
+
leakkill install-hook block commits that contain secrets (git pre-commit)
|
|
8
|
+
leakkill install-claude-hook stop Claude Code reading .env/keys or writing secrets
|
|
9
|
+
leakkill guard hook entry point (reads Claude Code hook JSON on stdin)
|
|
10
|
+
|
|
11
|
+
Common options: --staged (pre-commit), --history (all commits), --exclude-tests, --json.
|
|
12
|
+
Ignore a line with `leakkill:ignore`; ignore paths with globs in .leakkillignore.
|
|
13
|
+
"""
|
|
14
|
+
import argparse, json, os, sys
|
|
15
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
|
|
18
|
+
from . import __version__, guard as guard_mod, providers, report, scanner
|
|
19
|
+
|
|
20
|
+
LEGACY = {"--guard": "guard", "--install-hook": "install-hook", "--install-claude-hook": "install-claude-hook"}
|
|
21
|
+
COMMANDS = {"scan", "verify", "revoke", "report", "guard", "install-hook", "install-claude-hook"}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Item:
|
|
26
|
+
n: int
|
|
27
|
+
kind: str
|
|
28
|
+
secret: str
|
|
29
|
+
findings: list
|
|
30
|
+
result: providers.Result = None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def collect(args):
|
|
34
|
+
if args.history:
|
|
35
|
+
found = scanner.scan_history()
|
|
36
|
+
elif args.staged:
|
|
37
|
+
found = scanner.scan_staged()
|
|
38
|
+
else:
|
|
39
|
+
found = scanner.scan_paths(args.paths or ["."])
|
|
40
|
+
ignores = scanner.load_ignores()
|
|
41
|
+
found = [f for f in found if not scanner.ignored(f.path, ignores)]
|
|
42
|
+
if args.exclude_tests:
|
|
43
|
+
found = [f for f in found if not scanner.is_test_path(f.path)]
|
|
44
|
+
return [Item(n, k, s, fs) for n, (k, s, fs) in enumerate(scanner.group(found), 1)]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def verify_all(items):
|
|
48
|
+
aws_secrets = {}
|
|
49
|
+
for it in items:
|
|
50
|
+
if it.kind == "AWS secret key":
|
|
51
|
+
for f in it.findings:
|
|
52
|
+
aws_secrets.setdefault(f.path, []).append(it.secret)
|
|
53
|
+
all_aws = [it.secret for it in items if it.kind == "AWS secret key"]
|
|
54
|
+
|
|
55
|
+
def one(it):
|
|
56
|
+
ctx = {}
|
|
57
|
+
if it.kind == "AWS access key":
|
|
58
|
+
near = [s for f in it.findings for s in aws_secrets.get(f.path, [])]
|
|
59
|
+
ctx["aws_secrets"] = list(dict.fromkeys(near + all_aws))
|
|
60
|
+
it.result = providers.verify(it.kind, it.secret, ctx)
|
|
61
|
+
|
|
62
|
+
with ThreadPoolExecutor(8) as ex:
|
|
63
|
+
list(ex.map(one, items))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def as_json(items):
|
|
67
|
+
return json.dumps([{
|
|
68
|
+
"id": it.n, "type": it.kind, "value": it.findings[0].masked,
|
|
69
|
+
"status": it.result.status if it.result else None,
|
|
70
|
+
"identity": it.result.identity if it.result else None,
|
|
71
|
+
"note": it.result.note if it.result else None,
|
|
72
|
+
"locations": [f.location for f in it.findings],
|
|
73
|
+
} for it in items], indent=2)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def print_items(items):
|
|
77
|
+
for it in items:
|
|
78
|
+
r = it.result
|
|
79
|
+
status = f"{r.status:<13}" if r else ""
|
|
80
|
+
extra = " ".join(x for x in ((r.identity, r.note) if r else ()) if x)
|
|
81
|
+
locs = ", ".join(f.location for f in it.findings[:3]) + (f" (+{len(it.findings) - 3})" if len(it.findings) > 3 else "")
|
|
82
|
+
print(f"#{it.n:<3} {status}{it.kind:<22} {it.findings[0].masked:<20} {locs}" + (f"\n {extra}" if extra else ""))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def summary(items):
|
|
86
|
+
if not items:
|
|
87
|
+
return "Clean."
|
|
88
|
+
s = f"\n{len(items)} unique secret(s)"
|
|
89
|
+
if items[0].result:
|
|
90
|
+
live = sum(1 for i in items if i.result.status == providers.LIVE)
|
|
91
|
+
s += f", {live} LIVE"
|
|
92
|
+
return s + "."
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def cmd_scan(args, verify=False):
|
|
96
|
+
items = collect(args)
|
|
97
|
+
if verify and items:
|
|
98
|
+
verify_all(items)
|
|
99
|
+
if args.json:
|
|
100
|
+
print(as_json(items))
|
|
101
|
+
else:
|
|
102
|
+
print_items(items)
|
|
103
|
+
print(summary(items))
|
|
104
|
+
if verify:
|
|
105
|
+
return 1 if any(i.result.status == providers.LIVE for i in items) else 0
|
|
106
|
+
return 1 if items else 0
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def cmd_revoke(args):
|
|
110
|
+
items = collect(args)
|
|
111
|
+
only = {int(x) for x in args.only.split(",")} if args.only else None
|
|
112
|
+
if only:
|
|
113
|
+
items = [i for i in items if i.n in only]
|
|
114
|
+
if not items:
|
|
115
|
+
print("Nothing to revoke.")
|
|
116
|
+
return 0
|
|
117
|
+
verify_all(items)
|
|
118
|
+
live = [i for i in items if i.result.status == providers.LIVE]
|
|
119
|
+
print_items(items)
|
|
120
|
+
if not live:
|
|
121
|
+
print("\nNo live secrets: nothing to revoke.")
|
|
122
|
+
return 0
|
|
123
|
+
auto = [i for i in live if providers.PROVIDERS[i.kind].revoke]
|
|
124
|
+
manual = [i for i in live if i not in auto]
|
|
125
|
+
print(f"\n{len(live)} live secret(s): {len(auto)} can be revoked automatically, {len(manual)} need manual steps.")
|
|
126
|
+
for i in manual:
|
|
127
|
+
print(f" #{i.n} {i.kind}: {providers.PROVIDERS[i.kind].manual}")
|
|
128
|
+
if not args.yes:
|
|
129
|
+
if auto:
|
|
130
|
+
print(f"\nDry run. Re-run with --yes to revoke: " + ", ".join(f"#{i.n}" for i in auto))
|
|
131
|
+
return 1
|
|
132
|
+
failed = 0
|
|
133
|
+
for i in auto:
|
|
134
|
+
ok, msg = providers.revoke(i.kind, i.secret, i.result)
|
|
135
|
+
print(f" #{i.n} {i.kind}: {'REVOKED' if ok else 'FAILED'} ({msg})")
|
|
136
|
+
if not ok:
|
|
137
|
+
failed += 1
|
|
138
|
+
print(f" manual: {providers.PROVIDERS[i.kind].manual}")
|
|
139
|
+
return 1 if failed or manual else 0
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def cmd_report(args):
|
|
143
|
+
items = collect(args)
|
|
144
|
+
if items and not args.no_verify:
|
|
145
|
+
verify_all(items)
|
|
146
|
+
target = "git history" if args.history else "staged changes" if args.staged else " ".join(args.paths or ["."])
|
|
147
|
+
with open(args.output, "w", encoding="utf-8") as f:
|
|
148
|
+
f.write(report.render(items, target, verified=not args.no_verify))
|
|
149
|
+
print(f"Report written to {os.path.abspath(args.output)} ({len(items)} unique secret(s)).")
|
|
150
|
+
if args.replacements:
|
|
151
|
+
report.write_replacements(items, args.replacements)
|
|
152
|
+
print(f"Replacements for git filter-repo written to {args.replacements}. "
|
|
153
|
+
"It contains the raw secrets: delete it when done and never commit it.")
|
|
154
|
+
return 1 if items else 0
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def parser():
|
|
158
|
+
common = argparse.ArgumentParser(add_help=False)
|
|
159
|
+
common.add_argument("paths", nargs="*", help="files or directories (default: .)")
|
|
160
|
+
common.add_argument("--staged", action="store_true", help="scan staged git changes")
|
|
161
|
+
common.add_argument("--history", action="store_true", help="scan every commit on every branch")
|
|
162
|
+
common.add_argument("--exclude-tests", action="store_true", help="skip test_* files and tests/ dirs")
|
|
163
|
+
common.add_argument("--json", action="store_true", help="machine-readable output")
|
|
164
|
+
p = argparse.ArgumentParser(prog="leakkill", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
165
|
+
p.add_argument("--version", action="version", version=f"leakkill {__version__}")
|
|
166
|
+
sub = p.add_subparsers(dest="cmd")
|
|
167
|
+
sub.add_parser("scan", parents=[common], help="find secrets (offline)")
|
|
168
|
+
sub.add_parser("verify", parents=[common], help="find secrets and check which are live")
|
|
169
|
+
r = sub.add_parser("revoke", parents=[common], help="revoke live secrets (dry run unless --yes)")
|
|
170
|
+
r.add_argument("--only", help="comma-separated ids from `leakkill verify`, e.g. 1,3")
|
|
171
|
+
r.add_argument("--yes", action="store_true", help="actually revoke")
|
|
172
|
+
rp = sub.add_parser("report", parents=[common], help="write a Markdown incident report")
|
|
173
|
+
rp.add_argument("-o", "--output", default="leakkill-report.md")
|
|
174
|
+
rp.add_argument("--no-verify", action="store_true", help="don't contact providers")
|
|
175
|
+
rp.add_argument("--replacements", metavar="FILE", help="also write a git filter-repo --replace-text file")
|
|
176
|
+
for name in ("guard", "install-hook", "install-claude-hook"):
|
|
177
|
+
sub.add_parser(name)
|
|
178
|
+
return p
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def main(argv=None):
|
|
182
|
+
argv = list(sys.argv[1:] if argv is None else argv)
|
|
183
|
+
if argv and argv[0] in LEGACY:
|
|
184
|
+
argv[0] = LEGACY[argv[0]]
|
|
185
|
+
if not argv or (argv[0] not in COMMANDS and argv[0] not in ("-h", "--help", "--version")):
|
|
186
|
+
argv.insert(0, "scan")
|
|
187
|
+
args = parser().parse_args(argv)
|
|
188
|
+
if args.cmd == "guard":
|
|
189
|
+
return guard_mod.guard(sys.stdin.read())
|
|
190
|
+
if args.cmd == "install-hook":
|
|
191
|
+
return guard_mod.install_git_hook()
|
|
192
|
+
if args.cmd == "install-claude-hook":
|
|
193
|
+
return guard_mod.install_claude_hook()
|
|
194
|
+
if args.cmd == "revoke":
|
|
195
|
+
return cmd_revoke(args)
|
|
196
|
+
if args.cmd == "report":
|
|
197
|
+
return cmd_report(args)
|
|
198
|
+
return cmd_scan(args, verify=args.cmd == "verify")
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def main_cli():
|
|
202
|
+
sys.exit(main())
|
leakkill/guard.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Claude Code hook: keep secrets out of AI coding agents (prompts, file reads, shell reads, generated code)."""
|
|
2
|
+
import json, os, re, sys
|
|
3
|
+
|
|
4
|
+
from .scanner import scan_text
|
|
5
|
+
|
|
6
|
+
SENSITIVE_FILE = re.compile(
|
|
7
|
+
r"(?i)(^|[\\/])(\.env(\.(?!example$|sample$|template$|dist$)[\w-]+)?|id_rsa|id_ed25519|credentials|\.npmrc|\.pypirc"
|
|
8
|
+
r"|[^\\/]*\.(pem|key|p12|pfx))$")
|
|
9
|
+
# Any shell command that names a secrets file is blocked (cat, grep, base64, python -c, cp ...),
|
|
10
|
+
# except harmless metadata commands and template files like .env.example.
|
|
11
|
+
SENSITIVE_MENTION = re.compile(
|
|
12
|
+
r"(?i)(?<![\w.-])(\.env(\.(?!example|sample|template|dist)[\w-]+)?|id_rsa|id_ed25519|\.pypirc|\.npmrc"
|
|
13
|
+
r"|[\w.-]*\.(pem|key|p12|pfx))(?![\w-]|\.\w)")
|
|
14
|
+
SAFE_CMD = re.compile(r"^\s*(git\s+(add|status|check-ignore|rm|diff\s+--stat)|ls|touch|rm|mkdir|stat|test|chmod)\b")
|
|
15
|
+
READ_TOOLS = {"Read", "NotebookRead"}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _strings(obj):
|
|
19
|
+
if isinstance(obj, str):
|
|
20
|
+
yield obj
|
|
21
|
+
elif isinstance(obj, dict):
|
|
22
|
+
for v in obj.values():
|
|
23
|
+
yield from _strings(v)
|
|
24
|
+
elif isinstance(obj, list):
|
|
25
|
+
for v in obj:
|
|
26
|
+
yield from _strings(v)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def guard_check(event):
|
|
30
|
+
"""Return a list of human-readable reasons to block this Claude Code hook event."""
|
|
31
|
+
name, reasons = event.get("hook_event_name"), []
|
|
32
|
+
if name == "UserPromptSubmit":
|
|
33
|
+
for f in scan_text(event.get("prompt", ""), "prompt"):
|
|
34
|
+
reasons.append(f"prompt line {f.line} contains a {f.kind} ({f.masked})")
|
|
35
|
+
elif name == "PreToolUse":
|
|
36
|
+
tool, ti = event.get("tool_name", ""), event.get("tool_input") or {}
|
|
37
|
+
path = ti.get("file_path") or ti.get("path") or ti.get("notebook_path") or ""
|
|
38
|
+
if tool in READ_TOOLS and SENSITIVE_FILE.search(path):
|
|
39
|
+
reasons.append(f"reading {path} would put its secrets into the model context")
|
|
40
|
+
cmd = ti.get("command", "") if tool == "Bash" else ""
|
|
41
|
+
if cmd and SENSITIVE_MENTION.search(cmd) and not SAFE_CMD.match(cmd):
|
|
42
|
+
reasons.append("shell command reads a secrets file into the model context")
|
|
43
|
+
if not (path and SENSITIVE_FILE.search(path)): # writing real secrets into .env is fine
|
|
44
|
+
for text in _strings(ti):
|
|
45
|
+
for f in scan_text(text, tool):
|
|
46
|
+
reasons.append(f"{tool} input contains a {f.kind} ({f.masked}); use an environment variable instead")
|
|
47
|
+
return reasons
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def guard(raw):
|
|
51
|
+
try:
|
|
52
|
+
event = json.loads(raw)
|
|
53
|
+
except ValueError:
|
|
54
|
+
return 0 # never break the agent on malformed input
|
|
55
|
+
reasons = guard_check(event)
|
|
56
|
+
if reasons:
|
|
57
|
+
print("leakkill blocked this action:\n- " + "\n- ".join(dict.fromkeys(reasons)), file=sys.stderr)
|
|
58
|
+
return 2 # Claude Code: exit 2 = block, stderr is shown to the model
|
|
59
|
+
return 0
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _self_cmd(sub):
|
|
63
|
+
return f'"{sys.executable}" -m leakkill {sub}'
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def install_claude_hook():
|
|
67
|
+
path = os.path.join(".claude", "settings.json")
|
|
68
|
+
os.makedirs(".claude", exist_ok=True)
|
|
69
|
+
cfg = {}
|
|
70
|
+
if os.path.exists(path):
|
|
71
|
+
with open(path, encoding="utf-8") as f:
|
|
72
|
+
cfg = json.load(f)
|
|
73
|
+
cmd = _self_cmd("guard")
|
|
74
|
+
hooks = cfg.setdefault("hooks", {})
|
|
75
|
+
for event, matcher in (("UserPromptSubmit", None), ("PreToolUse", "Read|Write|Edit|MultiEdit|NotebookEdit|Bash")):
|
|
76
|
+
entry = {"hooks": [{"type": "command", "command": cmd}]}
|
|
77
|
+
if matcher:
|
|
78
|
+
entry["matcher"] = matcher
|
|
79
|
+
groups = [g for g in hooks.get(event, []) if "leakkill" not in json.dumps(g)]
|
|
80
|
+
hooks[event] = groups + [entry]
|
|
81
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
82
|
+
json.dump(cfg, f, indent=2)
|
|
83
|
+
print("Installed Claude Code guard in", path)
|
|
84
|
+
return 0
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def install_git_hook():
|
|
88
|
+
if not os.path.isdir(".git"):
|
|
89
|
+
print("Not a git repo root.", file=sys.stderr)
|
|
90
|
+
return 1
|
|
91
|
+
hook = os.path.join(".git", "hooks", "pre-commit")
|
|
92
|
+
cmd = _self_cmd("scan --staged").replace("\\", "/")
|
|
93
|
+
with open(hook, "w", newline="\n") as f:
|
|
94
|
+
f.write(f'#!/bin/sh\n{cmd} || {{ echo "Commit blocked by leakkill."; exit 1; }}\n')
|
|
95
|
+
os.chmod(hook, 0o755)
|
|
96
|
+
print("Installed", hook)
|
|
97
|
+
return 0
|
leakkill/providers.py
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"""Check whether a leaked secret is live, and revoke it where the provider allows.
|
|
2
|
+
|
|
3
|
+
Safety rules:
|
|
4
|
+
- A secret is only ever sent to the provider that issued it (hosts are hard-coded below).
|
|
5
|
+
- Redirects are never followed, so a credential can't be forwarded to another host.
|
|
6
|
+
- Verification uses read-only "who am I" calls. Revocation only runs on explicit request.
|
|
7
|
+
"""
|
|
8
|
+
import base64, json, os, re, urllib.error, urllib.parse, urllib.request
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
|
|
11
|
+
from . import __version__, aws
|
|
12
|
+
|
|
13
|
+
LIVE, DEAD, UNKNOWN, UNSUPPORTED = "LIVE", "DEAD", "UNKNOWN", "UNVERIFIABLE"
|
|
14
|
+
UA = f"leakkill/{__version__} (+https://github.com/ayushanand27/leakkill)"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class Result:
|
|
19
|
+
status: str
|
|
20
|
+
identity: str = ""
|
|
21
|
+
note: str = ""
|
|
22
|
+
extra: dict = field(default_factory=dict) # provider data needed later (e.g. paired AWS secret)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
26
|
+
def redirect_request(self, *a, **kw):
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
_opener = urllib.request.build_opener(_NoRedirect)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def http(method, url, headers=None, data=None, timeout=15):
|
|
34
|
+
"""Return (status, headers, body_bytes). HTTP errors are returned, network errors raise OSError."""
|
|
35
|
+
req = urllib.request.Request(url, data=data, method=method, headers={"User-Agent": UA, **(headers or {})})
|
|
36
|
+
try:
|
|
37
|
+
with _opener.open(req, timeout=timeout) as r:
|
|
38
|
+
return r.status, dict(r.headers), r.read()
|
|
39
|
+
except urllib.error.HTTPError as e:
|
|
40
|
+
return e.code, dict(e.headers or {}), e.read()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _json(body):
|
|
44
|
+
try:
|
|
45
|
+
return json.loads(body or b"{}")
|
|
46
|
+
except ValueError:
|
|
47
|
+
return {}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _by_status(code, live=(200,), dead=(401,), identity=""):
|
|
51
|
+
if code in live:
|
|
52
|
+
return Result(LIVE, identity)
|
|
53
|
+
if code in dead:
|
|
54
|
+
return Result(DEAD)
|
|
55
|
+
return Result(UNKNOWN, note=f"unexpected HTTP {code}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# ---------------------------------------------------------------- GitHub
|
|
59
|
+
def github_verify(s, ctx):
|
|
60
|
+
code, h, body = http("GET", "https://api.github.com/user",
|
|
61
|
+
{"Authorization": f"Bearer {s}", "Accept": "application/vnd.github+json"})
|
|
62
|
+
if code == 200:
|
|
63
|
+
scopes = {k.lower(): v for k, v in h.items()}.get("x-oauth-scopes", "")
|
|
64
|
+
return Result(LIVE, _json(body).get("login", "?"), f"scopes: {scopes}" if scopes else "")
|
|
65
|
+
return _by_status(code)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def github_revoke(s, res):
|
|
69
|
+
# Public endpoint built for exactly this: anyone can revoke a token they found exposed.
|
|
70
|
+
# GitHub notifies the token owner. https://docs.github.com/en/rest/credentials/revoke
|
|
71
|
+
code, _, body = http("POST", "https://api.github.com/credentials/revoke",
|
|
72
|
+
{"Accept": "application/vnd.github+json", "Content-Type": "application/json"},
|
|
73
|
+
json.dumps({"credentials": [s]}).encode())
|
|
74
|
+
return code == 202, f"HTTP {code}" + ("" if code == 202 else f": {body[:200]!r}")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# ---------------------------------------------------------------- GitLab
|
|
78
|
+
def _gitlab():
|
|
79
|
+
return os.environ.get("LEAKKILL_GITLAB_URL", "https://gitlab.com").rstrip("/")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def gitlab_verify(s, ctx):
|
|
83
|
+
code, _, body = http("GET", f"{_gitlab()}/api/v4/personal_access_tokens/self", {"PRIVATE-TOKEN": s})
|
|
84
|
+
if code == 200:
|
|
85
|
+
j = _json(body)
|
|
86
|
+
return Result(LIVE, f"token '{j.get('name')}' (user id {j.get('user_id')})",
|
|
87
|
+
f"scopes: {','.join(j.get('scopes', []))}; expires: {j.get('expires_at')}")
|
|
88
|
+
return _by_status(code)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def gitlab_revoke(s, res):
|
|
92
|
+
code, _, body = http("DELETE", f"{_gitlab()}/api/v4/personal_access_tokens/self", {"PRIVATE-TOKEN": s})
|
|
93
|
+
return code == 204, f"HTTP {code}"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# ---------------------------------------------------------------- Slack
|
|
97
|
+
SLACK_DEAD = {"invalid_auth", "token_revoked", "account_inactive", "not_authed", "token_expired"}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def slack_verify(s, ctx):
|
|
101
|
+
code, _, body = http("POST", "https://slack.com/api/auth.test", {"Authorization": f"Bearer {s}"})
|
|
102
|
+
j = _json(body)
|
|
103
|
+
if j.get("ok"):
|
|
104
|
+
return Result(LIVE, f"{j.get('user')} @ {j.get('team')} ({j.get('url')})")
|
|
105
|
+
if j.get("error") in SLACK_DEAD:
|
|
106
|
+
return Result(DEAD, note=j["error"])
|
|
107
|
+
return Result(UNKNOWN, note=j.get("error") or f"HTTP {code}")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def slack_revoke(s, res):
|
|
111
|
+
code, _, body = http("POST", "https://slack.com/api/auth.revoke", {"Authorization": f"Bearer {s}"})
|
|
112
|
+
j = _json(body)
|
|
113
|
+
return bool(j.get("revoked")), j.get("error") or f"HTTP {code}"
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def slack_webhook_verify(s, ctx):
|
|
117
|
+
# An empty JSON body is rejected as invalid, so nothing gets posted to the channel.
|
|
118
|
+
code, _, body = http("POST", s, {"Content-Type": "application/json"}, b"{}")
|
|
119
|
+
if code == 400:
|
|
120
|
+
return Result(LIVE, note=body.decode(errors="replace")[:60])
|
|
121
|
+
if code in (403, 404, 410):
|
|
122
|
+
return Result(DEAD, note=body.decode(errors="replace")[:60])
|
|
123
|
+
return Result(UNKNOWN, note=f"HTTP {code}")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# ---------------------------------------------------------------- Discord
|
|
127
|
+
def discord_webhook_verify(s, ctx):
|
|
128
|
+
code, _, body = http("GET", s)
|
|
129
|
+
if code == 200:
|
|
130
|
+
j = _json(body)
|
|
131
|
+
return Result(LIVE, f"webhook '{j.get('name')}' (guild {j.get('guild_id')}, channel {j.get('channel_id')})")
|
|
132
|
+
return _by_status(code, dead=(401, 404))
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def discord_webhook_revoke(s, res):
|
|
136
|
+
code, _, _ = http("DELETE", s) # "Delete Webhook with Token" needs no other auth
|
|
137
|
+
return code == 204, f"HTTP {code}"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# ---------------------------------------------------------------- Stripe
|
|
141
|
+
def stripe_verify(s, ctx):
|
|
142
|
+
auth = "Basic " + base64.b64encode(f"{s}:".encode()).decode()
|
|
143
|
+
code, _, body = http("GET", "https://api.stripe.com/v1/account", {"Authorization": auth})
|
|
144
|
+
if code == 200:
|
|
145
|
+
j = _json(body)
|
|
146
|
+
return Result(LIVE, f"{j.get('id')} {j.get('email') or j.get('business_profile', {}).get('name') or ''}".strip())
|
|
147
|
+
if code == 403: # restricted key without account read permission: valid but limited
|
|
148
|
+
return Result(LIVE, note="restricted key")
|
|
149
|
+
return _by_status(code)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# ---------------------------------------------------------------- AWS
|
|
153
|
+
def _aws_call(key_id, secret, host, service, params):
|
|
154
|
+
body = urllib.parse.urlencode(params).encode()
|
|
155
|
+
hdr = aws.sign("POST", f"https://{host}/", "us-east-1", service, body, key_id, secret,
|
|
156
|
+
{"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"})
|
|
157
|
+
return http("POST", f"https://{host}/", hdr, body)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _xml(body, tag):
|
|
161
|
+
m = re.search(rf"<{tag}>([^<]*)</{tag}>", body.decode(errors="replace"))
|
|
162
|
+
return m.group(1) if m else ""
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def aws_verify(key_id, ctx):
|
|
166
|
+
if key_id.startswith("ASIA"):
|
|
167
|
+
return Result(UNKNOWN, note="temporary (STS) key: needs a session token; it expires on its own")
|
|
168
|
+
secrets = ctx.get("aws_secrets") or []
|
|
169
|
+
if not secrets:
|
|
170
|
+
return Result(UNKNOWN, note="no matching AWS secret key found nearby; the key id alone can't be verified")
|
|
171
|
+
mismatch = False
|
|
172
|
+
for secret in secrets[:5]:
|
|
173
|
+
code, _, body = _aws_call(key_id, secret, "sts.amazonaws.com", "sts",
|
|
174
|
+
{"Action": "GetCallerIdentity", "Version": "2011-06-15"})
|
|
175
|
+
if code == 200:
|
|
176
|
+
return Result(LIVE, _xml(body, "Arn"), f"account {_xml(body, 'Account')}", {"aws_secret": secret})
|
|
177
|
+
err = _xml(body, "Code")
|
|
178
|
+
if err == "InvalidClientTokenId":
|
|
179
|
+
return Result(DEAD, note="key id is unknown or deactivated")
|
|
180
|
+
mismatch = mismatch or err == "SignatureDoesNotMatch"
|
|
181
|
+
return Result(UNKNOWN, note="key id exists but no paired secret matched" if mismatch else f"HTTP {code}")
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def aws_revoke(key_id, res):
|
|
185
|
+
secret = res.extra.get("aws_secret")
|
|
186
|
+
if not secret:
|
|
187
|
+
return False, "no verified secret for this key"
|
|
188
|
+
# Deactivate (reversible) rather than delete, as AWS recommends. Works only if the key has iam:UpdateAccessKey.
|
|
189
|
+
code, _, body = _aws_call(key_id, secret, "iam.amazonaws.com", "iam",
|
|
190
|
+
{"Action": "UpdateAccessKey", "AccessKeyId": key_id, "Status": "Inactive",
|
|
191
|
+
"Version": "2010-05-08"})
|
|
192
|
+
if code == 200:
|
|
193
|
+
return True, "access key set to Inactive"
|
|
194
|
+
return False, f"{_xml(body, 'Code') or 'HTTP ' + str(code)}: this key can't deactivate itself, use the console"
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
# ---------------------------------------------------------------- AI providers, npm, Telegram
|
|
198
|
+
def openai_verify(s, ctx):
|
|
199
|
+
code, _, _ = http("GET", "https://api.openai.com/v1/models", {"Authorization": f"Bearer {s}"})
|
|
200
|
+
if code in (403, 429): # authenticated but restricted / out of quota: still a working key
|
|
201
|
+
return Result(LIVE, note=f"HTTP {code}")
|
|
202
|
+
return _by_status(code)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def anthropic_verify(s, ctx):
|
|
206
|
+
code, _, _ = http("GET", "https://api.anthropic.com/v1/models",
|
|
207
|
+
{"x-api-key": s, "anthropic-version": "2023-06-01"})
|
|
208
|
+
if code in (403, 429):
|
|
209
|
+
return Result(LIVE, note=f"HTTP {code}")
|
|
210
|
+
return _by_status(code)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def npm_verify(s, ctx):
|
|
214
|
+
code, _, body = http("GET", "https://registry.npmjs.org/-/whoami", {"Authorization": f"Bearer {s}"})
|
|
215
|
+
return _by_status(code, dead=(401, 403), identity=_json(body).get("username", "") if code == 200 else "")
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def telegram_verify(s, ctx):
|
|
219
|
+
code, _, body = http("GET", f"https://api.telegram.org/bot{s}/getMe")
|
|
220
|
+
if code == 200:
|
|
221
|
+
return Result(LIVE, "@" + str(_json(body).get("result", {}).get("username")))
|
|
222
|
+
return _by_status(code, dead=(401, 404))
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@dataclass
|
|
226
|
+
class Provider:
|
|
227
|
+
verify: object = None
|
|
228
|
+
revoke: object = None
|
|
229
|
+
manual: str = ""
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
PROVIDERS = {
|
|
233
|
+
"GitHub token": Provider(github_verify, github_revoke,
|
|
234
|
+
"Delete it at https://github.com/settings/tokens (or the app's settings for gho_/ghu_ tokens)."),
|
|
235
|
+
"GitLab token": Provider(gitlab_verify, gitlab_revoke,
|
|
236
|
+
"Revoke it at https://gitlab.com/-/user_settings/personal_access_tokens."),
|
|
237
|
+
"Slack token": Provider(slack_verify, slack_revoke,
|
|
238
|
+
"Regenerate it in your app's 'OAuth & Permissions' page at https://api.slack.com/apps."),
|
|
239
|
+
"Slack webhook": Provider(slack_webhook_verify, None,
|
|
240
|
+
"Remove the webhook in your app's 'Incoming Webhooks' page at https://api.slack.com/apps."),
|
|
241
|
+
"Discord webhook": Provider(discord_webhook_verify, discord_webhook_revoke,
|
|
242
|
+
"Server Settings > Integrations > Webhooks > delete the webhook."),
|
|
243
|
+
"Stripe key": Provider(stripe_verify, None,
|
|
244
|
+
"Roll the key at https://dashboard.stripe.com/apikeys (Stripe has no API to revoke keys)."),
|
|
245
|
+
"AWS access key": Provider(aws_verify, aws_revoke,
|
|
246
|
+
"Deactivate then delete it in IAM > Users > Security credentials "
|
|
247
|
+
"(https://console.aws.amazon.com/iam/home#/security_credentials), then check CloudTrail "
|
|
248
|
+
"for activity from this key."),
|
|
249
|
+
"OpenAI API key": Provider(openai_verify, None, "Revoke it at https://platform.openai.com/api-keys."),
|
|
250
|
+
"Anthropic API key": Provider(anthropic_verify, None, "Delete it at https://console.anthropic.com/settings/keys."),
|
|
251
|
+
"npm token": Provider(npm_verify, None, "Run `npm token list` then `npm token revoke <id>`, "
|
|
252
|
+
"or use https://www.npmjs.com/settings/<user>/tokens."),
|
|
253
|
+
"Telegram bot token": Provider(telegram_verify, None, "Send /revoke to @BotFather and pick the bot."),
|
|
254
|
+
"Google API key": Provider(None, None, "Delete or restrict it at https://console.cloud.google.com/apis/credentials."),
|
|
255
|
+
"AWS secret key": Provider(None, None, "Rotate it together with its access key id (see the AWS access key entry)."),
|
|
256
|
+
"Private key block": Provider(None, None, "Generate a new key pair and remove the old public key everywhere it is "
|
|
257
|
+
"trusted (servers' authorized_keys, GitHub deploy keys, TLS certs)."),
|
|
258
|
+
"JWT": Provider(None, None, "If it is long-lived, rotate the signing secret that issued it."),
|
|
259
|
+
"Credentials in URL": Provider(None, None, "Change that password (database user: ALTER USER ... PASSWORD; proxy or "
|
|
260
|
+
"service account: its admin console) and restrict network access to it."),
|
|
261
|
+
"High-entropy secret": Provider(None, None, "Treat as compromised: rotate it with whoever issued it."),
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def verify(kind, secret, ctx=None):
|
|
266
|
+
p = PROVIDERS.get(kind)
|
|
267
|
+
if not p or not p.verify:
|
|
268
|
+
return Result(UNSUPPORTED)
|
|
269
|
+
try:
|
|
270
|
+
return p.verify(secret, ctx or {})
|
|
271
|
+
except Exception as e: # DNS, timeout, proxy refusal, truncated response... never crash the scan
|
|
272
|
+
return Result(UNKNOWN, note=f"network error: {getattr(e, 'reason', e)}")
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def revoke(kind, secret, result):
|
|
276
|
+
p = PROVIDERS.get(kind)
|
|
277
|
+
if not p or not p.revoke:
|
|
278
|
+
return False, "no revocation API: " + (p.manual if p else "rotate it manually")
|
|
279
|
+
try:
|
|
280
|
+
return p.revoke(secret, result)
|
|
281
|
+
except Exception as e:
|
|
282
|
+
return False, f"network error: {getattr(e, 'reason', e)}"
|
leakkill/report.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Incident report: what leaked, is it live, whose is it, and the exact steps to clean up."""
|
|
2
|
+
import os, subprocess
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
|
|
5
|
+
from .providers import LIVE, DEAD, PROVIDERS
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def tracked_files():
|
|
9
|
+
try:
|
|
10
|
+
out = subprocess.run(["git", "ls-files", "-z"], capture_output=True, text=True, check=True).stdout
|
|
11
|
+
return {os.path.normpath(p) for p in out.split("\0") if p}
|
|
12
|
+
except (OSError, subprocess.CalledProcessError):
|
|
13
|
+
return None # not a git repo
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def in_git(item, tracked):
|
|
17
|
+
return any(f.commit or (tracked is not None and os.path.normpath(f.path) in tracked) for f in item.findings)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _action(item):
|
|
21
|
+
p = PROVIDERS.get(item.kind)
|
|
22
|
+
if item.result and item.result.status == DEAD:
|
|
23
|
+
return "Already revoked/invalid. Still remove it from code and history."
|
|
24
|
+
if p and p.revoke:
|
|
25
|
+
return f"`leakkill revoke --only {item.n} --yes` (automatic), or manually: {p.manual}"
|
|
26
|
+
return p.manual if p else "Rotate it with whoever issued it."
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def render(items, target, verified=True):
|
|
30
|
+
tracked = tracked_files()
|
|
31
|
+
now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
|
|
32
|
+
count = lambda s: sum(1 for i in items if i.result and i.result.status == s)
|
|
33
|
+
lines = [
|
|
34
|
+
"# leakkill incident report", "",
|
|
35
|
+
f"Generated {now} · target `{target}` · **{len(items)} unique secret(s)**"
|
|
36
|
+
+ (f" · **{count(LIVE)} live**, {count(DEAD)} dead, {len(items) - count(LIVE) - count(DEAD)} not confirmed"
|
|
37
|
+
if verified else " · not verified (run without --no-verify to check which are live)"),
|
|
38
|
+
"",
|
|
39
|
+
]
|
|
40
|
+
if not items:
|
|
41
|
+
return "\n".join(lines + ["No secrets found. 🎉", ""])
|
|
42
|
+
lines += ["| # | Status | Type | Value | Account / identity | In git | Locations |",
|
|
43
|
+
"|---|---|---|---|---|---|---|"]
|
|
44
|
+
for it in items:
|
|
45
|
+
st = it.result.status if it.result else "-"
|
|
46
|
+
who = (it.result.identity if it.result else "") or ""
|
|
47
|
+
where = "<br>".join(f"`{f.location}`" for f in it.findings[:5]) + (
|
|
48
|
+
f"<br>+{len(it.findings) - 5} more" if len(it.findings) > 5 else "")
|
|
49
|
+
lines.append(f"| {it.n} | **{st}** | {it.kind} | `{it.findings[0].masked}` | {who} | "
|
|
50
|
+
f"{'yes' if in_git(it, tracked) else 'no'} | {where} |")
|
|
51
|
+
|
|
52
|
+
order = sorted(items, key=lambda i: (not (i.result and i.result.status == LIVE), i.n))
|
|
53
|
+
lines += ["", "## What to do, in order", "",
|
|
54
|
+
"Revoke first. Deleting a secret from code does **not** make it safe: bots scan new commits "
|
|
55
|
+
"within minutes, and every clone/fork keeps the history.", ""]
|
|
56
|
+
for it in order:
|
|
57
|
+
r = it.result
|
|
58
|
+
head = f"### #{it.n} {it.kind} `{it.findings[0].masked}`"
|
|
59
|
+
if r:
|
|
60
|
+
head += f" — {r.status}" + (f" ({r.identity})" if r.identity else "")
|
|
61
|
+
lines += [head, "", f"1. **Revoke / rotate:** {_action(it)}"]
|
|
62
|
+
if r and r.note:
|
|
63
|
+
lines[-1] += f" \n _Check result: {r.note}_"
|
|
64
|
+
lines += [f"2. **Remove from code:** load it from an environment variable or secret manager instead "
|
|
65
|
+
f"({', '.join('`' + f.location + '`' for f in it.findings[:3])}).", ""]
|
|
66
|
+
|
|
67
|
+
if any(in_git(i, tracked) for i in items):
|
|
68
|
+
lines += ["## Purge from git history (after revoking)", "",
|
|
69
|
+
"```sh",
|
|
70
|
+
"pip install git-filter-repo",
|
|
71
|
+
"leakkill report --history --no-verify --replacements .leakkill-replacements.txt",
|
|
72
|
+
"git filter-repo --replace-text .leakkill-replacements.txt",
|
|
73
|
+
"rm .leakkill-replacements.txt",
|
|
74
|
+
"git push --force --all && git push --force --tags",
|
|
75
|
+
"```", "",
|
|
76
|
+
"Rewriting history needs a force-push and every collaborator must re-clone. "
|
|
77
|
+
"If the repo was ever public, assume the secret was copied: revoking is what actually protects you.",
|
|
78
|
+
""]
|
|
79
|
+
return "\n".join(lines)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def write_replacements(items, path):
|
|
83
|
+
"""git filter-repo --replace-text file. Contains raw secrets: local use only, delete after."""
|
|
84
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
85
|
+
for it in items:
|
|
86
|
+
f.write(f"{it.secret}==>***REMOVED-{it.kind.upper().replace(' ', '-')}***\n")
|
|
87
|
+
try:
|
|
88
|
+
os.chmod(path, 0o600)
|
|
89
|
+
except OSError:
|
|
90
|
+
pass
|
leakkill/scanner.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""Find secrets in files, staged changes and git history. Never touches the network."""
|
|
2
|
+
import fnmatch, math, os, re, subprocess
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
# kind -> regex. Group 1 (if present) is the secret, otherwise the whole match.
|
|
6
|
+
RULES = {
|
|
7
|
+
"AWS access key": re.compile(r"\b((?:AKIA|ASIA)[0-9A-Z]{16})\b"),
|
|
8
|
+
"AWS secret key": re.compile(r"(?i)aws.{0,20}?(?:secret|sk).{0,20}?[\s:=\"']+([A-Za-z0-9/+=]{40})(?![A-Za-z0-9/+=])"),
|
|
9
|
+
"GitHub token": re.compile(r"\b(gh[pousr]_[A-Za-z0-9]{36,255}|github_pat_[A-Za-z0-9_]{22,255})\b"),
|
|
10
|
+
"GitLab token": re.compile(r"\b(glpat-[A-Za-z0-9_\-.]{20,})"),
|
|
11
|
+
"Slack token": re.compile(r"\b(xox[abposre]-[A-Za-z0-9-]{10,})"),
|
|
12
|
+
"Slack webhook": re.compile(r"(https://hooks\.slack\.com/services/T[A-Z0-9]+/B[A-Z0-9]+/[A-Za-z0-9]{20,})"),
|
|
13
|
+
"Discord webhook": re.compile(r"(https://(?:ptb\.|canary\.)?discord(?:app)?\.com/api/webhooks/\d+/[A-Za-z0-9_\-]{60,})"),
|
|
14
|
+
"Stripe key": re.compile(r"\b([sr]k_live_[0-9A-Za-z]{20,})\b"),
|
|
15
|
+
"Anthropic API key": re.compile(r"\b(sk-ant-[A-Za-z0-9_\-]{32,})"),
|
|
16
|
+
"OpenAI API key": re.compile(r"\b(sk-(?!ant-)(?:proj-|svcacct-|admin-)?[A-Za-z0-9_\-]{32,})"),
|
|
17
|
+
"npm token": re.compile(r"\b(npm_[A-Za-z0-9]{36})\b"),
|
|
18
|
+
"Telegram bot token": re.compile(r"\b(\d{8,10}:AA[A-Za-z0-9_\-]{33})(?![A-Za-z0-9_\-])"),
|
|
19
|
+
"Google API key": re.compile(r"\b(AIza[0-9A-Za-z_\-]{35})"),
|
|
20
|
+
"Private key block": re.compile(r"(-----BEGIN (?:RSA |EC |OPENSSH |DSA |PGP |ENCRYPTED )?PRIVATE KEY-----)"),
|
|
21
|
+
"JWT": re.compile(r"\b(eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,})"),
|
|
22
|
+
"Credentials in URL": re.compile(r"\b([a-z][a-z0-9+]*://[^\s:/@]+:[^\s:/@]{3,}@[^\s/\"']+)"),
|
|
23
|
+
}
|
|
24
|
+
# key = "value" where the key name looks sensitive and the value looks random
|
|
25
|
+
ASSIGN = re.compile(
|
|
26
|
+
r"""(?i)\b[\w.-]*(?:secret|token|passwd|password|api[_-]?key|private[_-]?key|auth)[\w.-]*\b
|
|
27
|
+
\s*[:=]\s*["']([^"'\s]{12,})["']""", re.X)
|
|
28
|
+
PLACEHOLDER = re.compile(r"(?i)example|placeholder|changeme|your[_-]|xxx|<.*>|\$\{|\{\{|dummy|sample|test")
|
|
29
|
+
SKIP_DIRS = {".git", "node_modules", "venv", ".venv", "__pycache__", "dist", "build", ".idea", ".tox", ".mypy_cache"}
|
|
30
|
+
SKIP_EXT = {".png", ".jpg", ".jpeg", ".gif", ".pdf", ".zip", ".gz", ".exe", ".dll", ".so", ".woff", ".woff2",
|
|
31
|
+
".ico", ".lock", ".pyc", ".mp4", ".mp3", ".jar", ".class"}
|
|
32
|
+
IGNORE_FILE = ".leakkillignore"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class Finding:
|
|
37
|
+
path: str
|
|
38
|
+
line: int
|
|
39
|
+
kind: str
|
|
40
|
+
secret: str # raw value: kept in memory only, never printed
|
|
41
|
+
commit: str = "" # set for --history findings
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def masked(self):
|
|
45
|
+
return mask(self.secret)
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def location(self):
|
|
49
|
+
return f"{self.commit}:{self.path}:{self.line}" if self.commit else f"{self.path}:{self.line}"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def entropy(s):
|
|
53
|
+
return -sum(s.count(c) / len(s) * math.log2(s.count(c) / len(s)) for c in set(s)) if s else 0.0
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def mask(s):
|
|
57
|
+
if CRED_URL.match(s): # keep scheme://user@host for context, hide the password
|
|
58
|
+
return CRED_URL.sub(r"\1****\3", s)
|
|
59
|
+
if s.startswith("https://"): # webhooks: keep host, hide the path secret
|
|
60
|
+
return re.sub(r"(https://[^/]+/).*", r"\1****", s)
|
|
61
|
+
return s[:4] + "*" * min(len(s) - 4, 12) if len(s) > 8 else "****"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
CRED_URL = re.compile(r"^([a-z][a-z0-9+]*://[^\s:/@]+:)([^\s:/@]+)(@.*)$")
|
|
65
|
+
FAKE_PASSWORDS = {"pass", "password", "passwd", "pwd", "pw", "secret", "foo", "bar", "baz", "test", "user", "username",
|
|
66
|
+
"admin", "root", "changeme", "xxx", "x", "p", "s"}
|
|
67
|
+
HASH_PREFIX = re.compile(r"^(pbkdf2_|argon2|bcrypt|\$2[aby]?\$|\$argon2|\$6\$|sha256\$|md5\$)")
|
|
68
|
+
TEST_NAME = re.compile(r"(?i)test|example|dummy|fake|mock|sample")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def real_url_password(url):
|
|
72
|
+
pw = CRED_URL.match(url).group(2)
|
|
73
|
+
words = [w for w in re.split(r"%[0-9a-fA-F]{2}|[^A-Za-z0-9]", pw) if w]
|
|
74
|
+
return bool(words) and not PLACEHOLDER.search(url) and not re.search(r"[{}$<>*]", pw) \
|
|
75
|
+
and not all(w.lower() in FAKE_PASSWORDS for w in words)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def scan_line(line):
|
|
79
|
+
"""Return [(kind, secret)] for one line."""
|
|
80
|
+
if "leakkill:ignore" in line:
|
|
81
|
+
return []
|
|
82
|
+
hits = []
|
|
83
|
+
for kind, rx in RULES.items():
|
|
84
|
+
for m in rx.finditer(line):
|
|
85
|
+
val = m.group(1) if rx.groups else m.group(0)
|
|
86
|
+
if kind == "Credentials in URL" and not real_url_password(val):
|
|
87
|
+
continue
|
|
88
|
+
if not any(val in h[1] or h[1] in val for h in hits):
|
|
89
|
+
hits.append((kind, val))
|
|
90
|
+
for m in ASSIGN.finditer(line):
|
|
91
|
+
v, name = m.group(1), m.group(0)[:m.start(1) - m.start(0)]
|
|
92
|
+
if (PLACEHOLDER.search(v) or TEST_NAME.search(name) or HASH_PREFIX.match(v) or entropy(v) < 3.5
|
|
93
|
+
or not re.search(r"\d", v) or not re.search(r"[A-Za-z]", v)): # real random secrets mix letters+digits
|
|
94
|
+
continue
|
|
95
|
+
if not any(v in h[1] or h[1] in v for h in hits):
|
|
96
|
+
hits.append(("High-entropy secret", v))
|
|
97
|
+
return hits
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def scan_text(text, path, commit=""):
|
|
101
|
+
return [Finding(path, i, kind, val, commit)
|
|
102
|
+
for i, line in enumerate(text.splitlines(), 1) for kind, val in scan_line(line)]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def load_ignores(root="."):
|
|
106
|
+
try:
|
|
107
|
+
with open(os.path.join(root, IGNORE_FILE), encoding="utf-8") as f:
|
|
108
|
+
return [l.strip() for l in f if l.strip() and not l.startswith("#")]
|
|
109
|
+
except OSError:
|
|
110
|
+
return []
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def ignored(path, patterns):
|
|
114
|
+
p = path.replace("\\", "/").lstrip("./")
|
|
115
|
+
return any(fnmatch.fnmatch(p, pat) or fnmatch.fnmatch(os.path.basename(p), pat) or p.startswith(pat.rstrip("/") + "/")
|
|
116
|
+
for pat in patterns)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def iter_files(paths):
|
|
120
|
+
for p in paths:
|
|
121
|
+
if os.path.isfile(p):
|
|
122
|
+
yield p
|
|
123
|
+
for root, dirs, files in os.walk(p):
|
|
124
|
+
dirs[:] = sorted(d for d in dirs if d not in SKIP_DIRS)
|
|
125
|
+
for f in sorted(files):
|
|
126
|
+
if os.path.splitext(f)[1].lower() not in SKIP_EXT:
|
|
127
|
+
yield os.path.join(root, f)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def scan_paths(paths):
|
|
131
|
+
out = []
|
|
132
|
+
for f in iter_files(paths):
|
|
133
|
+
try:
|
|
134
|
+
if os.path.getsize(f) > 2_000_000:
|
|
135
|
+
continue
|
|
136
|
+
with open(f, encoding="utf-8", errors="strict") as fh:
|
|
137
|
+
out += scan_text(fh.read(), os.path.relpath(f))
|
|
138
|
+
except (UnicodeDecodeError, OSError):
|
|
139
|
+
continue # binary / unreadable
|
|
140
|
+
return out
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _git(*args):
|
|
144
|
+
return subprocess.run(["git", *args], capture_output=True, text=True,
|
|
145
|
+
encoding="utf-8", errors="replace").stdout
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _scan_diff(diff, commit_of_header=None):
|
|
149
|
+
out, cur, commit, ln = [], "?", "", 0
|
|
150
|
+
for line in diff.splitlines():
|
|
151
|
+
if commit_of_header and line.startswith("commit "):
|
|
152
|
+
commit = line.split()[1]
|
|
153
|
+
elif line.startswith("+++ "):
|
|
154
|
+
cur = line[6:] if line.startswith("+++ b/") else line[4:]
|
|
155
|
+
elif line.startswith("@@"):
|
|
156
|
+
m = re.search(r"\+(\d+)", line)
|
|
157
|
+
ln = int(m.group(1)) if m else 0
|
|
158
|
+
elif line.startswith("+"):
|
|
159
|
+
out += [Finding(cur, ln, k, v, commit) for k, v in scan_line(line[1:])]
|
|
160
|
+
ln += 1
|
|
161
|
+
return out
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def scan_staged():
|
|
165
|
+
return _scan_diff(_git("diff", "--cached", "-U0", "--no-color"))
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def scan_history():
|
|
169
|
+
"""Every line ever added in any commit on any branch (catches secrets that were 'deleted')."""
|
|
170
|
+
return _scan_diff(_git("log", "-p", "--all", "-U0", "--no-color", "--format=commit %h"), commit_of_header=True)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def is_test_path(path):
|
|
174
|
+
p = path.replace("\\", "/")
|
|
175
|
+
return os.path.basename(p).startswith("test_") or "/tests/" in "/" + p or p.startswith("tests/")
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def group(findings):
|
|
179
|
+
"""Group findings by unique secret, preserving first-seen order. Returns [(kind, secret, [Finding])]."""
|
|
180
|
+
groups = {}
|
|
181
|
+
for f in findings:
|
|
182
|
+
groups.setdefault((f.kind, f.secret), []).append(f)
|
|
183
|
+
return [(k, s, fs) for (k, s), fs in groups.items()]
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: leakkill
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Find leaked secrets, check if they're live, revoke them in one command, and keep them out of AI coding agents
|
|
5
|
+
Author-email: Ayush <andymylove24@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ayushanand27/leakkill
|
|
8
|
+
Project-URL: Issues, https://github.com/ayushanand27/leakkill/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/ayushanand27/leakkill/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: secrets,security,leak,revoke,pre-commit,claude-code,ai-agents,devsecops
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Security
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# leakkill
|
|
21
|
+
|
|
22
|
+
**Leaked a key? Find it, see if it's live, and kill it in one command. Free, local, zero dependencies.**
|
|
23
|
+
|
|
24
|
+
Free tools are great at *finding* secrets. What happens *after* a leak is usually left to paid
|
|
25
|
+
platforms: is this key still working, whose account is it, how do I revoke it right now, and how do
|
|
26
|
+
I clean it out of git history? leakkill does that part too, from your terminal, for free.
|
|
27
|
+
|
|
28
|
+
```console
|
|
29
|
+
$ leakkill verify
|
|
30
|
+
#1 LIVE GitHub token ghp_************ config.py:3
|
|
31
|
+
octocat scopes: repo, workflow
|
|
32
|
+
#2 DEAD AWS access key AKIA************ deploy/old.sh:12
|
|
33
|
+
key id is unknown or deactivated
|
|
34
|
+
#3 UNVERIFIABLE Credentials in URL postgres://app:****@db.prod.internal .env.backup:1
|
|
35
|
+
|
|
36
|
+
3 unique secret(s), 1 LIVE.
|
|
37
|
+
|
|
38
|
+
$ leakkill revoke --only 1 --yes
|
|
39
|
+
#1 GitHub token: REVOKED (HTTP 202)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
pip install leakkill
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Python 3.9+, no dependencies. Latest development version:
|
|
49
|
+
`pip install git+https://github.com/ayushanand27/leakkill`
|
|
50
|
+
|
|
51
|
+
## Commands
|
|
52
|
+
|
|
53
|
+
| Command | What it does | Network? |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `leakkill [scan] [PATH ...]` | Find secrets. Exit code 1 if any. | **Never** |
|
|
56
|
+
| `leakkill verify` | Also check each secret against the provider that issued it: live or dead, which account, which scopes | Read-only "who am I" calls |
|
|
57
|
+
| `leakkill revoke` | Show what can be revoked. With `--yes`, revoke the live ones (`--only 1,3` to pick) | Only with `--yes` |
|
|
58
|
+
| `leakkill report` | Write `leakkill-report.md`: every leak, its status and owner, and the cleanup steps in order | Same as `verify` (`--no-verify` to skip) |
|
|
59
|
+
| `leakkill install-hook` | Git pre-commit hook that blocks commits containing secrets | Never |
|
|
60
|
+
| `leakkill install-claude-hook` | Stop Claude Code reading `.env` and keys or writing secrets into code | Never |
|
|
61
|
+
|
|
62
|
+
Every scan command also accepts `--staged` (pre-commit), `--history` (every commit on every branch,
|
|
63
|
+
including secrets you already "deleted"), `--exclude-tests` and `--json`.
|
|
64
|
+
|
|
65
|
+
## What it can verify and revoke
|
|
66
|
+
|
|
67
|
+
| Provider | Verify (live? whose?) | Revoke from the CLI |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| GitHub (`ghp_`, `github_pat_`, `gho_`, `ghu_`, `ghr_`) | ✅ user and scopes | ✅ via GitHub's [credential revocation API](https://docs.github.com/en/rest/credentials/revoke) (the owner is notified) |
|
|
70
|
+
| GitLab (`glpat-`) | ✅ token name, scopes, expiry | ✅ self-revoke |
|
|
71
|
+
| Slack tokens (`xox…`) | ✅ user and workspace | ✅ `auth.revoke` |
|
|
72
|
+
| Discord webhooks | ✅ server and channel | ✅ deletes the webhook |
|
|
73
|
+
| AWS access key and secret | ✅ IAM ARN and account (STS, needs no permissions) | ⚠️ deactivates the key if it has `iam:UpdateAccessKey`, otherwise console steps |
|
|
74
|
+
| Stripe, OpenAI, Anthropic, npm, Telegram, Slack webhooks | ✅ | ❌ the provider has no API for it, so you get the exact page or command |
|
|
75
|
+
| Google API keys, private keys, JWTs, credentials in URLs, generic high-entropy secrets | detected, not verifiable | step-by-step rotation guidance |
|
|
76
|
+
|
|
77
|
+
## How it compares
|
|
78
|
+
|
|
79
|
+
| | leakkill | Gitleaks | TruffleHog OSS | GitGuardian | GitHub Secret Protection |
|
|
80
|
+
|---|---|---|---|---|---|
|
|
81
|
+
| Price | **Free (MIT)** | Free (MIT) | Free (AGPL) | Free for individuals, roughly $15–30/dev/month for teams | Free on public repos, $19/committer/month on private |
|
|
82
|
+
| Runs fully local | ✅ | ✅ | ✅ | ❌ SaaS | ❌ GitHub only |
|
|
83
|
+
| Detectors | ~17 | 150+ | 800+ | 550+ | [provider list](https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns) |
|
|
84
|
+
| Checks if a key is live | ✅ 11 providers | ❌ | ✅ (its main strength) | ✅ | ✅ some |
|
|
85
|
+
| Revokes from the CLI | ✅ 5 providers | ❌ | ❌ (Enterprise) | partial | ❌ |
|
|
86
|
+
| Incident report and history-purge steps | ✅ Markdown file | ❌ | ❌ | ✅ dashboard and playbooks | ❌ |
|
|
87
|
+
| Guards AI coding agents | ✅ Claude Code hooks | ❌ | ❌ | ❌ | ❌ |
|
|
88
|
+
| Dependencies | none | Go binary | Go binary | CLI + account | GitHub |
|
|
89
|
+
|
|
90
|
+
Detector and pricing figures come from public sources in October 2026. Use what fits your needs:
|
|
91
|
+
if breadth of detection matters most, run Gitleaks or TruffleHog alongside leakkill.
|
|
92
|
+
|
|
93
|
+
### Tested with real credentials
|
|
94
|
+
|
|
95
|
+
End to end on Windows with a real GitHub token and a real Discord webhook: `verify` reported both
|
|
96
|
+
LIVE with the right account and channel, `revoke --yes` returned GitHub `202` and Discord `204`, and
|
|
97
|
+
re-running `verify` reported both DEAD. Against the real AWS, GitLab, Anthropic and npm APIs, invalid
|
|
98
|
+
keys are correctly reported DEAD. Providers not yet tested with a live key (Slack, Stripe, OpenAI,
|
|
99
|
+
Telegram) are covered by tests using simulated API responses.
|
|
100
|
+
|
|
101
|
+
### Benchmark (reproducible, run October 2026)
|
|
102
|
+
|
|
103
|
+
Noise on clean, popular repos (unique secrets reported, default settings):
|
|
104
|
+
|
|
105
|
+
| Repo | leakkill | Gitleaks 8.28 |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| psf/requests | 1 (private-key test fixtures) | 4 (same fixtures, one per file) |
|
|
108
|
+
| pallets/flask | 2 (docs example `SECRET_KEY`s) | 2 (same) |
|
|
109
|
+
| django/django | 1 (a CSRF test fixture) | 8 |
|
|
110
|
+
| expressjs/express | 0 | 0 |
|
|
111
|
+
|
|
112
|
+
Recall on 17 planted realistic secrets: **leakkill 17/17, Gitleaks 14/17**. Gitleaks missed a
|
|
113
|
+
Postgres URL with a password, a Discord webhook and a Telegram bot token. The planted set was written
|
|
114
|
+
by us, so it is biased toward formats we support. Gitleaks detects many formats we don't.
|
|
115
|
+
|
|
116
|
+
## Safety model
|
|
117
|
+
|
|
118
|
+
- `scan` never touches the network.
|
|
119
|
+
- A secret is only ever sent to **the provider that issued it**. Hosts are hard-coded, and HTTP
|
|
120
|
+
redirects are never followed, so a credential can't be bounced to another server (this is tested).
|
|
121
|
+
- Verification uses read-only identity calls: GitHub `GET /user`, Slack `auth.test`, AWS
|
|
122
|
+
`GetCallerIdentity` and so on.
|
|
123
|
+
- `revoke` is a dry run unless you pass `--yes`, and only touches keys that verified as live.
|
|
124
|
+
- Raw secrets are never printed or written to the report. The only exception is the opt-in
|
|
125
|
+
`report --replacements FILE` (needed by `git filter-repo`), which is created with permissions 600.
|
|
126
|
+
|
|
127
|
+
## Cleaning git history
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
leakkill revoke --history --yes # 1. kill live keys first: history rewrites don't help once copied
|
|
131
|
+
pip install git-filter-repo
|
|
132
|
+
leakkill report --history --replacements .leakkill-replacements.txt
|
|
133
|
+
git filter-repo --replace-text .leakkill-replacements.txt
|
|
134
|
+
rm .leakkill-replacements.txt
|
|
135
|
+
git push --force --all && git push --force --tags # every collaborator must re-clone
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## AI coding agent guard (Claude Code)
|
|
139
|
+
|
|
140
|
+
`leakkill install-claude-hook` adds hooks to `.claude/settings.json` that block:
|
|
141
|
+
|
|
142
|
+
- prompts that contain secrets (before they reach the model)
|
|
143
|
+
- reading `.env`, `*.pem`, `id_rsa`, `.npmrc` and similar, whether through the Read tool or any
|
|
144
|
+
shell command that names such a file (`cat`, `grep`, `base64`, `python -c`, `cp` …).
|
|
145
|
+
`.env.example` is allowed.
|
|
146
|
+
- writing hard-coded keys into code (writing them into `.env` is allowed)
|
|
147
|
+
|
|
148
|
+
This was tested live with the Claude Code CLI: prompts with keys, `Read .env`, `cat .env`,
|
|
149
|
+
`grep . .env` and writing an AWS key into `app.py` were all blocked. The check is pattern-based: a
|
|
150
|
+
command that builds the file name at runtime can get past it. Pair it with OS-level permissions for
|
|
151
|
+
hard guarantees.
|
|
152
|
+
|
|
153
|
+
## Use in CI (GitHub Actions)
|
|
154
|
+
|
|
155
|
+
```yaml
|
|
156
|
+
- run: pip install leakkill
|
|
157
|
+
- run: leakkill scan --exclude-tests .
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Use with the pre-commit framework
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
# .pre-commit-config.yaml
|
|
164
|
+
repos:
|
|
165
|
+
- repo: https://github.com/ayushanand27/leakkill
|
|
166
|
+
rev: v0.3.0
|
|
167
|
+
hooks:
|
|
168
|
+
- id: leakkill
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Or without the framework: `leakkill install-hook`.
|
|
172
|
+
|
|
173
|
+
## Suppressing false positives
|
|
174
|
+
|
|
175
|
+
- Add `leakkill:ignore` on a line.
|
|
176
|
+
- List paths or globs in `.leakkillignore` (for example `fixtures/` or `*.snap`).
|
|
177
|
+
- High-entropy matches ignore placeholders (`your_key`, `example`, `${VAR}`), variables named
|
|
178
|
+
test/example/fake/mock, password hashes and values without digits.
|
|
179
|
+
|
|
180
|
+
## Known limitations
|
|
181
|
+
|
|
182
|
+
- Fewer detectors than Gitleaks or TruffleHog.
|
|
183
|
+
- Verification behind a proxy that injects its own credentials (some corporate and sandbox proxies
|
|
184
|
+
do) can report the proxy's identity. Run `verify` from a normal network.
|
|
185
|
+
- AWS keys can only be verified when the secret key is found too (any file in the scan).
|
|
186
|
+
- Stripe, OpenAI, Anthropic, npm and Telegram offer no revoke API, so those need a manual click.
|
|
187
|
+
|
|
188
|
+
MIT licensed.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
leakkill/__init__.py,sha256=QDWpdcppcr2JGqDHSSZO-EDFhKuVjw4ogpRAdeHaxhI,123
|
|
2
|
+
leakkill/__main__.py,sha256=uNfX_JnVbAvr1itBU22ZwzRxIfJJR_xsR48GYpLwhEI,38
|
|
3
|
+
leakkill/aws.py,sha256=HadBpNSqY6sDpTZKxfMRUGSjAqdQ_GHL4P09aw_txB8,1653
|
|
4
|
+
leakkill/cli.py,sha256=j0R8o4qkbJbm8AeCbaRABgb-DZoFiebEvN7xtC8IYTE,8480
|
|
5
|
+
leakkill/guard.py,sha256=FTfOMrZQtdw4oYyCE14hPSiociuKj9uWiyiRLCFrj5Y,4120
|
|
6
|
+
leakkill/providers.py,sha256=Q7Mj4Qvf66WypVJz6g1BIEGdww_1PxOEPqHaFn5Ejy4,13074
|
|
7
|
+
leakkill/report.py,sha256=UNB7Nyd4j67rwuCn4AZfkx4eV8-NWTWdqRYgdJNyZRU,4344
|
|
8
|
+
leakkill/scanner.py,sha256=zgB5fcHnacdUFcsVisidJ7RMzqwVeuJMAelyTEyPq0Q,7970
|
|
9
|
+
leakkill-0.3.0.dist-info/licenses/LICENSE,sha256=8zWA-oJw0E8hExeKAbXeeVMICAtXqOsqu-098pCP6DA,1062
|
|
10
|
+
leakkill-0.3.0.dist-info/METADATA,sha256=fviTCG3Ioo_5zvzppcaNkHCIvAv0xu5XmuFascRvJGE,9108
|
|
11
|
+
leakkill-0.3.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
12
|
+
leakkill-0.3.0.dist-info/entry_points.txt,sha256=OPqW4GY0CVGHVmgSUiI4pjpdtTgkdeTAFQC628EAj5A,51
|
|
13
|
+
leakkill-0.3.0.dist-info/top_level.txt,sha256=h_zDtTmF5SNzvkWYxJ7tqyKKYw9TgY1xVBlWSSEkPFs,9
|
|
14
|
+
leakkill-0.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ayush
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
7
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
8
|
+
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
|
11
|
+
of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
14
|
+
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
15
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
16
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
leakkill
|