불법 로그인 시도 차단을 위한 fail2ban

Apache, SSL, SSH, telnet, ftp, webmin과 같이 로그인이 필요한 다양한 응용프로그램에 대해서

불법적인 로그인을 시도하면 이를 자동으로 감지해서 자동으로 차단시켜준다.

iptable을 이용하기 때문에 커널을 직접 빌드할 때는 Socket Filtering이 활성화되어 있어야 한다.

이와 같은 구현을 성능상의 문제로 커널단에서 직접 구현해서 최적화하는 경우도 있지만

범용성 보다는 프로토타입 형태인 경우가 많다.
(시도해보고 싶은 분들은 SSH 로그인시도, DoS 공격 시도 같은 것을 탐지해서 차단하는 기능을
커널단에서 직접 구현해보면 된다. 한 가지만 골라서 하는 것이 좋다)

fail2ban은 정규식을 이용한다. 정규식은 학습이 필요하지만 필터를 만들 필요가 있다면 그때가서 사용하고,

기본으로 대부분의 것들을 지원하니 공부하지 말자.

apt-get install fail2ban

한 방이면 된다. 데몬으로 실행되면서 설정까지 끝난다

/etc/fail2ban/jail.conf

에 보면 maxretry 3인데 5로 늘려서, 최대 5번 정도는 봐주자.

bantime은 시도횟수를 초과하면 600초 동안 금지한다. 좀 가혹하게 하고 싶다면 3600으로 설정해서

한시간 동안 접근금지 시키자.

jail.conf에 보면

[ssh]

enabled = true
port  = ssh,sftp
filter  = sshd
logpath  = /var/log/auth.log
maxretry = 6

[apache]

enabled = false
port  = http,https
filter  = apache-auth
logpath = /var/log/apache*/*access.log
maxretry = 6

# default action is now multiport, so apache-multiport jail was left
# for compatibility with previous (<0.7.6-2) releases
[apache-multiport]

enabled   = false
port    = http,https
filter    = apache-auth
logpath   = /var/log/apache*/*access.log
maxretry  = 6

[apache-noscript]

