본문 바로가기

해봐야 안다.OTL/Linux

“John The Ripper”를 이용한 패스워드 감사

<-작업 설명->

"John the ripper"를 사용하여 주기적으로 사용자 계정의 패스워드 감사를 한 후 취약한 패스워드를 사용하는

각 계정 사용자들에게   메일로
보내주는 작업을 할 수 있게 셋팅한다..

 

 

<-Download, Install & Test->

John The Ripper à http://www.openwall.com/john

[root@centa:~]#wget http://www.openwall.com/john/g/john-1.7.3.4.tar.gz

[root@centa:~]#tar xvfz john-1.7.3.4.tar.gz

[root@centa:~]#cd john-1.7.3.4/src

[root@centa:~/john-1.7.3.4/src]#make linux-x86-any

[root@centa:~/john-1.7.3.4/src]#useradd userb

[root@centa:~/john-1.7.3.4/src]#passwd userb à 패스워드는 "123456"으로 설정했다.

Changing password for user userb.

New UNIX password:

BAD PASSWORD: it is WAY too short

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

 

[root@centa:~/john-1.7.3.4/src]#cd ../run/

[root@centa:~/john-1.7.3.4/run]#./unshadow /etc/passwd /etc/shadow > passwd.1

à /etc/passwd /etc/shadow 파일을 합침. 밑 참고

 

[root@centa:~/john-1.7.3.4/run]#cat passwd.1 |grep userb

userb:$1$sGOJxYN/$6siPWWuE/k.lvh63V05ao0:502:502::/home/userb:/bin/bash

 

[root@centa:~/john-1.7.3.4/run]#ll passwd.1

-rw-r--r-- 1 root root 1799 Oct 28 07:05 passwd.1

 

[root@centa:~/john-1.7.3.4/run]#./john passwd.1

Loaded 4 password hashes with 4 different salts (FreeBSD MD5 [32/32])

123456 (userb)

1 (user1)

1111 (sakura)

guesses: 3 time: 0:00:00:09 27% (2) c/s: 4523 trying: texas5

Session aborted

à 쉬운 패스워드는 엄청 빠르게 크랙된 것을 알 수 있다.

 

<-User 계정 LOCK & UNLOCK->

[root@centa:~]#passwd -l userb

Locking password for user userb.

passwd: Success

[root@centa:~]#cat /etc/shadow |grep userb

userb:!!$1$sGOJxYN/$6siPWWuE/k.lvh63V05ao0:14544:0:99999:7:::

à shadow파일을 살펴보면 userb다음에 "!!"로 잠겨있다. 이 계정은 이제 접속할 수 없다.

 

[root@centa:~]#

[root@centa:~]#passwd -u userb

à 계정 다시 풀어 줌.

Unlocking password for user userb.

passwd: Success.

[root@centa:~]#cat /etc/shadow |grep userb

userb:$1$sGOJxYN/$6siPWWuE/k.lvh63V05ao0:14544:0:99999:7:::

 

<-Mailer: 메일보내기(cron에 넣을 shellscript파일만들기)->

[root@centa:~/john-1.7.3.4/run]#vi passwd-check

#!/bin/sh

cd /root/john-1.7.3.4/run/

rm -f john.pot restore passwd.1

./unshadow /etc/passwd /etc/shadow > passwd.1

./john passwd.1 //패스워드 크랙 실행

./mailer passwd.1 //passwd.1 파일에 크랙된 사용자계정으로 메일을 보낸다.

:wq

 

<-실행 권한 변경 후 cron디렉터리에 넣기->

[root@centa:~/john-1.7.3.4/run]#chmod 700 passwd-check

[root@centa:~/john-1.7.3.4/run]#ll passwd-check

-rwx------ 1 root root 149 Oct 28 07:25 passwd-check

[root@centa:~/john-1.7.3.4/run]#cp /root/john-1.7.3.4/run/passwd-check /etc/cron.weekly/

à 일주일에 한 번씩 john the ripper 를 돌려 취약한 패스워드를 갖고 있는 계정들에 메일을 날려 주의를 준다.

 

<-cron 관련 파일->

[root@centa:/]#cat /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

 

# run-parts

01 * * * * root run-parts /etc/cron.hourly

02 4 * * * root run-parts /etc/cron.daily

22 4 * * 0 root run-parts /etc/cron.weekly // 0=매주 월요일 , 4시 22분

42 4 1 * * root run-parts /etc/cron.monthl