Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Allow Configurator on secure desktop only (release mode) #95

Merged
merged 17 commits into from
Aug 5, 2018

Conversation

DonatJR
Copy link
Contributor

@DonatJR DonatJR commented Aug 4, 2018

fixes #55

regarding WIP: @SailReal the CageConfigurator.sconfig file must be copied to the public documents folder on install and the registry needs to have a corresponding entry

!! Only merge this after #91 !!

@@ -0,0 +1,12 @@
{
"application_name": "CageConfigurator",
"application_path": "C:\\sharkcage\\CageConfigurator.exe",
Copy link
Contributor

@SailReal SailReal Aug 4, 2018

Choose a reason for hiding this comment

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

I'm currently enhancing our installer. The application_path must be written by the installer or? It depends on the target folder specified by the user while installing.

Copy link
Contributor Author

@DonatJR DonatJR Aug 4, 2018

Choose a reason for hiding this comment

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

Yeah, we can change the path to a placeholder and then replace it when installing

using System.IO;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Security.Principal;

namespace CageServiceInstaller
Copy link
Contributor

Choose a reason for hiding this comment

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

I still have to rename the project...

@SailReal
Copy link
Contributor

SailReal commented Aug 5, 2018

regarding WIP: @SailReal the CageConfigurator.sconfig file must be copied to the public documents folder on install and the registry needs to have a corresponding entry

Should be fixed now.

@DonatJR will review your additions in this pr now. Maybe you can check my?

Copy link
Contributor

@SailReal SailReal left a comment

Choose a reason for hiding this comment

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

Awesome work, thx a lot 👍!!!

If I build the solution with release target, the cage manager will not be started by the chooser when selecting an config and pressing the start button. Only a error with message "Error communicating with service: Starting CageManager failed." is displayed.
If I start the CageManager manually before pressing the start button in the CageChooser, the desktop is switched and everything seems to be fine. After switching back, the same error message is displayed.

@@ -49,11 +49,11 @@ private void LoadConfigList()
{
foreach (var value_name in key.GetValueNames())
{

Copy link
Contributor

Choose a reason for hiding this comment

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

Pls remove this empty newline.

}
}

// FIXME might be easier to ask the service for this info in the future? :/
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should create an issue for that? Otherwise we can remove the FIXME.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#96

@@ -91,6 +94,7 @@ private void CheckPath(string path, string[] file_types, Action<string> onSucces
return path.EndsWith(type);
});

// fixme: check if path contains cage configurator and disallow it?
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should create an issue for that as 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.

this can just be deleted as we now explicitely want to be able to create a config for the Configurator

@DonatJR
Copy link
Contributor Author

DonatJR commented Aug 5, 2018

@SailReal Regarding your issue with the release mode: Did you copy all necessary files into the 'install folder'? If yes, did you recreate the config with the new release binary of the Configurator?

I think I know why (from the Service):

#ifdef _DEBUG
    return StartCageManager(session_id, filename, user_token);
#else
    if (SharedFunctions::ValidateCertificate(filename))
    {
        return StartCageManager(session_id, filename, user_token);
    }
    else
    {
        std::wostringstream os;
        os << "Failed to validate the integrity of CageManager! Not starting." << std::endl;
        ::OutputDebugString(os.str().c_str());
        return 0;
    }
#endif

In release mode the Manager must be signed ;)

Copy link
Contributor Author

@DonatJR DonatJR left a comment

Choose a reason for hiding this comment

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

@SailReal
can't request changes on my own PR :) additional things:

  • can you remove the Configurator desktop shortcut? it cannot be launched with the shortcut anyway

apart from the comments your changes look good, thx!

UninstallService();
}

private void AssimilateConfigToCurrentSystem(string dir_path)
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 don't quite get the name of this function, why 'assimilate'?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant something like customize...?

{
var config_path = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments),
"SharkCage\\CageConfigurator.sconfig");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can use @"one\slash\only" if you don't want to use characters which are needed to be escaped (with @ everything is interpreted literally

const string APPLICATION_HASH_PROPERTY = "binary_hash";
var path_to_config_exe = Path.Combine(dir_path, "CageConfigurator.exe");

var json = JObject.Parse(File.ReadAllText(config_path));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the json parsing can fail (if the file is missing or has a different structure), do we need a try catch here or does the installer handle it for us?

Copy link
Contributor

Choose a reason for hiding this comment

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

The installer is handling the exception and also will rollback all changes on the system, will display an error message with the content of the exception so nothing to do for us I think...

var json = JObject.Parse(File.ReadAllText(config_path));
var application_path = json.GetValue(APPLICATION_PATH_PROPERTY).ToString();
json[APPLICATION_PATH_PROPERTY] = path_to_config_exe;
json[APPLICATION_HASH_PROPERTY] = GetSha512Hash(path_to_config_exe);
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 patching the hash on the target system is a good idea. We can generate the hash once before creating the installer and just patch the correct path

Copy link
Contributor

Choose a reason for hiding this comment

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

The hash looks different on our machines with the same target (debug) so I thought it will be the same result with the release target. I don't know what but something on the system must have an influence on the calculation of the hash over the binary. So I think the only way is it to calculate the hash on the target system but I think that should not decrease the security at all especially because up to the point of installation, the config is writable.

Maybe we should create an issue for that to think about how we can install the cage in a secure way on a already infected system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but the hash only changes on creation. once it is created and signed the hash can be written to the config and the binary hash must be the same on the target machine for us to be sure there was no tampering during distribution

Copy link
Contributor

Choose a reason for hiding this comment

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

Will create an issue for that.

@SailReal
Copy link
Contributor

SailReal commented Aug 5, 2018

Did you copy all necessary files into the 'install folder'? If yes, did you recreate the config with the new release binary of the Configurator?

@DonatJR I used the installer to copy all files and also created new configs. Is it working on your device?

@SailReal
Copy link
Contributor

SailReal commented Aug 5, 2018

I think I know why (from the Service):

oh nooooo you're right, the CageManager wasn't signed 😅 now it's working like a charm 😍

@DonatJR DonatJR merged commit d457a7b into develop Aug 5, 2018
@DonatJR DonatJR changed the title WIP: Allow Configurator on secure desktop only (release mode) Allow Configurator on secure desktop only (release mode) Aug 5, 2018
@DonatJR DonatJR deleted the 55-config-in-cage branch August 5, 2018 21:56
@DonatJR DonatJR mentioned this pull request Aug 5, 2018
@bencikpeter
Copy link
Contributor

Shouldn´t there be a default entry in Chooser to launch Configurator? I am a bit confused about how should I start Configurator in Release? I need an entry to launch Configurator, and to create entry I need Configurator? 🤔

@DonatJR
Copy link
Contributor Author

DonatJR commented Aug 6, 2018

@bencikpeter
The installer creates an entry in the registry. On your dev system you can simple create your on in the registry itself at Computer\HKEY_LOCAL_MACHINE\SOFTWARE(\WOW6432Node)\SharkCage\Configs (REG_SZ, with name and the path to the config file as value)
image
Or you can use the debug build of the Configurator to create configs and use them with the release build of all the other applications

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants