This script extracts, filters and parses combined log format (apache and nginx default access.log format) with a easy and fast language syntax
Project description
QueryCombinedLogFormat
Description
This tool extracts, filters and parses combined log format (apache and nginx default access.log format) with a easy and fast language syntax.
This tool has been written in forensic lessons and challenges for certification. It's a little tool to reduce time for analysis.
- This tool implements a basic and permissive syntax to query combined log files (apache and nginx default access.log format) with details and typing.
- This tool can parses multiples logs files using glob syntax and parses Gzip compressed logs files. If you have configured the logs rotation and gzip compression you can use this tool to analyze all of your logs with a simple command line.
- With this tool you can extract logs in a CSV and mJSON format to analyse it faster when you start this script multiple times on the same logs (in incident response). You can use the CSV file in excel with filtered logs for analyze or retex.
- To identify faster suspicious logs, this script implements a statistics option to make a CLI table with values and counters.
Requirements
This package require:
- python3
- python3 Standard Library
Installation
Pip
python3 -m pip install QueryCombinedLogFormat
Git
git clone "https://github.com/mauricelambert/QueryCombinedLogFormat.git"
cd "QueryCombinedLogFormat"
python3 -m pip install .
Wget
wget https://github.com/mauricelambert/QueryCombinedLogFormat/archive/refs/heads/main.zip
unzip main.zip
cd QueryCombinedLogFormat-main
python3 -m pip install .
cURL
curl -O https://github.com/mauricelambert/QueryCombinedLogFormat/archive/refs/heads/main.zip
unzip main.zip
cd QueryCombinedLogFormat-main
python3 -m pip install .
Usages
Command line
QueryCombinedLogFormat # Using CLI package executable
python3 -m QueryCombinedLogFormat # Using python module
python3 QueryCombinedLogFormat.pyz # Using python executable
QueryCombinedLogFormat.exe # Using python Windows executable
QueryCombinedLogFormat [-s|--statistics] [-d|--to-db] <glob_syntax_log_files> <queries>...
QueryCombinedLogFormat -d 'access.log*' "method = POST" 'status ~ 5??' # print logs and generate a DB file with POST method or server error (http status 5XX)
QueryCombinedLogFormat -s 'access_log_db_*.csv' '(METHOD = post or url ~ *admin*) & (ip > 91.0.0.0 | referrer ~ *://*)' # use the precedent generated DB to get statistics for POST request or admin URL for all IP address greater than 91.0.0.0 or with a url referrer
Query syntax
Examples
- Query all requests with the method POST:
method = POST - Query all requests with a status code starting by 5 (server error):
status ~ 5?? - Query all requests with response size greater or equal than 60000000:
size >= 60000000 - Query all requests with a specific match on User-Agent and a specific IP address:
user_agent ~ *Version/6.0\ Mobile* and ip = 66.249.73.135 - Query all requests with the method POST or
adminin URL if IP address is greater than91.0.0.0and referrer is not empty (contains URL instead of-):(METHOD = post or url ~ *admin*) & (ip > 91.0.0.0 | referrer ~ *://*)
Fields
ip(IPv4Address)datetime(datetime)method(string)url(string)version(float)status(int)size(int)referrer(string)user_agent(string)
Operators
=~><>=<=!
Inter expression
and&or|
Priority
- Parenthesis
- Left to right
Escape character
\ works only before a spaces or operators characters else is the \ character.
Links
License
Licensed under the GPL, version 3.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file querycombinedlogformat-0.0.1.tar.gz.
File metadata
- Download URL: querycombinedlogformat-0.0.1.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f1362b50d1fffbfb5cfb63013cb9198c941f58b8bf6ab2e5978bf1cf83f820a
|
|
| MD5 |
5735166e81ae2d2b2befb547c27d2ba6
|
|
| BLAKE2b-256 |
fe9d7fce51a51c0d233930a26bb34b529872d65dfd46838b10db3810a8362eb8
|