1 पॉइंट द्वारा GN⁺ 2024-12-26 | 1 टिप्पणियां | WhatsApp पर शेयर करें
  • Portspoof सभी 65535 TCP पोर्ट को खुले हुए जैसा दिखाता है और service signatures को emulate करता है, जिससे attacker का reconnaissance चरण तेज़ scan से बदलकर लंबा और महंगा काम बन जाता है
  • हर connection attempt पर SYN+ACK लौटाता है, और 9000 से अधिक regex-आधारित dynamic service signatures के जरिए हर port अलग-अलग वैध service की तरह respond करता है
  • startup पर हर port को तुरंत banner, delayed response, या no-response hold जैसे mixed delivery modes assign करता है, और connection hold time में jitter जोड़कर timing-based filtering को कठिन बनाता है
  • default tarpit settings में full version scan nmap -sV -p- में 10 घंटे से अधिक लग सकते हैं और सैकड़ों MB fake data बन सकता है, जिससे attacker scanner का समय और threads खर्च होते हैं
  • implementation single-threaded epoll event loop का उपयोग करता है, user space में root privileges के बिना चलता है और प्रति running instance सिर्फ एक TCP port bind करता है

Portspoof जिस समस्या को हल करना चाहता है

  • Portspoof का लक्ष्य attacker के reconnaissance को धीमा, महंगा और भरोसा करने में कठिन बनाना है
  • आम 5-second Nmap scan से system की असली services map होने के बजाय, Portspoof के सामने सभी 65535 ports खुले हुए दिखाई देते हैं
  • हर port अलग-अलग वैध service जैसा दिखता है, और design ऐसा है कि कौन-सा port असली service है, इसे जल्दी अलग पहचानने का कोई तरीका न रहे

मुख्य features

  • सभी 65535 TCP ports के खुले होने जैसा response

    • port को CLOSED या FILTERED बताने के बजाय हर connection attempt पर SYN+ACK लौटाता है
  • Service emulation

    • 9000 से अधिक regex-आधारित dynamic service signatures का उपयोग करता है
    • हर port पर scanner के probes को अलग, भरोसेमंद service identity के साथ respond करता है
  • Mixed delivery mode

    • हर port को startup पर अलग behavior profile मिलता है
    • immediate banner delivery, delayed response, और no-response hold modes का mix होता है
    • hold times बड़े range में distributed होते हैं, जिससे full-range version detection nmap -sV -p- practical limits से आगे चला जाता है
  • Offensive defense

    • attacker के scanning tools की vulnerabilities को target करने वाले “Exploitation Framework Frontend” के रूप में इस्तेमाल किया जा सकता है
  • Lightweight execution model

    • user space में चलता है
    • root privileges की जरूरत नहीं होती
    • प्रति running instance सिर्फ एक TCP port bind करता है
    • CPU और memory usage कम रहता है

Scanner और version detection को confuse करने का तरीका

  • simple port scan में port 1~20 जैसे छोटे range भी सभी open के रूप में दिखाई देते हैं
    • example output में tcpmux, compressnet, echo, daytime, ftp-data जैसे service names mix होकर दिखते हैं
  • version detection scan में service probes के लिए valid dynamic signatures लौटाए जाते हैं
    • ports 1~100 के example में irc, http, pop3, ssh, ftp, smtp, telnet, tor-control जैसी कई services और version strings दिखाई देती हैं
  • नतीजतन attacker के लिए system द्वारा वास्तव में इस्तेमाल किए जा रहे port numbers तय करना मुश्किल हो जाता है
  • full version scan nmap -sV -p- default tarpit settings में 10 घंटे से अधिक लेता है और सैकड़ों MB fake data generate करता है
  • scanner उन connections पर समय और threads खर्च करता है जो असली results तक नहीं ले जाते

