stegdoc 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ReemX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # stegdoc
2
+
3
+ > Hide files inside Office documents with AES-256 encryption and steganography
4
+
5
+ [![npm version](https://img.shields.io/npm/v/stegdoc.svg)](https://www.npmjs.com/package/stegdoc)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ **stegdoc** is a CLI tool that encodes any file into legitimate-looking Office documents (Excel/Word). Your data is hidden within spreadsheets or documents that appear to contain normal server monitoring reports, while optionally being protected with military-grade AES-256-GCM encryption.
9
+
10
+ ## Features
11
+
12
+ - **Steganography** - Hide data in Excel spreadsheets (hidden sheets) or Word documents
13
+ - **AES-256-GCM Encryption** - Military-grade encryption with PBKDF2 key derivation (100k iterations)
14
+ - **Realistic Decoy Data** - Generated server metrics that make files look like IT monitoring reports
15
+ - **Multi-part Splitting** - Automatically split large files across multiple documents
16
+ - **Smart Compression** - Gzip compression for compressible files, skipped for images/video/archives
17
+ - **Integrity Verification** - SHA-256 hashing detects tampering
18
+ - **Folder Support** - Encode entire directories (automatically zipped)
19
+ - **Interactive Mode** - User-friendly prompts guide you through options
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install -g stegdoc
25
+ ```
26
+
27
+ Or run directly with npx:
28
+
29
+ ```bash
30
+ npx stegdoc encode myfile.pdf
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ```bash
36
+ # Encode a file with encryption (recommended)
37
+ stegdoc encode secret.pdf -p mypassword
38
+
39
+ # Decode it back
40
+ stegdoc decode server_metrics_20251215_1200_A1B2.xlsx -p mypassword
41
+
42
+ # View file info without decoding
43
+ stegdoc info server_metrics_20251215_1200_A1B2.xlsx
44
+
45
+ # Verify file integrity
46
+ stegdoc verify server_metrics_20251215_1200_A1B2.xlsx -p mypassword
47
+ ```
48
+
49
+ ## Commands
50
+
51
+ ### `encode` - Hide a file in an Office document
52
+
53
+ ```bash
54
+ stegdoc encode <file> [options]
55
+ ```
56
+
57
+ **Options:**
58
+ | Option | Description | Default |
59
+ |--------|-------------|---------|
60
+ | `-o, --output-dir <dir>` | Output directory | Current directory |
61
+ | `-s, --chunk-size <size>` | Split size: `5MB`, `25MB`, `3 parts`, `max`/`single`/`none` | `5MB` |
62
+ | `-f, --format <format>` | Output format: `xlsx` or `docx` | `xlsx` |
63
+ | `-p, --password <pass>` | Encryption password | None (unencrypted) |
64
+ | `--force` | Overwrite existing files | Prompt |
65
+ | `-q, --quiet` | Minimal output for scripting | Off |
66
+ | `-y, --yes` | Skip interactive prompts | Off |
67
+
68
+ **Examples:**
69
+
70
+ ```bash
71
+ # Basic encoding (will prompt for options)
72
+ stegdoc encode document.pdf
73
+
74
+ # Encode with password and Word format
75
+ stegdoc encode document.pdf -p mysecret -f docx
76
+
77
+ # Split into exactly 3 parts
78
+ stegdoc encode large-video.mp4 -p mysecret -s "3 parts"
79
+
80
+ # No splitting (single file output)
81
+ stegdoc encode archive.zip -p mysecret -s max
82
+
83
+ # Encode a folder
84
+ stegdoc encode ./my-folder -p mysecret
85
+ ```
86
+
87
+ ### `decode` - Recover the original file
88
+
89
+ ```bash
90
+ stegdoc decode <file> [options]
91
+ ```
92
+
93
+ **Options:**
94
+ | Option | Description | Default |
95
+ |--------|-------------|---------|
96
+ | `-o, --output <path>` | Output file path | Original filename |
97
+ | `-p, --password <pass>` | Decryption password | Prompt if needed |
98
+ | `--force` | Overwrite existing files | Prompt |
99
+ | `-q, --quiet` | Minimal output | Off |
100
+ | `-y, --yes` | Skip prompts, fail if password needed | Off |
101
+
102
+ **Examples:**
103
+
104
+ ```bash
105
+ # Decode with password
106
+ stegdoc decode server_metrics_20251215_1200_A1B2.xlsx -p mysecret
107
+
108
+ # Decode to specific location
109
+ stegdoc decode report.xlsx -p mysecret -o ./recovered/original.pdf
110
+
111
+ # Multi-part files are auto-detected
112
+ stegdoc decode server_metrics_20251215_1200_A1B2_part1.xlsx -p mysecret
113
+ ```
114
+
115
+ ### `info` - View metadata without decoding
116
+
117
+ ```bash
118
+ stegdoc info <file>
119
+ ```
120
+
121
+ Displays:
122
+ - Original filename and size
123
+ - Encryption status
124
+ - Compression status
125
+ - Part information (for split files)
126
+ - Content hash for verification
127
+
128
+ ### `verify` - Validate file integrity
129
+
130
+ ```bash
131
+ stegdoc verify <file> [options]
132
+ ```
133
+
134
+ **Options:**
135
+ | Option | Description |
136
+ |--------|-------------|
137
+ | `-p, --password <pass>` | Verify password is correct |
138
+
139
+ Checks:
140
+ - Metadata integrity
141
+ - All parts present (for multi-part files)
142
+ - Password validity (if provided)
143
+
144
+ ## How It Works
145
+
146
+ ### Encoding Pipeline
147
+
148
+ ```
149
+ Input File
150
+
151
+ [Compression] → gzip (if beneficial)
152
+
153
+ [Base64 Encoding]
154
+
155
+ [Encryption] → AES-256-GCM (optional)
156
+
157
+ [Office Wrapper] → XLSX or DOCX
158
+
159
+ [Decoy Layer] → Server metrics data
160
+
161
+ Output File(s)
162
+ ```
163
+
164
+ ### File Storage
165
+
166
+ **XLSX Format:**
167
+ - Sheet 1 ("Server Metrics"): Visible decoy data - looks like IT monitoring reports
168
+ - Sheet 2 ("Data"): Hidden sheet containing your encrypted payload
169
+
170
+ **DOCX Format:**
171
+ - Embedded text with metadata and payload
172
+ - Appears as a system report document
173
+
174
+ ### Encryption Details
175
+
176
+ - **Algorithm**: AES-256-GCM (Galois/Counter Mode)
177
+ - **Key Derivation**: PBKDF2-SHA256 with 100,000 iterations
178
+ - **Key Size**: 256 bits
179
+ - **IV**: 96 bits (randomly generated)
180
+ - **Salt**: 128 bits (randomly generated)
181
+ - **Authentication**: 128-bit auth tag (GCM provides authenticated encryption)
182
+
183
+ ### Filename Generation
184
+
185
+ Output files use deterministic, realistic filenames:
186
+ ```
187
+ server_metrics_YYYYMMDD_HH00_XXXX.xlsx
188
+ system_report_YYYYMMDD_HH00_XXXX.docx
189
+ ```
190
+
191
+ The date/time and ID are derived from a hash, ensuring files from the same encoding session are related.
192
+
193
+ ## Use Cases
194
+
195
+ - **Secure file transfer** - Send encrypted files that look like mundane reports
196
+ - **Backup storage** - Store sensitive data in plain sight
197
+ - **Privacy** - Keep personal files private on shared systems
198
+ - **Data portability** - Office documents work everywhere
199
+
200
+ ## Backward Compatibility
201
+
202
+ Files created with previous versions (whitener) are fully supported. The tool automatically detects and handles legacy formats.
203
+
204
+ ## Requirements
205
+
206
+ - Node.js 18.0.0 or higher
207
+
208
+ ## License
209
+
210
+ MIT License - see [LICENSE](LICENSE) for details.
211
+
212
+ ## Contributing
213
+
214
+ Contributions are welcome! Please feel free to submit a Pull Request.
package/bootstrap.js ADDED
@@ -0,0 +1,33 @@
1
+ // bootstrap.js - Decode whitener DOCX
2
+ const fs = require('fs');
3
+ const JSZip = require('jszip');
4
+
5
+ const docxPath = process.argv[2];
6
+ if (!docxPath) {
7
+ console.log('Usage: node bootstrap.js <file.docx>');
8
+ process.exit(1);
9
+ }
10
+
11
+ JSZip.loadAsync(fs.readFileSync(docxPath)).then(zip => {
12
+ return zip.file('word/document.xml').async('string');
13
+ }).then(xml => {
14
+ const matches = xml.match(/<w:t[^>]*>([^<]*)<\/w:t>/g) || [];
15
+ let text = '';
16
+ matches.forEach(m => {
17
+ let t = m.replace(/<w:t[^>]*>/, '').replace(/<\/w:t>/, '')
18
+ .replace(/&quot;/g, '"').replace(/&apos;/g, "'")
19
+ .replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
20
+ text += t;
21
+ });
22
+
23
+ const metaIdx = text.indexOf('WHITENER_METADATA:');
24
+ const sepIdx = text.indexOf('---', metaIdx);
25
+ const meta = JSON.parse(text.substring(metaIdx + 18, sepIdx).trim());
26
+ const base64 = text.substring(sepIdx + 3).trim();
27
+
28
+ fs.writeFileSync(meta.originalFilename, Buffer.from(base64, 'base64'));
29
+ console.log(`Decoded: ${meta.originalFilename}`);
30
+ }).catch(err => {
31
+ console.error('Error:', err.message);
32
+ process.exit(1);
33
+ });
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "stegdoc",
3
+ "version": "1.0.0",
4
+ "description": "Hide files inside Office documents (XLSX/DOCX) with AES-256 encryption and steganography",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "stegdoc": "src/index.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node src/index.js",
11
+ "dev": "node src/index.js",
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "keywords": [
15
+ "cli",
16
+ "steganography",
17
+ "encryption",
18
+ "aes-256",
19
+ "xlsx",
20
+ "docx",
21
+ "hide",
22
+ "encode",
23
+ "decode",
24
+ "covert",
25
+ "office",
26
+ "spreadsheet",
27
+ "security"
28
+ ],
29
+ "author": "ReemX",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/ReemX/stegdoc.git"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/ReemX/stegdoc/issues"
37
+ },
38
+ "homepage": "https://github.com/ReemX/stegdoc#readme",
39
+ "engines": {
40
+ "node": ">=18.0.0"
41
+ },
42
+ "files": [
43
+ "src",
44
+ "bootstrap.js",
45
+ "LICENSE",
46
+ "README.md"
47
+ ],
48
+ "packageManager": "pnpm@10.19.0",
49
+ "dependencies": {
50
+ "adm-zip": "^0.5.16",
51
+ "chalk": "4.1.2",
52
+ "commander": "^14.0.2",
53
+ "docx": "^9.5.1",
54
+ "exceljs": "^4.4.0",
55
+ "fast-xml-parser": "^5.3.2",
56
+ "file-type": "^21.1.1",
57
+ "inquirer": "^13.0.1",
58
+ "ora": "5.4.1"
59
+ }
60
+ }
@@ -0,0 +1,201 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const chalk = require('chalk');
4
+ const ora = require('ora');
5
+ const { readDocxBase64 } = require('../lib/docx-handler');
6
+ const { readXlsxBase64 } = require('../lib/xlsx-handler');
7
+ const { validateMetadata, isMultiPart } = require('../lib/metadata');
8
+ const { detectFormat, formatBytes, generateContentHash } = require('../lib/utils');
9
+ const { decrypt, unpackEncryptionMeta } = require('../lib/crypto');
10
+ const { decompress } = require('../lib/compression');
11
+ const { promptPassword, promptOverwrite } = require('../lib/interactive');
12
+ const { extractContent, findMultiPartFiles, mergeBase64Chunks } = require('../lib/file-utils');
13
+
14
+ /**
15
+ * Read file based on format
16
+ * @param {string} filePath - Path to file
17
+ * @param {string} format - File format
18
+ * @returns {Promise<object>} Read result
19
+ */
20
+ async function readFile(filePath, format) {
21
+ if (format === 'xlsx') {
22
+ return await readXlsxBase64(filePath);
23
+ } else {
24
+ return await readDocxBase64(filePath);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Decode a DOCX/XLSX file back to original format
30
+ * @param {string} inputFile - Path to input file
31
+ * @param {object} options - Command options
32
+ * @param {string} options.output - Output file path
33
+ * @param {string} options.password - Decryption password
34
+ * @param {boolean} options.force - Overwrite existing files without asking
35
+ * @param {boolean} options.quiet - Minimal output
36
+ */
37
+ async function decodeCommand(inputFile, options) {
38
+ const quiet = options.quiet || false;
39
+ const spinner = quiet ? { start: () => {}, succeed: () => {}, fail: () => {}, info: () => {}, warn: () => {}, text: '' } : ora('Starting decoding process...').start();
40
+
41
+ try {
42
+ // Detect format from extension
43
+ const format = detectFormat(inputFile);
44
+ if (!format) {
45
+ throw new Error('Unknown file format. Supported formats: .xlsx, .docx');
46
+ }
47
+
48
+ spinner.text = `Reading ${format.toUpperCase()} file...`;
49
+
50
+ // Read the first file
51
+ const readResult = await readFile(inputFile, format);
52
+ const { encryptedContent, encryptionMeta, metadata } = extractContent(readResult, format);
53
+
54
+ // Validate metadata
55
+ validateMetadata(metadata);
56
+
57
+ const isEncrypted = metadata.encrypted || (encryptionMeta && encryptionMeta.length > 0);
58
+ const isCompressed = metadata.compressed || false;
59
+
60
+ spinner.succeed && spinner.succeed(`${format.toUpperCase()} file read successfully`);
61
+
62
+ if (!quiet) {
63
+ console.log(chalk.cyan(` Original file: ${metadata.originalFilename}`));
64
+ console.log(chalk.cyan(` Original size: ${formatBytes(metadata.originalSize)}`));
65
+ console.log(chalk.cyan(` Encrypted: ${isEncrypted ? 'Yes' : 'No'}`));
66
+ console.log(chalk.cyan(` Compressed: ${isCompressed ? 'Yes' : 'No'}`));
67
+ }
68
+
69
+ // Check password for encrypted files - prompt if not provided and not in quiet mode
70
+ if (isEncrypted && !options.password) {
71
+ if (quiet || options.yes) {
72
+ throw new Error('Password is required for encrypted files. Use -p or --password to specify.');
73
+ }
74
+ // Prompt for password interactively
75
+ options.password = await promptPassword();
76
+ }
77
+
78
+ // Determine output path and check overwrite
79
+ const outputPath = options.output || path.join(process.cwd(), metadata.originalFilename);
80
+
81
+ if (fs.existsSync(outputPath) && !options.force) {
82
+ if (quiet || options.yes) {
83
+ throw new Error(`File already exists: ${outputPath}. Use --force to overwrite.`);
84
+ }
85
+ // Prompt for overwrite confirmation
86
+ const shouldOverwrite = await promptOverwrite(outputPath);
87
+ if (!shouldOverwrite) {
88
+ console.log(chalk.yellow('Operation cancelled.'));
89
+ process.exit(0);
90
+ }
91
+ }
92
+
93
+ // Check if multi-part
94
+ let finalBase64;
95
+
96
+ if (isMultiPart(metadata)) {
97
+ spinner.start && (spinner.text = `Multi-part file detected (${metadata.totalParts} parts)`);
98
+
99
+ // Find all parts
100
+ const inputDir = path.dirname(inputFile);
101
+ const allParts = findMultiPartFiles(inputDir, metadata.hash, format, metadata.totalParts);
102
+
103
+ if (allParts.length !== metadata.totalParts) {
104
+ throw new Error(
105
+ `Missing parts! Found ${allParts.length} of ${metadata.totalParts} parts. ` +
106
+ `Make sure all parts are in the same directory.`
107
+ );
108
+ }
109
+
110
+ spinner.succeed && spinner.succeed(`Found all ${metadata.totalParts} parts`);
111
+
112
+ // Read all parts
113
+ const chunks = [];
114
+
115
+ for (let i = 0; i < allParts.length; i++) {
116
+ const partSpinner = quiet ? spinner : ora(`Reading part ${i + 1} of ${metadata.totalParts}...`).start();
117
+ const partResult = await readFile(allParts[i].path, format);
118
+ const { encryptedContent: partContent } = extractContent(partResult, format);
119
+ chunks.push(partContent);
120
+ partSpinner.succeed && partSpinner.succeed(`Part ${i + 1} read`);
121
+ }
122
+
123
+ // Merge chunks
124
+ spinner.text = 'Merging parts...';
125
+ const mergedContent = mergeBase64Chunks(chunks);
126
+ spinner.succeed && spinner.succeed('Parts merged successfully');
127
+
128
+ // Decrypt if needed
129
+ if (isEncrypted) {
130
+ spinner.text = 'Decrypting content...';
131
+ const { iv, salt, authTag } = unpackEncryptionMeta(encryptionMeta);
132
+ finalBase64 = decrypt(mergedContent, options.password, iv, salt, authTag);
133
+ spinner.succeed && spinner.succeed('Content decrypted');
134
+ } else {
135
+ finalBase64 = mergedContent;
136
+ }
137
+ } else {
138
+ // Single file - Decrypt if needed
139
+ if (isEncrypted) {
140
+ spinner.text = 'Decrypting content...';
141
+ const { iv, salt, authTag } = unpackEncryptionMeta(encryptionMeta);
142
+ finalBase64 = decrypt(encryptedContent, options.password, iv, salt, authTag);
143
+ spinner.succeed && spinner.succeed('Content decrypted');
144
+ } else {
145
+ finalBase64 = encryptedContent;
146
+ }
147
+ }
148
+
149
+ // Decompress if needed
150
+ let fileBuffer;
151
+ if (isCompressed) {
152
+ spinner.text = 'Decompressing...';
153
+ const compressedBuffer = Buffer.from(finalBase64, 'base64');
154
+ fileBuffer = await decompress(compressedBuffer);
155
+ spinner.succeed && spinner.succeed(`Decompressed: ${formatBytes(compressedBuffer.length)} → ${formatBytes(fileBuffer.length)}`);
156
+ } else {
157
+ fileBuffer = Buffer.from(finalBase64, 'base64');
158
+ }
159
+
160
+ // Verify integrity if content hash is available
161
+ if (metadata.contentHash) {
162
+ spinner.text = 'Verifying integrity...';
163
+ const actualHash = generateContentHash(fileBuffer);
164
+
165
+ if (actualHash !== metadata.contentHash) {
166
+ throw new Error('Integrity check failed! The file may be corrupted or tampered with.');
167
+ }
168
+ spinner.succeed && spinner.succeed('Integrity verified (SHA-256 match)');
169
+ }
170
+
171
+ // Write to file
172
+ spinner.text = 'Writing output file...';
173
+
174
+ // Ensure output directory exists
175
+ const outputDir = path.dirname(outputPath);
176
+ if (!fs.existsSync(outputDir)) {
177
+ fs.mkdirSync(outputDir, { recursive: true });
178
+ }
179
+
180
+ fs.writeFileSync(outputPath, fileBuffer);
181
+
182
+ spinner.succeed && spinner.succeed('Decoding complete!');
183
+
184
+ if (!quiet) {
185
+ console.log();
186
+ console.log(chalk.green.bold('✓ File decoded successfully!'));
187
+ console.log(chalk.cyan(` Original: ${metadata.originalFilename}`));
188
+ console.log(chalk.cyan(` Output: ${outputPath}`));
189
+ console.log(chalk.cyan(` Size: ${formatBytes(fileBuffer.length)}`));
190
+ if (isMultiPart(metadata)) {
191
+ console.log(chalk.cyan(` Parts merged: ${metadata.totalParts}`));
192
+ }
193
+ }
194
+ } catch (error) {
195
+ spinner.fail && spinner.fail('Decoding failed');
196
+ console.error(chalk.red(`Error: ${error.message}`));
197
+ process.exit(1);
198
+ }
199
+ }
200
+
201
+ module.exports = decodeCommand;