본문 바로가기

컴퓨터/Python

유닉스 패스워드 크래거

SHA(Secure Hash Algorithm, 안전한 해시 알고리즘) 함수들은 서로 관련된 암호학적 해시 함수들의 모음이다. 이들 함수는 미국 국가안보국(NSA)이 1993년에 처음으로 설계했으며 미국 국가 표준으로 지정되었다. SHA 함수군에 속하는 최초의 함수는 공식적으로 SHA라고 불리지만, 나중에 설계된 함수들과 구별하기 위하여 SHA-0이라고도 불린다. 2년 후 SHA-0의 변형인 SHA-1이 발표되었으며, 그 후에 4종류의 변형, 즉 SHA-224SHA-256SHA-384SHA-512가 더 발표되었다. 이들을 통칭해서 SHA-2라고 하기도 한다.

SHA-1은 SHA 함수들 중 가장 많이 쓰이며, TLSSSLPGPSSHIPSec 등 많은 보안 프로토콜과 프로그램에서 사용되고 있다. SHA-1은 이전에 널리 사용되던 MD5를 대신해서 쓰이기도 한다.


adduser 명령어를 사용해 victim이라는 계정을 생성(비밀번호 egg)


root@bt:~/Desktop# adduser victim
Adding user `victim' ...
Adding new group `victim' (1001) ...
Adding new user `victim' (1001) with group `victim' ...
The home directory `/home/victim' already exists.  Not copying from `/etc/skel'.
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for victim
Enter the new value, or press ENTER for the default
    Full Name []: 123
    Room Number []: 123
    Work Phone []: 123
    Home Phone []: 123
    Other []: 123
Is the information correct? [Y/n] y


vi 편집기로 코딩해준다.


root@bt:~/Desktop# vi hello.py


import crypt


def testPass(cryptPass):

        if '$' in cryptPass:

                salt = cryptPass.rsplit('$', 1)[0].strip(' ')

                dictFile = open('dictionary.txt', 'r')

                for word in dictFile.readlines():

                        word = word.strip('\n')

                        cryptWord = crypt.crypt(word, salt)

                        if(cryptWord == cryptPass):

                                print '[+] Found Password: ' +word+'\n'

                                return

        print '[-] Password Not Found.\n'

        return

def main():

        passFile = open('/etc/shadow')

        for line in passFile.readlines():

                if ':' in line:

                        user = line.split(':')[0]

                        cryptPass = line.split(':')[1].strip(' ')

                        print '[*] Cracking Password For: ' + user

                        testPass(cryptPass)

if __name__ == '__main__':

        main()


크래커를 실행해 준다.


root@bt:~/Desktop# python hello.py
[*] Cracking Password For: victim
[+] Found Password: egg




'컴퓨터 > Python' 카테고리의 다른 글

압축파일에 잘못된 패스워드를 입력  (0) 2013.08.09
압축파일 해제  (0) 2013.08.09
pickle  (0) 2013.07.26
파일 입출력  (0) 2013.07.26
포맷팅  (0) 2013.07.26