stampery / mongoaudit

🔥 A powerful MongoDB auditing and pentesting tool 🔥
https://mongoaud.it
MIT License
1.32k stars 135 forks source link

The functions implementing security checks currently return several possible types #29

Closed aesedepece closed 7 years ago

aesedepece commented 7 years ago

As pointed out by @elecay in #28:

There is inconsistency on method responds. For example, some methods return magic numbers, like enabled() and some methods return boolean, like available().

Currently, possible return values are:

aesedepece commented 7 years ago

@elecay In your opinion, what would be a better practice instead? @kronolynx Same question ↑ :wink:

elecay commented 7 years ago

What about a named tuple?, like:

Status = namedtuple('Status', 'success, message')

def doing_some_magic_here():
    return Status(False, 'some message')

s = doing_some_magic_here()

if s.success:
    print('Wooha!')
else:
    print(s.message)

I think that tests pass or not pass. If pass, could have message (warning) or not (success). A "3" response should actually never been raise. If a previous condition did not pass, then, test didn't pass. But maybe I don't fully understand the logic yet.

aesedepece commented 7 years ago

Great suggestion!

The thing is that values 0, 1, 2, and 3 are indeed used for choosing the messages in the report without the need to use conditional expressions or switch/case constructions. Report messages are loaded from https://github.com/stampery/mongoaudit/blob/master/mongoaudit/data/tests.json and then accessed directly by index.

I know, not the most elegant stuff in the world, but the performance is likely unmatchable :sweat_smile:

elecay commented 7 years ago

I understand. Then, we can add another field, like:

Status = namedtuple('Status', 'success, severity, message')
return Status(False, 2, 'some message')

The important thing is to return always the same contract.

elecay commented 7 years ago

Can you give me some feedback on the branch that I've created?

aesedepece commented 7 years ago

Hi @elecay, thanks a lot! Everything seems fine but a single crash when reaching test 24 in the results summary (only happens on the advanced test suite):

Traceback (most recent call last):
  File "~/anaconda2/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "~/anaconda2/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "~/Stampery/Desarrollo/mongoaudit/mongoaudit/__main__.py", line 66, in <module>
    main()
  File "~/Stampery/Desarrollo/mongoaudit/mongoaudit/__main__.py", line 63, in main
    App().main()
  File "~/Stampery/Desarrollo/mongoaudit/mongoaudit/__main__.py", line 23, in __init__
    self.main()
  File "~/Stampery/Desarrollo/mongoaudit/mongoaudit/__main__.py", line 58, in main
    self.loop.run()
  File "~/anaconda2/lib/python2.7/site-packages/urwid/main_loop.py", line 278, in run
    self._run()
  File "~/anaconda2/lib/python2.7/site-packages/urwid/main_loop.py", line 376, in _run
    self.event_loop.run()
  File "~/anaconda2/lib/python2.7/site-packages/urwid/main_loop.py", line 682, in run
    self._loop()
  File "~/anaconda2/lib/python2.7/site-packages/urwid/main_loop.py", line 719, in _loop
    self._watch_files[fd]()
  File "~/anaconda2/lib/python2.7/site-packages/urwid/raw_display.py", line 393, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "~/anaconda2/lib/python2.7/site-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/main_loop.py", line 403, in _update
    self.process_input(keys)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/container.py", line 592, in keypress
    *self.calculate_padding_filler(size, True)), key)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/container.py", line 1587, in keypress
    key = self.focus.keypress(tsize, key)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/container.py", line 1587, in keypress
    key = self.focus.keypress(tsize, key)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/decoration.py", line 621, in keypress
    return self._original_widget.keypress(maxvals, key)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/decoration.py", line 385, in keypress
    return self._original_widget.keypress((maxcol, self.height), key)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/listbox.py", line 987, in keypress
    key = focus_widget.keypress((maxcol,),key)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/decoration.py", line 621, in keypress
    return self._original_widget.keypress(maxvals, key)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/container.py", line 2269, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/wimp.py", line 535, in keypress
    self._emit('click')
  File "~/anaconda2/lib/python2.7/site-packages/urwid/widget.py", line 464, in _emit
    signals.emit_signal(self, name, self, *args)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/signals.py", line 264, in emit
    result |= self._call_callback(callback, user_arg, user_args, args)
  File "~/anaconda2/lib/python2.7/site-packages/urwid/signals.py", line 294, in _call_callback
    return bool(callback(*args_to_pass))
  File "mongoaudit/widgets.py", line 380, in <lambda>
    lambda _: self.update_view(text))), 'button')
  File "mongoaudit/widgets.py", line 411, in update_view
    self.result[self.currently_displayed - 1], self.test_result.options)
  File "mongoaudit/widgets.py", line 361, in test_display
    test['extra_data'] + test['message'][1]
TypeError: coercing to Unicode: need string or buffer, NoneType found
elecay commented 7 years ago

Yes, we're getting WARNING type message instead of OMITTED ones. Let me check. BTW, next step will be adding unit tests.

elecay commented 7 years ago

Closed by: #29