Walks

网络安全爱好者

Python3学习系列(二):编写属于自己的网站后台扫描器

《Python3学习系列(二):编写属于自己的网站后台扫描器》 

前言:

最近在学Python,所以就想写点Python学习的文章,目的是为了让大家可以学习点东西的同时也让自己对这些模块的理解更加深一点。 

目录: 

0x01:处理流程 

0x02:代码实现 

0x03:逐行解析 


0x01 处理流程

《Python3学习系列(二):编写属于自己的网站后台扫描器》 

0x02 代码实现  

'''
Program:网站后台扫描工具
Function:通过字典扫描网站后台
 
Time:2017/10/13
Author:Walks
个人博客:http://www.bywalks.com
'''
 
import urllib.request
import time
import threading
 
#与用户交互,也可用命令行
url = input("输入你要扫描到的网址:")
txt = input("输入字典(php.txt):")
 
#保存存在的后台地址
open_url = []
all_url = []
 
#建立线程列表
threads = []
 
 
 
#从字典中读取每一行与url组合,然后添加到all_url
def search_url(url,txt):
    with open(txt,'r') as f:
        for each in f:
            each = each.replace('\n','')
            urllist = url + each
            all_url.append(urllist)
 
#处理URL
def handle_url(urllist):
    print("查找:"+urllist+'\n')    try:
        req = urllib.request.urlopen(urllist)
        #判断返回码
        if req.getcode()==200:
            open_url.append(urllist)
        if req.getcode()==301:
            open_url.append(urllist)
    except:
        pass
     
     
 
#主函数
def main():
    search_url(url,txt)
    #多线程处理
    for each in all_url:
        t = threading.Thread(target = handle_url,args=(each,))
        threads.append(t)
        t.start()
    #线程等待
    for t in threads:
        t.join()
    #扫描成功和不成功的回显
    if open_url:
        print("扫描成功,网站存在的后台地址为:")
        for each in open_url:
            print("[+]"+each)
    else:
        print("没有扫描到网站后台(可能是字典不够给力)")
 
if __name__=="__main__":
    #判断程序运行时间
    start = time.clock()
    main()
    end = time.clock()
    print("The function spend time is %.3f seconds" %(end-start))

0x03:逐行解析

#导入各种库,urllib.request是用来打开和阅读urls,等同于Python2.x的urllib2
#用来时间延时,time.sleep(1),就是延时一秒
#threading用来实现多线程
import urllib.request
import time
import threading
 
#与用户交互,也可用命令行argparse
url = input("输入你要扫描到的网址:")
txt = input("输入字典(php.txt):")
 
#保存存在的后台地址
open_url = []
all_url = []
 
#建立线程列表
   threads = []
 
 
#从字典中读取每一行与url组合,然后添加到all_url
def search_url(url,txt):
    with open(txt,'r') as f:
        for each in f:
            each = each.replace('\n','')
            urllist = url + each
            all_url.append(urllist)
 
#处理URL
def handle_url(urllist):
print("查找:"+urllist+'\n')
#try,防出错
try:
    #利用urlopen打开url
    req = urllib.request.urlopen(urllist)
    #判断返回码,如果为200或者301,则该网页存在,把该url加入到open_url
    if req.getcode()==200:
        open_url.append(urllist)
    if req.getcode()==301:
        open_url.append(urllist)
except:
    pass
 
 
 
#主函数
def main():
search_url(url,txt)
#多线程
for each in all_url:
#建立线程对象
t = threading.Thread(target = handle_url,args=(each,))
#把线程对象加入到线程列表中
threads.append(t)
#线程开始
t.start()
#线程等待(给每一个线程)
for t in threads:
    t.join()
#扫描成功和不成功的回显
if open_url:
    print("扫描成功,网站存在的后台地址为:")
    for each in open_url:
        print("[+]"+each)
else:
    print("没有扫描到网站后台(可能是字典不够给力)")
 
if __name__=="__main__":
    #判断程序运行时间
    #start为程序还没开始的时间,end为程序运行结束的时间
    start = time.clock()
    main()
    end = time.clock()
    print("The function spend time is %.3f seconds" %(end-start))

 最后附一张加了多线程和没加的时间区别

  《Python3学习系列(二):编写属于自己的网站后台扫描器》 

《Python3学习系列(二):编写属于自己的网站后台扫描器》 

可以看到,花费的时间是不同的,这是在扫描基数很少的情况下,我测试的时候只用了3个url,如果基数大的话,时间差距会更大

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

