knockd funktioniert nicht - bekomme keine Fehlermeldung

Alle weiteren Dienste, die nicht in die drei oberen Foren gehören.
Antworten
cosphi
Beiträge: 136
Registriert: 06.12.2008 08:33:46
Lizenz eigener Beiträge: MIT Lizenz

knockd funktioniert nicht - bekomme keine Fehlermeldung

Beitrag von cosphi » 12.07.2014 08:02:50

Hallo,
ich würde gerne knockd für openssh & openvpn einrichten.
Dazu habe ich mal eine Testkonfiguration erstellt.

Code: Alles auswählen

[test]
  sequence= 8000:tcp,8010:udp,8006:udp,8000:udp
  tcpflags= syn
  seq_timeout= 15
  cmd_timeout= 30
  start_command= sudo wall /tmp/open.txt
  stop_command= sudo wall /tmp/close.txt
Beim starten des Dienstes kommen keine Fehlermeldungen

Code: Alles auswählen

root@fry:/tmp# /etc/init.d/knockd restart
[ ok ] Stopping Port-knock daemon: knockd.
[ ok ] Starting Port-knock daemon: knockd.
Beim ausführen von

Code: Alles auswählen

root@fry:/tmp# knock -v 192.168.1.2 8000:tcp 8010:udp 8006:udp 8000:udp
hitting tcp 192.168.1.2:8000
hitting udp 192.168.1.2:8010
hitting udp 192.168.1.2:8006
hitting udp 192.168.1.2:8000
passiert leider gar nix :-(

hat jemand eine Idee?

Edit:

Code: Alles auswählen

root@fry:/tmp# cat /var/log/knockd.log
[2014-07-12 08:50] starting up, listening on eth0

Moo
Beiträge: 25
Registriert: 15.11.2013 11:41:53

Re: knockd funktioniert nicht - bekomme keine Fehlermeldung

Beitrag von Moo » 12.07.2014 12:03:55

Code: Alles auswählen

knockd --debug --verbose
Quelle: http://wiki.hetzner.de/index.php/Knockd

cosphi
Beiträge: 136
Registriert: 06.12.2008 08:33:46
Lizenz eigener Beiträge: MIT Lizenz

Re: knockd funktioniert nicht - bekomme keine Fehlermeldung

Beitrag von cosphi » 12.07.2014 20:28:51

Vielen Dank.
Das hat aber nicht zur Lösung geführt...
Nach einem kompletten reboot ging es. :roll:

cosphi
Beiträge: 136
Registriert: 06.12.2008 08:33:46
Lizenz eigener Beiträge: MIT Lizenz

Re: knockd funktioniert nicht - bekomme keine Fehlermeldung

Beitrag von cosphi » 14.07.2014 17:11:19

Ich habe jetzt nochmal eine Frage. Leider bin ich noch nicht sicher im Umgang mit iptables und bevor ich mich aussperre frag ich mal. :-)

Mit diesem Skript sollte bis auf die ausgehende Verbindungen NTP, DNS und HTTP (für updates) alles blockiert sein.

Code: Alles auswählen

#!/bin/sh
 
iptables=/sbin/iptables
 
# wenn iptables nicht installiert abbrechen
test -f $iptables || exit 0
 
