Atomic Search
Atomic Search is a Python package for detecting malicious JavaScript syntax through an atomic and molecule search approach. This package is designed to handle obfuscated JavaScript code using techniques like concatenation and syntax splitting, making it effective for detecting target syntax even when the code is heavily obfuscated.
Features
- Atomic Extraction: Extracts relevant syntax fragments (atoms) from obfuscated JavaScript.
- Molecule Search: Combines these atoms to form specific target syntax using a brute-force approach, enabling the detection of malicious JavaScript syntax.
- Logging and Debugging: Logs the extraction and molecule formation process for debugging purposes.
- Automated Task Management: Simplify development tasks with
invokecommands.
Installation
Ensure you are using Python 3.7 or newer.
-
Clone the repository:
git clone https://github.com/aflinxh/atomic_search.git cd atomic_search
-
Install the package using
pip:pip install .
-
For development, install additional dependencies:
pip install .[dev]
Usage
Here’s an example of using Atomic Search to detect JavaScript syntax:
from atomic_search import atomic_search
# List of target words to detect
target_words = ["getElementById", "addEventListener"]
# Example search space, which is obfuscated JavaScript code
search_space = "some obfuscated JavaScript code"
# Define minimum atom size and molecule similarity
min_atom_size = 2 # minimum atom size
molecule_similarity = {"getElementById": "90%", "addEventListener": "-2"} # tolerance or similarity level
# Run the atomic search
results = atomic_search(target_words, search_space, min_atom_size, molecule_similarity, logs=True)
# Display the results
print("Search Results:", results)
atomic_search Function Parameters
target_words: List of strings representing the target syntax to detect.search_space: The JavaScript string to analyze.min_atom_size: Minimum atom size required for validity.molecule_similarity: Dictionary setting the similarity or tolerance for each target.logs: Set toTrueto display logs.
Directory Structure
The project has the following structure:
atomic_search/
├── atomic_search.py # Main function for atom and molecule search
├── extract_atoms.py # Module for atom extraction
├── form_molecule.py # Module to form molecules from atoms
└── __init__.py # Package initializer
tasks.py # Task automation with Invoke
utils/ # Utility scripts for managing logs and datasets
tests/ # Test directory
README.md # This documentation
pyproject.toml # Project metadata
setup.py # Installation configuration
Utility Commands
This project uses invoke to manage development tasks, which are defined in tasks.py. Here are some commonly used commands:
-
Clear Logs: Removes all log files from the logs directory.
invoke clear-logs -
Clear Datasets: Removes all datasets from the dataset directory.
invoke clear-datasets -
Generate Datasets: Generates datasets with an optional
num_samplesargument.invoke generate-datasets --num-samples=100
Testing
This project uses pytest for running tests and invoke to manage and simplify test execution. Here are the available test commands using invoke:
-
Run Atom Tests: Runs tests for
extract_atoms.pylocated intests/test_extract_atoms.py. You can optionally specify a particular file to test and enable logs.invoke test-atoms --file-name="sample.js" --show-logs
--file-name: Specifies the JavaScript file to use for testing.--show-logs: Enables detailed logging during the test.
-
Run Molecule Tests: Runs tests for
form_molecule.pylocated intests/test_form_molecule.py. You can optionally specify a file name and enable logs.invoke test-molecule --file-name="sample.js" --show-logs
--file-name: Specifies the JavaScript file to use for testing.--show-logs: Enables detailed logging during the test.
-
Run Atomic Search Tests: Runs tests for the
atomic_searchfunction located intests/test_atomic_search.py. You can specify a file name and enable logs, similar to the other test commands.invoke test-atomic --file-name="sample.js" --show-logs
--file-name: Specifies the JavaScript file to use for testing.--show-logs: Enables detailed logging during the test.
Running All Tests
To run all tests in the tests/ directory, you can use pytest directly:
pytest tests/
These invoke commands allow you to run targeted tests with specific options for more control during development and debugging.
Contribution
Contributions are welcome! Follow these steps to contribute:
- Fork this repository.
- Create a branch for your feature or fix (
git checkout -b new-feature). - Commit your changes (
git commit -m 'Add new feature'). - Push to the branch (
git push origin new-feature). - Create a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for atomic-search 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| atomic_search-0.1.0.tar.gz | 10.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| atomic_search-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.3 kB
Release files / atomic_search-0.1.0.tar.gz
| Download URL | atomic_search-0.1.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8bc7c3ab6a4a9b29dcc8d494dade732369cc3b3fd24bc66628c605b31058b45
|
|
BLAKE2b-256 checksum How to use checksums |
23538e703c8a6c91f8f51e1ea05bd7a34401e1b7009efe446780430f1efbccfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Release files / atomic_search-0.1.0-py3-none-any.whl
| Download URL | atomic_search-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d7b5ef835a83943ef302e1097239cfd445e571b5fac84b5ee1d0ebd32abe538c
|
|
BLAKE2b-256 checksum How to use checksums |
f99fd6cf87efbb4042f973848484e3b8b610f4cc16a8643c8be2b0f3308778ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Security for atomic-search 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.