Skip to content
Proyectos

0xdea/semgrep-rules

Ver en GitHub

Acerca de

Una colección de mis reglas de Semgrep para facilitar la investigación de vulnerabilidades.

Seguridad y privacidad

Cómo se miden estas cifras

Crecimiento de estrellas medido

in 24h
+1
in 7 days
+1
in 15 days
+1
in 1 month
Recopilando historial

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

semgrep-rules

validate

"The attack surface is the vulnerability. Finding a bug there is just a detail."

-- Mark Dowd

"Some details are more important than others."

-- Fedor G. Pikus

A collection of my Semgrep rules to facilitate vulnerability research.

Program in C

Articles

See also

Setup and usage instructions

  1. Install Semgrep.
  2. To use these rules via the Semgrep registry, run the following from the root folder of your target source code repository:
# high priority scan (quick wins)
semgrep --severity ERROR --config "p/0xdea"

# high and medium priority scan (recommended)
semgrep --severity ERROR --severity WARNING --config "p/0xdea"

# full scan (might include marginal findings and more false positives)
semgrep --config "p/0xdea"

Alternatively, you can clone this GitHub repository locally and run:

# full scan
semgrep --config semgrep-rules/rules /path/to/source

# specific rule scan
semgrep --config semgrep-rules/rules/c/command-injection.yaml /path/to/source

[!TIP] Specify the --no-git-ignore switch to scan files regardless of git tracking status or .gitignore rules.

For a better streamlined experience, I recommend saving the Semgrep scan output in SARIF format and using SARIF Explorer in VS code:

semgrep --sarif --sarif-output=/path/to/source/SEMGREP.sarif --config semgrep-rules/rules /path/to/source
code /path/to/source # then open the SEMGREP.sarif file in VS code with SARIF Explorer 

See also the included SARIF output example.

Compatibility

Tested with Semgrep CLI 1.169.0.

Rules

C/C++

Battle-tested C (and sometimes C++) ruleset.

buffer overflows

integer overflows

format strings

memory management

command injection

race conditions

privilege management

denial of service

  • regex-dos. Regular expression that may exhibit exponential runtime and lead to ReDoS.

miscellaneous

Noisy

These rules are considered potentially too noisy and unsuitable for general use.

generic

  • bad-words. Keywords and comments that suggest the presence of bugs.

Changelog

TODO

Short-term action items

  • Process open issues and pull requests.
  • Add new checks to the existing rules and add new rules where needed.
  • Improve overall accuracy and reduce false positives, without missing potential hot spots in code.
  • Check performance (see test_public_repos.py).
  • Additional --time benchmarking against real-world code to spot slow rules in need of optimization.

Long-term action items

  • Add scripts to clean up pseudocode generated by common decompilers to improve Semgrep parsing.
  • Port the rules to the Semgrep Pro engine, which allows for inter-file and inter-function analysis.
  • Implement taint mode where suitable to improve rules with dataflow analysis.
  • Investigate symbolic propagation that might be useful to reduce some false positives.
  • Implement a Semgrep wrapper and post-processor as described in this research.

Domain-specific rulesets

  • Implement dedicated kernel rules (Linux, BSD, macOS, etc.).
  • Implement dedicated crypto and rng rules.
  • Implement dedicated C++ rules and move them in another folder separated from the one for C rules.
  • Create a specific ruleset for Rust.

Explorar proyectos relacionados

Cargando…