最近因為實習的原因,為了減少一部分的工作量,在阿里雲服務器上搭建了AWVS掃描器 方便摸魚
但是發現AWVS貌似沒有批量添加的方法,作者只好把整理的URL.txt捏了又捏
手動輸入是不可能手動輸入的,去查了查網上關於AWVS掃描器API的使用,找到兩篇文章:
https://blog.csdn.net/wy_97/article/details/106872773
https://blog.csdn.net/sinat_25449961/article/details/82985638
然后花一個小時的時間整理了一下,因為作者只需要添加任務,以及讓掃描任務啟動,所以我們也從這兩個功能入手,查看API接口。
添加任務接口是:
Method:POST URL: /api/v1/targets
發送參數 | 類型 | 說明 |
---|---|---|
address | string | 目標網址:需http或https開頭 |
criticality | Int | 危險程度;范圍:[30,20,10,0];默認為10 |
description | string | 備注 |
具體的使用如下:
''' create_target函數 功能: AWVS13 新增任務接口 Method : POST URL : /api/v1/targets 發送參數: 發送參數 類型 說明 address string 目標網址:需要http或https開頭 criticality int 危險程度;范圍:[30,20,10,0];默認為10 description string 備注 ''' def create_target(address,description,int_criticality): url = 'https://' + IP + ':13443/api/v1/targets' headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} values = { 'address': address, 'description': description, 'criticality': int_criticality, } data = bytes(json.dumps(values), 'utf-8') request = urllib.request.Request(url, data, headers) html = urllib.request.urlopen(request).read().decode('utf-8') return html
在create_target()函數中,如服務器IP是全局變量,即搭建AWVS的服務器的IP,后面接的端口需要根據實際情況修改。
可以看到現在還沒有任務:
簡單調用:
#這兩處需要修改為你自己的 IP = '' API_KEY = '' def main(): testurl='https://www.zsjjob.com/' description="null" int_criticality=10 print(create_target(testurl,description,int_criticality)) if __name__=='__main__': main()
運行返回結果為:
接着我們查看AWVS添加的任務里面
可以看到只是添加到了任務中,還未進行掃描,接着我們查看開始掃描的API:
Method:POST URL: /api/v1/scans
發送參數 | 類型 | 說明 |
profile_id | string | 掃描類型 |
ui_session_i | string | 可不傳 |
schedule | json | 掃描時間設置(默認即時) |
report_template_id | string | 掃描報告類型(可不傳) |
target_id | string | 目標id |
可以看到必選的就是 掃描類型,掃描時間設置,目標id
而掃描類型 profile_id 可以選擇的有:
掃描類型 | 值 | 翻譯 |
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 | 惡意軟件掃描 |
我們在代碼中使用的是掃描類型對應的值,一般都是直接使用完全掃描
掃描時間設置我們按照默認值設置,目標 id 我們之前已經看到過了,即:
所以我們只要將獲取到的target_id和其他兩個參數丟進去就行了。
具體使用如下:
''' start_target 功能: AWVS13 啟動掃描任務接口 Method : POST URL : /api/v1/scans 發送參數: 發送參數 類型 說明 profile_id string 掃描類型 ui_session_i string 可不傳 schedule json 掃描時間設置(默認即時) report_template string 掃描報告類型(可不傳) target_id string 目標id ''' def start_target(target_id,profile_id): url = 'https://' + IP + ':13443/api/v1/scans' # schedule={"disable": False, "start_date": None, "time_sensitive": False} headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} values = { 'target_id': target_id, 'profile_id': profile_id, 'schedule': {"disable":False,"start_date":None,"time_sensitive":False} } data = bytes(json.dumps(values), 'utf-8') request = urllib.request.Request(url, data, headers) html = urllib.request.urlopen(request).read().decode('utf-8') # return html return "now scan {}".format(target_id)
然后先將AWVS上面的任務清空一下,然后整合和調用之前的所有代碼。
清空后的AWVS如圖:
整合調用的全部代碼為(作者去掉了IP和API_KEY,需要讀者按照自己的搭建自行添加,另外還需要注意端口的問題)
import json import ssl import urllib.request import os ssl._create_default_https_context = ssl._create_unverified_context #os.environ['http_proxy'] = 'http://127.0.0.1:8080' #os.environ['https_proxy'] = 'https://127.0.0.1:8080' IP = '' API_KEY = '' ''' create_target函數 功能: AWVS13 新增任務接口 Method : POST URL : /api/v1/targets 發送參數: 發送參數 類型 說明 address string 目標網址:需要http或https開頭 criticality int 危險程度;范圍:[30,20,10,0];默認為10 description string 備注 ''' def create_target(address,description,int_criticality): url = 'https://' + IP + ':13443/api/v1/targets' headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} values = { 'address': address, 'description': description, 'criticality': int_criticality, } data = bytes(json.dumps(values), 'utf-8') request = urllib.request.Request(url, data, headers) html = urllib.request.urlopen(request).read().decode('utf-8') return html def get_target_list(): url = 'https://' + IP + ':3443/api/v1/targets' headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} request = urllib.request.Request(url=url, headers=headers) html = urllib.request.urlopen(request).read().decode('utf-8') return html def profiles_list(): url = 'https://' + IP + ':3443/api/v1/scanning_profiles' headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} request = urllib.request.Request(url=url, headers=headers) html = urllib.request.urlopen(request).read().decode('utf-8') return html ''' start_target 功能: AWVS13 啟動掃描任務接口 Method : POST URL : /api/v1/scans 發送參數: 發送參數 類型 說明 profile_id string 掃描類型 ui_session_i string 可不傳 schedule json 掃描時間設置(默認即時) report_template string 掃描報告類型(可不傳) target_id string 目標id ''' def start_target(target_id,profile_id): url = 'https://' + IP + ':13443/api/v1/scans' # schedule={"disable": False, "start_date": None, "time_sensitive": False} headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} values = { 'target_id': target_id, 'profile_id': profile_id, 'schedule': {"disable":False,"start_date":None,"time_sensitive":False} } data = bytes(json.dumps(values), 'utf-8') request = urllib.request.Request(url, data, headers) html = urllib.request.urlopen(request).read().decode('utf-8') # return html return "now scan {}".format(target_id) def stop_target(target_id): url = 'https://' + IP + ':3443/api/v1/scans/' + target_id + '/abort' headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} request = urllib.request.Request(url=url, headers=headers) html = urllib.request.urlopen(request).read().decode('utf-8') print(html) def target_status(target_id): url = 'https://' + IP + ':3443/api/v1/scans/' + target_id headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} request = urllib.request.Request(url=url, headers=headers) html = urllib.request.urlopen(request).read().decode('utf-8') print(html) def get_target_result(target_id, scan_session_id): url = 'https://' + IP + ':3443/api/v1/scans/' + target_id + '/results/' + scan_session_id + '/vulnerabilities ' headers = {"X-Auth": API_KEY, "content-type": "application/json", 'User-Agent': 'curl/7.53.1'} request = urllib.request.Request(url=url, headers=headers) html = urllib.request.urlopen(request).read().decode('utf-8') print(html) ''' 主要使用批量添加與啟動掃描任務的功能 即create_target()函數與start_target()函數 ''' def main(): testurl='https://www.zsjjob.com/' description="null" int_criticality=10 target_id=create_target(testurl,description,int_criticality).split('"')[21] print(start_target(target_id,'11111111-1111-1111-1111-111111111111')) if __name__=='__main__': main()
運行之
可以看到任務已經自動運行起來了,讀者可以根據自己的URL.txt,修改上述代碼,使其更符合業務需求。
另外需要注意的是,AWVS的批量添加URL中,都是需要http或者https開頭的!!
以上(開始快樂批量掃描趴)
參考鏈接:
https://blog.csdn.net/sinat_25449961/article/details/82985638