/
mms.py
executable file
·132 lines (108 loc) · 3.92 KB
/
mms.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
125
126
127
128
129
130
131
132
'''
Module Management System Class (MMS) - Copyright 2020 James Slaughter,
This file is part of MMS v0.2.
MMS v0.2 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MMS v0.2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MMS v0.2. If not, see <http://www.gnu.org/licenses/>.
'''
'''
Usage:
Import:
from mms import mms
Example to initialize the class:
MMS = mms(<list of modules>, <modules directory>, <module to be used>, <Debug True or False>)
Example to execute a module:
ret = 0
ret = MMS.OrganizeModules(<object containing information necessary to execute the module>)
'''
'''
MMS.py - This class is responsible for the dynamic loading of modules
'''
#python imports
import imp
import sys
from array import *
#programmer generated imports
'''
mms
Class: This class is responsible for the dynamic loading of modules
'''
class mms:
'''
Constructor
'''
def __init__(self, listofmodules, modulesdir, modules, debug):
self.debug = False
self.modulesdir = ''
self.modules = ''
self.listofmodules = []
self.listofmodules = listofmodules
self.modulesdir = modulesdir
self.modules = modules
self.debug = debug
'''
ExecuteModules()
Function: - takes module name from Organize modules and then tries to find and load it
'''
def ExecuteModules(self, modules, POE):
option = ''
mymod = ''
if (self.debug == True):
print ('[DEBUG] Modules Directory: ' + self.modulesdir.strip())
#Locate the dynamic module, create a file object for it
try:
fp, pathname, description = imp.find_module(modules, [self.modulesdir.strip()])
if (self.debug == True):
print ('\n[DEBUG] Module ' + modules + ' located')
print ('\n[DEBUG] fp: ' + str(fp) + ' pathname: ' + str(pathname) + ' description: ' + str(description) + '\n' )
except ImportError:
print ('\n[x] Unable to locate module: ' + modules)
return -1
#Load the module into memory
try:
mymod = imp.load_module(modules, fp, pathname, description)
if (self.debug == True):
print ('[DEBUG] Module ' + modules + ' loaded successfully')
except Exception as e:
print (e)
print ('\n[x] Unable to load module: ' + modules + ' -', e)
return -1
finally:
fp.close()
#Execute the module
try:
if (self.debug == True):
print ('[DEBUG] Executing module\n')
mymod.POE(POE)
except Exception as e:
print (e)
print ('\n[x] Unable to execute module: ' + modules + ' -', e)
return -1
return 0
'''
OrganizeModules()
Function: - Cycles through the arrays of available modules
- Sends the chosen one on to execution
'''
def OrganizeModules(self, POE):
ret = 0
print ('[-] Organize Modules...')
if (self.modules == 'all'):
for module_data in self.listofmodules:
if (self.debug == True):
print ('[DEBUG] ' + ': ' + module_data)
ret = self.ExecuteModules(module_data.strip(), POE)
else:
print ('[*] Module ' + self.modules)
ret = self.ExecuteModules(self.modules, POE)
return ret
'''
END OF LINE
'''