enabled = false
port    = http,https
filter  = apache-noscript
logpath = /var/log/apache*/*error.log
maxretry = 6

이렇게 되어 있는데, 각각의 섹션은 [section]으로 되어 있다.

ssh와 apache에도 적용하고 싶다면 enabled = true로 전부 바꿔주자.

출처 : http://www.jiny.kr/jiny/253

apt-get gpg error 발생시..

 한번씩 apt-get update 를 이용하여 업데이트 버전을 확인할때

 GPG Error 메시지를 확인할 때가 있다.

 이를 해결하는 방법에는 여러가지가 있는데…

 그 중 첫번째가

 http://wwwkeys.eu.pgp.net/ 에서 해당 저장소의 GPG 키를 확인하여 추가한 후, 이를 apt-key 로 추가하는 방법이 있다.

 이에 관한 자세한 설명은

http://syyune.egloos.com/2390377

 에서 확인할 수 있따.

 그리고 두번째 방법은 아래의 명령어를 입력하기만 하면 된다.

 apt-get install debian-archive-keyring

존 포스텔(Jonathan B. Postel, Jon Postel) – 인터넷 선구자

 IANA(Internet Assigned Numbers Authority) 는 모든 IP 주소, 최상위 도메인, 인터넷 프로토콜 포트 할당을 책임지는 기관이다. 1998년까지 이 기관은 엔지니어이자 컴퓨터 과학자인 포스텔(Jonathan B. Postel, Jon Postel) 단 1명이 운영했다. 포스텔은 실질적으로 인터넷의 동작 방식을 정의한 RFC(Requests for Comment) 문서 시리즈의 편집자로 유명하다. 그의 인터넷에 대한 공헌도가 너무 대단해 그의 업적을 기리기 위한 RFC(RFC 2468)가 따로 제정될 정도다. 이 RFC는 www.ietf.org/rfc/rfc2468.txt 에서 확인할 수 있다.

 아래는 그 RFC의 전문이다.





Network Working Group V. Cerf
Request for Comments: 2468 MCI
Category: Informational October 1998


I REMEMBER IANA

October 17, 1998


Status of this Memo

This memo provides information for the Internet community. It does
not specify an Internet standard of any kind. Distribution of this
memo is unlimited.

Copyright Notice

Copyright (C) The Internet Society (1998). All Rights Reserved.

Remembrance

A long time ago, in a network, far far away, a great adventure took
place!

Out of the chaos of new ideas for communication, the experiments, the
tentative designs, and crucible of testing, there emerged a
cornucopia of networks. Beginning with the ARPANET, an endless
stream of networks evolved, and ultimately were interlinked to become
the Internet. Someone had to keep track of all the protocols, the
identifiers, networks and addresses and ultimately the names of all
the things in the networked universe. And someone had to keep track
of all the information that erupted with volcanic force from the
intensity of the debates and discussions and endless invention that
has continued unabated for 30 years. That someone was Jonathan B.
Postel, our Internet Assigned Numbers Authority, friend, engineer,
confidant, leader, icon, and now, first of the giants to depart from
our midst.

Jon, our beloved IANA, is gone. Even as I write these words I cannot
quite grasp this stark fact. We had almost lost him once before in
1991. Surely we knew he was at risk as are we all. But he had been
our rock, the foundation on which our every web search and email was
built, always there to mediate the random dispute, to remind us when
our documentation did not do justice to its subject, to make
difficult decisions with apparent ease, and to consult when careful
consideration was needed. We will survive our loss and we will
remember. He has left a monumental legacy for all Internauts to



Cerf Informational [Page 1]

RFC 2468 I REMEMBER IANA October 1998


contemplate. Steadfast service for decades, moving when others
seemed paralyzed, always finding the right course in a complex
minefield of technical and sometimes political obstacles.

Jon and I went to the same high school, Van Nuys High, in the San
Fernando Valley north of Los Angeles. But we were in different
classes and I really didn't know him then. Our real meeting came at
UCLA when we became a part of a group of graduate students working
for Professor Leonard Kleinrock on the ARPANET project. Steve
Crocker was another of the Van Nuys crowd who was part of the team
and led the development of the first host-host protocols for the
ARPANET. When Steve invented the idea of the Request for Comments
series, Jon became the instant editor. When we needed to keep track
of all the hosts and protocol identifiers, Jon volunteered to be the
Numbers Czar and later the IANA once the Internet was in place.

Jon was a founding member of the Internet Architecture Board and
served continuously from its founding to the present. He was the
FIRST individual member of the Internet Society I know, because he
and Steve Wolff raced to see who could fill out the application forms
and make payment first and Jon won. He served as a trustee of the
Internet Society. He was the custodian of the .US domain, a founder
of the Los Nettos Internet service, and, by the way, managed the
networking research division of USC Information Sciences Institute.

Jon loved the outdoors. I know he used to enjoy backpacking in the
high Sierras around Yosemite. Bearded and sandaled, Jon was our
resident hippie-patriarch at UCLA. He was a private person but fully
capable of engaging photon torpedoes and going to battle stations in
a good engineering argument. And he could be stubborn beyond all
expectation. He could have outwaited the Sphinx in a staring
contest, I think.

Jon inspired loyalty and steadfast devotion among his friends and his
colleagues. For me, he personified the words "selfless service".
For nearly 30 years, Jon has served us all, taken little in return,
indeed sometimes receiving abuse when he should have received our
deepest appreciation. It was particularly gratifying at the last
Internet Society meeting in Geneva to see Jon receive the Silver
Medal of the International Telecommunications Union. It is an award
generally reserved for Heads of State, but I can think of no one more
deserving of global recognition for his contributions.

While it seems almost impossible to avoid feeling an enormous sense
of loss, as if a yawning gap in our networked universe had opened up
and swallowed our friend, I must tell you that I am comforted as I
contemplate what Jon has wrought. He leaves a legacy of edited
documents that tell our collective Internet story, including not only



Cerf Informational [Page 2]

RFC 2468 I REMEMBER IANA October 1998


the technical but also the poetic and whimsical as well. He
completed the incorporation of a successor to his service as IANA and
leaves a lasting legacy of service to the community in that role.
His memory is rich and vibrant and will not fade from our collective
consciousness. "What would Jon have done?", we will think, as we
wrestle in the days ahead with the problems Jon kept so well tamed
for so many years.

There will almost surely be many memorials to Jon's monumental
service to the Internet Community. As current chairman of the
Internet Society, I pledge to establish an award in Jon's name to
recognize long-standing service to the community, the Jonathan B.
Postel Service Award, which will be awarded to Jon posthumously as
its first recipient.

If Jon were here, I am sure he would urge us not to mourn his passing
but to celebrate his life and his contributions. He would remind us
that there is still much work to be done and that we now have the
responsibility and the opportunity to do our part. I doubt that
anyone could possibly duplicate his record, but it stands as a
measure of one man's astonishing contribution to a community he knew
and loved.

Security Considerations

Security issues are not relevant to this Remembrance.

Author's Address

Vinton G. Cerf
MCI

EMail: vcerf@mci.net


















Cerf Informational [Page 3]

RFC 2468 I REMEMBER IANA October 1998


Full Copyright Statement

Copyright (C) The Internet Society (1998). All Rights Reserved.

This document and translations of it may be copied and furnished to
others, and derivative works that comment on or otherwise explain it
or assist in its implementation may be prepared, copied, published
and distributed, in whole or in part, without restriction of any
kind, provided that the above copyright notice and this paragraph are
included on all such copies and derivative works. However, this
document itself may not be modified in any way, such as by removing
the copyright notice or references to the Internet Society or other
Internet organizations, except as needed for the purpose of
developing Internet standards in which case the procedures for
copyrights defined in the Internet Standards process must be
followed, or as required to translate it into languages other than
English.

The limited permissions granted above are perpetual and will not be
revoked by the Internet Society or its successors or assigns.

This document and the information contained herein is provided on an
"AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
























Cerf Informational [Page 4]


Kill() 을 이용한 프로세스 모니터링

 PID를 디스크에 기록하는 전략은 시스템 데몬들이 주로 사용하는 표준으로 syslog에서 OpenSSH까지의 모든 데몬이 이를 사용한다.

 일단 파일시스템에서 PID 파일을 이용할 수 있게 되면 프로세스는 ps 출력을 구문 분석하거나 유사 파일시스템(pseudo-filesystem) /proc 를 검색하지 않고도 자신의 다른 인스턴스가 이미 실행 중인지 확인할 수 있다. 이 해결책은 kill() 시스템 호출의 반환 값을 이용하는데, 확인하고자 하는 프로세스에게 SIGTERM, SIGHUP 또는 기타 표준 신호를 전송하는 대신 SIG_0 을 전송한다.

 이는 프로세스가 현재 실행 중이면(즉, 프로세스 테이블에 해당 프로세스 항목이 존재한다면) kill() 이 ‘0’을 반환하고 프로세스가 실행 중이지 않거나 오류 조건이 발생하면 ‘0이 아닌 값’을 반환하게 한다. psad 데몬이 실행 중인지 여부를 확인하는 데 이 방법을 어떻게 사용하는지 보이기 위해 다음과 같은 명령어를 사용할 수 있다.

User image
 0 이 반환됐으므로 psad 가 현재 시스템에서 실행 중임을 알 수 있다.

 kill() 시스템 호출이 실제로 어떻게 사용되며 무엇을 반환하는지 알아보기 위해 strace 유틸리티를 사용해보자. 마지막 행의 = 0 이 kill() 의 반환 값이다.

User image
 끝으로 충분히 발달한 모든 프로그래밍 언어가 kill() 시스템 호출에 대한 인터페이스를 제공하며 여기서는 psad 가 현재 실행 중인지 아니지를 탐지하기 위해 어떻게 펄을 사용하는지 알아본다.(kill() 시스템 호출은 굵게 나타낸 행에서 호출한다.)

User image

mail (메일 보내고 받기)

  터미널에서 사용하는 메일 클라이언트 프로그램

 mail [-옵션] [-s 제목] [-c 참조] [-b 숨은참조] 받는사람
 mail [-옵션] -f 파일명
 mail [-옵션] -u 사용자 ID

 -v : 메일을 보내는 과정의 메시지를 자세히 보여준다.
 -i : tty 인터럽트 신호를 무시한다.
 -n : 메일프로그램 시작 시 /etc/mail.rc 파일을 읽지 않는다.
 -N : 초기 화면에서 메일목록을 보여주지 않는다.
 -s 제목 : 발송 메일의 제목을 적는다.
 -c 참조 : 같이 메일을 받을 사람을 추가한다.
 -b 숨은참조 : 같이 메일을 받는 사람을 추가한다. 숨은 참조 된 사람은 메일을 받은 다른사람에게는 보이지 않는다.
 -f : 파일로부터 메일을 읽어 온다.
 -u : 사용자 계정 지정

 mail은 터미널에서 사용하는 메일 클라이언트 프로그램이다. 메일을 보내고 받고 정리할 수 있다.

 – 받은 편지 확인
 자신의 계정을 사용 중에 받은 편지를 확인하려면 mail 만 입력한다. 다음은 관리자 모드에서 특정 계정의 받은 편지를 확인할 때 쓰인다.

User image
 mail 을 실행하면 초기 화면에 받은 편지의 목록이 나온다. 초기 화면에 나오는 부분을 메일의 헤더 부분이라 하는데 다음과 같이 구성되어 있다.

==============================================================================
N/P/U/ | 3701 | root@Ultra60.SunS | Fri Sep 11 23:13 | 91/2971 | [psad-alert]
——————————————————————————
편지상태 | 편지번호 | 보낸 사람 | 날짜 시간 | 라인/글자수 | 편지 제목
==============================================================================

 – 편지 상태
 N : 새 메시지
 P : 시스템의 메일박스에 저장
 U : 읽지 않은 메일

 처음 수신된 편지부터 확인하려면 <Enter> 를 누른다. 특정 편지를 보기를 원한다면 & 편지 번호를 지정한다.

 – mail 명령어
 mail의 여러 기능은 명령어를 통해 이루어진다. 명령어 입력 모드는 “&”로 표시한다.

 명령어                          설명
 n                  다음 편지로 이동한다.
 f <편지 번호>    편지 목록을 보여준다. f* 또는 & f a 모든 편지 목록을 볼 수 있다.
 d <편지 번호>    지정한 편지 번호의 편지를 지운다.
 s <편지 번호>    파일파일에 지정한 편지 내용을 저장한다.
 u <편지 번호>    편지를 지우지 않는다.
 R <편지 번호>    회신 한다.
 r <편지 번호>    전체 회신 한다.
 q                  mail 종료
 x                  mail 종료, 시스템 메일박스에서 삭제 하지 않는다.
 h                  메시지의 헤더 부분을 출력한다.
 !                  쉘 명령어를 실행한다
 e                  Ex 모드로 메시지를 편집한다.

 – 회신 보내기
 편지 보기 명령 창에서 현재 메일에 회신을 보내기를 원하면 R 명령을 입력한다. 내용을 다 입력하면 <Ctrl+D>
를 눌러 편지 입력을 종료한다.
 참조인이 없을 경우 그냥 <Enter> 키를 누른다

 – 편지 보내기
 mail을 실행한 상태에서 명령창에 &m 주소의 형식으로 입력하는 것 만으로도 편지를 발송할 수 있다.
 메일을 쓰다가 내용을 수정하고 싶을 때에는 새 줄 첫 번째 칸에 ~v 라고 입력하면 vi 편집기 상태에서 내용을 수정할 수 있다.
 본문 중에 텍스트 파일을 첨부할 때에는 새 줄 첫 번째 칸에 ~r 파일이름 형식으로 입력한다.

 mail 명령으로는 바이너리 파일을 바로 첨부할 수 없었다. 그래서 파일을 디코드하여 텍스트 형태로 전송할 수 있게 만들어 보내곤 했다. 현재에는 pine이나 넷스케이프 메일러, K 메일러 등 파일 첨부가 자유로운 메일 클라이언트를 많이 사용한다.