Example #1
0
def web_flush(req):
    """
    请求所有的扫描任务
    :param req:
    :return:
    """
    http = Http('http', host, port)
    taskStr = http.get('/admin/0/flush')
    taskObj = json.loads(taskStr)
    return HttpResponse(json.dumps(taskObj, ensure_ascii=False))
Example #2
0
def add_task(req, tamper=""):
    """
    添加扫描任务
    :param req: 请求对象
    :param tamper: 绕过脚本
    :return:
    """
    data = json.loads(req.body)
    taskid = ""
    if tamper:
        data['tamper'] = tamper

    data = json.dumps(data)
    http = Http('http', host, port)
    taskObj = get_taskid(http)
    if taskObj.get('success') == 'true' or taskObj.get('success') == True:
        taskid = taskObj.get('taskid')
    else:
        taskObj["msg"] = u"获取taskID失败"
        return taskObj
    # 启动扫描任务
    taskObj = send2task(http, data, taskid)
    if taskObj.get("success") == "false":
        taskObj["msg"] = u"获取taskID成功但任务启动失败!"
    return taskid
Example #3
0
    def exploit(self):

        while True:
            if self.cms_queue.empty() is False:

                obj = CmsInfo.objects.get(id=self.id)
                if obj is None or obj.status == "stop":
                    #print "任务【%s】被删除" % self.id
                    break

                exp_info = eval(str(self.cms_queue.get()))
                # 不要忘记请求图片类型,无法获取content
                cms_name = exp_info.get("cms")
                version = exp_info.get("version")
                keyword = exp_info.get("keyword")
                cms_md5 = exp_info.get("md5")
                url = self.host + exp_info.get("url")
                http = Http('http', self.host, "")
                html_content,code = http.post_(url)

                # 计算进度
                progress = 1-float(format(float(self.cms_queue.qsize())/float(self.cms_queue_oldsize),'.4f'))
                progress = '%.2f' % (progress * 100)

                # 实时日志
                log = "【%s】正在测试【%s】" % (str(progress)+"%",str(url))
                #print log
                CmsInfo.objects.filter(id=self.id,locker="false").update(end_time=currenttime(),status="running",progress=progress,log=str(log))

                # 如果有关键字,就用关键字比较
                if code == 200:
                    md5 = self.get_md5_value(html_content)
                    if cms_md5 == "" or cms_md5 is None:
                        # 当md5为空时,比较关键字
                        if keyword in html_content:
                            self.save(exp_info,keyword,cms_name,version)
                            break
                    if md5 == cms_md5:
                        self.save(exp_info,md5,cms_name,version)
                        break

            else:
                CmsInfo.objects.filter(id=self.id,locker="false").update(end_time=currenttime(),status="success",progress="100",log="【%s】检测完成" % self.host,locker="true")
                self.cms_queue.queue.clear()
                break
Example #4
0
def web_log(req):
    """
    获取扫描日志
    :param req:
    :return:
    """
    http = Http('http', host, port)
    data = json.loads(req.body)
    log = get_taskLog(http, data.get("taskid"))
    return HttpResponse(json.dumps(log.get("log"), ensure_ascii=False))
Example #5
0
def task_stop(req):
    """
    结束扫描任务
    :param req:
    :return:
    """
    data = json.loads(req.body)
    http = Http('http', host, port)
    obj = {"success": "true", "msg": "任务已停止"}
    if data and data.get("taskid"):
        for taskid in data.get("taskid"):
            obj = stop(http, taskid)
            if obj.get("success") == "false" or obj.get("success") == False:
                return HttpResponse(json.dumps(obj, ensure_ascii=False))
    return HttpResponse(json.dumps(obj, ensure_ascii=False))
Example #6
0
def web_delete(req):
    """
    删除扫描任务
    :param req:
    :return:
    """
    data = json.loads(req.body)
    http = Http('http', host, port)
    obj = {"success": "true", "msg": "删除成功"}
    if data and data.get("taskid"):
        for taskid in data.get("taskid"):
            obj = task_delete(http, taskid)
            if obj.get("success") == "false" or obj.get("success") == False:
                obj["msg"] = obj.get("message")
                return HttpResponse(json.dumps(obj, ensure_ascii=False))
    return HttpResponse(json.dumps(obj, ensure_ascii=False))
Example #7
0
def alltasks(req):
    """
    获取sqlmap扫描任务列表
    :param req:
    :return:
    """

    http = Http('http', host, port)
    taskid = "0"
    lists = task_list(http, taskid)
    data = {"total": lists.get("tasks_num"), "rows": []}
    # 获取所有的任务id
    for taskid in lists.get("tasks"):
        rows = {
            "id": "id",
            "status": "1",
            "result": "1",
            "progress": "1",
            "start_time": "1H",
            "end_time": "1H"
        }
        rows["id"] = taskid
        rows["status"] = lists.get("tasks").get(taskid)
        rows["start_time"], rows["end_time"] = task_utime(http, taskid)
        taskData = get_taskData(http, taskid)
        if taskData.get("success") == True:
            if len(taskData.get("data")) == 0 and len(
                    taskData.get("error")) < 1:
                rows["result"] = u"扫描未完成或无漏洞"
            elif len(taskData.get("data")) == 0 and len(
                    taskData.get("error")) > 0:
                rows["result"] = u"扫描出错"
            elif len(taskData.get("data")) > 0 and taskData.get("data")[0].get(
                    "status") == 1:
                rows["result"] = u"有漏洞"
            else:
                rows["result"] = u"无漏洞"
        else:
            rows["result"] = u"任务失败"
        data["rows"].append(rows)
    data["rows"].sort(lambda x, y: cmp(x['start_time'], y['start_time']))
    data["rows"] = sorted(data["rows"], key=lambda x: x['start_time'])
    return HttpResponse(json.dumps(data["rows"], ensure_ascii=False))
Example #8
0
    """
    taskStr = http.get('/admin/%s/list' % (taskid))
    print taskStr


host = "127.0.0.1"
port = "8889"
taskid = ""
adminID = "ce5289b7c98f7304a791ef3c22ca3280"
url = 'http://192.168.1.175:8099/test.php?id=1'
data = {}
data['url'] = url
data['tamper'] = "versionedmorekeywords"
data = json.dumps(data)
http = Http('http', host, port)
taskObj = get_taskid(http)
print type(taskObj)
if taskObj.get('success') == 'true' or taskObj.get('success') == True:
    taskid = taskObj.get('taskid')
else:
    print u"获取taskid失败"
#taskid = "9b983be267d395a1"
# 启动扫描任务
send2task(http,data,taskid)
# 查看扫描结果
get_taskData(http,taskid)
# 查看扫描日志
get_taskLog(http,taskid)
# 查看扫描状态
get_taskStatus(http,taskid)