ProFTPD - 윈디하나의 솔라나라

목차

개요

설치

  1. 윈디하나의 솔라나라: OpenSSL를 참고해 OpenSSL을 설치하고, 윈디하나의 솔라나라: Let’s Encrypt를 참고해 인증서를 생성해 놓는다.
  2. 윈디하나의 솔라나라: SQLite를 참고해 SQLite을 설치한다.
  3. LibIDN

    국제화 도메인 라이브러리
    # wget https://ftp.gnu.org/gnu/libidn/libidn-1.36.tar.gz
    # tar xvfz libidn-1.36.tar.gz  
    # cd libidn-1.36
    # ./configure CFLAGS="-m64"
    # make
    # sudo make install
    
  4. 소스 설치

    ProFTPd 의 소스를 받아 빌드한다.

    windy@wl ~/src $ wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.7e.tar.gz
    windy@wl ~/src $ tar xvfz proftpd-1.3.7e.tar.gz
    windy@wl ~/src $ cd proftpd-1.3.7e
    windy@wl ~/src/proftpd-1.3.7e $ ./configure \
      --with-includes=/usr/local/include/ncursesw:/usr/local/include:/usr/include:/usr/local/ssl/include \
      --with-libraries=/usr/local/lib:/usr/lib:/usr/local/ssl/lib \
      --prefix=/usr/local/proftpd \
      --enable-sendfile \
      --enable-autoshadow \
      --enable-shadow \
      --enable-auth-pam \
      --enable-ctrls \
      --enable-openssl \
      --enable-facl \
      --enable-nls \
      --enable-dso \
      --enable-pcre \
      --with-modules=mod_unique_id:mod_site_misc:mod_sql:mod_sql_passwd:mod_sql_sqlite:mod_sftp:mod_sftp_pam:mod_tls:mod_tls_shmcache:mod_shaper:mod_auth_otp:mod_digest:mod_statcache:mod_deflate:mod_wrap2:mod_wrap2_file:mod_wrap2_sql \
      CFLAGS="-m64" CXXFLAGS="-m64" LDFLAGS="-m64"
      1)
    windy@wl ~/src/proftpd-1.3.7e $ vi include/openbsd-blowfish.h 2)
    
    #if defined(__sparc__) || defined(__ppc__) || defined(__sun__) || \
    defined(__hpux) || defined(__hppa)
    #ifndef __linux__
    
    #include <inttypes.h>
    
    #define u_int32_t uint32_t
    #define u_int16_t uint16_t
    #define u_int8_t uint8_t
    
    #endif
    #endif
    
    windy@wl ~/src/proftpd-1.3.7e $ make
    windy@wl ~/src/proftpd-1.3.7e $ make install
    
    1) --with-modules 옵션에 붙이는 모듈 이름의 순서는, 모듈의 의존성을 고려해 정해야 한다.
    2) 솔라리스에서 빌드시 이 파일에서 오류가 발생한다. u_int*_t 가 없어서 발생하는 문제로 아래와 같이 추가하자.

    각 모듈은 아래와 같은 기능을 가진다.

    1. mod_unique_id: 각 세션마다 유일한 키를 생성하는 모듈. 로그에 사용
    2. mod_site_misc: SITE 커맨드의 나머지 명령 구현 모듈
    3. mod_sql, mod_sql_passwd, mod_sql_sqlite: 데이터베이스를 사용한 인증 모듈. MySQL, PostgresSQL, SQLite, ODBC 등을 지원하며 이 문서에서는 SQLite 를 사용한다.
    4. mod_sftp: sftp 를 지원해주는 모듈. OpenSSL 라이브러리 필요.
    5. mod_tls, mod_tls_shmcache: ftps, ftpes를 지원해주는 모듈. OpenSSL 라이브러리 필요.
    6. mod_shaper: 점수 기반의 업로드/다운로드 조절 모듈
    7. mod_auth_otp: OTP 인증 모듈
    8. mod_digest: DIGEST 모듈
    9. mod_statcache: 상태 캐시 모듈
    10. mod_deflate: 압축 모듈
    11. mod_wrap2, mod_wrap2_file, mod_wrap2_sql: IP기반의 접근 제어 모듈
  5. 경로설정

    ProFTPD의 ftpwho(1), ftptop(1), ftpshut(8)등을 쉽게 사용하기 위해 PATH를 걸어준다. 솔라리스10 이하에는 같은 이름을 가진 wu-ftp에서 사용하는 ftpwho(1), ftpshut(1M)/usr/sbin에 설치되어있으니 주의하자.
    root@wl # vi /etc/profile
    ...
    if [ -x /usr/local/proftpd/bin/ftpwho ]; then
      PATH=/usr/local/proftpd/sbin:/usr/local/proftpd/bin:$PATH; export PATH;
    fi
    root@wl #
    

