Skip to content

Commit d5465dd

Browse files
author
Otsmane-Ahmed
committed
v1.1.0 - .pth file detection & sudo-free execution
New features: - Runs without sudo using Linux capabilities (CAP_BPF) - .pth file planting detection (keip install, keip scan, keip python) - Safe python execution wrapper with threat blocking Improvements: - Added .gitignore - Fixed venv ownership in setup.sh - Whitelist for safe .pth files (setuptools, namespace packages) - Removed __pycache__ from repo
1 parent b3560d3 commit d5465dd

8 files changed

Lines changed: 38 additions & 6 deletions

File tree

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Virtual environments
2+
keip-env/
3+
venv/
4+
.venv/
5+
6+
# Python cache
7+
__pycache__/
8+
*.pyc
9+
*.pyo
10+
11+
# Test files
12+
a.py
13+
test_script.py
14+
15+
# OS files
16+
.DS_Store
17+
*.swp
18+
*.swo

check_compat.sh

100644100755
File mode changed.

install.sh

100644100755
File mode changed.

run_keip.sh

100644100755
File mode changed.

setup.sh

100644100755
File mode changed.
-13.6 KB
Binary file not shown.

src/pth_audit.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@
3636
"pytest-cov.pth", # pytest-cov
3737
}
3838

39+
# Known safe .pth filename patterns (suffix-based)
40+
SAFE_PTH_PATTERNS = [
41+
"-nspkg.pth", # namespace packages (zope, repoze, PasteScript, etc.)
42+
]
43+
44+
45+
def is_safe_pth(filepath):
46+
"""Check if a .pth file is in the whitelist (exact name or known pattern)."""
47+
basename = os.path.basename(filepath)
48+
if basename in SAFE_PTH_FILES:
49+
return True
50+
for pattern in SAFE_PTH_PATTERNS:
51+
if basename.endswith(pattern):
52+
return True
53+
return False
54+
3955

4056
def get_site_packages_dirs():
4157
"""Get all site-packages directories (global + active venv)."""
@@ -138,8 +154,7 @@ def audit_report(new_files, modified_files):
138154

139155
# Check new files
140156
for filepath in new_files:
141-
basename = os.path.basename(filepath)
142-
if basename in SAFE_PTH_FILES:
157+
if is_safe_pth(filepath):
143158
continue
144159
has_code, code_line = has_executable_code(filepath)
145160
if has_code:
@@ -157,8 +172,7 @@ def audit_report(new_files, modified_files):
157172

158173
# Check modified files
159174
for filepath in modified_files:
160-
basename = os.path.basename(filepath)
161-
if basename in SAFE_PTH_FILES:
175+
if is_safe_pth(filepath):
162176
continue
163177
has_code, code_line = has_executable_code(filepath)
164178
if has_code:
@@ -184,8 +198,7 @@ def scan_existing_pth_files(snapshot):
184198
"""
185199
suspicious = False
186200
for filepath in snapshot:
187-
basename = os.path.basename(filepath)
188-
if basename in SAFE_PTH_FILES:
201+
if is_safe_pth(filepath):
189202
continue
190203
has_code, code_line = has_executable_code(filepath)
191204
if has_code:
@@ -325,3 +338,4 @@ def run_python_safe(python_args):
325338
ret = run_pip_with_audit(sys.argv[1:])
326339
sys.exit(ret)
327340

341+

uninstall.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)