-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
124 lines (119 loc) · 4.35 KB
/
main.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
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
import argparse
import os
from analyzers import apt_static_analysis
from analyzers import apt_chroot_analysis
from analyzers import rpm_chroot_analysis
from analyzers import rpm_static_analysis
class main():
def __init__(self) -> None:
parser = argparse.ArgumentParser(
prog="main.py",
description="""
STARTUP SBOM:
This is a automation to list out packages installed in
linux systems and map them to the appropriate service files.
The project is for analysis of packages installed and provide
an insight into the inner workings of the system.
"""
)
parser.add_argument(
'--analysis-mode',
type=str,
required=False,
default='static',
help="""
This is required to mention the mode of operation the
default mode is static and you can ether choose from static and
chroot.
"""
)
parser.add_argument(
'--static-type',
type=str,
required=False,
default="info",
help="""
This is a necessary option for the static processing mode only.
It will make sure you are using ether the Service file analysis
or the Info Directory analysis methods.
"""
)
parser.add_argument(
'--volume-path',
type=str,
required=False,
default='/mnt',
help="""
This the path to the mounted volume. The path is required and
the default path is /mnt and you can change it to your own
choice.
"""
)
parser.add_argument(
"--save-file",
type=str,
required=False,
default="",
help="""
Generates JSON output on what your are displayed and this can
be used for future intigrations.
"""
)
parser.add_argument(
"--info-graphic",
type=bool,
required=False,
default=True,
help="""
Provides visual plots on the the different packages and
associated Service Files and Target files which are being
executed at boot. This is based on time of execution and
is specific only to CHROOT analysis
"""
)
parser.add_argument(
"--pkg-mgr",
type=str,
required=False,
default="",
help="""
Provides visual plots on the the different packages and
associated Service Files and Target files which are being
executed at boot. This is based on time of execution and
is specific only to CHROOT analysis
"""
)
args = parser.parse_args()
mode: str = args.analysis_mode
volume_path: str = args.volume_path
static_type: str = args.static_type
output_opt: str = args.save_file
info_graphic: bool = args.info_graphic
package_mgr: str = args.pkg_mgr
if package_mgr == "":
if os.path.exists(f"{volume_path}/var/lib/dpkg"):
package_mgr = "apt"
elif os.path.exists(f"{volume_path}/var/lib/rpm"):
package_mgr = "rpm"
else:
print("Image not supported")
quit()
if package_mgr == "apt":
if mode == 'static':
apt_static_analysis(volume_path, static_type, output_opt)
elif mode == 'chroot':
apt_chroot_analysis(
volume_path,
output_opt,
graphic_plot=info_graphic
)
elif package_mgr == "rpm":
if mode == 'static':
rpm_static_analysis(volume_path, output_opt)
elif mode == 'chroot':
rpm_chroot_analysis(volume_path, output_opt,
graphic_plot=info_graphic)
else:
print("Image not supported")
if __name__ == "__main__":
main()