실행 및 설정

ProFTPD 실행

ProFTPD는 inetd(1M)를 이용해 띄울수 있지만 여기서는 단일 프로세스(standalone)로 띄우는 방법에 대해 설명한다.

기본 설정

필요하다고 생각되는 기본 설정에 대해 소개한다. 각 옵션에 대한 자세한 사항은 ProFTPD의 문서를 읽어보자.
root@wl ~ # vi /usr/local/proftpd/etc/proftpd.conf
DefaultAddress    0.0.0.0
Port              21

#AllowstoreRestart on
#RequireValidShell off
#UseReverseDNS     off
#IdentLookups      off
ShowSymlinks      on
DefaultRoot       ~
ServerIdent       on      "FTP server"
#DisplayConnect    /etc/proftp.connect.msg
#DisplayLogin      /etc/proftp.login.msg
MaxClients        100     "Sorry, the maximum number(%m) of allowed users are already connected"
MaxClientsPerHost 5       "Sorry, the maximum number clients (%m) from your host are already connected"
HideUser          root
HideGroup         root
AuthPAM           On
AuthPAMConfig     ftp
UseEncoding       on
LangDefault       ko_KR
LangPath          /usr/local/proftpd/share/locale
DeflateEngine     on
#AllowForeignAddress on
TCPAccessFiles /etc/hosts.allow /etc/hosts.deny

FTPES/FTPS 설정

1) ProFTPd 1.3.3 부터 기본값은 보안상 SSL 세션을 재사용 하는 것으로 변경되었다. 하지만 몇몇 클라이언트(cUrl, Filezilla, ...)는 세션을 재사용하지 않기 때문에 이 옵션을 주어야 한다. 이 옵션을 주지 않으면 아래와 같은 메시지가 출력되며 데이터 커넥션이 이뤄지지 않는다
※ ProFTPd 로그
mod_tls/2.4.3[1090]: TLSv1/SSLv3 renegotiation accepted, using cipher DHE-RSA-AES128-SHA (128 bits)
mod_tls/2.4.3[1090]: client did not reuse SSL session, rejecting data connection (see the NoSessionReuseRequired TLSOptions parameter)
mod_tls/2.4.3[1090]: unable to open data connection: TLS negotiation failed

※ 클라이언트(FileZilla) 로그
425 Unable to build data connection: Not owner
또는
425 Unable to build data connection: Operation not permitted

SFTP 설정

익명 FTP 설정

익명 FTP(Anonymous FTP)란, 사용자 인증 과정 없이 사용할 수 있는 FTP서비스를 말한다. ProFTPD를 익명 FTP로 설정해도, 접속하는 사람은 사용자 이름과 패스워드를 입력해야 하는데, 사용자 이름에 anonymous를, 패스워드에는 공란으로 두거나 임의의 e-Mail 주소를 입력해 접속하면 된다.
# 익명 FTP에 사용할 계정을 만든다. Anonymous FTP를 이 사용자의 권한으로 실행될 것이다.
root@wl ~ # /usr/sbin/groupadd -g 103 ftp
root@wl ~ # useradd -d /export/home/ftp -g ftp -u 104 -s /bin/false ftp
root@wl ~ # mkdir /export/home/ftp # Anonymous FTP의 홈 디렉토리. 소유자와 그룹 모두 root, staff로 놔둔다.
root@wl ~ # vi /usr/local/proftpd/etc/proftpd.conf # Anonymous태그의 코멘트를 풀면 설정은 완료된다.
# A basic anonymous configuration, no upload directories.  If you do not
# want anonymous users, simply delete this entire <Anonymous> section.
<Anonymous ~ftp>
  User                         ftp
  Group                                ftp

  # We want clients to be able to login with "anonymous" as well as "ftp"
  UserAlias                    anonymous ftp

  # Limit the maximum number of anonymous logins
  MaxClients                   10

  # We want 'welcome.msg' displayed at login, and '.message' displayed
  # in each newly chdired directory.
  DisplayLogin                 welcome.msg
#  DisplayFirstChdir           .message

  # Limit WRITE everywhere in the anonymous chroot
  <Limit WRITE>
    DenyAll
  </Limit>
