Securing Files via Lockdown: A Guide to Using GhostLock for Windows API File Blocking

By

Introduction

GhostLock is a proof-of-concept tool that demonstrates how a legitimate Windows file API can be used to prevent any process from opening a file, whether stored locally or on an SMB network share. This guide will walk you through using GhostLock to lock files, effectively blocking all read and write access until the lock is released. Intended for security researchers and IT professionals, this tool is for testing and educational purposes only. Misuse can disrupt system operations—always test in a controlled environment.

Securing Files via Lockdown: A Guide to Using GhostLock for Windows API File Blocking
Source: www.bleepingcomputer.com

What You Need

Step-by-Step Instructions

  1. Step 1: Download GhostLock – Visit the official GhostLock repository (e.g., on GitHub) and download the source code as a ZIP archive, or clone it using git clone <repository-url>. Extract the files if needed.
  2. Step 2: Compile the Tool – Open a Developer Command Prompt for Visual Studio (or use MinGW). Navigate to the extracted folder and run cl /nologo /O2 /W4 ghostlock.c (for Visual Studio) or gcc -o ghostlock.exe ghostlock.c -ladvapi32 (for MinGW). Ensure the build succeeds—you should now have ghostlock.exe in the same directory.
  3. Step 3: Verify Requirements – Right-click your Command Prompt shortcut and select Run as administrator if not already elevated. Check that the target file exists and that you have read permissions on it. For SMB shares, ensure network credentials are available.
  4. Step 4: Lock a File – Execute the following syntax: ghostlock.exe <path-to-file> (e.g., ghostlock.exe C:\test\secret.docx). If the file is on an SMB share, use its UNC path: ghostlock.exe \\server\share\file.txt. The tool will attempt to open the file with zero sharing mode (dwShareMode = 0), preventing any other handle from accessing it.
  5. Step 5: Confirm the Lock – While GhostLock is running, try to open the locked file with another program (e.g., Notepad, Word, or a file manager). You should receive an error like “The process cannot access the file because it is being used by another process.” This confirms the lock is active.
  6. Step 6: Release the Lock – To unlock the file, you must terminate the GhostLock process. Press Ctrl+C in the command window where GhostLock is running, or use Task Manager to end the ghostlock.exe process. After termination, the file will be accessible again.

Tips for Safe and Effective Use

Tags:

Related Articles

Recommended

Discover More

How to Test and Explore Python 3.15.0 Alpha 5: A Developer's GuideSolar Radio Bursts Expose Hidden Magnetic Folds, Parker Probe Data RevealsHow to Give Your Agentic Applications Persistent Memory with CopilotKit's Enterprise Intelligence PlatformCritical Linux Security Patches Released Across Major Distributions – Urgent Update RequiredBuilding VR Apps for Meta Quest: A Step-by-Step Guide with React Native