case "$1" in
   start)
      echo "Starte Firewall..."
      # alle Regeln löschen
      $iptables -t nat -F
      $iptables -t filter -F
      $iptables -X
 
      # neue Regeln erzeugen
      $iptables -N garbage
      $iptables -I garbage -p TCP -j LOG --log-prefix="DROP TCP-Packet: " --log-level error
      $iptables -I garbage -p UDP -j LOG --log-prefix="DROP UDP-Packet: " --log-level error
      $iptables -I garbage -p ICMP -j LOG --log-prefix="DROP ICMP-Packet: " --log-level error
 
      # Default Policy
      $iptables -P INPUT DROP
      $iptables -P OUTPUT DROP
      $iptables -P FORWARD DROP
 
      # über Loopback alles erlauben
      $iptables -I INPUT -i lo -j ACCEPT
      $iptables -I OUTPUT -o lo -j ACCEPT
 
      #####################################################
      # ausgehende Verbindungen
      ## FTP (Port 21)
      #$iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 21 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      #$iptables -I INPUT -i eth0 -p TCP --sport 21 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      #$iptables -I OUTPUT -o eth0 -p TCP --sport 49152:65535 --dport 20 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      #$iptables -I INPUT -i eth0 -p TCP --sport 20 --dport 49152:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      ## SSH (Port 22)
      #$iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 22 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      #$iptables -I INPUT -i eth0 -p TCP --sport 22 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      # DNS (Port 53)
      $iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      $iptables -I INPUT -i eth0 -p TCP --sport 53 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      $iptables -I OUTPUT -o eth0 -p UDP --sport 1024:65535 --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      $iptables -I INPUT -i eth0 -p UDP --sport 53 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      # HTTP (Port 80)
      $iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      $iptables -I INPUT -i eth0 -p TCP --sport 80 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      # NTP (Port 123)
      $iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 123 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      $iptables -I INPUT -i eth0 -p TCP --sport 123 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      $iptables -I OUTPUT -o eth0 -p UDP --sport 1024:65535 --dport 123 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      $iptables -I INPUT -i eth0 -p UDP --sport 123 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      ## HTTPS (Port 443)
      #$iptables -I OUTPUT -o eth0 -p TCP --sport 1024:65535 --dport 443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      #$iptables -I INPUT -i eth0 -p TCP --sport 443 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
      # ICMP
      $iptables -I OUTPUT -o eth0 -p ICMP --icmp-type echo-request -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      $iptables -I INPUT -i eth0 -p ICMP --icmp-type echo-reply -m state --state ESTABLISHED,RELATED -j ACCEPT
 
      #####################################################
      # Erweiterte Sicherheitsfunktionen
      # SynFlood
      $iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
      # PortScan
      $iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
      # Ping-of-Death
      $iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
      ## HTTP Limit pro Minute
      #$iptables -A INPUT -i eth0 -p tcp --dport 80 -j LOG --log-prefix "Apache Access" --log-level 6 -m limit --limit 3/m
 
      #####################################################
      # bestehende Verbindungen akzeptieren
      $iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
      $iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
 
      #####################################################
      # Garbage übergeben wenn nicht erlaubt
      $iptables -A INPUT -m state --state NEW,INVALID -j garbage
 
      #####################################################
      # alles verbieten was bisher erlaubt war
      $iptables -A INPUT -j garbage
      $iptables -A OUTPUT -j garbage
      $iptables -A FORWARD -j garbage
      ;;
	  
   stop)
      echo "Stoppe Firewall..."
      $iptables -t nat -F
      $iptables -t filter -F
      $iptables -X
      $iptables -P INPUT ACCEPT
      $iptables -P OUTPUT ACCEPT
      $iptables -P FORWARD ACCEPT
      ;;
	  
   restart|reload|force-reload)
   $0 stop
   $0 start
      ;;
   *)
      echo "Usage: /etc/init.d/firewall (start|stop)"
      exit 1
      ;;
esac
exit 0
Was muss ich denn machen um SSH am Ende per knockd wieder zu verbieten?

Bzw. wie kann ich meine Freigabe von SSH aus der den INPUT / OUTPUT Ketten löschen?
Für

Code: Alles auswählen

iptables -D <Kette> <num>
muss ich ja die Position wissen...
Kennt jemand eine andere Möglichkeit?

Code: Alles auswählen

 
      /sbin/iptables -I INPUT -i eth0 -p TCP --sport 1024:65535 --dport 22 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
      /sbin/iptables -I OUTPUT -o eth0 -p TCP --sport 22 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
 
Vielen Dank

Lookbehind
Beiträge: 143
Registriert: 12.08.2011 18:09:13

Re: knockd funktioniert nicht - bekomme keine Fehlermeldung

Beitrag von Lookbehind » 24.07.2014 18:12:33

Hi, ich benutze in meinem knockd folgende Kommandos um den Zugriff zu erlauben und anschließend wieder dicht zu machen:

Code: Alles auswählen

[options]
       logfile = /var/log/knockd.log
      
[SSH]
       sequence    = sach,ich,nich
       seq_timeout = 30
       command     = /sbin/iptables -I INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
       tcpflags    = syn
       cmd_timeout   = 30
       stop_command  = /sbin/iptables -D INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
Das funktioniert auch nach dem 30 Sekunden Time-Out noch, da die eigentliche SSH-Verbindung über einen random High-Port läuft, den Client und Server bei Verbindungsaufbau aushandeln. Somit braucht Port 22 nur für die paar Sekunden beim Login offen zu sein.
Im Unterschied zu dir blockiere ich Port 22 allerdings nur auf input.

Antworten