Skip to content

Improve detection of code execution via compile() and vars() indirection (Python)#643

Merged
sobregosodd merged 2 commits intoDataDog:mainfrom
dwBruijn:dwBruijn/code-execution-improvement
Jan 13, 2026
Merged

Improve detection of code execution via compile() and vars() indirection (Python)#643
sobregosodd merged 2 commits intoDataDog:mainfrom
dwBruijn:dwBruijn/code-execution-improvement

Conversation

@dwBruijn
Copy link
Copy Markdown
Contributor

@dwBruijn dwBruijn commented Jan 5, 2026

Hello,

Added patterns to code-execution rule to detect malicious packages using compile() and vars(__builtins__) indirection to access exec(), eval(), and compile().

These patterns were not being detected:

vars(__builtins__)['exec']("malicious code")
vars(__builtins__).get('eval')("malicious code")
vars(globals()['__builtins__'])['exec'](...)
vars(locals()['__builtins__'])['eval'](...)
compile(__import__('base64').b64decode('...'), '<string>', 'exec')

@sobregosodd sobregosodd merged commit 8619cdd into DataDog:main Jan 13, 2026
10 checks passed
@sobregosodd
Copy link
Copy Markdown
Contributor

Thanks for contributing @dwBruijn !

christophetd pushed a commit that referenced this pull request Apr 10, 2026
…ment

Improve detection of code execution via compile() and vars() indirection (Python)
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