The PicMetaStegSec (PicMetaStegSec.py) is a Python script designed to manage image metadata and perform steganography. It serves as a command-line wrapper for ExifTool to read, write, and strip metadata from images. Additionally, it allows users to embed and extract hidden messages in .png or .bmp files, with an optional layer of AES encryption using a passphrase. It can process single files or entire directories.
PicMetaStegSec.py: The main script containing all logic for metadata manipulation and steganography.[output_file].png: (User-defined) Output image file created when embedding a message.[output_file].txt: (User-defined) Optional output file when saving metadata from thereadcommand.
- Python standard libraries:
argparseossubprocesshashlibbase64
- External libraries:
cryptography(for encryption/decryption)stegano(for steganography)
- External tools:
- ExifTool: This tool is required and must be installed and accessible in your system's PATH for all metadata functions (read, write, strip).
- Purpose: A wrapper to execute ExifTool commands safely.
- Logic:
- Uses
subprocess.runto call theexiftoolexecutable. - Can read all tags (no arguments), write a tag (
-tag=value), or strip all tags (-all=).
- Uses
- Purpose: To secure hidden messages with a passphrase.
- Logic:
- Derives a 32-byte key from the user's passphrase using
hashlib.sha256. - Uses the
cryptography.fernetlibrary (AES-128-CBC) to encrypt or decrypt the message text.
- Derives a 32-byte key from the user's passphrase using
- Purpose: Hides or reveals a message within an image file.
- Logic:
- Uses
stegano.lsb.hideto embed the message andstegano.lsb.revealto extract it. - Before embedding, it optionally calls
encrypt_messageif a passphrase is provided. - After extracting, it optionally calls
decrypt_message. - Checks for supported formats (
.png,.bmp).
- Uses
- Purpose: Applies a chosen action to all supported images in a directory.
- Logic:
- Uses
os.walkto find all files in the given directory. - For each file, it checks the extension and calls the appropriate function (e.g.,
strip_metadata,read_metadata).
- Uses
- Purpose: Handles user input and directs traffic to other functions.
- Logic:
- Uses
argparsewithsubparsersto create distinct commands (read,write,strip,embed,extract). - Parses command-line arguments and passes them to the correct functions.
- Handles file vs. directory logic, sending directory paths to
process_directory.
- Uses
The script uses subcommands to perform different actions: read, write, strip, embed, and extract.
| Argument | Description |
|---|---|
file |
Path to the image file or directory to read metadata from. |
--save |
Save the metadata output to the specified text file. |
| Argument | Description |
|---|---|
file |
Path to the image file or directory to write metadata to. |
tag |
Metadata tag to modify (e.g., 'Comment', 'Artist'). |
value |
Value(s) to set for the specified tag. |
--save |
Save the operation log to the specified text file (directory mode). |
| Argument | Description |
|---|---|
file |
Path to the image file or directory to strip metadata from. |
| Argument | Description |
|---|---|
file |
Path to the input image file (e.g., .png, .bmp). |
message |
The message(s) to embed into the image. |
output_file |
Path to save the new image with the embedded message. |
--passphrase |
Optional passphrase to encrypt the hidden message. |
| Argument | Description |
|---|---|
file |
Path to the image file to extract the hidden message from. |
--passphrase |
Optional passphrase to decrypt the hidden message. |
Read metadata from a single file:
python PicMetaStegSec.py read example.jpgWrite a 'Comment' tag to a file:
python PicMetaStegSec.py write example.jpg Comment "This is a test image."Strip all metadata from all images in a directory:
python PicMetaStegSec.py strip ./my_images/Embed an encrypted message into a PNG file:
python PicMetaStegSec.py embed input.png "My secret message" output.png --passphrase "StrongPassword123"Extract an encrypted message:
python PicMetaStegSec.py extract output.png --passphrase "StrongPassword123"- Standard Output (stdout): By default, the script prints results (read metadata, success/error messages) directly to the console.
- Image Files: The
embedcommand creates a new image file. Thestripandwritecommands modify the image file in-place (ExifTool often creates a_originalbackup). - Text Files: Using the
--saveargument with thereadorwrite/strip(in directory mode) commands saves the output log to a specified.txtfile.
- Steganography (embedding/extracting) is only supported for lossless image formats like
.pngand.bmp. - Metadata functions (read, write, strip) work with any file type supported by ExifTool (e.g., JPEG, PNG, GIF, etc.).
- Providing an incorrect passphrase during extraction will result in an error or corrupted data.
Contributions are welcome! Feel free to submit issues or pull requests to improve the tool.