点赞
  1. lebron 13说道:

    Needed to draft you the very little remark so as to say thank you over again for the pleasant strategies you have contributed in this article. This is simply pretty generous with you to give unreservedly just what many people would've distributed as an e-book in making some money for themselves, even more so considering the fact that you might well have done it in case you desired. The solutions additionally served as the great way to know that other people online have similar dreams just as my personal own to figure out a little more around this matter. I think there are lots of more pleasant opportunities ahead for many who look into your site.

  2. moncler jacket说道:

    I am also writing to make you be aware of of the helpful discovery my child found visiting yuor web blog. She learned plenty of details, which include what it is like to have an awesome helping character to make folks without difficulty know specific complicated things. You really did more than readers' desires. Many thanks for coming up with the helpful, dependable, informative and even easy tips about your topic to Evelyn.

  3. nike huarache说道:

    I wish to show my appreciation for your generosity giving support to men and women who absolutely need guidance on that content. Your special commitment to getting the message throughout has been exceedingly interesting and has consistently empowered guys like me to reach their ambitions. Your entire insightful guidelines means much a person like me and a whole lot more to my peers. With thanks; from each one of us.

  4. I must express my appreciation to this writer just for bailing me out of this difficulty. Right after surfing through the online world and getting techniques that were not powerful, I thought my life was done. Being alive devoid of the strategies to the difficulties you have solved all through the write-up is a serious case, and those that could have adversely damaged my entire career if I hadn't discovered your web site. Your know-how and kindness in dealing with a lot of stuff was priceless. I'm not sure what I would have done if I hadn't come across such a solution like this. I can now look forward to my future. Thanks for your time so much for the reliable and sensible help. I will not be reluctant to endorse your web sites to anybody who needs direction on this problem.

  5. mlb jerseys说道:

    I together with my guys were found to be viewing the great guidelines on your website while suddenly came up with a horrible suspicion I had not expressed respect to the website owner for those strategies. Those young men happened to be so happy to read all of them and already have surely been taking advantage of those things. Appreciation for being very accommodating and then for using this form of brilliant issues millions of individuals are really eager to discover. My personal sincere apologies for not expressing gratitude to earlier.

  6. My wife and i were absolutely thankful Louis managed to finish off his inquiry from the precious recommendations he acquired out of the blog. It's not at all simplistic to just always be offering methods that some people may have been trying to sell. And we also fully understand we now have you to appreciate because of that. All of the illustrations you have made, the easy web site navigation, the relationships you can assist to promote - it's got many impressive, and it's helping our son in addition to us recognize that the article is exciting, which is certainly truly essential. Many thanks for all the pieces!

  7. yeezy boost 350说道:

    My wife and i ended up being now thankful Chris managed to complete his inquiry via the precious recommendations he discovered out of your web site. It's not at all simplistic to just always be freely giving techniques many people might have been making money from. And we also fully understand we've got the blog owner to appreciate for that. The main illustrations you've made, the simple web site navigation, the relationships you give support to engender - it's most awesome, and it's leading our son and the family understand this topic is enjoyable, which is certainly rather essential. Many thanks for the whole thing!

  8. air max 270说道:

    My husband and i ended up being thrilled that Peter could carry out his web research out of the ideas he discovered in your web page. It is now and again perplexing to just find yourself giving freely solutions the rest have been making money from. Therefore we fully understand we've got the blog owner to thank because of that. All of the illustrations you have made, the simple website navigation, the relationships you can assist to create - it's everything impressive, and it is facilitating our son in addition to the family feel that that issue is brilliant, and that's extremely mandatory. Thank you for the whole thing!

  9. hermes belts说道:

    I must point out my respect for your generosity in support of individuals who really need help on that study. Your real dedication to getting the solution all-around had been unbelievably powerful and has without exception allowed employees much like me to achieve their pursuits. This insightful guidelines entails a lot to me and somewhat more to my office colleagues. Best wishes; from all of us.

  10. ysl handbags说道:

    I have to express thanks to the writer just for bailing me out of this matter. Because of looking out throughout the the net and finding techniques that were not powerful, I thought my life was gone. Being alive minus the answers to the difficulties you've resolved as a result of the report is a crucial case, as well as the ones that might have negatively damaged my career if I hadn't encountered your web page. Your primary understanding and kindness in playing with all the things was valuable. I don't know what I would've done if I hadn't discovered such a thing like this. I'm able to now relish my future. Thanks so much for the impressive and results-oriented guide. I won't think twice to endorse the website to anybody who desires guidance about this problem.

  11. I precisely had to appreciate you once again. I'm not certain the things I would've used in the absence of the solutions discussed by you concerning such a concern. It became the traumatic crisis in my circumstances, nevertheless taking note of a expert strategy you treated it took me to cry for joy. I'm just happy for your service and then believe you recognize what an amazing job that you are accomplishing educating some other people all through your website. I am sure you've never met all of us.

  12. I and also my friends were actually looking through the great items found on your website and then the sudden got an awful suspicion I never thanked you for those techniques. All the women are already as a consequence passionate to see them and now have really been tapping into those things. Many thanks for really being quite considerate and for obtaining this sort of helpful themes most people are really desperate to discover. My very own honest apologies for not expressing appreciation to earlier.

  13. off-white说道:

    I have to point out my appreciation for your kind-heartedness giving support to individuals that need help on this particular concern. Your very own commitment to getting the message up and down appeared to be extraordinarily valuable and has usually empowered professionals much like me to realize their aims. Your new valuable tutorial indicates a great deal a person like me and further more to my peers. Thanks a lot; from each one of us.

  14. yeezy shoes说道:

    I just wanted to send a quick note so as to say thanks to you for these awesome hints you are giving at this site. My considerable internet search has now been paid with good facts and strategies to go over with my family and friends. I would believe that most of us website visitors are undoubtedly lucky to exist in a useful network with very many wonderful individuals with insightful points. I feel rather fortunate to have encountered your web pages and look forward to tons of more entertaining moments reading here. Thank you once again for all the details.

  15. supreme hoodie说道:

    I just wanted to write a note so as to appreciate you for some of the lovely techniques you are giving at this website. My particularly long internet search has at the end been compensated with high-quality ideas to write about with my pals. I would assume that we website visitors actually are undoubtedly blessed to live in a remarkable community with very many lovely professionals with helpful tips and hints. I feel extremely blessed to have used your entire site and look forward to many more enjoyable minutes reading here. Thank you once again for a lot of things.

  16. yeezy boost 350说道:

    I wanted to compose you one very little note to be able to give many thanks once again regarding the pleasing pointers you have documented on this site. It's so remarkably generous of people like you to grant extensively exactly what numerous people would've offered as an e book in making some profit for their own end, most importantly now that you might have tried it in case you decided. The ideas as well served to be a great way to be aware that other people have the identical dream just as my own to understand a good deal more with regards to this matter. I think there are several more pleasurable opportunities ahead for folks who browse through your blog post.

  17. I simply wanted to thank you so much once again. I'm not certain the things that I would have taken care of in the absence of the entire pointers provided by you concerning this field. It truly was a real challenging scenario in my view, however , understanding a new skilled style you solved the issue made me to weep with joy. I will be thankful for this information and as well , hope you realize what a powerful job you were accomplishing educating men and women through the use of your webblog. I know that you've never met any of us.

  18. westbrook shoes说道:

    I'm just writing to make you know what a excellent encounter my friend's daughter found browsing your webblog. She came to find a good number of details, most notably what it is like to have an awesome coaching heart to let other people with no trouble know just exactly selected problematic things. You really exceeded our expected results. Thank you for giving these valuable, dependable, explanatory and even cool tips about the topic to Mary.

  19. My spouse and i got quite relieved Chris managed to complete his basic research from your precious recommendations he came across from your very own web page. It is now and again perplexing to just happen to be freely giving points which often the others may have been selling. And we also figure out we've got the blog owner to be grateful to for this. The specific illustrations you have made, the easy site navigation, the friendships you can give support to foster - it's got mostly powerful, and it's aiding our son in addition to us know that that concept is enjoyable, which is pretty indispensable. Thanks for everything!

  20. adidas nmd说道:

    Thank you so much for giving everyone an extremely remarkable chance to read articles and blog posts from this web site. It really is very beneficial and as well , stuffed with fun for me personally and my office friends to search your web site not less than 3 times in 7 days to study the latest issues you have got. Of course, I'm also usually contented for the incredible solutions you serve. Selected 4 areas in this post are easily the most suitable we have all had.

  21. nike air max说道:

    Thank you a lot for providing individuals with remarkably special opportunity to discover important secrets from this blog. It is always very pleasing and also stuffed with amusement for me personally and my office co-workers to search the blog more than three times in a week to learn the latest stuff you will have. Not to mention, we're usually satisfied concerning the astounding ideas served by you. Some 4 ideas in this post are without a doubt the most beneficial I've ever had.

  22. reebok outlet说道:

    I in addition to my pals happened to be looking at the best tricks found on your web page and then then got a terrible suspicion I never thanked the web site owner for those secrets. All of the young boys were as a consequence passionate to see them and have in actuality been loving these things. Appreciation for turning out to be so thoughtful and for making a decision on varieties of fantastic issues most people are really desperate to learn about. My very own honest regret for not expressing appreciation to sooner.

  23. I'm also writing to make you know of the great encounter my wife's girl had using yuor web blog. She came to understand so many details, which include what it is like to have an incredible giving heart to have men and women quite simply completely grasp certain specialized things. You undoubtedly exceeded our own expected results. Many thanks for providing such useful, dependable, revealing and also unique tips about your topic to Kate.

发表评论

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