Design approach: single-threaded epoll tarpit

  • SSH, SMTP, FTP, HTTP जैसी असली services banner भेजती हैं, connection बनाए रखती हैं और client input का इंतज़ार करती हैं
  • भरोसेमंद emulation को भी इसी तरह accept, send, hold flow follow करना चाहिए
  • प्रति client thread रखने वाला model memory और CPU खर्च करता है, और context switching cost के कारण defender पहले resources exhaust कर सकता है
  • Portspoof single-threaded epoll event loop का उपयोग करता है
    • हर port को startup पर delivery mode assign होता है
    • कुछ ports तुरंत banner भेजते हैं, कुछ client data के बाद respond करते हैं, और कुछ silent रहते हैं
    • hold time दसियों milliseconds से लेकर कई minutes तक कई orders of magnitude में distributed होता है
    • हर connection में jitter होता है, इसलिए same port को बार-बार detect करने पर भी identical timing नहीं लौटती
  • यह तरीका सभी ports पर garbage data भेजकर response timing measure करने वाले attacks को कठिन बनाता है
    • simple tarpit कुछ seconds तक connection पकड़े रख सकता है, जबकि real service wrong protocol पर जल्दी close हो सकती है
    • mixed mode और wide timing distribution में हजारों fake ports भी real services जैसी range में close होते हैं
    • filtering के लिए कोई साफ threshold नहीं बचता

Cost asymmetry

  • defender cost प्रति idle connection लगभग 1~2KB kernel memory है
  • epoll loop single-threaded है, इसलिए context switching overhead नहीं है
  • सामान्य स्तर का hardware भी 10,000 से अधिक concurrent connections संभाल सकता है
  • attacker cost समय और effort में shift हो जाती है
    • सिर्फ port scan से सभी ports open दिखते हैं, इसलिए meaningful information पाना कठिन होता है
    • real services खोजने के लिए सभी 65535 ports पर version detection और promising targets पर protocol-level detection चाहिए
    • 5-second scan 10 घंटे से अधिक की active task में बदल जाता है और result फिर भी haystack जैसा रहता है

v2.0 changes

  • v2.0 पुराने banner भेजकर connection close करने वाले तरीके से हटता है
  • पुराना तरीका Vicarius/Hored1971 blog post में discuss किए गए connection-close bypass के लिए vulnerable था
  • नया tarpit engine सभी connections को mixed timing के साथ open state में रखता है
  • इस तरीके का लक्ष्य connection-close filtering, timing fingerprinting, banner analysis, और statistical pattern modeling को रोकना है

Installation और basic configuration

  • build के लिए C++ compiler और CMake 3.10+ की जरूरत है
  • source build procedure इस प्रकार है
mkdir build && cd build
cmake -DCMAKE_INSTALL_SYSCONFDIR=/etc ..
make
sudo make install
  • Portspoof user space में चलता है, लेकिन दूसरे ports की तरफ जाने वाले traffic को intercept करने के लिए system firewall rules चाहिए
  • default port 4444 है, और real service ports को पहले exclude करने के बाद बाकी TCP traffic को Portspoof पर redirect किया जाता है
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 22 -j RETURN
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp -j REDIRECT --to-ports 4444
  • eth0 को actual network interface से बदलना चाहिए
  • जिन-जिन ports पर real services चल रही हैं, उनमें RETURN rule जोड़ना चाहिए
  • permanent application के लिए iptables rules save करना या system_files directory का iptables-config इस्तेमाल किया जा सकता है
  • startup scripts के लिए system_files/init.d/ के examples इस्तेमाल किए जा सकते हैं

Execution modes

  • Service emulation mode recommended mode है
    • port scanner को fake service signatures generate करके deliver करता है
portspoof -c /etc/portspoof.conf -s /etc/portspoof_signatures -D
  • custom tarpit timing -t और -T से specify की जाती है
    • example हर connection को 10~60 seconds तक hold करता है
portspoof -s /etc/portspoof_signatures -t 10 -T 60 -D
  • Open Port Mode service banner के बिना सभी connection attempts पर केवल OPEN state लौटाता है
    • connection फिर भी tarpit process होता है
portspoof -D
  • Fuzzing Mode scanning tools को random या wordlist-based payloads भेजने के लिए इस्तेमाल किया जा सकता है
portspoof -1 -v
portspoof -f payloads.txt -v

iptables-based hardening

  • केवल default REDIRECT rule से भी काम हो जाता है, लेकिन aggressive scanners connection count से Portspoof पर दबाव डाल सकते हैं
  • hardening rules rate limiting और automatic blocking जोड़ते हैं
    • real service ports को redirect से exclude करते हैं
    • example में SSH port 22 exclude किया गया है
    • global blocking rules real services पर भी apply होते हैं
  • rule example में ये elements शामिल हैं
    • loopback allow
    • PORTSCAN के रूप में marked IP को 60 seconds तक drop
    • प्रति source IP new SYN को 10 per second, burst 30 से ऊपर होने पर drop
    • यदि एक IP Portspoof port 4444 पर 100 से अधिक connections hold करता है, तो mark करके drop
    • established/related traffic और new SYN allow करने के बाद बाकी drop
  • high-traffic deployment में xt_recent list size बढ़ाया जा सकता है
