diff --git a/analyzers/QrDecode/Dockerfile b/analyzers/QrDecode/Dockerfile new file mode 100644 index 000000000..b30d080a2 --- /dev/null +++ b/analyzers/QrDecode/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3 +WORKDIR /worker +COPY . QrDecode +RUN test ! -e QrDecode/requirements.txt || pip install --no-cache-dir -r QrDecode/requirements.txt +RUN apt-get update && \ + apt-get install -y libzbar0 poppler-utils +ENTRYPOINT ["QrDecode/qrdecode.py"] diff --git a/analyzers/QrDecode/QrDecode.json b/analyzers/QrDecode/QrDecode.json new file mode 100755 index 000000000..a01c691b8 --- /dev/null +++ b/analyzers/QrDecode/QrDecode.json @@ -0,0 +1,11 @@ +{ + "name": "QrDecode", + "version": "1.0", + "author": "THA-CERT", + "url": "https://github.com/TheHive-Project/Cortex-Analyzers", + "license": "AGPL-V3", + "description": "Extracts data from one or more QR codes.", + "dataTypeList": ["file"], + "command": "QrDecode/qrdecode.py", + "baseConfig": "QrDecode" +} diff --git a/analyzers/QrDecode/README.md b/analyzers/QrDecode/README.md new file mode 100755 index 000000000..be6d30c3f --- /dev/null +++ b/analyzers/QrDecode/README.md @@ -0,0 +1,84 @@ + +# QrDecode + +## Overview + +QrDecode is a QR code analyzer used to extracts and categorizes data from QR codes embedded in various file formats. It supports images in JPEG, PNG, GIF formats, and PDF documents. + +## Features + +- **Multi-format support:** Handles JPEG, PNG, GIF, and PDF files. +- **Data extraction:** Decodes QR codes and identifies data types such as URLs, email addresses, IP addresses, and cryptocurrency addresses. +- **Categorization:** Categorizes extracted data into predefined types and categories. +- **Report Templates:** Report templates available for readability. +- **Error handling:** Detects and reports errors in QR code reading and file format issues. + +## Requirements + +The following dependencies are required for QrDecode: + +### System Libraries + +```bash +sudo apt-get install libzbar0 +sudo apt-get install poppler-utils +``` + +### Python Libraries + +```plaintext +cortexutils +pyzbar +pdf2image +pillow +``` + +To install the Python libraries, run: + +```bash +pip install -r requirements.txt +``` + +## Usage + +Once installed and configured, QrDecode analyzes files containing QR codes. The analyzer extracts data from QR codes, categorizes it, and returns the results in a structured format. For PDF files, the analyzer automatically converts each page to an image format for comprehensive analysis. It also efficiently processes multiple QR codes within a single image or PDF. + +### Running the Analyzer + +To run the analyzer, submit a file through The Hive or Cortex interface, selecting QrDecode as the analyzer. The analyzer will process the file and return results including: + +- Decoded data from QR codes +- Data types and categories + +## Results Details + +When the analyze is finished, the report can display: +* A Summary: with qualitative information about the detection + +![](assets/qrdecode-summary-report.png) + +* Stats: with information like : File Name, File Extension, Total number of QR Codes + +![](assets/qrdecode-stats.png) + +## Extracted Observables + +Moreover, these domains, IP addresses, URLs, bitcoin addresses, email addresses are added to the extracted Observables, ready to be imported and actioned in TheHive. + +![](assets/qrdecode-extracted-observables.png) + +### Error Handling + +The analyzer includes a set of predefined errors to handle cases such as unsupported file formats, failed PDF conversion, and QR code reading issues. These errors are reported back in the analysis results. + +## License + +QrDecode is licensed under the AGPL-V3 license. + +## Version + +**1.0** + +## Author + +- **THA-CERT** \ No newline at end of file diff --git a/analyzers/QrDecode/assets/qrdecode-extracted-observables.png b/analyzers/QrDecode/assets/qrdecode-extracted-observables.png new file mode 100755 index 000000000..4787594b4 Binary files /dev/null and b/analyzers/QrDecode/assets/qrdecode-extracted-observables.png differ diff --git a/analyzers/QrDecode/assets/qrdecode-stats.png b/analyzers/QrDecode/assets/qrdecode-stats.png new file mode 100755 index 000000000..44e57dc78 Binary files /dev/null and b/analyzers/QrDecode/assets/qrdecode-stats.png differ diff --git a/analyzers/QrDecode/assets/qrdecode-summary-report.png b/analyzers/QrDecode/assets/qrdecode-summary-report.png new file mode 100755 index 000000000..100f25fc1 Binary files /dev/null and b/analyzers/QrDecode/assets/qrdecode-summary-report.png differ diff --git a/analyzers/QrDecode/qrdecode.py b/analyzers/QrDecode/qrdecode.py new file mode 100755 index 000000000..1e8a922c7 --- /dev/null +++ b/analyzers/QrDecode/qrdecode.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python3 +# Author : THA-CERT + +import sys +import os +import re +from cortexutils.analyzer import Analyzer +from pyzbar.pyzbar import decode, ZBarSymbol +from PIL import Image +from pdf2image import convert_from_path + +class QrDecode(Analyzer): + def __init__(self): + Analyzer.__init__(self) + self.filename = self.get_param("filename", None, "Filename is missing.") + self.num_page = None + self.nb_page = None + self.file_format = None + self.message = "" + self.total_qr_codes = 0 + self.nb_qrcode = 0 + self.num_qrcode = 0 + self.results_list = [] + self.regex_ipv4 = r'\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b' + self.regex_domain = r'^(?!-)[A-Za-z0-9-]{1,63}(? +
+
+ Stats +
+
+ + + + + + + + + + + + + +
File Name{{ content["stats"]["file_name"] }}
File Extension{{ content["stats"]["file_extension"] }}
Total QR Code(s){{ content["stats"]["total_qr_codes"] }}
+
+
+ +
+
+ QR: {{ result.results.QR }} +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Data Category{{ result.results.data_category }}
Data Type{{ result.results.data_type }}
Info{{ result.results.info }}
Data{{ result.results.data }}
Brute Data{{ result.results.brute_data }}
On PDF page{{ result.results.page }}
+
+
+ + + +
+
+ Error +
+
+
+
+ QrDecode: +
+
{{ content.stats.error }}
+
+
+
diff --git a/thehive-templates/QrDecode_1_0/short.html b/thehive-templates/QrDecode_1_0/short.html new file mode 100755 index 000000000..5fc0dabfb --- /dev/null +++ b/thehive-templates/QrDecode_1_0/short.html @@ -0,0 +1,3 @@ + + {{t.namespace}}:{{t.predicate}}="{{t.value}}" +