Python实现AWVS13批量添加、删除任务(1)

Python实现AWVS13批量添加、删除任务(一)

环境
运行平台:Windows
Python版本:Python3.7
AWVS13访问地址:https://192.168.10.100:3443/

1、获取AWVS13的 API_KEY

在这里插入图片描述
在这里插入图片描述

2、AWVS13的各个接口

新增任务接口
URL:https://192.168.10.100:3443/api/v1/targets
Method:post
POST参数类型:
address:需要扫描的url;以http或https开头(str类型)
criticality:危险程度;范围:[30,20,10,0];默认为10(str类型)
description:备注(str类型)

代码:

add_url_api = 'https://192.168.10.100:3443/api/v1/targets'
header = {'X-Auth': 'x',
          'Content-type': 'application/json'}
datas = json.dumps({'address':'http://www.baidu.com/',
                    'description':'http://www.baidu.com/',
                    'criticality':'10'})
response= requests.post(url=add_url_api, headers=header, data=datas,verify=False).json()
<response. status_code [201]>	#代表执行成功

返回包如下:

{'address': 'http://www.baidu.com/', 'criticality': 10, 'description': 'http://www.baidu.com/', 'type': 'default', 'domain': 'baidu.com', 'target_id': '13564b22-7fd8-46d5-b10f-3c87a6cc6afa', 'target_type': None, 'canonical_address': 'baidu.com', 'canonical_address_hash': '823a9c89d4aea02ab8a4f5d31fd603c7'}

返回包参数详解:

address:目标网址
criticality:危险程度
description:备注
type:类型
domain:域名
target_id:目标id
target_type:目标类型
canonical_address:根域名
canonical_address_hash:根域名hash
扫描速度接口
URL:https://192.168.10.100:3443/api/v1/targets/{target_id}/configuration
Method:patch
PATCH参数类型:
scan_speed string:slow(慢)、moderate(中)、fasts(快) 三种模式(str类型)

代码:

speed_url_api = 'https://192.168.10.100:3443/api/v1/targets/{target_id}/configuration'
header = {'X-Auth': 'x',
          'Content-type': 'application/json'}
datas = json.dumps({"scan_speed":"fasts"})
response = requests.patch(url=speed_url_api, headers=header, data=datas, verify=False)
<response. status_code [204]>	#代表执行成功
启动任务接口
URL:https://192.168.10.100:3443/api/v1/scans
Method:post
POST参数类型:
target_id:目标id(str类型)
schedule:扫描时间设置(默认即时)( json格式)
profile_id: 扫描类型(str格式)
ui_session_i:可以不传
report_template_id string:可以不传

扫描类型有以下几种:
Full Scan 11111111-1111-1111-1111-111111111111 完全扫描
High Risk Vulnerabilities 11111111-1111-1111-1111-111111111112 高风险漏洞
Cross-site Scripting Vulnerabilities 11111111-1111-1111-1111-111111111116 XSS漏洞
SQL Injection Vulnerabilities 11111111-1111-1111-1111-111111111113 SQL注入漏洞
Weak Passwords 11111111-1111-1111-1111-111111111115 弱口令检测
Crawl Only 11111111-1111-1111-1111-111111111117 Crawl Only
Malware Scan 11111111-1111-1111-1111-111111111120 恶意软件扫描

代码:

scan_url_api = 'https://192.168.10.100:3443/api/v1/scans'
header = {'X-Auth': 'x',
          'Content-type': 'application/json'}
datas = json.dumps({'profile_id':'11111111-1111-1111-1111-111111111111',
                    'schedule':{'disable':false,'start_date':null,'time_sensitive':false},
                    'target_id':''})
response=requests.post(url=scan_url_api, headers=header, data=datas, verify=False).json()
<response. status_code [201]>	#代表执行成功

返回包如下:

