吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 40643|回复: 85
收起左侧

[原创工具] awvs11批量添加扫描\删除小脚本

  [复制链接]
jamesj 发表于 2017-5-24 12:03
本帖最后由 jamesj 于 2017-6-19 08:58 编辑

AWVS11的PojIe版本出来了,但是好像没有批量添加的功能,分享一个我写的脚本可以批量添加扫描内容。
用python写的小工具,使用方法在脚本里面写了出来。新人第一次发帖请多包涵

脚本文件

脚本文件

图一为代码
22.png
图二为效果

===================================================================================
2017/06/11 update:
1、新增批量删除功能,新增批量删除脚本添加的任务。(*判断依据为脚本添加的任务,description为“222”,请悉知!避免造成误删除。)
2、增加交互。
3、分解成多个函数便于大家分析awvs的接口
4、更多说明请看备注,使用大量备注:)
@2337880337
图一代码
222.png
新增批量删除功能
图二、界面
111.png
图三、效果
333.png

链接: https://pan.baidu.com/s/1i4Pl3Ad 密码: jye7

免费评分

参与人数 17吾爱币 +21 热心值 +15 收起 理由
larry_liu + 1 + 1 我很赞同!
小呆瓜 + 1 谢谢@Thanks!
Matrix_17 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
你要昂首挺胸! + 1 + 1 伸手要一下awvs~~~
arryboom + 2 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
唯爱是诺 + 1 热心回复!
fifysky + 1 + 1 多谢分享
52пойиe + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
203156 + 1 + 1 楼主能不能给我发个 原版安装包
jtfz + 1 我很赞同!
kk85125a + 1 + 1 谢谢@Thanks!
szqever + 1 谢谢@Thanks!
漢煙鍋 + 1 + 1 我很赞同!
纸条 + 1 + 1 谢谢大神!能否把批量删除任务也加上。
asm_siliing1949 + 1 + 1 谢谢@Thanks!
ermao + 1 + 1 谢谢@Thanks!
Hmily + 6 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Dlan 发表于 2017-6-4 13:15
[Java] 纯文本查看 复制代码
package com.acunetix;

import com.google.common.base.Charsets;
import net.sf.json.JSONArray;
import net.sf.json.JSONNull;
import net.sf.json.JSONObject;

import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.URL;
import java.nio.file.Paths;
import java.util.*;


public class Engine {
    private String apiUrl;
    private String apiKey;
    private static final Map<String, String[]> threatCategory = new HashMap<>();

    static {
        threatCategory.put("High", new String[]{"3"});
        threatCategory.put("Medium", new String[]{"3", "2"});
        threatCategory.put("Low", new String[]{"3", "2", "1"});
    }

    public Engine(String apiUrl, String apiKey) {
//        System.setProperty("proxySet", "true");
//        System.getProperty("proxySet");

        this.apiUrl = apiUrl;
        this.apiKey = apiKey;
    }

    public static String getThreatName(String threat) {
        switch (threat) {
            case "3":
                return "High";
            case "2":
                return "Medium";
            case "1":
                return "Low";
        }
        return null;
    }

    private static class Resp {
        int respCode;
        String respStr = null;
        JSONObject jso = null;
    }


    private HttpsURLConnection openConnection(String endpoint, String method) throws IOException {
        return openConnection(endpoint, method, "application/json; charset=UTF-8");
    }

    private HttpsURLConnection openConnection(String endpoint) throws IOException {
        return openConnection(endpoint, "GET", "application/json; charset=UTF-8");
    }

    private HttpsURLConnection openConnection(String endpoint, String method, String contentType) throws IOException {
        URL url = new URL(endpoint);
        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
        connection.setRequestMethod(method);
        connection.setRequestProperty("Content-Type", contentType);
        connection.setRequestProperty("User-Agent", "Mozilla/5.0");
        connection.addRequestProperty("X-AUTH", apiKey);
        return connection;
    }


    public Resp doGet(String urlStr) throws IOException {
        HttpsURLConnection connection = openConnection(urlStr);
        try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"))) {
            String inputLine;
            StringBuilder resbuf = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                resbuf.append(inputLine);
            }

