Exemplo n.º 1
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
Exemplo n.º 2
0
def scope():
    scope = ScopeItem.getScope()
    scopeSize = current_app.ScopeManager.getScopeSize()
    if scopeSize == 0:  # if it's zero, let's update the app's scopemanager
        current_app.ScopeManager.update()
        scopeSize = current_app.ScopeManager.getScopeSize(
        )  # if it's zero again that's fine, we just had to check
    newForm = NewScopeForm()
    delForm = ScopeDeleteForm()
    editForm = ScopeToggleForm()
    importForm = ImportScopeForm()
    addTagForm = TagScopeForm()
    addTagForm.tagname.choices = [(row.name, row.name)
                                  for row in Tag.query.all()]
    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=False)
        db.session.add(newTarget)
        db.session.commit()
        current_app.ScopeManager.update()
        flash('%s added!' % newTarget.target, 'success')
        return redirect(url_for('admin.scope'))
    return render_template("admin/scope.html", scope=scope, scopeSize=scopeSize, delForm=delForm, editForm=editForm, newForm=newForm, importForm=importForm, \
     addTagForm=addTagForm)
Exemplo n.º 3
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.")
Exemplo n.º 4
0
    def update_scope(self):
        from app.models import ScopeItem

        self.scope = [
            IPNetwork(item.target, False) for item in ScopeItem.getScope()
        ]
        self.scope_set = IPSet(self.scope)
        self.scopeSize = self.scope_set.size
Exemplo n.º 5
0
 def updateScope(self):
     from app.models import ScopeItem
     newScopeSize = 0
     for item in ScopeItem.getScope():
         newItem = ipaddress.ip_network(item.target, False)
         self.scope.append(newItem)
         newScopeSize += newItem.num_addresses
     self.scopeSize = newScopeSize
Exemplo n.º 6
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)
Exemplo n.º 7
0
def test_import_items_scope_flag(runner):
    with runner.isolated_filesystem():
        scope_file = mock_scope_file()
        result = runner.invoke(import_items, ["--scope", scope_file])
        assert result.exit_code == 0
        imported_scope = [item.target for item in ScopeItem.getScope()]
        assert DEFAULT_SCOPE_ITEMS == imported_scope
        result_dict = json.loads(result.output)
        assert len(result_dict["scope"]) == len(DEFAULT_SCOPE_ITEMS)
Exemplo n.º 8
0
 def update_scope(self):
     from app.models import ScopeItem
     newScope = []
     newScopeSet = IPSet()
     for item in ScopeItem.getScope():
         newItem = ipaddress.ip_network(item.target, False)
         newSetItem = IPNetwork(item.target, False)
         newScope.append(newItem)
         newScopeSet.add(newSetItem)
     self.scope = newScope
     self.scope_set = newScopeSet
     self.scopeSize = len(self.scope_set)
Exemplo n.º 9
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))
Exemplo n.º 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
Exemplo n.º 11
0
def scope():
    scope = ScopeItem.getScope()
    scopeSize = current_app.ScopeManager.get_scope_size()

    # if it's zero, let's make sure the ScopeManager is up to date
    if scopeSize == 0:
        current_app.ScopeManager.update()
        scopeSize = current_app.ScopeManager.get_scope_size()
        # if it's zero again that's fine, we just had to check

    effectiveScopeSize = current_app.ScopeManager.get_effective_scope_size()

    newForm = forms.NewScopeForm()
    delForm = forms.ScopeDeleteForm()
    editForm = forms.ScopeToggleForm()
    importForm = forms.ImportScopeForm()
    addTagForm = forms.TagScopeForm()
    addTagForm.tagname.choices = [(row.name, row.name)
                                  for row in Tag.query.all()]
    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=False)
        db.session.add(newTarget)
        db.session.commit()
        current_app.ScopeManager.update()
        flash(f"{newTarget.target} added!", "success")
        return redirect(url_for("admin.scope"))
    return render_template(
        "admin/scope.html",
        scope=scope,
        scopeSize=scopeSize,
        delForm=delForm,
        editForm=editForm,
        newForm=newForm,
        importForm=importForm,
        addTagForm=addTagForm,
        effectiveScopeSize=effectiveScopeSize,
    )
Exemplo n.º 12
0
def scope():
    render = {
        "scope": ScopeItem.getScope(),
        "scopeSize": current_app.ScopeManager.get_scope_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=False)
        db.session.add(newTarget)
        db.session.commit()
        current_app.ScopeManager.update()
        flash(f"{newTarget.target} added.", "success")
        return redirect(url_for("admin.scope"))
    return render_template("admin/scope.html", **render)