본문 바로가기

컴퓨터/Python

압축 파일의 패스워드 찾기

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

import zipfile
zFile = zipfile.ZipFile('evil.zip')            zip된 파일 열기
passFile = open('dictionary.txt')        dictionary 파일 열기
for line in passFile.readlines():
        password = line.strip('\n')
        try:
                zFile.extractall(pwd=password)        사전에서 가지고 온 패스워드를 인자로 전달
                print '[+] Password = ' + password + '\n'
                exit(0)
        except Exception, e:
                pass

root@bt:~/Desktop# python unzip.py
[+] Password = secret



함수를 가지고 모듈화 해보기

import zipfile
zFile = zipfile.ZipFile('evil.zip')
passFile = open('dictionary.txt')
for line in passFile.readlines():
        password = line.strip('\n')
        try:
                zFile.extractall(pwd=password)
                print '[+] Password = ' + password + '\n'
                exit(0)
        except Exception, e:
                pass




쓰레드 사용해 보기

import zipfile
from threading import Thread

def extractFile(zFile, password):
        try:
                zFile.extractall(pwd=password)
                print '[+] Found password ' + password +'\n'
        except:
                pass
def main():
        zFile = zipfile.ZipFile('evil.zip')
        passFile = open('dictionary.txt')
        for line in passFile.readlines():
                password = line.strip('\n')
                t = Thread(target=extractFile, args=(zFile, password))
                t.start()

if __name__ == '__main__':
        main()



크랙할 압축 파일의 이름과 크랙에 사용할 딕셔너리 파일의 이름을 사용자가 직접 정의한다.
optparse 라이브러리를 임포드한다.

import zipfile
import optparse
from threading import Thread

def extractFile(zFile, password):
        try:
                zFile.extractall(pwd=password)
                print '[+] Found password ' + password + '\n'
        except:
                pass
def main():
        parser = optparse.OptionParser('usage%prog '+\
        '-f <zipfile> -d <dictionary>')
        parser.add_option('-f', dest='zname', type='string',\
        help='specify zip file')
        parser.add_option('-d', dest='dname', type='string',\
        help='specify dictionary file')
        (options, args) = parser.parse_args()
        if(options.zname == None) | (options.dname == None):
                print parser.usage
                exit(0)
        else:
                zname = options.zname
                dname = options.dname
        zFile = zipfile.ZipFile(zname)
        passFile = open(dname)
        for line in passFile.readlines():
                password = line.strip('\n')
                t = Thread(target=extractFile, args=(zFile, password))
                t.start()
if __name__ == '__main__':
        main()

root@bt:~/Desktop# python unzip.py -f evil.zip -d dictionary.txt

[+] Password = secret


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

nmap 포트 스캐너 통합하기  (0) 2013.08.13
포트 스캐너  (0) 2013.08.12
압축파일에 잘못된 패스워드를 입력  (0) 2013.08.09
압축파일 해제  (0) 2013.08.09
유닉스 패스워드 크래거  (0) 2013.08.07