            Resp resp = new Resp();
            resp.respCode = connection.getResponseCode();
            resp.jso = JSONObject.fromObject(resbuf.toString());
            return resp;
        }
    }

    public String doDownload(String urlStr, String savePath, String buildNumber) throws IOException {
        HttpsURLConnection connection = openConnection(urlStr, "GET", "text/html; charset=UTF-8");

        try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"))) {
            // get the file name
            String cd = connection.getHeaderField("Content-Disposition");
            String fileName = null;
            if (cd != null && cd.contains("=")) {
                fileName = cd.split("=")[1].trim().replaceAll("\"", "");
            }
            String filePath = findAvailableFileName(savePath, buildNumber, fileName);
            String inputLine;
            try {
                try (FileOutputStream dfile = new FileOutputStream(filePath)) {
                    while ((inputLine = in.readLine()) != null) {
                        dfile.write(inputLine.getBytes(Charsets.UTF_8));
                    }
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            return fileName;
        }
    }

    public int doTestConnection(String urlStr) throws IOException {
        HttpsURLConnection connection = openConnection(urlStr);
        return connection.getResponseCode();
    }

    public Resp doPost(String urlStr) throws IOException {
        HttpsURLConnection connection = openConnection(urlStr,"POST");
        connection.setUseCaches(false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        Resp resp = new Resp();
        resp.respCode = connection.getResponseCode();
        return resp;
    }

    public Resp doPostLoc(String urlStr, String urlParams) throws IOException {
        HttpsURLConnection connection = openConnection(urlStr, "POST");
        connection.setUseCaches(false);
        connection.setDoInput(true);
        connection.setDoOutput(true);

        try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
            outputStream.writeBytes(urlParams);
        }

        String location = connection.getHeaderField("Location");
        Resp resp = new Resp();
        resp.respCode = connection.getResponseCode();
        resp.respStr = location.substring(location.lastIndexOf("/") + 1);
        return resp;
    }

    public JSONArray getTargets() throws IOException {
        Resp resp = doGet(apiUrl + "/targets");
        if (resp.respCode == 200) {
            return resp.jso.getJSONArray("targets");
        }
        throw new IOException(SR.getString("bad.response.0", resp.respCode));
    }

    public String getTargetName(String targetId) throws IOException {
        JSONObject jso = doGet(apiUrl + "/targets").jso;
        JSONArray targets = jso.getJSONArray("targets");
        for (int i = 0; i < targets.size(); i++) {
            JSONObject item = targets.getJSONObject(i);
            String target_id = item.getString("target_id");
            if (target_id.equals(targetId)) {
                String address = item.getString("address");
                String description = item.getString("description");
                String target_name = address;
                if (description.length() > 0) {
                    if (description.length() > 100) {
                        description = description.substring(0, 100);
                    }
                    target_name += "  (" + description + ")";
                }
                return target_name;
            }
        }
        return null;
    }

    public JSONArray getScanningProfiles() throws IOException {
        Resp resp = doGet(apiUrl + "/scanning_profiles");
        if (resp.respCode == 200) {
            return resp.jso.getJSONArray("scanning_profiles");
        }
        throw new IOException(SR.getString("bad.response.0", resp.respCode));
    }

    public Boolean checkScanExist(String scanId) {
        try {
            JSONArray scans = getScans();
            for (int i = 0; i < scans.size(); i++) {
                JSONObject item = scans.getJSONObject(i);
                String id = item.getString("scan_id");
                if (id.equals(scanId)) {
                    return true;
                }
            }
        }
        catch (IOException e){
            e.printStackTrace();
        }
        return false;
    }

    public String startScan(String scanningProfileId, String targetId, Boolean waitFinish) throws IOException {
        JSONObject jso = new JSONObject();
        jso.put("target_id", targetId);
        jso.put("profile_id", scanningProfileId);
        JSONObject jsoChild = new JSONObject();
        jsoChild.put("disable", false);
        jsoChild.put("start_date", JSONNull.getInstance());
        jsoChild.put("time_sensitive", false);
        jso.put("schedule", jsoChild);
        String scanId = doPostLoc(apiUrl + "/scans", jso.toString()).respStr;
        if (waitFinish) {
            while (!getScanStatus(scanId).equals("completed")) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        return scanId;
    }


    private JSONArray getScans() throws IOException {
        Resp resp = doGet(apiUrl + "/scans");
        if (resp.respCode == 200) {
            return resp.jso.getJSONArray("scans");
        }
        throw new IOException(SR.getString("bad.response.0", resp.respCode));
    }

    public String getScanThreat(String scanId) throws IOException {
        JSONObject jso = doGet(apiUrl + "/scans/" + scanId).jso;
        return jso.getJSONObject("current_session").getString("threat");
    }


    public String getScanStatus(String scanId) throws IOException {
        JSONObject jso = doGet(apiUrl + "/scans/" + scanId).jso;
        return jso.getJSONObject("current_session").getString("status");
    }

    public void stopScan(String scanId) {
        try {
            Resp resp = doPost(apiUrl + "/scans/" + scanId + "/abort");
            if (resp.respCode != 204) {
                throw new IOException(SR.getString("bad.response.0", resp.respCode));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public JSONArray getReportTemplates() throws IOException {
        Resp resp = doGet(apiUrl + "/report_templates");
        if (resp.respCode == 200) {
            return resp.jso.getJSONArray("templates");
        }
        throw new IOException(SR.getString("bad.response.0", resp.respCode));
    }

    public String getReportTemplateName(String reportTemplateId) throws IOException {
        Resp resp = doGet(apiUrl + "/report_templates");
        if (resp.respCode == 200) {
            JSONArray jsa = resp.jso.getJSONArray("templates");
            for (int i = 0; i < jsa.size(); i++) {
                JSONObject item = jsa.getJSONObject(i);
                if (item.getString("template_id").equals(reportTemplateId)) {
                    return item.getString("name");
                }
            }
            return null;
        }
        throw new IOException(SR.getString("bad.response.0", resp.respCode));
    }

    private String getReportStatus(String reportId) throws IOException {
        JSONObject jso = doGet(apiUrl + "/reports/" + reportId).jso;
        return jso.getString("status");
    }

    public void waitReportStatus(String reportId) throws IOException, InterruptedException {
        while (!getReportStatus(reportId).equals("completed")) {
            Thread.sleep(1000);
        }
    }

    public String generateReport(String sourceId, String reportTemplateId, String listType) throws IOException, InterruptedException {
        //returns download link of html report
        JSONObject jso = new JSONObject();
        jso.put("template_id", reportTemplateId);
        JSONObject jsoChild = new JSONObject();
        jsoChild.put("list_type", listType);
        List<String> id_list = new ArrayList<>();
        id_list.add(sourceId);
        jsoChild.put("id_list", id_list);
        jso.put("source", jsoChild);
        String reportId = doPostLoc(apiUrl + "/reports", jso.toString()).respStr;
        waitReportStatus(reportId);
        String[] downloadLinkList = doGet(apiUrl + "/reports/" + reportId).jso.getString("download").split(",");
        String downloadLink = null;
        for (String item : downloadLinkList) {
            if (item.contains(".html")) {
                downloadLink = item.replaceAll("\"", "").replaceAll("\\[", "".replaceAll("]", ""));
                break;
            }
        }
        // download report
        return downloadLink;
    }

    public Boolean checkThreat(String checkThreat, String scanThreat) {
        //return true if the threat detected is equal or greater than threat set
        //checkthreat is the level set in plugin config and scanThreat from the scan result
        if (checkThreat.equals("DoNotFail")) {
            return false;
        }
        return Arrays.asList(threatCategory.get(checkThreat)).contains(scanThreat);
    }

    public String findAvailableFileName(String savePath, String buildNumber, String reportName) {
        int i = 1;
        while (true) {
            String fileName = Paths.get(savePath, buildNumber + "_" + i + "_" + reportName).toString();
            File f = new File(fileName);
            if (f.exists()) {
                i++;
            } else {
                return fileName;
            }
        }
    }

}
 楼主| jamesj 发表于 2017-5-24 12:19
本帖最后由 jamesj 于 2017-5-25 17:11 编辑

------username------- 替换为用户名,
------pw---------替换为密码sha256后的密码。可以使用以下网址进行加密。http://tool.oschina.net/encrypt?type=2
servers替换awvs地址
默认端口3443,如果有设置不同的端口请批量替换3443,url列表,保存成testawvs.txt文件放到这个脚本同目录下。

不用添加http://的,添加之后会出现下图
尴尬.png
头像被屏蔽
sstm 发表于 2017-5-24 16:51
邪梦 发表于 2017-5-24 17:42
过来支持一下,谢谢楼主分享,
★邪梦 发表于 2017-5-24 17:46
支持楼主,谢谢分享,
tliangg 发表于 2017-5-24 18:31 来自手机
我来学习的,学习学习
六个木 发表于 2017-5-24 18:39 来自手机
支持一下,学习了!
lx403450 发表于 2017-5-24 19:10 来自手机
支持楼主。可以学习下
ganzhijun 发表于 2017-5-24 22:39
看看看这个,谢谢。
 楼主| jamesj 发表于 2017-5-25 00:27
第一次主题贴,有点小紧张{:1_903:}
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-26 03:04

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表