{'profile_id': '11111111-1111-1111-1111-111111111111', 'schedule': {'disable': False, 'start_date': None, 'time_sensitive': False, 'triggerable': False}, 'target_id': '', 'incremental': False, 'max_scan_time': 0, 'ui_session_id': None}
仪表盘接口
URL: https://192.168.10.100:3443/api/v1/me/stats
Method:get

代码:

stats_url_api = 'https://192.168.10.100:3443/api/v1/me/stats'
header = {'X-Auth': 'x',
          'Content-type': 'application/json'}
response=requests.get(url=stats_url_api, headers=header, verify=False).json()

返回包如下:

{'most_vulnerable_targets': [], 'scans_conducted_count': 0, 'scans_running_count': 0, 'scans_waiting_count': 0, 'targets_count': 0, 'top_vulnerabilities': [], 'vuln_count': {'high': None, 'low': None, 'med': None}, 'vuln_count_by_criticality': {'critical': None, 'high': None, 'low': None, 'normal': None}, 'vulnerabilities_open_count': 0}

返回包参数详解:

most_vulnerable_targets:最脆弱的目标
scans_conducted_count:总进行扫描个数
scans_running_count:正在扫描的个数
scans_waiting_count:等待扫描的个数
targets_count:所有任务数量
top_vulnerabilities:排名靠前漏洞分布
vuln_count_by_criticality:通过危险程度进行漏洞等级个数分布
vuln_count:漏洞数据
vulnerabilities_open_count:共发现漏洞总数
删除任务接口
URL: https://192.168.10.100:3443//api/v1/targets/{target_id}
Method:delete

代码:

del_target_api = 'https://192.168.10.100:3443/api/v1/me/stats'
header = {'X-Auth': 'x',
          'Content-type': 'application/json'}
response=requests.delete(url=del_target_api ,headers=header,verify=False)
<response. status_code [201]>	#代表执行成功

3、主体代码

# /usr/bin/env python3
# -*-coding:utf-8-*-
# @Author:malphite.tang
import json
import requests
from queue import Queue
requests.packages.urllib3.disable_warnings()	# 消除equests提示警告

class Awvs():
    def __init__(self):
        self.host = 'https://192.168.10.100:3443'
        self.add_url_api = self.host + '/api/v1/targets'  # 新增任务接口
        self.speed_url_api = self.host + '/api/v1/targets/{}/configuration'  # 设置扫描速度接口
        self.scan_url_api = self.host + '/api/v1/scans'  # 启动扫描任务接口
        self.stats_url_api = self.host + '/api/v1/me/stats'  # 仪表盘接口
        self.del_target_api = self.host + '/api/v1/targets/{}' #删除任务接口
        self.API_KEY = '1986ad8c0a5b3df4d7028d5f3c06e936c35c8df009cb04b49a18e844f8717cfe8'
        self.header = {'X-Auth': self.API_KEY, 'content-type': 'application/json'}  # header格式
        self.target_url = Queue()  # 创建扫描url队列
        self.target_id = Queue()  # 创建任务id号队列
        self.speed = 'fast'  # 定义扫描速度

    def main(self):  # 主程序-选择对应的功能
        print('选择要使用的功能(输入相应的编号):')
        print('1.使用target.txt添加扫描任务  (注:url必须带有http或https)')
        print('2.查看扫描器详情')
        print('3.删除所有任务')
        print('4.退出')
        choice = input('>')
        if choice == '1':
            self.run1()
            exit()
        if choice == '2':
            self.run2()
            exit()
        if choice == '3':
            self.run3()
            exit()
        if choice == '4':
            exit()
        else:
            self.main()

    def run1(self):  # 创建任务,自动设置为fast模式,并开启扫描。
        pass
    def run2(self):  # 查看仪表盘
        pass
    def run3(self):  # 删除所有任务
        pass

if __name__ == '__main__':
    aw = Awvs()
    aw.main()

*注:无授权 请勿扫描,后果自负

转载请注明作者和出处:https://blog.csdn.net/qq_33005553/article/details/108366182
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值