CALDERA入门(2)(构建插件入门)
一、编写插件代码
1.在caldera/plugins文件夹中创建文件夹test
2.在test文件夹中创建hook.py文件,以下是hook.py此次用的代码
from aiohttp_jinja2 import template, web
from app.service.auth_svc import check_authorization
name = 'test'
description = 'A sample plugin for demonstration purposes'
address = '/plugin/abilities/gui'
async def enable(services):
app = services.get('app_svc').application
fetcher = AbilityFetcher(services)
app.router.add_route('*', '/plugin/abilities/gui', fetcher.splash)
app.router.add_route('GET', '/get/abilities', fetcher.get_abilities)
class AbilityFetcher:
def __init__(self, services):
self.services = services
self.auth_svc = services.get('auth_svc')
async def get_abilities(self, request):
abilities = await self.services.get('data_svc').locate('abilities')
return web.json_response(dict(abilities=[a.display for a in abilities]))
@check_authorization
@template('abilities.html')
async def splash(self, request):
abilities = await self.services.get('data_svc').locate('abilities')
return(dict(abilities=[a.display for a in abilities]))
3.在test文件夹中创建templates文件夹,并在templates文件夹中创建test.html文件,此次html文件代码如下:
<table border='1'>
<p style="text-align:center ">功课表</p>
<tr>
<th>战术</th>
<th>技术</th>
<th>能力</th>
<th>描述</th>
<th>命令</th>
<th>结果</th>
<th>系统</th>
</tr>
<tr>
<td>collection</td>
<td>T1005|Data from Local System</td>
<td>Find Git Repositories</td>
<td>此功能将定位作为克隆Git存储库的目录。</td>
<td>1234</td>
<td></td>
<td>Windows/Linux</td>
</tr>
</table>
二、启用插件
1.在caldera/conf/local.yml中的plugin一栏加入- test
2.在左侧菜单栏的configuration中启用插件
最后重启插件便启用成功了