# Scrambled

## Gaining Access

Nmap Scan:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-09f72183eca83e91ae5c28ef506ac3e6f502f850%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### ScrambleCorp

The website was another corporate webpage.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-9eb82f37967a32002794ac2e742d3cd9d5eb0312%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

In the IT Services tab, we can view this warning:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-fb3a01ce2411b24206fd459d6807b670d10c7383%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

So this machine presented the challenge of not using NTLM at all, but **only Kerberos tickets.** Enumerating further, we can find more resources in the page source:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-06657c7b7d73d6ac65a90b567f019fd55b8baf13%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Heading to the Support Request page shows this:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-f6a4744a2fe674569eb7ded7fa401c83776a53ed%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

One interesting thign we get from this is that there is a `ksimpson` user within the domain. the image there seems intentionally left there.

Additionally, the Sales Order page reveals more information which could be useful:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-6b553f77c6a4ff9e6d9b37606b7046bec3c502dd%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

There's some binary that would conenct to `dc1.scrm.local` on port 4411, which we can note down. Might be BOF exploit later on.

### getTGT + SMB Shares

Armed with one user, I attmepted to request for a TGT using his username as the password:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-78ad1af0ffc4141e848dbed11b37609bf52bd98f%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Now we have one ticket, we can attempt to access some SMB shares using `smbclient.py`.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-4304744cc7f5695d78a0f2675cd276638ddc98fe%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Ton of shares here, but we can only access the `Public` share. We can find one interesting file here.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-5f90d0e24f1e66392c0a8266a2069fca1b140e2b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-edd26f8760c8dfaed383933717af6bcb03ecb187%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Kerberoasting

Within this PDF, we can find some useful hints on where to head to next:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-3df56256aa41ac2d737b094fe3d8266bbde6a2fb%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

So an attacker was able to retrieve stuff from an SQL database used by HR. Furthermore, the Kerberos authentication bit made me realise that we should be attempting to resolve User SPNs to Kerberoast whatever SQL users there were.

We can use `getUserSPNs.py` to do so.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-8d28d0ace634720b10a7a034698979d6bb527f2c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Afterwards, we can retrieve the tickets using the `-request` flag. Thsi would give us a hash that we can crack using `john`.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-3d4d13063c2113059e9431f2f77ac2f8f4ef9ae1%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Converting to Ticket + RCE

NTLM authentication was totally shut down, so we have to take this password and convert it to a valid ticket. I used `impacket-secretsdump` to get the Domain SIDs of the users present:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-f307cc11becbbfdc5aeb9e197c3d5c0f05b6977a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then, we can use `impacket-ticketer` to create a ticket, export it and also run `impacket-mssqlclient` to connect to the MSSQL instance using Kerberos:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-b13bdd3c666b8b18ad2119667f7cd0aa16a5bb1e%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then, we can enable `xp_cmdshell` to gain RCE on the machine.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-10f4a6323a9364111d4413114d7edfd4e033c89e%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Using this, we can gain a reverse shell using whatever method. I always prefer to download a copy of `nc.exe` onto the machine and run it (not the stealthiest).

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-6ead6bfad02ca8a686e23b4938f5115d4465fdfb%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-1ccf6cb6ea0e1b756d7b08c761c1c95d1b62981c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## Privilege Escalation

I was unable to do much as this user. So instead, I went to enumerate the SQL database a bit more to hopefully find some credentials within it (as hinted by the PDF earlier).

### Miscsvc

Was able to find this:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-35e1ee6cc4c4c59aa772977d9b93456f373212f1%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then, we can take a look at the ScrambleHR database.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-b662c83a3f1faff0341f6aca7cdce46f3bbd0872%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

I took a look at the UserImport table and found some new credentials.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-34ad4dc8e0e1ee8ae4d349faf89df329cc287812%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

With these credentials, we can attempt to `evil-winrm` in. However this does not work as the user is not part of the Remote Management Group.

Instead, I used some remote Powershell to gain RCE via ScriptBlocks.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-04be08c583169360530a0b2a6cded2fcc8152d79%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We can gain another reverse shell easily and capture the user flag.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-eb808d35cfed139442f5ab977da708111dc1f836%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Scramble Client

Taking a look around the machine, we can go ahead and view all the other Shares that we could not access just now by reading the `C:\Shares` directory. There, I was able to find the ScrambleClient.exe file that was running on port 4411.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-4ee5bd228b27ee5590a0cb2d3946da092067ddce%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Transferred this back to my machine via nc.exe, and then took a look at it using `strings`.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-9fa461607693756d321fc85197019ab21a46c3c7%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

I see DeserializeFromBase64, which is a huge security flaw as user input should never be deserialized. I transferred this binary to another Windows VM (Commando VM in this case) and then opened it up in dnSpy.

As usual, it first asks for creds (as per the image we found earlier). We can find this snippet in code for the login authentication:

```csharp
public bool Logon(string Username, string Password)
{
    bool result;
    try
    {
        if (string.Compare(Username, "scrmdev", true) == 0)
        {
            Log.Write("Developer logon bypass used");
            result = true;
        }
```

There was a custom backdoor using the `scrmdev` user! We can easily login then. Afterwards, I took a look back at port 4411 on the machine, which was running this binary as I found out the binary accepts some commands based on reading the dnSpy code.

We can send LIST\_ORDERS to the port, and it would return some base64 stuff:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-9097396b1c2bf796b908cde199b2bd9870f052a7%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

This was interesting, and reading the code also allowed us to send an UPLOAD\_ORDER; command, followed by base64 encoded stuff. I knew the payload was being deserialized, just had to find out what was the function used as it might be vulnerable to RCE.

Took a look at the base64 functions and found this:

```csharp
public string SerializeToBase64()
{
    BinaryFormatter binaryFormatter = new BinaryFormatter();
    Log.Write("Binary formatter init successful");
    string result;
    using (MemoryStream memoryStream = new MemoryStream())
    {
        binaryFormatter.Serialize(memoryStream, this);
        result = Convert.ToBase64String(memoryStream.ToArray());
    }
    return result;
}
```

This program was using `BinaryFormatter()`, which an insecure function that could be exploited via `ysoserial`.

### Constructing Payload

I had to download `ysoserial.exe` on my Windows VM to build my payload. We can then use it to create this payload:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-c160b94baf725fd7867aeb30444f4737b6a6f7ea%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Afterwards, we just need to prepend a UPLOAD\_ORDER; string, and send this to port 4411. On our listener port, we would catch a SYSTEM shell.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-1828335744f15ad7b95a8b58fa93e5f749fe5cdb%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-ea3d15c5e47874a0475448c26be18df1ae0b3809%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
