Git Product home page Git Product logo

gitdoorcheck's Introduction

gitdoorcheck - Static code analyser for git repos using OpenAI compatible LLMs

image

  • I find myself pulling way too many random git repos, this is just a simple means of doing some static analysis.
  • Uses GPT-4 (or another openAI compatible API endpoint) to check for any backdoors, malicious code and so on within compilable or executable code.
  • Outputs as a json file
  • Can be used in CI pipeline and fail build if threshold is exceeded
  • Uses list of programming languages extensions from: https://github.com/aymen-mouelhi

Hive mind

  • The day this was published there was also an article on arstechnica about git repos containing backdoor code and mimicking common libraries (typosquatting etc.)

Setup

  • Place your openAI API key in the .env file (if required)

Usage

usage: gitdoorcheck.py [-h] --repo-url REPO_URL --local-repo-path LOCAL_REPO_PATH [--output OUTPUT]

Example usage

python3 gitdoorcheck.py --repo-url="https://github.com/Inplex-sys/BlackCap-Grabber-NoDualHook" --local-repo-path ./blackcap-grabber
{
  "project_name": "BlackCap-Grabber-NoDualHook",
  "project_url": "https://github.com/Inplex-sys/BlackCap-Grabber-NoDualHook",
  "analysis_date": "2024-03-01T05:11:35.762317",
  "total_files_analyzed": 8,
  "total_threats_detected": 18,
  "detected_threats": [
    {
      "type": "Credential Theft",
      "file_name": "builder.py",
      "line_number": "23",
      "code_snippet": "self.webhook = input(...)",
      "confidence": "100",
      "severity": "High",
      "description": "Collects a webhook URL from the user, which could be used to exfiltrate data."
    },
...
    {
      "type": "Credential Theft",
      "file_name": "inject.js",
      "line_number": "N/A",
      "code_snippet": "var tokenScript = ...getToken()",
      "confidence": "100",
      "severity": "Critical",
      "description": "Extracts Discord tokens, potentially leading to account compromise."
    },
    {
      "type": "Data Exfiltration",
      "file_name": "inject.js",
      "line_number": "N/A",
      "code_snippet": "const post = async (params) => {...}",
      "confidence": "100",
      "severity": "Critical",
      "description": "Sends collected data to an external server, indicating data exfiltration."
    },
    {
      "type": "Malicious Code",
      "file_name": "inject.js",
      "line_number": "N/A",
      "code_snippet": "electron.session.defaultSession.webRequest.onBeforeRequest(...)",
      "confidence": "100",
      "severity": "High",
      "description": "Intercepts and potentially alters web requests, which can be used for malicious purposes."
    },
    {
      "type": "Malicious Code",
      "file_name": "inject.js",
      "line_number": "N/A",
      "code_snippet": "electron.session.defaultSession.webRequest.onHeadersReceived(...)",
      "confidence": "90",
      "severity": "High",
      "description": "Modifies HTTP headers to bypass content security policies."
    }
  ],
  "overall_confidence": "90"
}

Integrating as a Github Action

name: Security Analysis Workflow

on: [push, pull_request]

jobs:
  security-analysis:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.8'

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install gitpython openai dotenv shutil

    - name: Run Security Analysis
      run: |
        python gitdoorcheck.py --repo-url ${{ github.event.repository.html_url }} --local-repo-path ./repo --threshold 50
      env:
        OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

    - name: Save Analysis Report
      if: always()
      uses: actions/upload-artifact@v2
      with:
        name: security-analysis-report
        path: analysis-report.json

gitdoorcheck's People

Contributors

referefref avatar

Stargazers

Git79 avatar Bryan Onel avatar Pedro Rodriguez avatar  avatar  avatar Chance Barkley avatar  avatar Francisco Boni avatar Raffi avatar Taha  DRAIDIA avatar JK avatar  avatar Andrew Antles avatar Nicolas RUFF avatar 3zbumban avatar Sean DiSanti avatar Monty Rhodes avatar Navid-Radkusha avatar  avatar Jordi Serrano avatar Pasi Juurikas avatar Lucas Recknagel avatar RT avatar Ken avatar Simon Shrestha avatar Park Sang kil avatar  avatar Maxime Veber avatar Raul Barreras avatar Michael Clermont avatar  avatar Jefferson Phillips avatar Lucas Maurice avatar Raven Spann avatar David Martinez avatar Jason Trost avatar Logan Long avatar Ryan Armstrong avatar merve avatar Shiv Trivedi avatar Xavier Pich avatar Benjamin-Yves Trapp avatar Antonio avatar Deepanshu Tiwari avatar Derrick Roach avatar Zachary Loeber avatar Kai Berberich avatar Stefan Streichsbier avatar Cory Todd avatar Riccardo Mazza avatar  avatar samy kamkar avatar Maksim Balabash avatar (⋆❛ ہ ❛⋆)⊃.:☆..:*・☆ avatar Rafael  avatar Wajih Yassine avatar Rocco Gränitz avatar  avatar Borko avatar Eric Brown avatar Rewanth Tammana avatar Frenchie avatar  avatar  avatar The Red Operator avatar tudouya avatar Ali avatar Nick avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.