</Anonymous>
root@wl ~ # pkill proftpd
root@wl ~ # /usr/local/proftpd/sbin/proftpd
익명 사용자도 업로드 할 수 있도록 incomming디렉토리 만들어 보자. 접근 제한 설정이 없다면 일주일 이내에 익명의 업로더에 장악될 수 있으니, TCPWrapper등을 이용해 접근제한을 하자.
root@wl ~ # mkdir /export/home/ftp/incomming
root@wl ~ # chmod 777 /export/home/ftp/incomming
root@wl ~ # vi /usr/local/proftpd/etc/proftpd.conf
# 다음을 추가한다.
<Anonymous ~ftp>
  ...
  # <Anonymous ~ftp>와 </Anonymous> 사이에 아래를 추가한다.
  <Directory incoming>
  AllowOverwrite                on
  AllowStoreRestart             on
    <Limit STOR MKD>
      AllowALL
    </Limit>
  </Directory>
</Anonymous>
root@wl ~ # pkill proftpd
root@wl ~ # /usr/local/proftpd/sbin/proftpd # ProFTPD는 재시작하는 것이 없다.
※ 익명 사용자로서 사용할 시스템 계정을 (User 및 Group) 모두 ftp로 하였고, 익명으로 접속한 유저는 ftp:ftp 권한을 가진다는 것을 생각하면 이해하기 쉬울 것이다.

IP기반의 접근 제어

TCPWrapper 를 사용해 접속할 IP를 제한할 수 있다. 아래 예제는 192.168.0.3,192.168.0.2 에서만 접근 가능하도록 설정한 것이다. 그 외의 호스트에서는, ProFTPd 와 TCP/IP 접속은 되지만, 아이디와 패스워드를 제대로 입력하더라도 인증이 실패한다. 만약 21번 포트에 접속조차 되지 않도록 하려면 방화벽을 사용해야 한다.
root@wl ~ # vi /usr/local/proftpd/etc/proftpd.conf
# TCPAccessFiles부분을 추가한다.
TCPAccessFiles /etc/hosts.allow /etc/hosts.deny
root@wl ~ # vi /etc/hosts.deny
ALL:ALL
root@wl ~ # vi /etc/hosts.allow
proftpd: 192.168.0.3,192.168.0.2
root@wl ~ # pkill proftpd
root@wl ~ # /usr/local/proftpd/sbin/proftpd

SQL 사용

OTP 사용

로그

FTP 데몬은 전송 로그를 /var/log/xferlog에 저장한다. (ProFTPd 뿐만 아니라, VSFTPD, WU-FTPD 도 마찬가지다) 로그 형식은 아래와 같다. 자세한 형식은 xferlog(4)를 읽어보자.

로그시간 전송시간 원격호스트이름 파일크기 파일이름 전송종류 특별전송플래그 방향 접근모드 유저이름 서비스이름 인증방법 인증된유저ID 완료여부

로그 파일은 아래와 같이 해석될 수 있다.

root@wl ~ # tail /var/log/xferlog
Fri Nov 11 11:56:28 2005 0 xxx.xxx.xxx.xxx zzzz /sample.txt a _ i r webmaster ftp  1  *  c
-----------------------1 2 --------------3 ---4 ----------5 6 7 8 9 -------10 -11 12 13 14
  1. 로그시간. 로그가 저장된 호스트의 현재 시간
  2. 전송시간. 전송에 소요된 시간. 초
  3. 원격호스트이름. 없는 경우 IP로 저장됨
  4. 전송크기. 바이트
  5. 파일경로및이름.
  6. 전송종류. a: 아스키 전송, b: 바이너리 전송
  7. 특별전송플래그. C: 파일 압축됨, U: 파일 압축풀림, T: 아카이브 (예 TAR), _: 해당없음
  8. 방향. o: 외부(Outgoing), i:내부(Incoming), d:삭제(Deleted)
  9. 접근모드. a: 익명유저(Anonymous), g: 손님유저(Guest), r: 로컬 인증된 유저(Real)
  10. 유저이름. 로컬 유저이름. 손님인 경우 주어진 ID.
  11. 서비스이름. 수행될때의 서비스/프로토콜 이름. ftp, ftps, sftp 중 하나
  12. 인증방법. 0: 없음, 1: RFC 931 - Authentication server에 의한 인증
  13. 인증된유저ID. 인증 메쏘드에 의해 얻은 유저ID. *의 경우 존재하지 않음
  14. 완료여부. c: 전송이 완료됨, i: 전송이 완료되지 않음
RSS ATOM XHTML 5 CSS3