Adversarial attacks for perceptual image hashing functions
Project description
AdvHash: Adversarial collision attacks on perceptual hashing functions
Summary
AdvHash is a Python package that provides a simple to use interface for performing adversarial collision attacks on perceptual hashing functions.
PyTorch is used to re-create the target hashing functions and generating adversarial examples. AdvHash supports both CPU and GPU computations. Install the CUDA enabled version of PyTorch to use a GPU with AdvHash and specify device='cuda'
when instantiating an attack
or hash
.
- Adversarial collision attacks on image hashing functions
- Components
- Getting Started
- Attacks
- Future Development
- Contributing
Adversarial collision attacks on image hashing functions
Currently AdvHash supports collision attacks on hashing functions from the popular imagehash
package using methods described in Adversarial collision attacks on image hashing functions.
Components
AdvHash is divided into multiple granular components:
Component | Description |
---|---|
advhash | a PyTorch based library for performing adversarial attacks |
advhash.attack | adversarial attack methods |
advhash.hash | perceptual hashing functions |
advhash.utils | utility functions for performing common resizing, conversion, and comparison operations |
Getting Started
Installation
pip install advhash
*Install a CUDA enabled version of PyTorch to use a GPU with AdvHash.
Example Usage
This example shows how the L2Attack
can be used to perform an adversarial collision attack on dHash
using the resize
method as the target split point.
import torch
import numpy as np
from PIL import Image
from advhash.attack.l2 import L2Attack
target_img = Image.open('forest.jpg')
source_img = Image.open('cat.jpg')
target = torch.tensor((np.array(target_img).astype('float32')))
source = torch.tensor((np.array(source_img).astype('float32')))
l2 = L2Attack(hash_fn='dhash', split_point='resize')
im_adv = l2.attack(target, source)
Attacks
Collision Attacks for Image Hashing
advhash.attack.l2.L2Attack
advhash.attack.hinge.HingeAttack
The above attacks accept a source image, target image, and hashing function as an input. The source image will be perturbed to create an adversarial image that has the same hash as the target image when hashed by the selected hashing function. Some attacks require additional configuration.
Hashing Functions
Future Development
Hashing Functions
pHash
aHash
pqd
Attack Methods
- TBD
Defense Methods
- TBD
Contributing
Contributions are welcome! If you plan to contribute new features, methods, or enhancements, please open an issue to discuss the addition further, or comment on an existing issue.
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
Built Distribution
File details
Details for the file advhash-0.1.1.tar.gz
.
File metadata
- Download URL: advhash-0.1.1.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1ac49ff6935b003f81a74861b2a315f57dd007e006eb99044b5e45d08600b02 |
|
MD5 | a45029949b56685d2177f5f0af19e287 |
|
BLAKE2b-256 | 67db14b0f743c600629045fe83723ea800f5b8750ecf323ad1fcb4c0f2987731 |
File details
Details for the file advhash-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: advhash-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03d9e81bdbea0e3463adfa490cec7ce26db4cf432960bd7c35facfb00cff6e9f |
|
MD5 | 63d9cbb7d3189c3e50c4e33f4eaf843a |
|
BLAKE2b-256 | e733eda33c0c05ec3c9bda58de4ebc0d30d2484162145812527dc35e2eeb2454 |