SharkCagey / SharkCage

1 stars 3 forks source link

Token manipulation integration and proper security setup #66

Closed bencikpeter closed 6 years ago

bencikpeter commented 6 years ago
DonatJR commented 6 years ago

Randomize group name (currently static testname)

We already create a randomized name for the desktop and labeler window class, maybe you find this code useful:

#include <Rpc.h>
#pragma comment(lib, "Rpcrt4.lib")

// name should be unique every time -> create UUID
UUID uuid;
if (::UuidCreate(&uuid) != RPC_S_OK)
{
    std::cout << "Failed to create UUID" << std::endl;
    return;
}

RPC_WSTR uuid_str;
if (::UuidToString(&uuid, &uuid_str) != RPC_S_OK)
{
    std::cout << "Failed to convert UUID to rpc string" << std::endl;
    return;
}

std::wstring uuid_stl(reinterpret_cast<wchar_t*>(uuid_str));
if (uuid_stl.empty())
{
    ::RpcStringFree(&uuid_str);
    std::cout << "Failed to convert UUID rpc string to stl string" << std::endl;
    return;
}

::RpcStringFree(&uuid_str);

const std::wstring DESKTOP_NAME = std::wstring(L"shark_cage_desktop_").append(uuid_stl);
bencikpeter commented 6 years ago

Currently blocked by #68

bencikpeter commented 6 years ago

Resolved in #72 and #71

bencikpeter commented 6 years ago

In case you are interested, current status update on #71 problems:

       ULONG sessionId = ::WTSGetActiveConsoleSessionId();
    if (!WTSQueryUserToken(sessionId, &userToken)) {
        std::wcout << L"Cannot query user token";
        changeTcbPrivilege(false);
        return std::nullopt;
    }
    HANDLE duplicatedUserToken = nullptr;
    if (!DuplicateTokenEx(userToken, MAXIMUM_ALLOWED, NULL, SecurityImpersonation, TokenPrimary, &duplicatedUserToken)) {
        std::wcout << L"Cannot duplicate token" << std::endl;
        return std::nullopt;
    }
    HANDLE currentProcessHandle;
    HANDLE userTokenHandle;
    currentProcessHandle = GetCurrentProcess();
    if (!OpenProcessToken(currentProcessHandle, TOKEN_ALL_ACCESS, &userTokenHandle)) {
        wprintf(L"Error getting token for privilege escalation\n");
        return std::nullopt;
    }
    return userTokenHandle;
DonatJR commented 6 years ago

Thank you for the update! :) and tell us if you need help of any kind from us ;)

bencikpeter commented 6 years ago

I think I’ve mostly figured that out by now... now I am trying to get out of the git hell created by that revert 😅

SailReal commented 6 years ago

Sounds awesome 👍! What kind of problems have you now because of the revert?

bencikpeter commented 6 years ago

Well... because of the revert, all the reverted changes cannot be merged into the develop branch again due to the fact, that git considers them already merged and revert is viewed as a more recent change so it ignores everything until revert and includes only changes that happened afterwards.

Obvious solution of cherry-picking a revert commit into my feature branch, then "reverting a revert" (yeah I know 😅) and then applying additional fixes does not work, due to the fact that the revert didn´t happen on develop directly but instead on a separate branch and then was merged, which messes up the history even more....

What should work is creating a new branch, cherry-pick individual commits to it, iteratively resolve conflicts and then merge (which will create new commit hashes so they wont be ignored anymore). But... that´s like 13 commits that are interdependent with a different pull request and a branch that was merged and deleted in a meantime... so a proper git hell 😬

bencikpeter commented 6 years ago

Git hell already resolved and changes posted in #91.

Moral of the story: don´t revert through PR, do it directly on develop

DonatJR commented 6 years ago

Ugh, sorry to hear the revert did so much damage. :/