Beispiel #1
0
def blacklist():
    scope = ScopeItem.getBlacklist()
    blacklistSize = current_app.ScopeManager.get_blacklist_size()
    newForm = forms.NewScopeForm()
    delForm = forms.ScopeDeleteForm()
    editForm = forms.ScopeToggleForm()
    importForm = forms.ImportBlacklistForm()
    addTagForm = forms.TagScopeForm()
    addTagForm.tagname.choices = [(row.name, row.name) for row in Tag.query.all()]
    if newForm.validate_on_submit():
        target = ipaddress.ip_network(newForm.target.data, False)
        newTarget = ScopeItem(target=target.with_prefixlen, blacklist=True)
        db.session.add(newTarget)
        db.session.commit()
        current_app.ScopeManager.update()
        flash(f"{newTarget.target} blacklisted!", "success")
        return redirect(url_for("admin.blacklist"))
    return render_template(
        "admin/blacklist.html",
        scope=scope,
        blacklistSize=blacklistSize,
        delForm=delForm,
        editForm=editForm,
        newForm=newForm,
        importForm=importForm,
        addTagForm=addTagForm,
    )
Beispiel #2
0
def test_get_scope(app):
    test_scope1 = ScopeItem(target="127.0.0.1/8", blacklist=False)
    test_scope2 = ScopeItem(target="172.16.0.0/16", blacklist=True)
    db.session.add(test_scope1)
    db.session.add(test_scope2)
    assert len(ScopeItem.getScope()) == 1
    assert len(ScopeItem.getBlacklist()) == 1
    def update_blacklist(self):
        from app.models import ScopeItem

        self.blacklist = [
            IPNetwork(item.target, False) for item in ScopeItem.getBlacklist()
        ]
        self.blacklist_set = IPSet(self.blacklist)
        self.blacklistSize = self.blacklist_set.size
Beispiel #4
0
 def updateBlacklist(self):
     from app.models import ScopeItem
     newBlacklistSize = 0
     for item in ScopeItem.getBlacklist():
         newItem = ipaddress.ip_network(item.target, False)
         self.blacklist.append(newItem)
         newBlacklistSize += newItem.num_addresses
     self.blacklistSize = newBlacklistSize
Beispiel #5
0
	def updateScanManager(self):
		from app.models import ScopeItem
		self.scanmanager = None
		try:
			scanrange = [IPNetwork(n.target) for n in ScopeItem.getScope()]
			blacklistrange = [IPNetwork(n.target) for n in ScopeItem.getBlacklist()]
			self.scanmanager = IPScanManager(scanrange, blacklistrange)
		except Exception as e:
			log("Scan manager could not be instantiated because there was no scope configured.", printm=True)
Beispiel #6
0
def test_import_items_blacklist_flag(runner):
    with runner.isolated_filesystem():
        scope_file = mock_scope_file()
        result = runner.invoke(import_items, ["--blacklist", scope_file])
        assert result.exit_code == 0
        imported_blacklist = [item.target for item in ScopeItem.getBlacklist()]
        assert DEFAULT_SCOPE_ITEMS == imported_blacklist
        result_dict = json.loads(result.output)
        assert len(result_dict["blacklist"]) == len(DEFAULT_SCOPE_ITEMS)
Beispiel #7
0
 def update_blacklist(self):
     from app.models import ScopeItem
     newBlacklist = []
     newBlacklistSet = IPSet()
     for item in ScopeItem.getBlacklist():
         newItem = ipaddress.ip_network(item.target, False)
         newSetItem = IPNetwork(item.target, False)
         newBlacklist.append(newItem)
         newBlacklistSet.add(newSetItem)
     self.blacklist = newBlacklist
     self.blacklist_set = newBlacklistSet
     self.blacklistSize = len(self.blacklist_set)
Beispiel #8
0
def export_items():
    result = {
        "timestamp":
        datetime.utcnow().isoformat(),
        "scope": [{
            "target": item.target,
            "blacklist": item.blacklist,
            "tags": item.get_tag_names(),
        } for item in ScopeItem.getScope()],
        "blacklist": [{
            "target": item.target,
            "blacklist": item.blacklist,
            "tags": item.get_tag_names(),
        } for item in ScopeItem.getBlacklist()],
    }
    print(json.dumps(result, indent=2))
Beispiel #9
0
def blacklist():
    scope = ScopeItem.getBlacklist()
    blacklistSize = current_app.ScopeManager.getBlacklistSize()
    newForm = NewScopeForm()
    delForm = ScopeDeleteForm()
    editForm = ScopeToggleForm()
    importForm = ImportBlacklistForm()
    if newForm.validate_on_submit():
        if '/' not in newForm.target.data:
            newForm.target.data = newForm.target.data + '/32'
        target = ipaddress.ip_network(newForm.target.data, False)
        newTarget = ScopeItem(target=target.with_prefixlen, blacklist=True)
        db.session.add(newTarget)
        db.session.commit()
        current_app.ScopeManager.updateBlacklist()
        flash('%s blacklisted!' % newTarget.target, 'success')
        return redirect(url_for('admin.blacklist'))
    return render_template("admin/blacklist.html", scope=scope, blacklistSize=blacklistSize, delForm=delForm, editForm=editForm, newForm=newForm, importForm=importForm)
Beispiel #10
0
    def update_scan_manager(self):
        from app.models import ScopeItem

        self.scanmanager = None
        try:
            scanrange = [IPNetwork(n.target) for n in ScopeItem.getScope()]
            blacklistrange = [
                IPNetwork(n.target) for n in ScopeItem.getBlacklist()
            ]
            self.scanmanager = IPScanManager(
                scanrange, blacklistrange,
                current_app.config["CONSISTENT_SCAN_CYCLE"])
        except Exception as e:
            if self.scanmanager is None or self.scanmanager.get_total() == 0:
                log(
                    "Scan manager could not be instantiated because there was no scope configured.",
                    printm=True,
                )
            else:
                raise e
Beispiel #11
0
def blacklist():
    render = {
        "scope": ScopeItem.getBlacklist(),
        "blacklistSize": current_app.ScopeManager.get_blacklist_size(),
        "effectiveScopeSize": current_app.ScopeManager.get_effective_scope_size(),
        "newForm": forms.NewScopeForm(),
        "delForm": forms.ScopeDeleteForm(),
        "editForm": forms.ScopeToggleForm(),
        "importForm": forms.ImportScopeForm(),
        "addTagForm": forms.TagScopeForm(),
    }
    render["addTagForm"].tagname.choices = [
        (row.name, row.name) for row in Tag.query.all()
    ]
    if render["newForm"].validate_on_submit():
        target = ipaddress.ip_network(render["newForm"].target.data, False)
        newTarget = ScopeItem(target=target.with_prefixlen, blacklist=True)
        db.session.add(newTarget)
        db.session.commit()
        current_app.ScopeManager.update()
        flash(f"{newTarget.target} blacklisted.", "success")
        return redirect(url_for("admin.blacklist"))
    return render_template("admin/blacklist.html", **render)
Beispiel #12
0
 def updateScanManager(self):
     from app.models import ScopeItem
     self.scanmanager = None
     try:
         self.scanmanager = IPScanManager([IPNetwork(n.target) for n in ScopeItem.getScope()], [IPNetwork(n.target) for n in ScopeItem.getBlacklist()])
     except Exception as e:
         print("Scan manager could not be instantiated because there was no scope configured.")