利用acunetix-api进行扫描

来源:互联网 发布:淘宝上出售游戏账号 编辑:程序博客网 时间:2024/04/29 16:28
自从Acunetix Web Vulnerability Scanner 11.x被52的大大Hmily破解以后,被它的界面惊艳到了。想着这玩意如果分布式的部署起来扫描应该会很爽。找了资料,发现api从官方获取好像需要联系他们。网速的相关东西很少。

主要依靠https://github.com/jenkinsci/acunetix-plugin/blob/master/src/main/java/com/acunetix/Engine.java里面所提供的api改写而来.

全局依赖于获取到的api-key
headers = {"X-Auth":apikey,"content-type": "application/json"}
1.添加任务
post /api/v1/targets
data = {"address":url,"description":url,"criticality":"10"}
2.扫描任务
post /api/v1/scans
data = {"target_id":target_id,"profile_id":"11111111-1111-1111-1111-111111111111","schedule": {"disable": False,"start_date":None,"time_sensitive": False}}
target_id 为第一步添加任务返回的结果
3.获取任务概要
get /api/v1/scans
4.获取任务详情
get /api/v1/scans/+scan_id
5.生成报告
post /api/v1/reports
data = {"template_id":"11111111-1111-1111-1111-111111111111","source":{"list_type":"scans","id_list":[scan_id]}}



转换了python格式的。添加的时候检测是否重复,获取全部的扫描查看状态是否结束,结束就输出报告
复制代码
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-

  3. import json
  4. import requests
  5. import requests.packages.urllib3
  6. '''
  7. import requests.packages.urllib3.util.ssl_
  8. requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL'

  9. or

  10. pip install requests[security]
  11. '''
  12. requests.packages.urllib3.disable_warnings()

  13. tarurl = "https://127.0.0.1:3443/"
  14. apikey="yourapikey"
  15. headers = {"X-Auth":apikey,"content-type": "application/json"}

  16. def addtask(url=''):
  17.     #添加任务
  18.     data = {"address":url,"description":url,"criticality":"10"}
  19.     try:
  20.         response = requests.post(tarurl+"/api/v1/targets",data=json.dumps(data),headers=headers,timeout=30,verify=False)
  21.         result = json.loads(response.content)
  22.         return result['target_id']
  23.     except Exception as e:
  24.         print(str(e))
  25.         return

  26. def startscan(url):
  27.     # 先获取全部的任务.避免重复
  28.     # 添加任务获取target_id
  29.     # 开始扫描
  30.     targets = getscan()
  31.     if url in targets:
  32.         return "repeat"
  33.     else:
  34.         target_id = addtask(url)
  35.         data = {"target_id":target_id,"profile_id":"11111111-1111-1111-1111-111111111111","schedule": {"disable": False,"start_date":None,"time_sensitive": False}}
  36.         try:
  37.             response = requests.post(tarurl+"/api/v1/scans",data=json.dumps(data),headers=headers,timeout=30,verify=False)
  38.             result = json.loads(response.content)
  39.             return result['target_id']
  40.         except Exception as e:
  41.             print(str(e))
  42.             return

  43. def getstatus(scan_id):
  44.     # 获取scan_id的扫描状况
  45.     try:
  46.         response = requests.get(tarurl+"/api/v1/scans/"+str(scan_id),headers=headers,timeout=30,verify=False)
  47.         result = json.loads(response.content)
  48.         status = result['current_session']['status']
  49.         #如果是completed 表示结束.可以生成报告
  50.         if status == "completed":
  51.             return getreports(scan_id)
  52.         else:
  53.             return result['current_session']['status']
  54.     except Exception as e:
  55.         print(str(e))
  56.         return

  57. def getreports(scan_id):
  58.     # 获取scan_id的扫描报告
  59.     data = {"template_id":"11111111-1111-1111-1111-111111111111","source":{"list_type":"scans","id_list":[scan_id]}}
  60.     try:
  61.         response = requests.post(tarurl+"/api/v1/reports",data=json.dumps(data),headers=headers,timeout=30,verify=False)
  62.         result = response.headers
  63.         report = result['Location'].replace('/api/v1/reports/','/reports/download/')
  64.         return tarurl.rstrip('/')+report
  65.     except Exception as e:
  66.         print(str(e))
  67.         return

  68. def getscan():
  69.     #获取全部的扫描状态
  70.     targets = []
  71.     try:
  72.         response = requests.get(tarurl+"/api/v1/scans",headers=headers,timeout=30,verify=False)
  73.         results = json.loads(response.content)
  74.         for result in results['scans']:
  75.             targets.append(result['target']['address'])
  76.             print result['scan_id'],result['target']['address'],getstatus(result['scan_id'])#,result['target_id']
  77.         return list(set(targets))
  78.     except Exception as e:
  79.         raise e

  80. if __name__ == '__main__':
  81.     print startscan('http://testhtml5.vulnweb.com/')

感觉排版有点问题.原文件在https://github.com/0xa-saline/acunetix-api/blob/master/acunetix.py

详情参考
http://0cx.cc/about_awvs11_api.jspx


无耻的打了个广告



last:有人问咋个可以远程访问
[attachment=5443]