All pastes #391904 Raw Edit

LachienneSSHMarchepa

public text v1 · immutable
·published 2007-03-12 14:59 UTC
rendered paste body
elie@zerox ~ $ cat /etc/hosts.allow
ALL:127.0.0.1,192.168.
ssh:ALL
elie@zerox ~ $ cat /etc/hosts.deny
ALL:ALL
elie@zerox ~ $ cat /etc/conf.d/net.rules.ppp0
#!/bin/bash

IPTABLES="$(which iptables)"
TC="$(which tc)"


IF="ppp0"
SUBNET="192.168.0.0/16"

function start {
	echo 0 >/proc/sys/net/ipv4/ip_forward
	
	modprobe ip_conntrack_netlink
	
	$IPTABLES -P INPUT ACCEPT
	$IPTABLES -P OUTPUT ACCEPT
	$IPTABLES -P FORWARD ACCEPT
	
	$IPTABLES -t nat -P POSTROUTING ACCEPT
	$IPTABLES -t nat -P PREROUTING ACCEPT
	
	$IPTABLES -t mangle -P OUTPUT ACCEPT
	$IPTABLES -t mangle -P PREROUTING ACCEPT
	
	# Pare-feu
	$IPTABLES -A INPUT -i $IF -p tcp --dport 23 -j DROP # telnet
	$IPTABLES -A INPUT -i $IF -p tcp --dport 79 -j DROP # finger
	$IPTABLES -A INPUT -i $IF -p tcp --dport 135 -j DROP # smb
	$IPTABLES -A INPUT -i $IF -p tcp --dport 139 -j DROP # smb
	$IPTABLES -A INPUT -i $IF -p tcp --dport 445 -j DROP # smb
	$IPTABLES -A INPUT -i $IF -p tcp --dport 512:514 -j DROP # insecure login
	$IPTABLES -A INPUT -i $IF -p tcp --dport 6000:6009 -j DROP # X11
	$IPTABLES -A INPUT -i $IF -p tcp --dport 7100 -j DROP # X Font Server
	
	$IPTABLES -A INPUT -p icmp --icmp-type 0 -j ACCEPT
	$IPTABLES -A INPUT -p icmp --icmp-type 3 -j ACCEPT
	$IPTABLES -A INPUT -p icmp --icmp-type 11 -j ACCEPT
	$IPTABLES -A INPUT -p icmp --icmp-type 8 -m limit --limit 2/second -j ACCEPT
	$IPTABLES -A INPUT -i $IF -p icmp --icmp-type echo-request -j DROP
	
	# Masquerading
	$IPTABLES -t nat -A POSTROUTING -s $SUBNET ! -d $SUBNET -o $IF -j MASQUERADE
	
	$IPTABLES -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
	
	
	# Mise en forme du traffic
	$TC qdisc add dev $IF root handle 1: htb default 12
	
	$TC class add dev $IF parent 1: classid 1:1 htb rate 110kbit ceil 110kbit
	
	$TC class add dev $IF parent 1:1 classid 1:11 htb rate 70kbit ceil 110kbit prio 1 burst 5k # Haute priorité
	$TC class add dev $IF parent 1:1 classid 1:12 htb rate 24kbit ceil 110kbit prio 2 burst 2k # Moyenne priorité : HTTP, IM, ..
	$TC class add dev $IF parent 1:1 classid 1:13 htb rate 16kbit ceil 110kbit prio 3 burst 512 # Très basse priorité
	$TC class add dev $IF parent 1:13 classid 1:131 htb rate 8kbit ceil 110kbit prio 3 burst 512 # Bittorrent, ..
	$TC class add dev $IF parent 1:13 classid 1:132 htb rate 4kbit ceil 110kbit prio 4 burst 512 # FTP, ..
	$TC class add dev $IF parent 1:13 classid 1:133 htb rate 4kbit ceil 110kbit prio 5 burst 512 # eMule, ..
	
	$TC qdisc add dev $IF parent 1:11 handle 21:0 pfifo limit 20
	$TC qdisc add dev $IF parent 1:12 handle 22:0 sfq perturb 10
	$TC qdisc add dev $IF parent 1:131 handle 231:0 sfq perturb 20
	$TC qdisc add dev $IF parent 1:132 handle 232:0 sfq perturb 20
	$TC qdisc add dev $IF parent 1:133 handle 233:0 sfq perturb 20
	
	
	
	# ACK
	$TC filter add dev $IF parent 1: protocol ip prio 1 u32 \
		match ip protocol 6 0xff \
		match u8 0x05 0x0f at 0 \
		match u16 0x0000 0xffc0 at 2 \
		match u8 0x10 0xff at 33 \
		flowid 1:11
	
	for i in 7757 7758 7777 7778 7787 7788; do
		$IPTABLES -t mangle -A POSTROUTING -o $IF -p udp --sport $i -j MARK --set-mark 3
		$IPTABLES -t mangle -A POSTROUTING -o $IF -p udp --dport $i -j MARK --set-mark 3
	done
	for i in 28902 42292 27900; do
		$IPTABLES -t mangle -A POSTROUTING -o $IF -p tcp --sport $i -j MARK --set-mark 3
		$IPTABLES -t mangle -A POSTROUTING -o $IF -p tcp --dport $i -j MARK --set-mark 3
	done

	$IPTABLES -t mangle -A PREROUTING -i $IF -j NFQUEUE
	$IPTABLES -t mangle -A POSTROUTING -o $IF -j NFQUEUE
	start-stop-daemon -S -x $(which l7-filter) -b -p /var/run/l7-filter.pid -m -- -f /etc/l7-filter.conf -s # marche pas..
	
	$TC filter add dev $IF parent 1: protocol ip handle 3 fw flowid 1:11
	$TC filter add dev $IF parent 1: protocol ip handle 4 fw flowid 1:12
	$TC filter add dev $IF parent 1: protocol ip handle 51 fw flowid 1:131
	$TC filter add dev $IF parent 1: protocol ip handle 52 fw flowid 1:132
	$TC filter add dev $IF parent 1: protocol ip handle 53 fw flowid 1:133
	
	echo 1 >/proc/sys/net/ipv4/ip_forward
}

function stop {
	start-stop-daemon -K -p /var/run/l7-filter.pid -o >/dev/null 2>&1
	$IPTABLES -t mangle -F
	$IPTABLES -t nat -F
	$IPTABLES -F
	$IPTABLES -X
	$IPTABLES -Z
	$TC qdisc del dev $IF root >/dev/null 2>&1
}


case "$1" in
"stop")
stop
;;

"start")
stop
start
;;
esac


elie@zerox ~ $ cat /etc/ssh/sshd_config
#	$OpenBSD: sshd_config,v 1.74 2006/07/19 13:07:10 dtucker Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
Protocol 2
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile	.ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no

#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no

# no default banner path
#Banner /some/path

# override default of no subsystems
Subsystem	sftp	/usr/lib/misc/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	ForceCommand cvs server