function checkall(clickchk, relChkbox) {
var checker = $('#' + clickchk);
var multichk = $('.' + relChkbox);
checker.click(function() {
multichk.prop('checked', $(this).prop('checked'));
});
}
function multiCheck(tb_var) {
tb_var.on("change", ".chk-parent", function() {
var e = $(this).closest("table").find("td:first-child .child-chk"),
a = $(this).is(":checked");
$(e).each(function() {
a ? ($(this).prop("checked", !0), $(this).closest("tr").addClass("active")) : ($(this).prop("checked", !1), $(this).closest("tr").removeClass("active"))
})
}),
tb_var.on("change", "tbody tr .new-control", function() {
$(this).parents("tr").toggleClass("active")
})
}
function GetIEVersion() {
var sAgent = window.navigator.userAgent;
var Idx = sAgent.indexOf("MSIE");
// If IE, return version number.
if (Idx > 0) return parseInt(sAgent.substring(Idx + 5, sAgent.indexOf(".", Idx)));
// If IE 11 then look for Updated user agent string.
else if (!!navigator.userAgent.match(/Trident\/7\./)) return 11;
else return 0; //It is not IE
}
function truncate(str, n) {
return (str.length > n) ? str.substr(0, n - 1) + '…' : str;
};
function return_str_if_not_null(val) {
return val ? val : '';
}
// separate hostname and url
// Referenced from https://stackoverflow.com/questions/736513/how-do-i-parse-a-url-into-hostname-and-path-in-javascript
function getParsedURL(url) {
var parser = new URL(url);
return parser.pathname + parser.search;
};
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
// Source: https://portswigger.net/web-security/cross-site-scripting/preventing#encode-data-on-output
function htmlEncode(str) {
return String(str).replace(/[^\w. ]/gi, function(c) {
return '' + c.charCodeAt(0) + ';';
});
}
// Source: https://portswigger.net/web-security/cross-site-scripting/preventing#encode-data-on-output
function jsEscape(str) {
return String(str).replace(/[^\w. ]/gi, function(c) {
return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4);
});
}
function deleteScheduledScan(id) {
const delAPI = "../delete/scheduled_task/" + id;
swal.queue([{
title: 'Are you sure you want to delete this?',
text: "This action can not be undone.",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(delAPI, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
}).then(function(response) {
return response.json();
}).then(function(data) {
// TODO Look for better way
return location.reload();
}).catch(function() {
swal.insertQueueStep({
icon: 'error',
title: 'Oops! Unable to delete the scheduled task!'
})
})
}
}])
}
function change_scheduled_task_status(id, checkbox) {
if (checkbox.checked) {
text_msg = 'Schedule Scan Started';
} else {
text_msg = 'Schedule Scan Stopped';
}
Snackbar.show({
text: text_msg,
pos: 'top-right',
duration: 2500
});
const taskStatusApi = "../toggle/scheduled_task/" + id;
return fetch(taskStatusApi, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
}
function change_vuln_status(id) {
const vulnStatusApi = "../toggle/vuln_status/" + id;
return fetch(vulnStatusApi, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
}
// splits really long strings into multiple lines
// Souce: https://stackoverflow.com/a/52395960
function split_into_lines(str, maxWidth) {
const newLineStr = "";
done = false;
res = '';
do {
found = false;
// Inserts new line at first whitespace of the line
for (i = maxWidth - 1; i >= 0; i--) {
if (test_white_space(str.charAt(i))) {
res = res + [str.slice(0, i), newLineStr].join('');
str = str.slice(i + 1);
found = true;
break;
}
}
// Inserts new line at maxWidth position, the word is too long to wrap
if (!found) {
res += [str.slice(0, maxWidth), newLineStr].join('');
str = str.slice(maxWidth);
}
if (str.length < maxWidth) done = true;
} while (!done);
return res + str;
}
function test_white_space(x) {
const white = new RegExp(/^\s$/);
return white.test(x.charAt(0));
};
// span values function will separate the values by comma and put badge around it
function parse_comma_values_into_span(data, color, outline = null) {
if (data) {
var badge = ``;
var data_with_span = "";
data.split(/\s*,\s*/).forEach(function(split_vals) {
data_with_span += badge + split_vals + "";
});
return data_with_span;
}
return '';
}
function get_severity_badge(severity) {
switch (severity) {
case 'Info':
return " INFO ";
break;
case 'Low':
return " LOW ";
break;
case 'Medium':
return " MEDIUM ";
break;
case 'High':
return " HIGH ";
break;
case 'Critical':
return " CRITICAL ";
break;
case 'Unknown':
return " UNKNOWN ";
default:
return "";
}
}
// Source: https://stackoverflow.com/a/54733055
function typingEffect(words, id, i) {
let word = words[i].split("");
var loopTyping = function() {
if (word.length > 0) {
let elem = document.getElementById(id);
elem.setAttribute('placeholder', elem.getAttribute('placeholder') + word.shift());
} else {
deletingEffect(words, id, i);
return false;
};
timer = setTimeout(loopTyping, 150);
};
loopTyping();
};
function deletingEffect(words, id, i) {
let word = words[i].split("");
var loopDeleting = function() {
if (word.length > 0) {
word.pop();
document.getElementById(id).setAttribute('placeholder', word.join(""));
} else {
if (words.length > (i + 1)) {
i++;
} else {
i = 0;
};
typingEffect(words, id, i);
return false;
};
timer = setTimeout(loopDeleting, 90);
};
loopDeleting();
};
function fullScreenDiv(id, btn) {
let fullscreen = document.querySelector(id);
let button = document.querySelector(btn);
document.fullscreenElement && document.exitFullscreen() || document.querySelector(id).requestFullscreen()
fullscreen.setAttribute("style", "overflow:auto");
}
function get_randid() {
return '_' + Math.random().toString(36).substr(2, 9);
}
function delete_all_scan_results() {
const delAPI = "../scan/delete/scan_results/";
swal.queue([{
title: 'Are you sure you want to delete all scan results?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(delAPI, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
}).then(function(response) {
return response.json();
}).then(function(data) {
// TODO Look for better way
return location.reload();
}).catch(function() {
swal.insertQueueStep({
icon: 'error',
title: 'Oops! Unable to delete Delete scan results!'
})
})
}
}])
}
function delete_all_screenshots() {
const delAPI = "../scan/delete/screenshots/";
swal.queue([{
title: 'Are you sure you want to delete all Screenshots?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(delAPI, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
}).then(function(response) {
return response.json();
}).then(function(data) {
// TODO Look for better way
return location.reload();
}).catch(function() {
swal.insertQueueStep({
icon: 'error',
title: 'Oops! Unable to delete Empty Screenshots!'
})
})
}
}])
}
function load_image_from_url(src, append_to_id) {
img = document.createElement('img');
img.src = src;
img.style.width = '100%';
document.getElementById(append_to_id).appendChild(img);
}
function setTooltip(btn, message) {
hide_all_tooltips();
const instance = tippy(document.querySelector(btn));
instance.setContent(message);
instance.show();
setTimeout(function() {
instance.hide();
}, 500);
}
function hide_all_tooltips() {
$(".tooltip").tooltip("hide");
}
function get_response_time_text(response_time) {
if (response_time) {
var text_color = 'danger';
if (response_time < 0.5) {
text_color = 'success'
} else if (response_time >= 0.5 && response_time < 1) {
text_color = 'warning'
}
return `${response_time.toFixed(4)}s`;
}
return '';
}
function parse_technology(data, color, scan_id = null, domain_id=null) {
var badge = `` + data[key]['name'] + "";
} else if (domain_id) {
data_with_span += badge + ` onclick="get_tech_details('${data[key]['name']}', scan_id=null, domain_id=domain_id)">` + data[key]['name'] + "";
}
}
return data_with_span;
}
// span values function will separate the values by comma and put badge around it
function parse_ip(data, cdn) {
if (cdn) {
var badge = ``;
} else {
var badge = ``;
}
var data_with_span = "";
data.split(/\s*,\s*/).forEach(function(split_vals) {
data_with_span += badge + split_vals + "";
});
return data_with_span;
}
//to remove the image element if there is no screenshot captured
function removeImageElement(element) {
element.parentElement.remove();
}
// https://stackoverflow.com/a/18197341/9338140
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function vuln_status_change(checkbox, id) {
if (checkbox.checked) {
checkbox.parentNode.parentNode.parentNode.className = "table-success text-strike";
} else {
checkbox.parentNode.parentNode.parentNode.classList.remove("table-success");
checkbox.parentNode.parentNode.parentNode.classList.remove("text-strike");
}
change_vuln_status(id);
}
function report_hackerone(vulnerability_id, severity) {
message = ""
if (severity == 'Info' || severity == 'Low' || severity == 'Medium') {
message = "We do not recommended sending this vulnerability report to hackerone due to the severity, do you still want to report this?"
} else {
message = "This vulnerability report will be sent to Hackerone.";
}
const vulnerability_report_api = "../../api/vulnerability/report/?vulnerability_id=" + vulnerability_id;
swal.queue([{
title: 'Reporting vulnerability to hackerone',
text: message,
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Report',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(vulnerability_report_api, {
method: 'GET',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log(data.status)
if (data.status == 111) {
swal.insertQueueStep({
icon: 'error',
title: 'Target does not has team_handle to send report to.'
})
} else if (data.status == 201) {
swal.insertQueueStep({
icon: 'success',
title: 'Vulnerability report successfully submitted to hackerone.'
})
} else if (data.status == 400) {
swal.insertQueueStep({
icon: 'error',
title: 'Invalid Report.'
})
} else if (data.status == 401) {
swal.insertQueueStep({
icon: 'error',
title: 'Hackerone authentication failed.'
})
} else if (data.status == 403) {
swal.insertQueueStep({
icon: 'error',
title: 'API Key forbidden by Hackerone.'
})
} else if (data.status == 423) {
swal.insertQueueStep({
icon: 'error',
title: 'Too many requests.'
})
}
}).catch(function() {
swal.insertQueueStep({
icon: 'error',
title: 'Oops! Unable to send vulnerability report to hackerone, check your target team_handle or hackerone configurarions!'
})
})
}
}])
}
function get_interesting_subdomains(target_id, scan_history_id) {
if (target_id) {
url = `/api/listInterestingEndpoints/?target_id=${target_id}&format=datatables`;
non_orderable_targets = [0, 1, 2, 3];
} else if (scan_history_id) {
url = `/api/listInterestingSubdomains/?scan_id=${scan_history_id}&format=datatables`;
non_orderable_targets = [];
}
var interesting_subdomain_table = $('#interesting_subdomains').DataTable({
"drawCallback": function(settings, start, end, max, total, pre) {
// if no interesting subdomains are found, hide the datatable and show no interesting subdomains found badge
if (this.fnSettings().fnRecordsTotal() == 0) {
$('#interesting_subdomain_div').empty();
// $('#interesting_subdomain_div').append(`
//
//
//
//
Interesting subdomains could not be identified
//
//
//
// reNgine could not identify any interesting subdomains. You can customize interesting subdomain keywords from here and this section would be automatically updated.
//
//
`);
} else {
// show nav bar
$('.interesting-tab-show').removeAttr('style');
$('#interesting_subdomain_alert_count').html(`${this.fnSettings().fnRecordsTotal()} Interesting Subdomains`)
$('#interesting_subdomain_count_badge').empty();
$('#interesting_subdomain_count_badge').html(`${this.fnSettings().fnRecordsTotal()}`);
}
},
"oLanguage": {
"oPaginate": {
"sPrevious": '',
"sNext": ''
},
"sInfo": "Showing page _PAGE_ of _PAGES_",
"sSearch": '',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"processing": true,
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'f><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center'l>>>" + "<'table-responsive'tr>" + "<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>",
"destroy": true,
"bInfo": false,
"stripeClasses": [],
'serverSide': true,
"ajax": url,
"order": [
[3, "desc"]
],
"lengthMenu": [5, 10, 20, 50, 100],
"pageLength": 10,
"columns": [{
'data': 'name'
}, {
'data': 'page_title'
}, {
'data': 'http_status'
}, {
'data': 'content_length'
}, {
'data': 'http_url'
}, {
'data': 'technologies'
}, ],
"columnDefs": [{
"orderable": false,
"targets": non_orderable_targets
}, {
"targets": [4],
"visible": false,
"searchable": false,
}, {
"targets": [5],
"visible": false,
"searchable": true,
}, {
"className": "text-center",
"targets": [2]
}, {
"render": function(data, type, row) {
tech_badge = '';
if (row['technologies']) {
// tech_badge = `` + parse_technology(row['technologies'], "primary", outline=true, scan_id=null);
}
if (row['http_url']) {
return `` + data + `` + tech_badge;
}
return `` + data + `` + tech_badge;
},
"targets": 0
}, {
"render": function(data, type, row) {
// display badge based on http status
// green for http status 2XX, orange for 3XX and warning for everything else
if (data >= 200 && data < 300) {
return "" + data + "";
} else if (data >= 300 && data < 400) {
return "" + data + "";
} else if (data == 0) {
// datatable throws error when no data is returned
return "";
}
return `` + data + ``;
},
"targets": 2,
}, ],
});
}
function get_interesting_endpoints(target_id, scan_history_id) {
var non_orderable_targets = [];
if (target_id) {
url = `/api/listInterestingEndpoints/?target_id=${target_id}&format=datatables`;
// non_orderable_targets = [0, 1, 2, 3];
} else if (scan_history_id) {
url = `/api/listInterestingEndpoints/?scan_id=${scan_history_id}&format=datatables`;
// non_orderable_targets = [0, 1, 2, 3];
}
$('#interesting_endpoints').DataTable({
"drawCallback": function(settings, start, end, max, total, pre) {
if (this.fnSettings().fnRecordsTotal() == 0) {
$('#interesting_endpoint_div').remove();
} else {
$('.interesting-tab-show').removeAttr('style');
$('#interesting_endpoint_alert_count').html(`, ${this.fnSettings().fnRecordsTotal()} Interesting Endpoints`)
$('#interesting_endpoint_count_badge').empty();
$('#interesting_endpoint_count_badge').html(`${this.fnSettings().fnRecordsTotal()}`);
}
},
"oLanguage": {
"oPaginate": {
"sPrevious": '',
"sNext": ''
},
"sInfo": "Showing page _PAGE_ of _PAGES_",
"sSearch": '',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"processing": true,
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'f><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center'l>>>" + "<'table-responsive'tr>" + "<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>",
'serverSide': true,
"destroy": true,
"bInfo": false,
"ajax": url,
"order": [
[3, "desc"]
],
"lengthMenu": [5, 10, 20, 50, 100],
"pageLength": 10,
"columns": [{
'data': 'http_url'
}, {
'data': 'page_title'
}, {
'data': 'http_status'
}, {
'data': 'content_length'
}, ],
"columnDefs": [{
"orderable": false,
"targets": non_orderable_targets
}, {
"className": "text-center",
"targets": [2]
}, {
"render": function(data, type, row) {
var url = split_into_lines(data, 70);
return "" + url + "";
},
"targets": 0
}, {
"render": function(data, type, row) {
// display badge based on http status
// green for http status 2XX, orange for 3XX and warning for everything else
if (data >= 200 && data < 300) {
return "" + data + "";
} else if (data >= 300 && data < 400) {
return "" + data + "";
} else if (data == 0) {
// datatable throws error when no data is returned
return "";
}
return `` + data + ``;
},
"targets": 2,
}, ],
});
}
function get_important_subdomains(target_id, scan_history_id) {
var url = `/api/querySubdomains/?only_important&no_lookup_interesting&format=json`;
if (target_id) {
url += `&target_id=${target_id}`;
} else if (scan_history_id) {
url += `&scan_id=${scan_history_id}`;
}
$.getJSON(url, function(data) {
$('#important-count').empty();
$('#important-subdomains-list').empty();
if (data['subdomains'].length > 0) {
$('#important-count').html(`${data['subdomains'].length}`);
for (var val in data['subdomains']) {
subdomain = data['subdomains'][val];
div_id = 'important_' + subdomain['id'];
$("#important-subdomains-list").append(`
`);
if (response['result'].length > 0) {
if (response['subscan']['task'] == 'port_scan') {
$('#xl-modal-content').append(``);
for (var ip in response['result']) {
var ip_addr = response['result'][ip]['address'];
var id_name = `ip_${ip_addr}`;
$('#port_results_li').append(`
IP Address: ${ip_addr}${response['result'][ip]['ports'].length} Ports Open
`);
$('#port_results_li').append(`
`);
for (var port_obj in response['result'][ip]['ports']) {
var port = response['result'][ip]['ports'][port_obj];
var port_color = 'primary';
if (port["is_uncommon"]) {
port_color = 'danger';
}
$('#port_results_li ul').append(`
`);
}
$('#modal_xl_scroll_dialog').modal('show');
$("body").tooltip({
selector: '[data-toggle=tooltip]'
});
});
}
function get_http_status_badge(data) {
if (data >= 200 && data < 300) {
return "" + data + "";
} else if (data >= 300 && data < 400) {
return "" + data + "";
} else if (data == 0) {
// datatable throws error when no data is returned
return "";
}
return "" + data + "";
}
function render_endpoint_in_xlmodal(endpoint_count, subdomain_name, result) {
// This function renders endpoints datatable in xl modal
// Used in Subscan results and subdomain to endpoints modal
$('#xl-modal-content').append(`
${endpoint_count} Endpoints Discovered on subdomain ${subdomain_name}
`);
$('#xl-modal-content').append(`
HTTP URL
Status
Page Title
Tags
Content Type
Content Length
Response Time
`);
$('#endpoint_tbody').empty();
for (var endpoint_obj in result) {
var endpoint = result[endpoint_obj];
var tech_badge = '';
var web_server = '';
if (endpoint['technologies']) {
tech_badge = '
' + parse_technology(endpoint['technologies'], "primary", outline = true);
}
if (endpoint['webserver']) {
web_server = `${endpoint['webserver']}`;
}
var url = split_into_lines(endpoint['http_url'], 70);
var rand_id = get_randid();
tech_badge += web_server + '
';
var http_url = vuln_obj['http_url'].includes('http') ? "" + htmlEncode(vuln_obj['http_url']) + "" : vuln_obj['http_url'];
var description = vuln_obj['description'] ? `
${split_into_lines(vuln_obj['description'], 30)}
` : '';
// show extracted results, and show matcher names, matcher names can be in badges
if (vuln_obj['matcher_name']) {
description += `${vuln_obj['matcher_name']}`;
}
if (vuln_obj['extracted_results'] && vuln_obj['extracted_results'].length > 0) {
description += ` Extracted Results `;
description += `
City: ${response.technical_contact.city} State: ${response.technical_contact.state} Zip Code: ${response.technical_contact.zipcode} Country:
${response.technical_contact.country}
${response.raw_text}
`;
for (var ns in response.nameservers) {
var ns_object = response.nameservers[ns];
content += `${ns_object}`;
}
content += `
`;
if (show_add_target_btn) {
content += `
`
}
$('#modal-content').append(content);
$('[data-toggle="tooltip"]').tooltip();
}
function show_quick_add_target_modal() {
// this function will display the modal to add target
$('#modal_title').html('Add target');
$('#modal-content').empty();
$('#modal-content').append(`
If you would like to add IP/CIDRs, multiple domain, Please click here.
`);
$('#modal_dialog').modal('show');
}
function add_quick_target() {
// this function will be a onclick for add target button on add_target modal
$('#modal_dialog').modal('hide');
var domain_name = $('#target_name_modal').val();
var description = $('#target_description_modal').val();
var h1_handle = $('#h1_handle_modal').val();
add_target(domain_name, h1_handle = h1_handle, description = description);
}
function add_target(domain_name, h1_handle = null, description = null) {
// this function will add domain_name as target
console.log('Adding new target ' + domain_name)
const add_api = '/api/add/target/?format=json';
const data = {
'domain_name': domain_name,
'h1_team_handle': h1_handle,
'description': description
};
swal.queue([{
title: 'Add Target',
text: `Would you like to add ${domain_name} as target?`,
icon: 'info',
showCancelButton: true,
confirmButtonText: 'Add Target',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(add_api, {
method: 'POST',
credentials: "same-origin",
headers: {
'X-CSRFToken': getCookie("csrftoken"),
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(function(response) {
console.log(response)
return response.json();
}).then(function(data) {
console.log(data)
if (data.status) {
swal.queue([{
title: 'Target Successfully added!',
text: `Do you wish to initiate the scan on new target?`,
icon: 'success',
showCancelButton: true,
confirmButtonText: 'Initiate Scan',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
window.location = `/scan/start/${data.domain_id}`;
}
}]);
} else {
swal.insertQueueStep({
icon: 'error',
title: data.message
});
}
}).catch(function() {
swal.insertQueueStep({
icon: 'error',
title: 'Oops! Unable to add target !'
});
})
}
}]);
}
function loadSubscanHistoryWidget(scan_history_id = null, domain_id = null) {
// This function will load the subscan history widget
if (scan_history_id) {
var data = {
'scan_history_id': scan_history_id
}
}
if (domain_id) {
var data = {
'domain_id': domain_id
}
}
fetch('/api/listSubScans/?format=json', {
method: 'POST',
credentials: "same-origin",
body: JSON.stringify(data),
headers: {
"X-CSRFToken": getCookie("csrftoken"),
"Content-Type": 'application/json',
}
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log(data);
$('#subscan_history_widget').empty();
if (data['status']) {
$('#sub_scan_history_count').append(`
${data['results'].length}
`)
for (var result in data['results']) {
var error_message = '';
var result_obj = data['results'][result];
var task_name = get_task_name(result_obj);
if (result_obj.status == 0) {
color = 'danger';
bg_color = 'bg-soft-danger';
status_badge = 'Failed';
error_message = `Error: ${result_obj.error_message}`;
} else if (result_obj.status == 3) {
color = 'danger';
bg_color = 'bg-soft-danger';
status_badge = 'Aborted';
} else if (result_obj.status == 2) {
color = 'success';
bg_color = 'bg-soft-success';
status_badge = 'Task Completed';
} else if (result_obj.status == 1) {
color = 'primary';
bg_color = 'bg-soft-primary';
status_badge = 'Running';
}
$('#subscan_history_widget').append(`
No Subscans has been initiated for any subdomains. You can select individual subdomains and initiate subscans like Directory Fuzzing, Vulnerability Scan etc.
`);
}
});
}
function get_ips(scan_id=null, domain_id=null){
// this function will fetch and render ips in widget
var url = '/api/queryIps/?';
if (scan_id) {
url += `scan_id=${scan_id}`;
}
if (domain_id) {
url += `target_id=${domain_id}`;
}
url += `&format=json`;
$.getJSON(url, function(data) {
$('#ip-address-count').empty();
for (var val in data['ips']){
ip = data['ips'][val]
badge_color = ip['is_cdn'] ? 'warning' : 'primary';
if (scan_id) {
$("#ip-address").append(`${ip['address']}`);
}
else if (domain_id) {
$("#ip-address").append(`${ip['address']}`);
}
// $("#ip-address").append(`${ip['address']}`);
}
$('#ip-address-count').html(`${data['ips'].length}`);
$("body").tooltip({ selector: '[data-toggle=tooltip]' });
});
}
function get_technologies(scan_id=null, domain_id=null){
// this function will fetch and render tech in widget
var url = '/api/queryTechnologies/?';
if (scan_id) {
url += `scan_id=${scan_id}`;
}
if (domain_id) {
url += `target_id=${domain_id}`;
}
url += `&format=json`;
$.getJSON(url, function(data) {
$('#technologies-count').empty();
for (var val in data['technologies']){
tech = data['technologies'][val]
if (scan_id) {
$("#technologies").append(`${tech['name']}`);
}
else if (domain_id) {
$("#technologies").append(`${tech['name']}`);
}
}
$('#technologies-count').html(`${data['technologies'].length}`);
$("body").tooltip({ selector: '[data-toggle=tooltip]' });
});
}
function get_ports(scan_id=null, domain_id=null){
// this function will fetch and render ports in widget
var url = '/api/queryPorts/?';
if (scan_id) {
url += `scan_id=${scan_id}`;
}
if (domain_id) {
url += `target_id=${domain_id}`;
}
url += `&format=json`;
$.getJSON(url, function(data) {
$('#ports-count').empty();
for (var val in data['ports']){
port = data['ports'][val]
badge_color = port['is_uncommon'] ? 'danger' : 'primary';
if (scan_id) {
$("#ports").append(`${port['number']}/${port['service_name']}`);
}
else if (domain_id){
$("#ports").append(`${port['number']}/${port['service_name']}`);
}
}
$('#ports-count').html(`${data['ports'].length}`);
$("body").tooltip({ selector: '[data-toggle=tooltip]' });
});
}
function get_ip_details(ip_address, scan_id=null, domain_id=null){
var port_url = `/api/queryPorts/?ip_address=${ip_address}`;
var subdomain_url = `/api/querySubdomains/?ip_address=${ip_address}`;
if (scan_id) {
port_url += `&scan_id=${scan_id}`;
subdomain_url += `&scan_id=${scan_id}`;
}
else if(domain_id){
port_url += `&target_id=${domain_id}`;
subdomain_url += `&target_id=${domain_id}`;
}
port_url += `&format=json`;
subdomain_url += `&format=json`;
var interesting_badge = `Interesting`;
var port_loader = ``;
var subdomain_loader = ``;
// add tab modal title
$('#modal_title').html('Details for IP: ' + ip_address + '');
$('#modal-content').empty();
$('#modal-tabs').empty();
$('#modal-content').append(`
IP Addresses ${ip_address} has ${data['ports'].length} Open Ports`);
$('#modal-open-ports-count').html(`${data['ports'].length} `);
for (port in data['ports']){
port_obj = data['ports'][port];
badge_color = port_obj['is_uncommon'] ? 'danger' : 'info';
$("#modal_content_port").append(`
${data['ips'].length} IP Addresses have Port ${port} Open`);
$('#modal-ip-count').html(`${data['ips'].length} `);
for (ip in data['ips']){
ip_obj = data['ips'][ip];
text_color = ip_obj['is_cdn'] ? 'warning' : '';
$("#modal_ip_ul").append(`
${ip_obj['address']}
`)
}
$('#modal_ip_ul').append(`*IP Address highlighted are CDN IP Address`);
$("#ip-modal-loader").remove();
});
// query subdomains
$.getJSON(subdomain_url, function(data) {
$('#modal_subdomain_ul').empty();
$('#modal_subdomain_ul').append(`
${data['subdomains'].length} Subdomains have Port ${port} Open`);
$('#modal-subdomain-count').html(`${data['subdomains'].length} `);
for (subdomain in data['subdomains']){
subdomain_obj = data['subdomains'][subdomain];
badge_color = subdomain_obj['http_status'] >= 400 ? 'danger' : '';
li_id = get_randid();
if (subdomain_obj['http_url']) {
$("#modal_subdomain_ul").append(`
`);
for (var res in response.result) {
var vuln_obj = response.result[res];
var vuln_badge = '';
switch (vuln_obj.severity) {
case -1:
vuln_badge = get_severity_badge('Unknown');
break;
case 0:
vuln_badge = get_severity_badge('Info');
break;
case 1:
vuln_badge = get_severity_badge('Low');
break;
case 2:
vuln_badge = get_severity_badge('Medium');
break;
case 3:
vuln_badge = get_severity_badge('High');
break;
case 4:
vuln_badge = get_severity_badge('Critical');
break;
default:
vuln_badge = get_severity_badge('Unknown');
}
$('#most_common_vuln_tbody').append(`
${vuln_obj.name}
${vuln_obj.count}
${vuln_badge}
`);
}
}
else{
$('#most_common_vuln_div').append(`
Could not find Most Common Vulnerabilities.
Once the vulnerability scan is performed, reNgine will identify the Most Common Vulnerabilities.
`);
}
});
}
function highlight_search(search_keyword, content){
// this function will send the highlighted text from search keyword
var reg = new RegExp('('+search_keyword+')', 'gi');
return content.replace(reg, '$1');
}
function validURL(str) {
// checks for valid http url
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return !!pattern.test(str);
}
function shadeColor(color, percent) {
//https://stackoverflow.com/a/13532993
var R = parseInt(color.substring(1,3),16);
var G = parseInt(color.substring(3,5),16);
var B = parseInt(color.substring(5,7),16);
R = parseInt(R * (100 + percent) / 100);
G = parseInt(G * (100 + percent) / 100);
B = parseInt(B * (100 + percent) / 100);
R = (R<255)?R:255;
G = (G<255)?G:255;
B = (B<255)?B:255;
var RR = ((R.toString(16).length==1)?"0"+R.toString(16):R.toString(16));
var GG = ((G.toString(16).length==1)?"0"+G.toString(16):G.toString(16));
var BB = ((B.toString(16).length==1)?"0"+B.toString(16):B.toString(16));
return "#"+RR+GG+BB;
}