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
|
from core.vectors import PhpCode, ShellCmd, ModuleExec, Os
from core.module import Module
from core import modules
from core import messages
from core.loggers import log
class Enum(Module):
"""Check existence and permissions of a list of paths."""
def init(self):
self.register_info(
{
'author': [
'Emilio Pinna'
],
'license': 'GPLv3'
}
)
self.register_arguments([
{ 'name' : 'paths', 'help' : 'One or more paths', 'nargs' : '*' },
{ 'name' : '-lpath-list', 'help' : 'The local file containing the list of paths' },
{ 'name' : '-print', 'help' : 'Print the paths not found too', 'action' : 'store_true', 'default' : False }
])
def run(self, **kwargs):
paths = []
lpath = self.args.get('lpath_list')
if lpath:
try:
with open(lpath, 'r') as lfile:
paths = lfile.read().split('\n')
except Exception as e:
log.warning(
messages.generic.error_loading_file_s_s % (lpath, str(e)))
return
paths += self.args.get('paths') if self.args.get('paths') else []
results = {}
for path in paths:
result = ModuleExec( "file_check", [ path, "perms" ]).run()
if result or self.args.get('print'):
results[path] = result
return results
def print_result(self, result):
if not result: return
result_verbose = {}
for path, perms in result.items():
if len(perms) == 1 and perms[0] == 'e':
result_verbose[path] = 'exists'
else:
verbose_string = ' '.join([
'writable' if 'w' in perms else '',
'readable' if 'r' in perms else '',
'executable' if 'x' in perms else ''
])
# Re split to delete multiple whitespaces
result_verbose[path] = ' '.join(
verbose_string.strip().split()
)
return Module.print_result(self, result_verbose)
|