Example #1
0
def get_scan(req, scan_id):
    db = UmitDB()
    if scan_id not in [str(sid) for sid in db.get_scans_ids()]:
        raise Http404

    scan = Scans(scans_id=scan_id)
    ftemp = open(mktemp(), "w", 0)
    ftemp.write(scan.nmap_xml_output)
    ftemp.flush()
    parser = NmapParser(ftemp.name)
    parser.parse()
    return HttpResponse("{'result': 'OK', 'output': '%s', 'xml': '%s'}" % \
                        (parser.get_nmap_output().replace("'", "\\'").\
                        replace("\r", "").replace("\n", "\\n' + \n'"),
                        open(ftemp.name).read().replace('"', "'").\
                        replace("'", "\\'").\
                        replace("\n", "\\n' + \n'")),
                        "text/plain")
Example #2
0
def get_scan(req, scan_id):
    db = UmitDB()
    if scan_id not in [str(sid) for sid in db.get_scans_ids()]:
        raise Http404

    scan = Scans(scans_id=scan_id)
    ftemp = open(mktemp(), "w", 0)
    ftemp.write(scan.nmap_xml_output)
    ftemp.flush()
    parser = NmapParser(ftemp.name)
    parser.parse()
    return HttpResponse(
        "{'result': 'OK', 'output': '%s', 'xml': '%s'}"
        % (
            parser.get_nmap_output().replace("'", "\\'").replace("\r", "").replace("\n", "\\n' + \n'"),
            open(ftemp.name).read().replace('"', "'").replace("'", "\\'").replace("\n", "\\n' + \n'"),
        ),
        "text/plain",
    )
Example #3
0
def upload_result(req):
    if req.POST:
        if req.POST['type'] == "file":
            try:
                parser = NmapParser()
                parser.set_xml_file(req.FILES['scan_result']['temp_file'])
                parser.parse()
                parsed_scan = ScanJsonParser(parser).parse()
                junk = r"odpojfsdkjfpisudŕij208u-0w9rsdnfkdfçwrtwqr/fsasd~/???çds"
                key = md5.new(str(random.randint(0, sys.maxint-1)) \
                                  + str(random.randint(1, sys.maxint-1)//2) \
                                  + junk).hexdigest()
                req.session['scan_result_' + key] = open(
                    req.FILES['scan_result']['temp_name'], 'r').read()
                text_out = parser.nmap_output.replace("'", "\\'").replace(
                    "\r", "").replace("\n", "\\n' + \n'")
                parsed_scan = parsed_scan.replace("\n", "\\n' + \n'")
                return HttpResponse(("{'result': 'OK', 'id': '%s', 'output': " + \
                                    "{'plain': '%s', 'full': %s}}") % \
                                    (key, text_out, parsed_scan), "text/plain")
            except Exception, ex:
                logger.error("ERROR PARSING SCAN: %s" % str(ex))
                return HttpResponse(
                    "{'result': 'FAIL', 'output': '%s'}" %
                    str(ex).replace("'", "\\'"), "text/plain")
        else:
            scan_id = req.POST['scanId']
            db = UmitDB()
            if scan_id not in [str(sid) for sid in db.get_scans_ids()]:
                return HttpResponse(
                    "{'result': 'FAIL', 'output': 'Scan not found!'}")

            scan = Scans(scans_id=scan_id)
            ftemp = open(mktemp(), "w", 0)
            ftemp.write(scan.nmap_xml_output)
            ftemp.flush()
            parser = NmapParser(ftemp.name)
            parser.parse()
            return HttpResponse("{'result': 'OK', 'output': {'plain': '%s', 'full': %s}}" % \
                                (parser.get_nmap_output().replace("'", "\\'").\
                                replace("\r", "").replace("\n", "\\n' + \n'"),
                                ScanJsonParser(parser).parse()),
                                "text/plain")
Example #4
0
def upload_result(req):
    if req.POST:
        if req.POST["type"] == "file":
            try:
                parser = NmapParser()
                parser.set_xml_file(req.FILES["scan_result"]["temp_file"])
                parser.parse()
                parsed_scan = ScanJsonParser(parser).parse()
                junk = r"odpojfsdkjfpisudŕij208u-0w9rsdnfkdfçwrtwqr/fsasd~/???çds"
                key = md5.new(
                    str(random.randint(0, sys.maxint - 1)) + str(random.randint(1, sys.maxint - 1) // 2) + junk
                ).hexdigest()
                req.session["scan_result_" + key] = open(req.FILES["scan_result"]["temp_name"], "r").read()
                text_out = parser.nmap_output.replace("'", "\\'").replace("\r", "").replace("\n", "\\n' + \n'")
                parsed_scan = parsed_scan.replace("\n", "\\n' + \n'")
                return HttpResponse(
                    ("{'result': 'OK', 'id': '%s', 'output': " + "{'plain': '%s', 'full': %s}}")
                    % (key, text_out, parsed_scan),
                    "text/plain",
                )
            except Exception, ex:
                logger.error("ERROR PARSING SCAN: %s" % str(ex))
                return HttpResponse("{'result': 'FAIL', 'output': '%s'}" % str(ex).replace("'", "\\'"), "text/plain")
        else:
            scan_id = req.POST["scanId"]
            db = UmitDB()
            if scan_id not in [str(sid) for sid in db.get_scans_ids()]:
                return HttpResponse("{'result': 'FAIL', 'output': 'Scan not found!'}")

            scan = Scans(scans_id=scan_id)
            ftemp = open(mktemp(), "w", 0)
            ftemp.write(scan.nmap_xml_output)
            ftemp.flush()
            parser = NmapParser(ftemp.name)
            parser.parse()
            return HttpResponse(
                "{'result': 'OK', 'output': {'plain': '%s', 'full': %s}}"
                % (
                    parser.get_nmap_output().replace("'", "\\'").replace("\r", "").replace("\n", "\\n' + \n'"),
                    ScanJsonParser(parser).parse(),
                ),
                "text/plain",
            )