-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_linux_simple.py
More file actions
535 lines (436 loc) · 15.7 KB
/
create_linux_simple.py
File metadata and controls
535 lines (436 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
#!/usr/bin/env python3
# Simplified Linux Package Creator for Windows Development Environment
# Creates package structure and installation scripts
import os
import sys
import shutil
from pathlib import Path
def create_deb_structure():
"""Create Debian package structure that can be built on Linux"""
print("📦 Creating Debian Package Structure...")
project_root = Path(__file__).parent
# Check required files
main_py = project_root / "main.py"
src_dir = project_root / "src"
config_dir = project_root / "config"
if not all([main_py.exists(), src_dir.exists(), config_dir.exists()]):
print("❌ Required files not found:")
print(f" main.py: {'✓' if main_py.exists() else '❌'}")
print(f" src/: {'✓' if src_dir.exists() else '❌'}")
print(f" config/: {'✓' if config_dir.exists() else '❌'}")
return False
# Package info
package_name = "abscanner"
version = "1.0.0"
architecture = "all"
# Create package directory structure
pkg_dir = project_root / "debian_package"
if pkg_dir.exists():
shutil.rmtree(pkg_dir)
# Create directory structure
deb_dir = pkg_dir / "DEBIAN"
app_dir = pkg_dir / "opt" / "abscanner"
bin_dir = pkg_dir / "usr" / "local" / "bin"
doc_dir = pkg_dir / "usr" / "share" / "doc" / "abscanner"
for directory in [deb_dir, app_dir, bin_dir, doc_dir]:
directory.mkdir(parents=True)
print("📁 Created directory structure")
# Copy application files
shutil.copy2(main_py, app_dir / "main.py")
shutil.copytree(src_dir, app_dir / "src")
shutil.copytree(config_dir, app_dir / "config")
# Copy documentation
readme_file = project_root / "README.md"
if readme_file.exists():
shutil.copy2(readme_file, doc_dir / "README.md")
print("📋 Copied application files")
# Create control file
control_content = f"""Package: {package_name}
Version: {version}
Architecture: {architecture}
Maintainer: CyberSinister <contact@cybersinister.com>
Depends: python3 (>= 3.6), python3-pip
Section: utils
Priority: optional
Homepage: https://github.com/CyberSinister/ABScanner
Description: Advanced Sensitive Data Scanner
ABScanner is a powerful tool for detecting sensitive data in files and directories.
It can identify credentials, API keys, passwords, credit card numbers, and other
sensitive information using advanced pattern matching and false positive filtering.
.
Features:
* Multi-threaded scanning for performance
* Comprehensive pattern detection
* False positive filtering
* Multiple output formats
* Recursive directory scanning
* Configurable patterns and exclusions
Installed-Size: 150
"""
with open(deb_dir / "control", 'w', encoding='utf-8') as f:
f.write(control_content)
# Create launcher script
launcher_content = """#!/bin/bash
# ABScanner Launcher Script
SCRIPT_DIR="/opt/abscanner"
cd "$SCRIPT_DIR"
if command -v python3 &> /dev/null; then
python3 main.py "$@"
elif command -v python &> /dev/null; then
python main.py "$@"
else
echo "Error: Python 3 is required but not installed."
echo "Please install Python 3: sudo apt install python3"
exit 1
fi
"""
launcher_path = bin_dir / "abscanner"
with open(launcher_path, 'w', encoding='utf-8') as f:
f.write(launcher_content)
# Create postinst script
postinst_content = """#!/bin/bash
set -e
echo "Installing ABScanner dependencies..."
if command -v pip3 &> /dev/null; then
pip3 install --break-system-packages colorama lxml openpyxl python-docx python-pptx PyPDF2 xlsxwriter pillow 2>/dev/null || \\
pip3 install colorama lxml openpyxl python-docx python-pptx PyPDF2 xlsxwriter pillow
elif command -v pip &> /dev/null; then
pip install colorama lxml openpyxl python-docx python-pptx PyPDF2 xlsxwriter pillow
fi
echo "ABScanner installation completed!"
echo "Usage: abscanner [directory_to_scan]"
echo "Help: abscanner --help"
exit 0
"""
with open(deb_dir / "postinst", 'w', encoding='utf-8') as f:
f.write(postinst_content)
# Create prerm script
prerm_content = """#!/bin/bash
set -e
echo "Removing ABScanner..."
exit 0
"""
with open(deb_dir / "prerm", 'w', encoding='utf-8') as f:
f.write(prerm_content)
# Create copyright file
copyright_content = """Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ABScanner
Source: https://github.com/CyberSinister/ABScanner
Files: *
Copyright: 2025 CyberSinister
License: MIT
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
with open(doc_dir / "copyright", 'w', encoding='utf-8') as f:
f.write(copyright_content)
print("📄 Created package files")
# Create build script
build_script = f"""#!/bin/bash
# ABScanner Debian Package Builder
# Run this script on a Debian/Ubuntu system to create the .deb package
set -e
echo "Building ABScanner Debian package..."
# Make scripts executable
chmod +x debian_package/usr/local/bin/abscanner
chmod +x debian_package/DEBIAN/postinst
chmod +x debian_package/DEBIAN/prerm
# Build the package
dpkg-deb --build debian_package {package_name}_{version}_{architecture}.deb
if [ -f "{package_name}_{version}_{architecture}.deb" ]; then
echo "✅ Package created successfully!"
echo "📦 File: {package_name}_{version}_{architecture}.deb"
echo ""
echo "📋 Installation:"
echo " sudo dpkg -i {package_name}_{version}_{architecture}.deb"
echo " sudo apt-get install -f # Fix any dependency issues"
echo ""
echo "🎯 Usage:"
echo " abscanner /path/to/scan"
echo " abscanner --help"
echo ""
echo "🗑️ Uninstall:"
echo " sudo apt remove {package_name}"
else
echo "❌ Package build failed"
exit 1
fi
"""
build_script_path = project_root / "build_deb.sh"
with open(build_script_path, 'w', encoding='utf-8') as f:
f.write(build_script)
print(f"✅ Debian package structure created!")
print(f"📁 Package directory: {pkg_dir}")
print(f"🔨 Build script: {build_script_path}")
print(f"\n📋 To build on Linux:")
print(f" chmod +x build_deb.sh")
print(f" ./build_deb.sh")
return str(pkg_dir)
def create_simple_installer():
"""Create simple installer script"""
print("🔧 Creating Simple Linux Installer...")
project_root = Path(__file__).parent
install_script = """#!/bin/bash
# ABScanner Simple Linux Installer
set -e
echo "========================================"
echo " ABScanner Installation Script"
echo "========================================"
echo ""
# Check if running as root
if [[ $EUID -eq 0 ]]; then
INSTALL_DIR="/opt/abscanner"
BIN_DIR="/usr/local/bin"
echo "Installing system-wide..."
else
INSTALL_DIR="$HOME/.local/opt/abscanner"
BIN_DIR="$HOME/.local/bin"
echo "Installing for current user..."
# Create local bin directory
mkdir -p "$BIN_DIR"
# Add to PATH if needed
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
echo "Added $HOME/.local/bin to PATH in ~/.bashrc"
echo "Please run: source ~/.bashrc"
fi
fi
echo "Installation directory: $INSTALL_DIR"
echo "Binary directory: $BIN_DIR"
echo ""
# Check Python 3
if ! command -v python3 &> /dev/null; then
echo "Error: Python 3 is required but not installed."
echo "Please install Python 3:"
echo " Ubuntu/Debian: sudo apt install python3 python3-pip"
echo " CentOS/RHEL: sudo yum install python3 python3-pip"
echo " Fedora: sudo dnf install python3 python3-pip"
exit 1
fi
echo "Python 3 found: $(python3 --version)"
# Create installation directory
echo "Creating installation directory..."
mkdir -p "$INSTALL_DIR"
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Copy files
echo "Copying ABScanner files..."
cp "$SCRIPT_DIR/main.py" "$INSTALL_DIR/"
cp -r "$SCRIPT_DIR/src" "$INSTALL_DIR/"
cp -r "$SCRIPT_DIR/config" "$INSTALL_DIR/"
if [ -f "$SCRIPT_DIR/README.md" ]; then
cp "$SCRIPT_DIR/README.md" "$INSTALL_DIR/"
fi
# Install dependencies
echo "Installing Python dependencies..."
pip3 install --user colorama lxml openpyxl python-docx python-pptx PyPDF2 xlsxwriter pillow || {
echo "Warning: Some dependencies may not have installed correctly."
}
# Create launcher
echo "Creating launcher script..."
cat > "$BIN_DIR/abscanner" << 'EOF'
#!/bin/bash
# Find installation directory
if [ -d "/opt/abscanner" ]; then
ABSCANNER_DIR="/opt/abscanner"
elif [ -d "$HOME/.local/opt/abscanner" ]; then
ABSCANNER_DIR="$HOME/.local/opt/abscanner"
else
echo "Error: ABScanner installation not found"
exit 1
fi
cd "$ABSCANNER_DIR"
if command -v python3 &> /dev/null; then
python3 main.py "$@"
elif command -v python &> /dev/null; then
python main.py "$@"
else
echo "Error: Python 3 is required"
exit 1
fi
EOF
chmod +x "$BIN_DIR/abscanner"
# Create uninstaller
cat > "$INSTALL_DIR/uninstall.sh" << EOF
#!/bin/bash
echo "Removing ABScanner..."
rm -rf "$INSTALL_DIR"
rm -f "$BIN_DIR/abscanner"
echo "ABScanner has been removed."
EOF
chmod +x "$INSTALL_DIR/uninstall.sh"
echo ""
echo "========================================"
echo " Installation Complete!"
echo "========================================"
echo ""
echo "ABScanner installed to: $INSTALL_DIR"
echo ""
echo "Usage:"
echo " abscanner /path/to/scan"
echo " abscanner --help"
echo ""
echo "Examples:"
echo " abscanner /home/user/documents"
echo " abscanner /var/log --output scan_results.txt"
echo ""
echo "Uninstall:"
echo " $INSTALL_DIR/uninstall.sh"
echo ""
# Test installation
if command -v abscanner &> /dev/null; then
echo "Installation successful! 'abscanner' command is available."
else
echo "Installation completed but 'abscanner' not in PATH."
echo "You may need to restart your terminal or run: source ~/.bashrc"
fi
"""
installer_path = project_root / "install_linux.sh"
with open(installer_path, 'w', encoding='utf-8') as f:
f.write(install_script)
print(f"✅ Simple installer created: {installer_path}")
print(f"📋 Usage:")
print(f" chmod +x install_linux.sh")
print(f" ./install_linux.sh # User install")
print(f" sudo ./install_linux.sh # System install")
return str(installer_path)
def create_rpm_spec():
"""Create RPM spec file"""
print("🔴 Creating RPM Spec File...")
project_root = Path(__file__).parent
spec_content = """Name: abscanner
Version: 1.0.0
Release: 1%{?dist}
Summary: Advanced Sensitive Data Scanner
License: MIT
URL: https://github.com/CyberSinister/ABScanner
BuildArch: noarch
Requires: python3 >= 3.6
Requires: python3-pip
%description
ABScanner is a powerful tool for detecting sensitive data in files and directories.
It can identify credentials, API keys, passwords, credit card numbers, and other
sensitive information using advanced pattern matching and false positive filtering.
%prep
# No preparation needed
%build
# No building needed
%install
rm -rf $RPM_BUILD_ROOT
# Create directories
mkdir -p $RPM_BUILD_ROOT/opt/abscanner
mkdir -p $RPM_BUILD_ROOT/usr/local/bin
mkdir -p $RPM_BUILD_ROOT/usr/share/doc/abscanner
# Copy application files (assumes source files are in current directory)
cp main.py $RPM_BUILD_ROOT/opt/abscanner/
cp -r src $RPM_BUILD_ROOT/opt/abscanner/
cp -r config $RPM_BUILD_ROOT/opt/abscanner/
# Copy documentation
if [ -f "README.md" ]; then
cp README.md $RPM_BUILD_ROOT/usr/share/doc/abscanner/
fi
# Create launcher script
cat > $RPM_BUILD_ROOT/usr/local/bin/abscanner << 'EOF'
#!/bin/bash
SCRIPT_DIR="/opt/abscanner"
cd "$SCRIPT_DIR"
if command -v python3 &> /dev/null; then
python3 main.py "$@"
elif command -v python &> /dev/null; then
python main.py "$@"
else
echo "Error: Python 3 is required but not installed."
echo "Please install Python 3: sudo yum install python3"
exit 1
fi
EOF
chmod +x $RPM_BUILD_ROOT/usr/local/bin/abscanner
%files
/opt/abscanner
/usr/local/bin/abscanner
/usr/share/doc/abscanner
%post
echo "Installing ABScanner dependencies..."
if command -v pip3 &> /dev/null; then
pip3 install colorama lxml openpyxl python-docx python-pptx PyPDF2 xlsxwriter pillow
fi
echo "ABScanner installation completed!"
echo "Usage: abscanner [directory_to_scan]"
%preun
echo "Removing ABScanner..."
%postun
if [ $1 -eq 0 ]; then
echo "ABScanner has been removed."
fi
%changelog
* Mon Jan 01 2025 CyberSinister <contact@cybersinister.com> - 1.0.0-1
- Initial RPM release
- Multi-threaded sensitive data scanning
- Advanced pattern matching with false positive filtering
"""
spec_path = project_root / "abscanner.spec"
with open(spec_path, 'w', encoding='utf-8') as f:
f.write(spec_content)
print(f"✅ RPM spec file created: {spec_path}")
print(f"📋 To build RPM:")
print(f" 1. Install: sudo yum install rpm-build")
print(f" 2. Setup: rpmdev-setuptree")
print(f" 3. Copy spec to ~/rpmbuild/SPECS/")
print(f" 4. Copy sources to ~/rpmbuild/SOURCES/")
print(f" 5. Build: rpmbuild -ba ~/rpmbuild/SPECS/abscanner.spec")
return str(spec_path)
if __name__ == "__main__":
print("🐧 ABScanner Linux Package Creator (Windows-Compatible)")
print("=" * 60)
results = []
# Create Debian package structure
try:
deb_result = create_deb_structure()
if deb_result:
results.append(("Debian Package Structure", deb_result))
print()
except Exception as e:
print(f"❌ Debian structure creation failed: {e}")
# Create simple installer
try:
installer_result = create_simple_installer()
if installer_result:
results.append(("Simple Linux Installer", installer_result))
print()
except Exception as e:
print(f"❌ Simple installer creation failed: {e}")
# Create RPM spec
try:
rpm_result = create_rpm_spec()
if rpm_result:
results.append(("RPM Spec File", rpm_result))
print()
except Exception as e:
print(f"❌ RPM spec creation failed: {e}")
# Summary
if results:
print("✅ Linux Package Files Created:")
for name, path in results:
print(f" 📦 {name}: {Path(path).name}")
print(f"\n🚀 Next Steps:")
print(f" 1. Transfer files to a Linux system")
print(f" 2. Run ./build_deb.sh to create .deb package")
print(f" 3. Use abscanner.spec for RPM building")
print(f" 4. ./install_linux.sh works on any Linux distribution")
print(f"\n🎯 Your ABScanner is ready for Linux distribution!")