Skip to content

Commit

Permalink
wdutil: add client and config
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed May 18, 2024
1 parent e0f0cbb commit 10c3c04
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Github issues and feature requests welcomed.
| Google Cloud | google auth api<br/>google people api<br/>google sheets api |
| Helpers | os<br/>subprocess<br/>threading<br/>socket<br/>datetime |
| Logging | sentryio |
| MacOS | airport<br/>macchanger |
| MacOS | airport<br/>macchanger<br/>wdutil |
| Python | logging<br/>requests |
| SOAR | swimlane<br/>splunk soar |
| Recon | nmap |
Expand Down
2 changes: 2 additions & 0 deletions automon/integrations/mac/wdutil/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .client import WdutilClient
from .config import WdutilConfig
34 changes: 34 additions & 0 deletions automon/integrations/mac/wdutil/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from automon import logging
from automon import log_secret
from automon.helpers import Run

from .config import WdutilConfig

log = logging.getLogger(__name__)
log.setLevel(level=logging.DEBUG)


class WdutilClient(object):

def __init__(self, config: WdutilConfig = None, wdutil_path: str = None):
self.config = config or WdutilConfig(wdutil_path=wdutil_path)
self.wdutil = self.config.wdutil_path()

self._runner = Run()

def run(self, arg: str):
self.config.is_ready()

secret = f'echo {self.config.password} | '
command = f'sudo -S {self.wdutil} {arg}'

log.info(f'echo {log_secret(self.config.password)} | {command}')
return self._runner.run(command=f'{secret}{command}', shell=True)

def is_ready(self):
if self.config.is_ready():
return True
return False

def help(self):
return self.run('help')
44 changes: 44 additions & 0 deletions automon/integrations/mac/wdutil/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from automon import Run
from automon import environ
from automon import logging
from automon import os_is_mac

from .exceptions import *

log = logging.getLogger(__name__)
log.setLevel(level=logging.DEBUG)


class WdutilConfig(object):

def __init__(self, password: str = None, wdutil_path: str = None):
self.password = password or environ('WDUTIL_PASSWORD')
self._wdutil_path = wdutil_path
self._runner = Run()

def is_ready(self):
if not self.password:
log.error(f'missing WDUTIL_PASSWORD')

if not self.wdutil_path():
log.error(f'missing wdutil')

if self.password and self.wdutil_path():
return True

return False

def wdutil_path(self):
if os_is_mac():

if self._wdutil_path:
return self._wdutil_path

if self._runner.which('wdutil'):
self._wdutil_path = self._runner.stdout.decode().strip()
log.info(str(dict(
wdutil_path=self._wdutil_path
)))
return self._wdutil_path

return False
2 changes: 2 additions & 0 deletions automon/integrations/mac/wdutil/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class WdutilConfigNotReady(Exception):
pass
Empty file.
18 changes: 18 additions & 0 deletions automon/integrations/mac/wdutil/tests/test_client_ready.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest

from automon import os_is_mac
from automon.integrations.mac.wdutil import WdutilClient, WdutilConfig


class MyTestCase(unittest.TestCase):
if os_is_mac():
if WdutilConfig().is_ready():

def test_something(self):
self.assertTrue(
WdutilClient().is_ready()
)


if __name__ == '__main__':
unittest.main()
16 changes: 16 additions & 0 deletions automon/integrations/mac/wdutil/tests/test_client_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

from automon import os_is_mac
from automon.integrations.mac.wdutil import WdutilClient


class MyTestCase(unittest.TestCase):
if WdutilClient().is_ready():
def test_something(self):
client = WdutilClient()
self.assertTrue(client.run('info'))
pass


if __name__ == '__main__':
unittest.main()
14 changes: 14 additions & 0 deletions automon/integrations/mac/wdutil/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest

from automon import os_is_mac
from automon.integrations.mac.wdutil import WdutilConfig


class MyTestCase(unittest.TestCase):
if os_is_mac():
def test_something(self):
self.assertFalse(WdutilConfig().is_ready())


if __name__ == '__main__':
unittest.main()
15 changes: 15 additions & 0 deletions automon/integrations/mac/wdutil/tests/test_wdutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

from automon import os_is_mac
from automon.integrations.mac.wdutil import WdutilClient


class MyTestCase(unittest.TestCase):

if os_is_mac():
def test_something(self):
self.assertTrue(WdutilClient().wdutil)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion automon/log/tests/test_log_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class MyTestCase(unittest.TestCase):
def test_something(self):
self.assertEqual(log_secret(secret='password'), '********') # add assertion here
self.assertEqual(log_secret(secret='password'), '********************************') # add assertion here


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions env-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ LDAP_PORT=
VDS_BIND_USER=cn=automon,ou=people,dc=automon,dc=com
VDS_BASE_DN=dc=automon,dc=com
VDS_PASSWORD=

# Wdutil
WDUTIL_PASSWORD=

0 comments on commit 10c3c04

Please sign in to comment.