Skip to main content

ShareQL: A domain specific language to provide rule matching in network shares exploration

A Domain Specific Language to control access to files, directories, and shares in network shares crawling
PyPI GitHub release (latest by date) YouTube Channel Subscribers

Features

  • Rule-based Access Control: Define complex rules for share crawling to control access to files, directories, and shares
  • Flexible Conditions: Support for multiple operators including MATCHES, IN, comparison operators, and regex patterns
  • Boolean Logic: Combine conditions with AND, OR, XOR, and NOT operators
  • Multiple Object Types: Rules apply to files, directories, and shares based on their properties
  • Field-based Filtering: Filter based on element size, name, path, modification time, creation time, and more
  • Operation Control: Control specific operations like PROCESSING and EXPLORATION
  • Syntax Highlighting: Syntax highlighting for this langugage is provided in VSCode by the extension shareql-vscode-ext

Installation

You can get the latest version from pypi:

pip install shareql

Or you can build it from source:

git clone https://github.com/p0dalirius/shareql
cd shareql
make install

Language Syntax

ShareQL uses a simple but powerful syntax for defining access rules:

Basic Rule Structure

ACTION [OPERATION] [IF condition]
  • ACTION: ALLOW or DENY
  • OPERATION: ALL, PROCESSING, or EXPLORATION (optional)
  • condition: Boolean expression using available fields and operators

Available Fields

File Fields:

  • FILE.SIZE - File size in bytes
  • FILE.NAME - File name
  • FILE.PATH - Full file path
  • FILE.MODIFIED_AT - Last modification timestamp
  • FILE.CREATED_AT - Creation timestamp

Directory Fields:

  • DIRECTORY.PATH - Full directory path
  • DIRECTORY.NAME - Directory name
  • DIRECTORY.MODIFIED_AT - Last modification timestamp
  • DIRECTORY.CREATED_AT - Creation timestamp

Share Fields:

  • SHARE.NAME - Share name
  • SHARE.DESCRIPTION - Share description
  • SHARE.TYPE - Share type

Other Fields:

  • DEPTH - Directory depth level

Operators

  • MATCHES - String matching
  • IN - Check if value is in a list
  • >=, <=, >, <, == - Comparison operators
  • STARTSWITH - String starts with pattern
  • ENDSWITH - String ends with pattern
  • CONTAINS - String contains pattern

Values

  • Strings: "quoted string" or 'single quoted'
  • Numbers: 1234
  • Lists: ["item1", "item2", "item3"]
  • Regex: REGEX("pattern.*")

Examples

Basic Rules

# Deny all access
DENY ALL

# Allow file processing
ALLOW PROCESSING

# Deny directory exploration
DENY EXPLORATION

Conditional Rules

# Deny processing of backup files
DENY PROCESSING IF FILE.PATH MATCHES "backup"

# Allow only small files
ALLOW PROCESSING IF FILE.SIZE <= 1000

# Deny access to admin directories
DENY EXPLORATION IF DIRECTORY.NAME MATCHES "admin"

Complex Conditions

# Deny large backup files
DENY PROCESSING IF FILE.PATH MATCHES "backup" AND FILE.SIZE >= 1000

# Allow specific file types
ALLOW PROCESSING IF FILE.NAME ENDSWITH ".pdf" OR FILE.NAME ENDSWITH ".docx"

# Deny files in specific directories
DENY PROCESSING IF FILE.PATH STARTSWITH "C:/temp" AND FILE.SIZE >= 500

# Allow files not in restricted list
ALLOW PROCESSING IF NOT FILE.NAME IN ["backup.exe", "temp.dll"]

Regex Patterns

# Deny files matching regex pattern
DENY PROCESSING IF FILE.PATH MATCHES REGEX(".*\\.(zip|rar|7z)$")

# Allow files with specific naming pattern
ALLOW PROCESSING IF FILE.NAME MATCHES REGEX("^report_[0-9]{4}\\.pdf$")

Nested Boolean Logic

# Complex nested conditions
ALLOW PROCESSING IF ((FILE.PATH MATCHES "documents" AND FILE.SIZE <= 1000) OR (FILE.PATH MATCHES "images" AND FILE.SIZE <= 5000))

# Multiple directory restrictions
DENY EXPLORATION IF (DIRECTORY.NAME MATCHES "private" OR DIRECTORY.PATH MATCHES "C:/system") AND NOT DIRECTORY.MODIFIED_AT < 1670000000

Usage

Python API

from shareql.grammar.parser import RuleParser
from shareql.evaluate.evaluator import RulesEvaluator

# Parse rules from text
parser = RuleParser()
rules, errors = parser.parse("""
DENY PROCESSING IF FILE.SIZE >= 1000
ALLOW EXPLORATION IF DIRECTORY.NAME MATCHES "public"
""")

# Create evaluator
evaluator = RulesEvaluator(rules)

# Evaluate against target objects
# (target_object should be a RuleObjectFile, RuleObjectDirectory, or RuleObjectShare)
rule, allowed, result = evaluator.evaluate(target_object)

Example of usage

Parse and validate rules file

# Parse and validate rules file
shareql --rules rules.txt --validate

Contributing

Pull requests are welcome. Feel free to open an issue if you want to add other features.

License

This project is licensed under the GPL v2 License - see the LICENSE file for details.

Metadata

Release files for shareql 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for shareql 1.0.0
File Interpreter ABI Platform
shareql-1.0.0-py3-none-any.whl Python 3 none any Details

Release files / shareql-1.0.0-py3-none-any.whl

Download URL shareql-1.0.0-py3-none-any.whl
Size 35.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
565819e3bfa0de9a680526d3c73bf6d371ea61176521cc6bb418fd4b229ab186
BLAKE2b-256 checksum
How to use checksums
b24afe6157d91a15bea2be37cc821e04b3a7c7d6227222a0048444a527092f8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page