New: add special categories quickly

pull/925/head
AntoniaBK 2024-07-03 09:43:48 +02:00
parent a8f9d16ae1
commit 52590c0fe3
4 changed files with 148 additions and 16 deletions

View File

@ -303,7 +303,8 @@ class Lookyloo():
if categ_file.exists():
with categ_file.open() as f:
current_categories = [line.strip() for line in f.readlines()]
return {e: self.taxonomies.revert_machinetag(e) for e in current_categories}
# return {e: self.taxonomies.revert_machinetag(e) for e in current_categories}
return {e: e for e in current_categories}
return {}
def categorize_capture(self, capture_uuid: str, /, category: str) -> None:
@ -311,7 +312,7 @@ class Lookyloo():
if not get_config('generic', 'enable_categorization'):
return
# Make sure the category is mappable to a taxonomy.
self.taxonomies.revert_machinetag(category)
# self.taxonomies.revert_machinetag(category)
categ_file = self._captures_index[capture_uuid].capture_dir / 'categories'
# get existing categories if possible
@ -335,9 +336,10 @@ class Lookyloo():
current_categories = {line.strip() for line in f.readlines()}
else:
current_categories = set()
current_categories.remove(category)
with categ_file.open('w') as f:
f.writelines(f'{t}\n' for t in current_categories)
if category in current_categories:
current_categories.remove(category)
with categ_file.open('w') as f:
f.writelines(f'{t}\n' for t in current_categories)
def trigger_modules(self, capture_uuid: str, /, force: bool=False, auto_trigger: bool=False) -> dict[str, Any]:
'''Launch the 3rd party modules on a capture.

View File

@ -660,19 +660,31 @@ def historical_lookups(tree_uuid: str) -> str | WerkzeugResponse | Response:
circl_pdns=data.get('circl_pdns'))
@app.route('/tree/<string:tree_uuid>/categories_capture/', defaults={'query': ''})
@app.route('/tree/<string:tree_uuid>/categories_capture/', defaults={'query': ''}, methods=['GET', 'POST'])
@app.route('/tree/<string:tree_uuid>/categories_capture/<string:query>', methods=['GET'])
def categories_capture(tree_uuid: str, query: str) -> str | WerkzeugResponse | Response:
if not enable_categorization:
return redirect(url_for('tree', tree_uuid=tree_uuid))
current_categories = lookyloo.categories_capture(tree_uuid)
matching_categories = None
if query:
if 'verification-status' in request.form:
# fast categories
categories = []
possible_ctgs = {'legitime': ["parking-page", "default-page", 'institution', 'captcha', 'authentication-form', 'adult-content', 'shop'],
'malicious': ['clone', 'phishing', 'captcha', 'authentication-form', 'adult-content', 'shop'],
'unclear': ['captcha', 'authentication-form', 'adult-content', 'shop']}
if request.form.get('verification-status') in possible_ctgs.keys():
for category in possible_ctgs[request.form.get('verification-status')]:
if category in request.form:
categories.append(category)
for category in categories:
lookyloo.categorize_capture(tree_uuid, category)
if 'query' in request.form and request.form.get('query').strip():
matching_categories = {}
t = get_taxonomies()
entries = t.search(query)
if entries:
matching_categories = {e: t.revert_machinetag(e) for e in entries}
current_categories = lookyloo.categories_capture(tree_uuid)
return render_template('categories_capture.html', tree_uuid=tree_uuid,
current_categories=current_categories,
matching_categories=matching_categories)

View File

@ -185,4 +185,16 @@ hr {
background: white;
border: 2px solid;
padding: 5px;
}
}
/* Fast categories*/
.fast-categories {
border: 2px solid;
margin: 5px;
padding: 5px;
}
.fast-categories fieldset {
border: 1px solid;
padding: 5px;
}

View File

@ -65,15 +65,79 @@
$('#categoriesModal').on('show.bs.modal', function(e) {
var button = $(e.relatedTarget);
var modal = $(this);
modal.find('#categoriesModal .modal-body').load(button.data("remote"));
modal.find('.modal-body').load(button.data("remote"));
});
$('#searchCategories').submit(function(event){
/*$('#searchCategories').submit(function(event){
var query = $("#query").val();
$('#categoriesModal .modal-body').load("{{ url_for('categories_capture', tree_uuid=tree_uuid) }}" + query, function() {
$('#categoriesModal .modal-body').load("{ url_for('categories_capture', tree_uuid=tree_uuid) }}" + query, function() {
$('#categoriesModal').modal({show:true});
});
event.preventDefault();
});
*/
$('#fast-categories').submit(function(event){
event.preventDefault();
var query = $('#fast-categories').serialize(); // Serialize form data
$.ajax({
type: 'POST',
url: '{{ url_for('categories_capture', tree_uuid=tree_uuid) }}',
data: query,
success: function(response) {
$('#categoriesModal .modal-body').html(response);
$('#categoriesModal').modal({show:true});
},
error: function(error) {
console.log("An error occurred: ", error);
}
});
});
// Fast categories
document.getElementById("legitime").addEventListener('change', function(){
if (this.checked){
disableInput(document.getElementById('malicious-categories'));
enableInput(document.getElementById('legitime-categories'));
}
});
document.getElementById("malicious").addEventListener('change', function(){
if (this.checked){
enableInput(document.getElementById('malicious-categories'));
disableInput(document.getElementById('legitime-categories'));
}
});
document.getElementById("unclear").addEventListener('change', function(){
if (this.checked){
disableInput(document.getElementById('malicious-categories'));
disableInput(document.getElementById('legitime-categories'));
}
});
document.getElementById("legitime-categories").addEventListener('click', function(){
if (this.querySelectorAll('input[type="checkbox"]:checked').length > 0) {
document.getElementById("legitime").checked = true;
}
});
document.getElementById("malicious-categories").addEventListener('click', function(){
if (this.querySelectorAll('input[type="checkbox"]:checked').length > 0) {
document.getElementById("malicious").checked = true;
}
});
function disableInput(container) {
const Input = container.querySelectorAll('input');
Input.forEach(function(checkbox){
checkbox.disabled = true;
checkbox.checked = false;
});
container.hidden = true;
}
function enableInput(container) {
const Input = container.querySelectorAll('input');
Input.forEach(checkbox => checkbox.disabled = false);
container.hidden = false;
}
</script>
<script>
@ -917,6 +981,7 @@
</div>
</div>
</div>
############# got it ####
<div class="modal fade" id="modulesModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-xl" role="document">
@ -1035,7 +1100,6 @@
{% if enable_categorization %}
<div class="modal fade" id="categoriesModal" tabindex="-1" role="dialog">
<!-- bla -->
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
@ -1046,11 +1110,53 @@
... loading the categorization options ...
</div>
<p>
<form id=searchCategories>
<form id="fast-categories" class="fast-categories">
<fieldset id="verification-status">
<input type="radio" id="legitime" name="verification-status" value="legitime">
<label for="legitime">legitime</label>
<input type="radio" id="malicious" name="verification-status" value="malicious">
<label for="malicious">malicious</label>
<input type="radio" id="unclear" name="verification-status" value="unclear">
<label for="unclear">unclear</label>
</fieldset>
<div id="content-categoies">
<p>Content Categories (Multiple Choices possible)</p>
<fieldset id="legitime-categories">
<p>Only if legitime:</p>
<input type="checkbox" id="parking-page" name="parking-page" value="parking-page">
<label for="parking-page">parking-page</label><br>
<input type="checkbox" id="default-page" name="default-page" value="default-page">
<label for="default-page">default-page</label><br>
<input type="checkbox" id="institution" name="institution" value="institution">
<label for="institution">institution / company</label><br>
<!-- the name of the institution/company could be added here in the future, maybe with propositions
<label for="institution-name">Enter the name of the institution/company:</label><br>
<input type="text" id="institution-name" name="institution-name">
-->
</fieldset>
<fieldset id="malicious-categories">
<p>Only if malicious:</p>
<input type="checkbox" id="clone" name="clone" value="clone">
<label for="clone">clone</label><br>
<input type="checkbox" id="phishing" name="phishing" value="phishing">
<label for="phishing">phishing</label><br>
</fieldset>
<input type="checkbox" id="captcha" name="captcha" value="captcha">
<label for="captcha">captcha</label><br>
<input type="checkbox" id="authentication-form" name="authentication-form" value="authentication-form">
<label for="authentication-form">authentication-form</label><br>
<input type="checkbox" id="adult-content" name="adult-content" value="adult-content">
<label for="adult-content">adult-content</label><br>
<input type="checkbox" id="shop" name="shop" value="shop">
<label for="shop">shop</label><br>
</div>
<label for="query" class="form-label">Category to search</label>
<input type="text" class="form-control" name="query" id="query" placeholder="Query">
<button type="submit" class="btn btn-success">Search</button>
</form>
<button type="submit" class="btn btn-success" name="submit">Submit</button>
</form>
</p>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>