-
Notifications
You must be signed in to change notification settings - Fork 0
/
SourceCodeFinder.py
56 lines (44 loc) · 1.47 KB
/
SourceCodeFinder.py
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
import os
from dotenv import load_dotenv
from rich.console import Console
from templates.PHPBackup import PHPBackup
from templates.ArchiveFileBackup import ArchiveFileBackup
from templates.GitConfig import GitConfig
from templates.GitHead import GitHead
import argparse
load_dotenv()
console = Console()
classes = [
ArchiveFileBackup,
PHPBackup,
GitHead,
GitConfig,
]
parser = argparse.ArgumentParser(description="Source Code Finder")
parser.add_argument("-u", "--url", type=str, help="Single URL to scan")
parser.add_argument("-f", "--file", type=str, help="File containing URLs to scan")
args = parser.parse_args()
targets = None
if args.url:
targets = [args.url]
elif args.file:
try:
with open(args.file, "r") as f:
targets = f.read()
except FileNotFoundError:
console.print("File not found!", style="bold red")
exit(1)
else:
parser.print_help()
exit(1)
max_cpu_count = os.cpu_count() + 4
env_thread_count = int(os.getenv("THREAD_COUNT", 1))
if env_thread_count >= max_cpu_count:
console.print(f"THREAD_COUNT is too high! THREAD_COUNT should be lower than {max_cpu_count}", style="bold red")
exit(1)
for url in targets.split("\n"):
for cls in classes:
instance = cls(url.strip())
console.print(f"Scanning {url.strip()} with {cls.__name__} Template", style="bold blue")
instance.find()
console.print(f"Scanning {url.strip()} with {cls.__name__} done!", style="bold green")