DenyHosts로 sshd brute-force attack 막기

What is DenyHosts?

“DenyHosts is a script intended to be run by Linux system administrators to help
thwart SSH server attacks (also known as dictionary based attacks and brute force

If you’ve ever looked at your ssh log (/var/log/secure on Redhat, /var/log/auth.log on Mandrake, etc…) you may be
alarmed to see how many hackers attempted to gain access to your server. Hopefully, none of them were successful (but
then again, how would you know?). Wouldn’t it be better to automatically prevent that attacker from continuing to gain
entry into your system?

DenyHosts attempts to address the above..”

사용된 버전: DenyHosts-2.6

1. python 설치(설치 안되어 있을 경우)

fs> ipkg install python24

2. DenyHosts-2.6.tar.gz 다운로드:

3. DenyHosts-2.6 설치

fs> tar xvzf DenyHosts-2.6.tar.gz
cd DenyHosts-2.6
python install
fs> cp -R DenyHosts /usr/share/denyhosts
fs> ln -s /usr/share/denyhosts/DenyHosts /usr/bin/DenyHosts
fs> cd /usr/share/denyhosts
cp denyhosts.cfg-dist denyhosts.cfg

fs> cp daemon-control-dist daemon-control
fs> chown root daemon-control
chmod 700 daemon-control

4. /usr/share/denyhosts/denyhosts.cfg 수정

# Debian:
SECURE_LOG = /var/log/messages

# Another possibility (also see the next option):
HOSTS_DENY = /etc/hosts.evil


# Debian
LOCK_FILE = /var/run/

# To enable synchronization, you must uncomment the following line:

# The default is SYNC_UPLOAD = yes

# The default is SYNC_DOWNLOAD = yes

5. /usr/share/denyhosts/daemon-control 수정

DENYHOSTS_LOCK = “/var/run/”

6. /etc/hosts.deny 설정

ALL: /etc/hosts.evil

7. 차단할 IP 주소를 기록할 파일 생성

fs> touch /etc/hosts.evil

8. 자동 실행 설정: /etc/rc.local 수정

# denyhosts
/usr/share/denyhosts/daemon-control start

9. DenyHosts 실행(최초 1회)

fs> /usr/share/denyhosts/daemon-control start

10. /etc/hosts.evil 확인: 아래와 같은 형식으로 공격자의 IP 주소가 기록됨

*. 참고사항
/usr/share/denyhosts/daemon-control start 실행 시 다음과 같은 에러가 발생할 경우

starting DenyHosts:    /usr/bin/env python /usr/bin/ –daemon –config=/usr/share/denyhosts/denyhosts.cfg
Traceback (most recent call last):
  File “/usr/bin/”, line 5, in ?
    import DenyHosts.python_version
  File “/usr/bin/”, line 5, in ?
    import DenyHosts.python_version
ImportError: No module named python_version

에는 다음과 같이 처리하면 됩니다.

fs> cp -R DenyHosts /usr/share/denyhosts
fs> ln -s /usr/share/denyhosts/DenyHosts /usr/bin/DenyHosts

설치 과정은 다음 사이트를 참고하였습니다.

2 thoughts to “DenyHosts로 sshd brute-force attack 막기”

  1. user> python install
    -ash: python: not found

    라면서 진행이 안되는데, 분명히 ipkg install python24 해서 설치가 된 것 같거든요? 혹시 무슨 문제인지 알고 계실까요? 제가 워낙 초보라;;

    1. python이 제대로 설치가 안된 거 같습니다.
      ll /opt/bin/python
      명령을 내려보세요..
      전 위 명령을 내리니
      /opt/bin/python -> python2.5
      이렇게 되어 있네요.. 이 글을 작성한 후 업데이트 되어서 2.5로 나온 것 같습니다.
      혹시 /opt/bin/python이 없다면
      ln -s /opt/bin/python2.4 /opt/bin/python
      명령으로 링크를 걸어주세요.

답글 남기기

이메일은 공개되지 않습니다.