USB Logger is a C++ application designed to monitor USB device insertions on Windows systems. Upon detecting a new USB drive, the program logs the directory structure and identifies suspicious files (such as .exe
, .bat
, and .scr
files). The application runs in the background, ensuring minimal disruption while providing robust monitoring capabilities.
- Real-Time USB Monitoring: Detects when a USB drive is connected to the system.
- Directory Structure Logging: Recursively scans and logs the entire directory structure of the connected USB drive.
- Suspicious File Detection: Identifies and logs potentially malicious files based on their extensions.
- Threaded Operations: Performs scanning in separate threads to maintain application responsiveness.
- Timestamped Logging: All logs are timestamped for accurate tracking.
- Thread-Safe Logging: Ensures logs are written safely in multi-threaded environments.
- Configurable Extensions: Easily modify the list of file extensions considered suspicious.
- Error Handling: Comprehensive error messages and exception handling for robust performance.
- Operating System: Windows 10 or later
- Compiler: Microsoft Visual Studio 2019 or later (with C++ support)
- C++ Standard: C++17 or later
-
Clone the Repository
git clone https://github.com/texploder/usb-logger.git cd usb-logger
-
Open the Project
Open the
usb-logger
project in Visual Studio. -
Build the Project
- Select the desired build configuration (
Debug
orRelease
). - Build the solution by pressing
Ctrl + Shift + B
or navigating toBuild > Build Solution
.
- Select the desired build configuration (
-
Run the Application
- After a successful build, navigate to the output directory (e.g.,
bin/Release
). - Execute the
USBLogger.exe
file.
- After a successful build, navigate to the output directory (e.g.,
Once the application is running, it operates silently in the background. To test its functionality:
-
Insert a USB Drive:
- Plug a USB drive into your computer.
- The application will detect the insertion and begin scanning the drive.
-
Check Logs:
- Logs are saved in the
Structures
directory located in the same directory as the executable. - Each USB drive will have a unique log file named based on its volume name and serial number, e.g.,
MyUSB-1A2B3C4D.txt
.
- Logs are saved in the
-
Review Suspicious Files:
- Suspicious files are marked with
[SUSPICIOUS]
in the log file. - Additionally, these detections are printed to the console with timestamps.
- Suspicious files are marked with
[2025-01-27 10:15:30] USB Drive detected: E:\
[2025-01-27 10:15:31] Created log file: C:\Path\To\USBLogger\Structures\MyUSB-1A2B3C4D.txt
[2025-01-27 10:15:31] Folder structure saved to C:\Path\To\USBLogger\Structures\MyUSB-1A2B3C4D.txt
[Folder] Documents
[File] report.docx
[Folder] Executables
[File] setup.exe [SUSPICIOUS]
[File] installer.bat [SUSPICIOUS]
The application currently flags .exe
, .bat
, and .scr
files as suspicious. To modify this list:
-
Open the
main.cpp
file in your preferred code editor. -
Locate the
suspicious_extensions
vector:std::vector<std::string> suspicious_extensions = { ".exe", ".bat", ".scr" };
-
Add or remove extensions as needed:
std::vector<std::string> suspicious_extensions = { ".exe", ".bat", ".scr", ".dll" };
-
Rebuild the application to apply changes.
By default, logs are saved in a Structures
folder within the executable's directory. To change the log directory:
-
Open the
main.cpp
file. -
Locate the
check_usb_drive
function and modify thestructures_dir
path:std::string structures_dir = exe_dir + "\\YourDesiredDirectory";
-
Rebuild the application.
-
Logging Mechanism:
Handles thread-safe logging with timestamps.
std::mutex log_mutex; std::string current_timestamp() { // Generates current timestamp } void log_message(const std::string& message) { std::lock_guard<std::mutex> guard(log_mutex); std::cout << "[" << current_timestamp() << "] " << message << std::endl; }
-
USB Detection:
Utilizes Windows API to detect USB device insertions.
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WM_DEVICECHANGE && wParam == DBT_DEVICEARRIVAL) { // Handle USB arrival } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
-
Directory Scanning:
Recursively scans USB directories and logs structure and suspicious files.
void save_tree_and_check_files(const std::string& path, const std::string& output_file, std::vector<std::string> suspicious_extensions, int level = 0) { // Recursive directory scanning }
-
Multithreading:
Ensures scanning runs in separate threads to maintain responsiveness.
std::thread usb_thread(check_usb_drive, drive_path); usb_thread.detach();
This project is licensed under the MIT License. See the LICENSE file for details.
For any inquiries or support, please contact:
- Best Choice - DISCORD: Join Now
- Name: TEXploder
- Email: business@texploder.com
- GitHub: TEXploder
Disclaimer: This application is intended for monitoring USB devices for legitimate purposes. Ensure you have appropriate permissions to use this software, especially in environments with sensitive data.