Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for password authentication with island #260

Merged
merged 1 commit into from Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion monkey/infection_monkey/requirements_linux.txt
@@ -1,6 +1,6 @@
enum34
impacket
PyCrypto
pycryptodome
pyasn1
cffi
twisted
Expand Down
2 changes: 1 addition & 1 deletion monkey/infection_monkey/requirements_windows.txt
@@ -1,6 +1,6 @@
enum34
impacket
PyCrypto
pycryptodome
pyasn1
cffi
twisted
Expand Down
12 changes: 12 additions & 0 deletions monkey/monkey_island/cc/environment/__init__.py
@@ -1,6 +1,7 @@
import abc
from datetime import timedelta
import os
from Crypto.Hash import SHA3_512

__author__ = 'itay.mizeretz'

Expand All @@ -13,6 +14,12 @@ class Environment(object):
_DEBUG_SERVER = False
_AUTH_EXPIRATION_TIME = timedelta(hours=1)

def __init__(self):
self.config = None

def set_config(self, config):
self.config = config

def get_island_port(self):
return self._ISLAND_PORT

Expand All @@ -25,6 +32,11 @@ def is_debug(self):
def get_auth_expiration_time(self):
return self._AUTH_EXPIRATION_TIME

def hash_secret(self, secret):
h = SHA3_512.new()
h.update(secret)
return h.hexdigest()

@abc.abstractmethod
def is_auth_enabled(self):
return
Expand Down
4 changes: 2 additions & 2 deletions monkey/monkey_island/cc/environment/aws.py
@@ -1,7 +1,7 @@
import cc.auth
from cc.environment import Environment
from common.cloud.aws import AWS

from Crypto.Hash import SHA3_512
__author__ = 'itay.mizeretz'


Expand All @@ -23,5 +23,5 @@ def is_auth_enabled(self):

def get_auth_users(self):
return [
cc.auth.User(1, 'monkey', self._instance_id)
cc.auth.User(1, 'monkey', self.hash_secret(self._instance_id))
]
18 changes: 13 additions & 5 deletions monkey/monkey_island/cc/environment/environment.py
@@ -1,16 +1,22 @@
import json
import logging
import standard
import aws

from cc.environment import standard
from cc.environment import aws
from cc.environment import password

__author__ = 'itay.mizeretz'

logger = logging.getLogger(__name__)

AWS = 'aws'
STANDARD = 'standard'
PASSWORD = 'password'

ENV_DICT = {
'standard': standard.StandardEnvironment,
'aws': aws.AwsEnvironment
STANDARD: standard.StandardEnvironment,
AWS: aws.AwsEnvironment,
PASSWORD: password.PasswordEnvironment,
}


Expand All @@ -25,8 +31,10 @@ def load_env_from_file():
return config_json['server_config']

try:
__env_type = load_env_from_file()
config_json = load_server_configuration_from_file()
__env_type = config_json['server_config']
env = ENV_DICT[__env_type]()
env.set_config(config_json)
logger.info('Monkey\'s env is: {0}'.format(env.__class__.__name__))
except Exception:
logger.error('Failed initializing environment', exc_info=True)
Expand Down
15 changes: 15 additions & 0 deletions monkey/monkey_island/cc/environment/password.py
@@ -0,0 +1,15 @@
from cc.environment import Environment
import cc.auth

__author__ = 'itay.mizeretz'


class PasswordEnvironment(Environment):

def is_auth_enabled(self):
return True

def get_auth_users(self):
return [
cc.auth.User(1, self.config['user'], self.config['hash'])
]