Skip to content

Conversation

itaymmguardicore
Copy link
Contributor

@itaymmguardicore itaymmguardicore commented Feb 13, 2018

Feature

DB now stores its credentials encrypted.
All credentials are encrypted in DB. Preventing simple non-targeted malware from stealing credentials from the DB.

  • Have you added an explanation of what your changes do and why you'd like to include them?
  • Have you successfully tested your changes locally?

@danielguardicore
Copy link
Contributor

  • What happens if the configuration is not encrypted? If ConfigService should_encrypt is false, we should make sure not to encrypt when not needed, and more importantly, not decrypt encrypted data.

@itaymmguardicore itaymmguardicore self-assigned this Feb 19, 2018
@itaymmguardicore itaymmguardicore added island Feature Issue that describes a new feature to be implemented. labels Feb 19, 2018
Copy link
Contributor

@danielguardicore danielguardicore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly worried about any changes requiring very careful attention to the actual API to avoid double encryption/decryption of data.

ConfigService._encrypt_config(config, False)

@staticmethod
def _encrypt_config(config, is_decrypt=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the best name for this function? Just to avoid code duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think two functions is better. I just think this will end up confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename it do _encrypt_or_decrypt_config?
Longer name but I think it solves the confusion, and is only used from withing encrypt_config and decrypt_config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@@ -794,29 +797,42 @@
}
}

ENCRYPTED_CONFIG_ARRAYS = \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated here (with schema information) and in add_system_info_creds_to_config
Can we avoid this somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I know what you're talking about

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two seperate places in the code where what fields need to be encrypted are listed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 places are (sort of) unrelated. It's true that currently the credentials are the only config values being encrypted. Maybe in the future we'll have further secrets we'd want to encrypt but not use in add_system_info_creds_to_config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the problem is that keeping track of whats encrypted requires a double lookup. If we can't avoid it oh well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't avoid it right now

@@ -17,60 +20,60 @@
"type": "string",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this entire schema to a seperate file? Out of 970 lines, 785 are the schema, making the file hard to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. But let's not do it in this branch. I've added as task to tasklist

@@ -124,6 +125,8 @@ def process_exploit_telemetry(telemetry_json):
if new_exploit['result']:
EdgeService.set_edge_exploited(edge)

Telemetry.encrypt_exploit_creds(telemetry_json)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, what happened to the plain text creds in the telemetry_json which were written to the mongodb under new_exploit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're asking what happened up to this point, nothing happened. They were sent plain text from the monkey (over HTTPS).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant the line where mongo.db.edge.update
With something that's a deep clone of telemetry_json['data']
which is what's being encrypted later.

We're encrypting the data when we add the creds but it seems the data is also saved without encryption under edges.

def __init__(self):
pass

@staticmethod
def get_config(is_initial_config=False):
def get_config(is_initial_config=False, should_decrypt=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document when get_config and get_config_value should each be used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

def get_config_value(config_key_as_arr, is_initial_config=False):
config_key = reduce(lambda x, y: x+'.'+y, config_key_as_arr)
def get_config_value(config_key_as_arr, is_initial_config=False, should_decrypt=True):
config_key = reduce(lambda x, y: x + '.' + y, config_key_as_arr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer you use functools.reduce

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return config

@staticmethod
def get_config_value(config_key_as_arr, is_initial_config=False):
config_key = reduce(lambda x, y: x+'.'+y, config_key_as_arr)
def get_config_value(config_key_as_arr, is_initial_config=False, should_decrypt=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're inconsistent on when are you explicit/implict on should_decrypt.
get_config, 2 implicit true, 1 explicit false
get_config_value - all explicitly true
get_flat_config - 1 implicit true

Why? I'm not sure it really matters except I'd rather be explicit where possible, so we know when are we passing plain credentials and we can verify it's always to the monkey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

ConfigService.default_config = config

@staticmethod
def get_default_config(should_decrypt=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun with naming
should_decrypt leads to encrypt_config, this does not make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

enum34
PyCrypto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line at end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@itaymmguardicore itaymmguardicore merged commit 1a3ca06 into develop Mar 8, 2018
@itaymmguardicore itaymmguardicore deleted the feature/secure-island-db branch March 8, 2018 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue that describes a new feature to be implemented.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants