Rey의 Open Source Software 이야기

iptables cookbook

by Rey on 4.19, 2011, under Linux

1. iptables로 ssh brute force attack 방어

iptables -N blacklist
iptables -N ssh
iptables -A INPUT -m state --state NEW -p tcp --dport ssh -j ssh
iptables -A blacklist -m recent --set --name blacklist
iptables -A blacklist -j REJECT
iptables -A ssh -m recent --update --seconds 600 --hitcount 1 --name blacklist -j REJECT
iptables -A ssh -m recent --set --name ssh
iptables -A ssh -m recent --update --seconds 20 --hitcount 5 --name ssh -j blacklist
iptables -A ssh -j ACCEPT

2. ssh 접속을 했을때 80 포트를 열어 웹서비스를 이용할수 있게 하기

ssh 포트로 접속이 이루어져 패킷 교환이 이루어 지면 goodhttp 에 해당 정보를 넣고서 해당 IP 에 대하여 80 포트 접속 허용

iptables -A INPUT -m state –state ESTABLISHED -p tcp –dport ssh -m recent –set –name goodhttp
iptables -A INPUT -p tcp -m tcp –dport 80 -m recent –rcheck –second 10 –name goodhttp -j ACCEPT
사내 IP 80 포트 접속 허용 하고 나머지는 모두 거부

iptables -A INPUT -s xxx.xxx.xxxx.xxx/24 -p tcp -m tcp –dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m tcp –dport 80 -j REJECT

일반 계정으로 접속했을때에는 watch -n 8 date 등을 실해 시켜야 웹페이지를 계속 볼수 있고 임의 의 계정을 만들어 기본 쉘 대신 에 일정 패킷을 주고 받으면서 유지 할수 있도록.. /etc/passwd 파일에 shell 부분에 아래 와 유사한 스크립트로 대체

#!/bin/bash
watch -n 8 cal
 

 

Mega World News Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google Yahoo Buzz StumbleUpon Weekend Joy

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
:,

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!