echo "options xt_recent ip_list_tot=10000" > /etc/modprobe.d/xt_recent.conf
  • kernel connection tracking और backlog-related settings भी adjust की जा सकती हैं
sysctl -w net.netfilter.nf_conntrack_max=131072
sysctl -w net.core.somaxconn=4096

Portspoof Pro

  • Portspoof Pro deception को single host के बजाय पूरे network level तक expand करता है
  • एक single sensor पूरे /16 network को emulate करता है
    • हजारों IPs provide करता है
    • हर IP के सभी ports पर unique services होती हैं
    • stateful multi-stage conversations बनाए रखता है
  • network-wide deception capabilities provide करता है
    • dark IP space और unused subnets को active deception grid में बदलता है
    • हर emulated host source IP के अनुसार अलग personality वाली unique services present करता है
    • active tarpit attacker के socket pool को exhaust करता है और automation tools को throttle करता है
  • scan detection और tool fingerprinting support करता है
    • SYN, FIN, NULL, XMAS, ACK scan techniques detect करता है
    • Nmap, Masscan, ZMap, custom scanners की fingerprinting करता है
    • MITRE ATT&CK mapping वाली structured JSON telemetry को SIEM में stream करता है
  • operational environment deployment को ध्यान में रखता है
    • production traffic के पास sandbox environment में चलता है
    • routing policies deception traffic को sensor तक भेजती हैं
    • inline tap नहीं है और real workloads पर कोई risk नहीं है, ऐसा बताया गया है
  • NIS2, DORA, ISO 27001, NIST CSF, CIS Controls को support करता है

License और issue reporting

  • Portspoof GNU GPLv2 license का उपयोग करता है
  • commercial और legal applications के लिए appropriate license discussion हेतु author से संपर्क करने को कहता है
  • bugs और feature requests GitHub Issue Tracker या email से report किए जा सकते हैं

