zoukankan      html  css  js  c++  java
  • w3a Scan 插件结构的构想问题

    在还没开始W3A Scan以前,从未考虑过插件结构这么个东西。直到想起以后更新功能的各种问题,

    我发现应该要考虑插件结构,晚上回家的时候问了下好基友。他说没接触过,但大体明白。。。瞬间就结了。说半天还是没你弄懂。。。

    最后还是昨晚自己去搜了下有关的资料,其实国内确实有人已经实现了,而且这种方法很成熟。

    Python非常适合动态扩展,而这种插件更新的方法给了大伙一个很好的解决方案。对于一个庞大未知的平台或工具。

    动态扩展非常适合它的需求,可能你不需要去修改主程序,只需要不断填充插件就可以满足你现有的技术需求。

    好比做安全,插件开发比平台开发更加有价值。主要体现在技术革新,例如现在出了某个Oday,而这个Oday的检测方式

    不太符合你目前的平台设计需求,同时你的接口也无法利用成功。而领导却非常想你做到这个功能,怎么办?

    这个时候插件出现了。。。你可以利用它来做一些你想做的功能,只要接口没问题,不影响主程序结构。

    既能高效开发,又能解决需求。何乐而不为?

    对此做了个Demo根据实际应用场景。需要自己深度琢磨。(不管你懂不懂,反正我是懂了)

    整体结构:

    1 root@smart:~/tmp_poject/python_poject# tree
    2 .
    3 ├── main.py
    4 └── plugin
    5     ├── DirectioryScan.py
    6     ├── __init__.py
    7     └── SQLinjectScan.py

    主程序代码main.py:

    root@smart:~/tmp_poject/python_poject# cat main.py 
    #-*- encoding: utf-8 -*-
    import os
    import sys
    
    class Scan_Main:
        def __init__(self):
            self.plugins=[]
            self.__loadPlugins()
    
        def __loadPlugins(self):
            ScanFilepath=os.path.split(os.path.realpath(__file__))[0]
            if os.path.exists(ScanFilepath+"/plugin"):
                for filename in os.listdir(ScanFilepath+'/plugin'):
                    if not filename.endswith('.py') or filename.startswith('_'):
                        continue
                    self.__runPlugins(filename)
            else:
                print "[*] Plugins directory not in here!"
                print "[*] Done."
    
        def __runPlugins(self,filename):
            plugins_name=os.path.splitext(filename)[0]
            plugin=__import__("plugin."+plugins_name,fromlist=[plugins_name])
            clazz=plugin.getPluginClass()
            o=clazz()
            o.setScan_Main(self)
            o.start()
            self.plugins.append(o)
            # plugin.do(self)
    
        def shutdown(self):
            for o in self.plugins:
                print o
                o.stop()
                o.setScan_Main(None)
            self.plugins=[]
    
        def print_load(self,item):
            print "[*] load plugins: %s" % item
    
    
    if __name__=="__main__":
        scan_main=Scan_Main()
        scan_main.shutdown()

    测试模块一:

    root@smart:~/tmp_poject/python_poject# cat plugin/DirectioryScan.py 
    #-*- encoding: utf-8 -*-
    
    class Plugin1:
        def setScan_Main(self, scan_main):
            self.scan_main=scan_main
    
        def start(self):
            self.scan_main.print_load("plugin1")
    
        def stop(self):
            self.scan_main.sayGoodbye("plugin1")
    
    def getPluginClass():
        return Plugin1

    后续会把这些模块进行改进到w3a_Scan_console里面。。

    欢迎关注并fork我的项目,更加欢迎小星星:https://github.com/smarttang/w3a_scan_console/

  • 相关阅读:
    【Leetcode】【hard】Binary Tree Postorder Traversal
    【Leetcode】【Easy】Contains Duplicate
    【Leetcode】【Easy】Isomorphic Strings
    【Leetcode】【Medium】Simplify Path
    【Leetcode】【Medium】Add Two Numbers
    【Leetcode】【Hard】Copy List with Random Pointer
    安装torch-opencv
    【转】ubuntu下修改文件夹权限
    Lua 中的 function、closure、upvalue
    多目标跟踪方法 NOMT 学习与总结
  • 原文地址:https://www.cnblogs.com/xiaoCon/p/3510580.html
Copyright © 2011-2022 走看看