Introduction to CodeQL

  1. describe the system using diagrams as reference point, with details from existing docs

  2. Update https://github.com/hohn/codeql-cli-end-to-end

  3. https://github.com/hohn/codeql-workshop-sql-injection-java

    • version for C#

CodeQL overview

  • /Users/hohn/local/codeql-dataflow-sql-injection/CodeQL-workshop-overview-only.pdf

There are two identifyable tracks for codeql users: devops and query writers. The first one focuses on setup, deployment, and query selection; the second on query writing. There is significant overlap; the CodeQL CLI Setup is needed by both.

CodeQL CLI Setup

Test Problem Setup

Hello World Sample

  # Install sdk
  brew install --cask dotnet-sdk
  dotnet --version

  # Create template project
  mkdir HelloWorld
  cd HelloWorld
  dotnet new console

  # Compile template project
  cd ~/work-gh/codeql-intro-csharp/HelloWorld/
  dotnet build

  # Run template project
  dotnet run
  # or
  ./bin/Debug/net9.0/HelloWorld

SQL Injection

  # Project Setup
  cd ~/work-gh/codeql-intro-csharp/
  dotnet new console -n SqliDemo
  cd SqliDemo

  dotnet add package Microsoft.Data.Sqlite

  # Database Init
  cd ~/work-gh/codeql-intro-csharp/SqliDemo
  sqlite3 users.sqlite
  CREATE TABLE users (id INTEGER, info TEXT);
  .exit

  # Build
  cd ~/work-gh/codeql-intro-csharp/SqliDemo
  dotnet build

  # Run
  dotnet run
  First User

  # Check db
  echo '
      SELECT * FROM users;
  ' | sqlite3 users.sqlite 

  # Add Johnny Droptable 
  dotnet run
  Johnny'); DROP TABLE users; --

  # Check db
  echo '
      SELECT * FROM users;
  ' | sqlite3 users.sqlite 
  # Parse error near line 2: no such table: users

CodeQL VS Code Setup

CodeQL for Devops and Administrators

Description
No description provided
Readme MIT 589 KiB
Languages
HTML 50.2%
CodeQL 19.1%
Shell 12.2%
PowerShell 10.1%
C# 8.4%