3 January 2024 | by Xavier Bellekens
Among the intricate chess game of cybersecurity, canary and seed files have long been touted as silent sentinels, guarding the most sensitive data corridors against unauthorized access. These files are meant to act as traps for intruders, silently alerting me to their presence. But how effective are they in the grand scheme of security?
In this blog post, I will unveil the limitations and potential failures of relying only on canary and seed files for security.
I will also provide a script for red teams to detect canary files without triggering an alert.
Canary and seed files are often introduced as clever ploys, set as traps for the unsuspecting intruder. At their core, these files are simple yet seemingly valuable data or system elements that are strategically placed to appear enticing or crucial. They are monitored closely, and any interaction with these files is considered a red flag, signalling a potential security breach.
What Are Canary and Seed Files?
Canary files are typically dummy files or tokens placed within a system’s critical areas. They might mimic the appearance of sensitive data, system configurations, or credentials. The term ‘canary’ harks back to an older practice in coal mining, where canaries were used as early warning systems for toxic gases. Similarly, in cybersecurity, seed files serve as early indicators of unauthorized access or data breaches.
How Do They Work?
The principle behind canary and seed files is straightforward: place a file that looks important where an attacker is likely to stumble upon it during their unauthorized exploration of a network. These files are silently monitored by security systems. When an attacker interacts with the file — be it opening — an alert is triggered. Theoretically, this allows security teams to detect and respond to the breach promptly.
While canary and seed files are crafted with the intention of acting as early warning systems in the cybersecurity landscape, they come with a set of inherent weaknesses that can significantly diminish their effectiveness. These limitations not only affect the reliability of such measures but also raise questions about their viability as standalone security solutions.
Resource and Maintenance Overhead
Implementing and maintaining canary and seed files require continuous effort and resources. Each file must be convincingly disguised, properly placed, and meticulously monitored. As the network environment changes, these files may need updates or repositioning to remain effective, adding to the administrative burden. For organizations with limited cybersecurity resources, the cost of maintaining these files can outweigh the benefits, especially when considering the availability of more dynamic and less resource-intensive alternatives.
Risk of Desensitization
The effectiveness of canary and seed files is predicated on the assumption that any interaction with them is suspicious. However, false positives can occur — legitimate users might mistakenly access these files, or routine network operations might trigger alerts. Over time, frequent false positives can lead to alert fatigue, where security teams become desensitized to warnings, potentially overlooking genuine threats. This desensitization undermines the very purpose of these files, turning them into a source of noise rather than a reliable signal.
Subscribed
As part of a comprehensive cybersecurity strategy, red teams — need effective tools for detecting potential canary and seed files.
Below is a Python script aimed at scanning for, and identifying suspected canary and seed files (specifically docx, pptx, and xlsx files) quietly and efficiently.
Purpose of the Script: This script is designed to help red teams detect the presence of canary and seed files within the environments being tested. By scanning file systems for these files discreetly, the script aims at avoiding canaries and seed files.
import os
import zipfile
import re
import shutil
import time
PATH_TO_CHECK = '/Users/XXXXX/Downloads/file.xlsx'
RED = '\033[91m'
RESET = '\033[0m'
def decompress_and_scan(file_path):
suspicious = False # Flag to track if suspicious URLs are found
temp_dir = "temp_extracted"
os.makedirs(temp_dir, exist_ok=True)
original_path = file_path # Store the original file path
new_path = file_path + ".zip" # Define the new file path
try:
if os.path.exists(file_path):
os.rename(file_path, new_path)
with zipfile.ZipFile(new_path, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
url_pattern = re.compile(r'https?://\S+')
ignored_domains = ['schemas.openxmlformats.org', 'schemas.microsoft.com', 'purl.org','w3.org']
for root, dirs, files in os.walk(temp_dir):
for file in files:
file_path = os.path.join(root, file)
with open(file_path, 'r', errors='ignore') as file:
contents = file.read()
urls = url_pattern.findall(contents)
for url in urls:
if not any(domain in url for domain in ignored_domains):
print(f"URL Found: {url}")
suspicious = True # Mark as suspicious if a non-ignored URL is found
except Exception as e:
print(f"Error processing file {original_path}: {e}")
finally:
shutil.rmtree(temp_dir)
try:
if os.path.exists(new_path):
os.rename(new_path, original_path)
except Exception as e:
print(f"Error cleaning up: {e}")
return suspicious
def is_suspicious(file_path):
if file_path.endswith(('.docx', '.xlsx', '.pptx')):
return decompress_and_scan(file_path)
return False
def main():
if os.path.isfile(PATH_TO_CHECK):
if is_suspicious(PATH_TO_CHECK):
print(RED + f"The file {PATH_TO_CHECK} is suspicious." + RESET)
else:
print(f"The file {PATH_TO_CHECK} seems normal.")
elif os.path.isdir(PATH_TO_CHECK):
for root, dirs, files in os.walk(PATH_TO_CHECK):
for name in files:
file_path = os.path.join(root, name)
if is_suspicious(file_path):
print(RED + f"The file {file_path} is suspicious." + RESET)
else:
print(f"The file {file_path} seems normal.")
if __name__ == "__main__":
main()
The script operates in several steps:
Using the Script:
To use the script, you need a basic Python environment and some understanding of file paths and regular expressions. Here’s how you can deploy and utilize this script:
Seed and Canary files have inherent limitations and, often, fall short against the sophisticated and continuously evolving strategies of today’s attackers.
Instead, embracing fully-fledged decoys as a means of deception provides a far more robust and effective solution for misleading and trapping adversaries and are much harder to detect.
Furthermore, the script provided, while focused on Microsoft Office documents (docx, pptx, xlsx), represents just the tip of the iceberg in terms of what’s possible of detecting. Similar silent detection strategies can be applied to a wide range of file types and assets, including PDFs, AWS credentials, SVG images, HTML files, and much more.
In conclusion, by moving beyond the limited scope of traditional canary and seed files and embracing a more nuanced and sophisticated approach to deception, organizations can significantly enhance their ability to deceive red teams, adversaries, and ultimately protect their critical assets from the ever-present threats in the digital world.
Link to the code
Come and have a chat with us, if you want to try our deception as a service solution.
3 January 2024 | by Xavier Bellekens