1 टिप्पणियां

 
GN⁺ 2024-12-26
Hacker News की राय
  • पोर्ट 65536 होते हैं, और पोर्ट 0 भी कुछ ऑपरेटिंग सिस्टमों में ऐसा पोर्ट है जिस पर इंटरनेट से पहुंच योग्य सेवा चलाई जा सकती है
    और अगर MariaDB डेवलपर देखें, तो इंटरनेट एक्सेस रोकने के लिए डेटाबेस को पोर्ट 0 पर listen कराने वाली default setting असल में काफी सारे सिस्टमों पर DB की इंटरनेट एक्सेस नहीं रोकती

    • MariaDB TCP socket पर listen करने से पहले साफ तौर पर जांचता है कि port 0 नहीं है: https://github.com/MariaDB/server/blob/ae998c22b2ce4f1023a6c...
      if (mysqld_port) का मतलब है कि mysqld_port 0 से अलग हो, और लगता है कि यह व्यवहार कम-से-कम MariaDB 5.5 से मौजूद है
    • Linux में भी चाहें तो port 0 इस्तेमाल किया जा सकता है। सीधे bind नहीं कर सकते, लेकिन firewall से port 0 को किसी दूसरे port पर redirect किया जा सकता है
  • Computer security आखिरकार ऊपर जैसी active defense की दिशा में लगातार evolve होने को मजबूर लगती है
    immune system कितना जटिल और कई layers वाला है, यह देखें तो लगता है कि किसी दिन computer या network भी कुछ वैसा ही दिखेगा

    • यह अब भी obfuscation पर निर्भर passive security के ज्यादा करीब लगता है। active defense तो ज्यादा वैसा होगा जैसे किसी known intruder को zip bomb वापस भेजकर उसका process kill कर देना
    • IT भी धीरे-धीरे mature हो रहा है। security की चिंता किए अभी कुछ दशकों ही हुए हैं, और उसका ज्यादातर हिस्सा मैंने खुद देखा है
      किसी दिन IT भी काफी परिपक्व field बन जाएगा, लेकिन आज अभी वह दिन नहीं है
    • immune system अक्सर allergy या cancer की तरह malfunction करके host को नुकसान भी पहुंचाता है, इसलिए मुझे यह analogy पसंद नहीं
      हालांकि अगर उन बातों को भी शामिल करें तो बल्कि चिंताजनक समानताएं दिखती हैं
    • AI अच्छी quality और depth वाले honeypot संभव बना सकता है। मौजूदा LLM क्षमताओं के लिए यह बिल्कुल फिट use case है, और बस इतना चाहिए कि वह credible लगे
    • मुझे नहीं लगता कि त्वचा मुंह होने का नाटक करती है
  • email harvesting spambots को रोकने के लिए, मैंने कभी अनंत random email address बनाने वाला web page बनाया था: http://web.archive.org/web/20020610054821/http://www.sourtim...

  • ऐसा कुछ चलाने पर, कोई मेरी machine scan करके “X का known vulnerable version चल रहा है” कहते हुए दर्जनों bug bounty requests भेज सकता है

  • 90 के दशक के मध्य में CyberCop Sting नाम का honeypot product था, और यह Secure Networks के Ballista से पहले आया था
    CyberCop Sting कई implementations के TCP/UDP services simulate कर सकता था, और अगर मेरी याद सही है तो अलग-अलग operating systems जैसा दिखने के लिए TCP/IP stack behavior भी configure किया जा सकता था। करीब 30 साल पहले के हिसाब से यह काफी innovative feature था
    [1] https://theswissbay.ch/pdf/Gentoomen%20Library/Security/0321...
    [2] https://news.ycombinator.com/item?id=26440139

    • दिलचस्प। मैं पूछने ही वाला था कि क्या कोई similar project रहा है
      जाहिर है किसी ने यह किया होगा, फिर भी यह थोड़ा हैरान करता है कि पहले कभी मेरे मन में यह बात नहीं आई, और उससे भी ज्यादा कि मैं यह idea पहली बार सुन रहा हूं
  • ऐसा करने से अंत में शायद hackers या bots server को और detail में देखने लगेंगे, या कम-से-कम traffic ज्यादा बढ़ेगा
    मुझे नहीं लगता कि ज्यादातर script kiddies अपने tools में potential honeypot या ऐसे mechanisms को filter कर रहे होंगे

    • अगर 3 random services ऐसी दिखें जिन्हें अब कोई इस्तेमाल नहीं करता, तो server पर portspoof चल रहा है यह जल्दी सामने आ जाएगा
      लेकिन host alive है यह पता चलने के बाद सवाल यह है कि किस port को छेड़ा जाए। अगर हर server के हर port को scan या attack करने की cost समान मानें, तो spoofed ports को अलग पहचान पाने पर भी ज्यादा success probability वाली दूसरी machine ढूंढना बेहतर है। local 127.0.0.35 पर portspoof चलाकर response data या timing differences compare भी किए जा सकते हैं, लेकिन search space आम तौर पर खुले कुछ ports की तुलना में अचानक करीब 5000 गुना बड़ा हो जाता है, और दूसरे server के ports ज्यादा सफल होने की संभावना वाले लग सकते हैं
    • common ports पर plausible banner लौटाना कम दिखाई देने के बजाय ज्यादा जांच-पड़ताल करवाने की संभावना रखता है
      ज्यादातर tools इस स्थिति को ध्यान में नहीं रखते कि सभी ports खुले हैं और false positives दिखा रहे हैं। penetration testing में यह common situation है और समय बर्बाद कराती है, लेकिन मैं attacker को अपनी infrastructure और देखने की वजह नहीं देना चाहूंगा। इसके बजाय मुझे इस तरीके के लगभग उलट port knocking पसंद है
    • मैं network security expert नहीं हूं, लेकिन जो असली है यह पता लगाने के लिए जितना traffic चाहिए, उस दौरान दूसरे detection mechanisms में पकड़े जाने की संभावना ज्यादा है
    • अगर चिंता large-scale internet scans की है, तो इसका drawback दिखता है। लेकिन अगर चिंता किसी specific attacker द्वारा सिर्फ organization की IP range scan करने की है, तो यह काफी बाधा डाल सकता है
    • थोड़ा सोचें तो लगता है कि जिस threat model में यह tool मददगार है, वह सीमित होगा
      व्यापक attacks के खिलाफ असर के लिए इसे करोड़ों hosts पर deploy होना पड़ेगा, तभी attacker के लिए सिर्फ honeypots ढूंढकर उनसे interact करना अव्यावहारिक होगा। अगर targeted attack हो रहा है, तो honeypot ports को exploit करने की कोशिश में थोड़ी delay हो सकती है, लेकिन अगर vulnerable service चला रहे हैं तो आखिरकार breach हो जाएगा। और अगर आप vendor हैं, तो potential customer की security team के scan करने पर बहुत परेशान करने वाले security questionnaire का जवाब देना पड़ सकता है
  • मेरी वेबसाइट पर भी ऐसा ही कुछ चलता है। https://bini.wales सभी endpoints पर 200 लौटाता है और हर कोशिश को log करता है, इसलिए automated attacks के लिए एक ठीक-ठाक honeypot बन जाता है
    ज़्यादातर कमजोर WordPress plugins या छोड़े गए backdoors को mass-scan करने वाली चीज़ें पकड़ता है। इसी तरह https://varun.ch/login थोड़े twist के साथ WordPress site की नकल करता है

    • आप जो भी लौटाएँ, WordPress scan वैसे भी आएँगे
  • अच्छा है। खुशी है कि “honeypot” शब्द एक बार भी नहीं आया
    पहले मुझे एक “असली” honeypot विरासत में मिला था; देखा तो करीब 30 ports खुले थे, और सचमुच मेरे मुँह से निकला, “ये क्या कचरा है”

    • मुझे लगता है honeypot का काम ही यही तो है
      ports खुले छोड़ना ताकि script kiddie को लगे कि उसने कुछ access कर लिया है और वह उत्साहित हो जाए, जबकि असल में वहाँ कुछ भी नहीं है। locked-down honeypot उस point पर ज़्यादा honeypot जैसा नहीं लगता
    • हो सकता है हम दोनों में से कोई एक honeypot शब्द को गलत समझ रहा हो, शायद मैं ही। फिर भी यह network के अंदर honeypot system बनाने के लिए काफी उपयोगी लगता है
      honeypot attackers को आकर्षित करने और detect करने के लिए इस्तेमाल होते हैं, और आम तौर पर उनके behavior और patterns को log करके analysis या blocking की जाती है। इस tool में iptables के अलावा और logging होती तो अच्छा रहता; यह अपने-आप में honeypot नहीं है, लेकिन idea उससे बहुत दूर भी नहीं है। हालांकि GitHub page का यह कहना कि यह “OS security को मजबूत करता है”, मुझे बिल्कुल भरोसेमंद नहीं लगता। यह automated service scanners के खिलाफ थोड़ी obfuscation देगा, लेकिन अगर MySQL server 3306 पर listen कर रहा है और attacker 3306 से connect करता है, तो वह फिर भी MySQL से ही बात कर रहा होगा। बाकी 65534 ports garbage responses दे रहे हैं या नहीं, इससे फर्क नहीं पड़ता
  • इसमें लिखा है कि “चल रहा हर instance सिर्फ एक TCP port से bind करता है”; सोच रहा हूँ यह काम कैसे करता है
    सारे ports cover करने के लिए क्या 65535 instances चलाने पड़ेंगे?

    • iptables rule मशीन के सभी closed ports को उस single port पर redirect करता है जिस पर portspoof listen कर रहा होता है: https://github.com/drk1wi/portspoof/blob/c3f3c34531c59df229e...
      फिर getsockopt call करके पता लगाता है कि original port कौन सा था: https://github.com/drk1wi/portspoof/blob/c3f3c34531c59df229e...
    • यह NAT redirection है
    • एक single process कई ports से bind कर सकता है, तो यह क्यों नहीं हो सकता समझ नहीं आता
      actual hard limit या memory usage का पता नहीं, लेकिन शायद port redirect ज्यादा सरल होगा
  • क्या यह संभावित रूप से DoS amplifier भी बन सकता है?
    सही तरीके से spoofed packets भेजने पर क्या यह दिखने वाले source को बहुत सारे packets वापस भेज सकता है?

    • अगर TCP service है, तो “client” सही ACK packet भेजकर 3-way handshake पूरा करने से पहले यह बड़े packets नहीं भेजेगी
      UDP होता तो यह सचमुच बेतुकी समस्या बन सकती थी
    • amplification attacks मुख्य रूप से UDP में समस्या होते हैं। क्योंकि UDP में यह verify करने की प्रक्रिया नहीं होती कि return path वाकई संभव है, जबकि TCP में होती है