Added net scan options to welcome wizard
This commit is contained in:
parent
f7dbd8f3b2
commit
d1c6c9843b
|
@ -1324,8 +1324,6 @@ class HostDevices extends Wizard
|
|||
);
|
||||
}
|
||||
|
||||
hd($snmp_available_keys);
|
||||
|
||||
if (check_acl($config['id_user'], 0, 'UM')) {
|
||||
$link_to_cs = '<a class="ext_link" href="'.ui_get_full_url(
|
||||
'index.php?sec=gmodules&sec2=godmode/groups/group_list&tab=credbox'
|
||||
|
@ -1366,7 +1364,7 @@ class HostDevices extends Wizard
|
|||
'hidden' => !$show_snmp_auth,
|
||||
'block_content' => [
|
||||
[
|
||||
'label' => __('Credentials'),
|
||||
'label' => __('Credentials to try with'),
|
||||
'extra' => $link_to_cs,
|
||||
],
|
||||
],
|
||||
|
@ -1490,7 +1488,7 @@ class HostDevices extends Wizard
|
|||
'hidden' => !$show_auth,
|
||||
'block_content' => [
|
||||
[
|
||||
'label' => __('Credentials'),
|
||||
'label' => __('Credentials to try with'),
|
||||
'extra' => $link_to_cs,
|
||||
],
|
||||
],
|
||||
|
|
|
@ -129,7 +129,12 @@ if ($check_connectivity) {
|
|||
|
||||
if ($create_net_scan) {
|
||||
$ip_target = get_parameter('ip_target', '192.168.10.0/24');
|
||||
$id_net_scan = create_net_scan($ip_target);
|
||||
$snmp_version = get_parameter('snmp_version', '1');
|
||||
$snmp_communities = get_parameter('snmp_communities', 'public');
|
||||
$wmi_credentials = get_parameter('wmi_credentials', []);
|
||||
$rcmd_credentials = get_parameter('rcmd_credentials', []);
|
||||
|
||||
$id_net_scan = create_net_scan($ip_target, $snmp_version, $snmp_communities, $wmi_credentials, $rcmd_credentials);
|
||||
if ($id_net_scan > 0) {
|
||||
$id_recon_server = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_DISCOVERY], 'id_server')['id_server'];
|
||||
ui_print_success_message(__('Basic net created and scan in progress. <a href='.ui_get_full_url('index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&server_id='.$id_recon_server.'&force='.$id_net_scan).'>Click here to view the data</a>. Please note that it may take a few seconds to see data if your server is busy'));
|
||||
|
|
|
@ -848,13 +848,22 @@ class WelcomeWindow extends Wizard
|
|||
</div>
|
||||
<div id="dialog_basic_net" class="invisible">
|
||||
<?php
|
||||
$serverIP = $_SERVER['SERVER_ADDR'];
|
||||
$ipParts = explode('.', $serverIP);
|
||||
if (count($ipParts) === 4) {
|
||||
$ipParts[3] = '0/24';
|
||||
$network = implode('.', $ipParts);
|
||||
} else {
|
||||
$network = '192.168.10.0/24';
|
||||
}
|
||||
|
||||
echo html_print_input_hidden('create_net_scan', 1);
|
||||
echo html_print_label_input_block(
|
||||
__('Ip target'),
|
||||
html_print_input_text(
|
||||
'ip_target_discovery',
|
||||
'192.168.10.0/24',
|
||||
'192.168.10.0/24',
|
||||
$network,
|
||||
$network,
|
||||
false,
|
||||
18,
|
||||
true,
|
||||
|
@ -874,8 +883,302 @@ class WelcomeWindow extends Wizard
|
|||
)
|
||||
);
|
||||
|
||||
echo html_print_div(
|
||||
[
|
||||
'class' => '',
|
||||
'content' => '<br>To detect and find systems on your network we will need access credentials. The SNMP community for network devices, and at least one set of credentials for Linux and Windows environments (they do not need to be super administrators, but they do need to be able to connect remotely). Without the credentials, we will only be able to detect if the devices are connected to the network.<br><br>',
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
// SNMP Communities
|
||||
echo html_print_label_input_block(
|
||||
__('SNMP communities to try with').ui_print_help_tip(
|
||||
__(
|
||||
'You can specify several values, separated by commas, for example: public,mysecret,1234'
|
||||
),
|
||||
true
|
||||
),
|
||||
html_print_input(
|
||||
[
|
||||
'name' => 'community',
|
||||
'type' => 'text',
|
||||
'value' => 'public',
|
||||
'size' => 25,
|
||||
'return' => true
|
||||
],
|
||||
'div',
|
||||
true
|
||||
),
|
||||
[
|
||||
'div_id' => 'snmp-communities-div'
|
||||
]
|
||||
);
|
||||
ui_require_jquery_file('tag-editor.min','include/javascript/',true);
|
||||
ui_require_jquery_file('caret.min','include/javascript/',true);
|
||||
ui_require_css_file('jquery.tag-editor','include/styles/',true);
|
||||
|
||||
echo '<br>';
|
||||
|
||||
// WMI Credentials
|
||||
echo html_print_label_input_block(
|
||||
__('WMI credentials'),
|
||||
html_print_div(
|
||||
[
|
||||
'id' => 'wmi-creds',
|
||||
'content' => ''
|
||||
],
|
||||
true
|
||||
)
|
||||
);
|
||||
echo html_print_div(
|
||||
[
|
||||
'id' => 'wmi-cred-form',
|
||||
'hidden' => true,
|
||||
'style' => 'margin: 3px; display: flex; align-items: center;',
|
||||
'content' => html_print_div(
|
||||
[
|
||||
'id' => 'wmi-cred-user-div',
|
||||
'style' => 'width: 260px;',
|
||||
'content' => html_print_label_input_block(' '.__('User').' ', html_print_input_text(
|
||||
'wmi-cred-user',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
50, // Max length
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
'w100p',
|
||||
'',
|
||||
'off',
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
'Username'
|
||||
),['div_style' => 'display: flex; align-items: center;'])
|
||||
],
|
||||
true
|
||||
)
|
||||
.
|
||||
html_print_div(
|
||||
[
|
||||
'id' => 'wmi-cred-pass-div',
|
||||
'style' => 'width: 260px;',
|
||||
'content' => html_print_label_input_block(' '.__('Password').' ', html_print_input_password(
|
||||
'wmi-cred-pass',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
50, // Max length
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'w100p',
|
||||
'off',
|
||||
false,
|
||||
''
|
||||
),['div_style' => 'display: flex; align-items: center;'])
|
||||
],
|
||||
true
|
||||
)
|
||||
.
|
||||
html_print_div(
|
||||
[
|
||||
'id' => 'wmi-cred-namespace-div',
|
||||
'style' => 'width: 260px;',
|
||||
'content' => html_print_label_input_block(' '.__('Namespace').' ', html_print_input_text(
|
||||
'wmi-cred-namespace',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
50, // Max length
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
'w100p',
|
||||
'',
|
||||
'off',
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
'Namespace'
|
||||
),['div_style' => 'display: flex; align-items: center;'])
|
||||
],
|
||||
true
|
||||
)
|
||||
.
|
||||
'<a onClick="delete_discovery_credential(this);">'.html_print_image(
|
||||
'images/delete.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Delete'),
|
||||
'style' => 'cursor: pointer;',
|
||||
'class' => 'main_menu_icon invert_filter',
|
||||
]
|
||||
).'</a>'
|
||||
],
|
||||
true
|
||||
);
|
||||
echo '<br>';
|
||||
echo html_print_button(
|
||||
__('Add'),
|
||||
'add-wmi-cred',
|
||||
false,
|
||||
'add_discovery_credential("wmi-cred-form","wmi-creds");',
|
||||
[
|
||||
'icon' => 'plus',
|
||||
'mode' => 'secondary',
|
||||
'class' => 'mini'
|
||||
],
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
''
|
||||
);
|
||||
|
||||
echo '<br>';
|
||||
|
||||
// RCM Credentials
|
||||
echo html_print_label_input_block(
|
||||
__('Remote commands credentials'),
|
||||
html_print_div(
|
||||
[
|
||||
'id' => 'rcmd-creds',
|
||||
'content' => ''
|
||||
],
|
||||
true
|
||||
)
|
||||
);
|
||||
echo html_print_div(
|
||||
[
|
||||
'id' => 'rcmd-cred-form',
|
||||
'hidden' => true,
|
||||
'style' => 'margin: 3px; display: flex; align-items: center;',
|
||||
'content' => html_print_div(
|
||||
[
|
||||
'id' => 'rcmd-cred-user-div',
|
||||
'style' => 'width: 260px;',
|
||||
'content' => html_print_label_input_block(' '.__('User').' ', html_print_input_text(
|
||||
'rcmd-cred-user',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
50, // Max length
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
'w100p',
|
||||
'',
|
||||
'off',
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
'Username'
|
||||
),['div_style' => 'display: flex; align-items: center;'])
|
||||
],
|
||||
true
|
||||
)
|
||||
.
|
||||
html_print_div(
|
||||
[
|
||||
'id' => 'rcmd-cred-pass-div',
|
||||
'style' => 'width: 260px;',
|
||||
'content' => html_print_label_input_block(' '.__('Password').' ', html_print_input_password(
|
||||
'rcmd-cred-pass',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
50, // Max length
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'w100p',
|
||||
'off',
|
||||
false,
|
||||
''
|
||||
),['div_style' => 'display: flex; align-items: center;'])
|
||||
],
|
||||
true
|
||||
)
|
||||
.
|
||||
'<a onClick="delete_discovery_credential(this);">'.html_print_image(
|
||||
'images/delete.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Delete'),
|
||||
'style' => 'cursor: pointer;',
|
||||
'class' => 'main_menu_icon invert_filter',
|
||||
]
|
||||
).'</a>'
|
||||
],
|
||||
true
|
||||
);
|
||||
echo '<br>';
|
||||
echo html_print_button(
|
||||
__('Add'),
|
||||
'add-rcmd-cred',
|
||||
false,
|
||||
'add_discovery_credential("rcmd-cred-form","rcmd-creds");',
|
||||
[
|
||||
'icon' => 'plus',
|
||||
'mode' => 'secondary',
|
||||
'class' => 'mini'
|
||||
],
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
''
|
||||
);
|
||||
|
||||
echo html_print_submit_button(__('Create'), 'basic_net', false, ['icon' => 'next', 'style' => 'margin-top:15px; float:right;']);
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('#snmp-communities-div .tag-editor').remove();
|
||||
$('#text-community').tagEditor({
|
||||
forceLowercase: false
|
||||
});
|
||||
});
|
||||
|
||||
var credentialCounters = {};
|
||||
|
||||
function add_discovery_credential(sourceFormId, targetDivId) {
|
||||
// Increment the counter for this type of credential
|
||||
credentialCounters[targetDivId] = (credentialCounters[targetDivId] || 0) + 1;
|
||||
|
||||
// Clone the source form
|
||||
var newCredential = $("#" + sourceFormId).clone();
|
||||
|
||||
// Generate a unique ID for the new credential
|
||||
var uniqueId = targetDivId + "-" + credentialCounters[targetDivId];
|
||||
|
||||
// Set a new ID for the cloned form
|
||||
newCredential.attr("id", uniqueId);
|
||||
|
||||
// Append the cloned form to the target div
|
||||
$("#" + targetDivId).append(newCredential);
|
||||
|
||||
// Ensure the cloned div is visible
|
||||
newCredential.show().css("display", "flex");
|
||||
}
|
||||
|
||||
function delete_discovery_credential(clickedElement) {
|
||||
$(clickedElement).parent().remove();
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
<div id="dialog_alert_mail" class="invisible">
|
||||
<?php
|
||||
|
@ -1308,8 +1611,8 @@ class WelcomeWindow extends Wizard
|
|||
draggable: true,
|
||||
modal: true,
|
||||
close: false,
|
||||
height: 200,
|
||||
width: 480,
|
||||
height: 590,
|
||||
width: 925,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
|
@ -1407,6 +1710,35 @@ class WelcomeWindow extends Wizard
|
|||
});
|
||||
|
||||
$('#button-basic_net').click(function(){
|
||||
var wmi_credentials = [];
|
||||
$("#wmi-creds [id^='wmi-creds-']").each(function() {
|
||||
var credentialId = $(this).attr("id");
|
||||
var credentialValues = {
|
||||
user: $(this).find('[name="wmi-cred-user"]').val(),
|
||||
pass: $(this).find('[name="wmi-cred-pass"]').val(),
|
||||
namespace: $(this).find('[name="wmi-cred-namespace"]').val()
|
||||
};
|
||||
|
||||
wmi_credentials.push({
|
||||
id: credentialId,
|
||||
credential: credentialValues
|
||||
});
|
||||
});
|
||||
|
||||
var rcmd_credentials = [];
|
||||
$("#rcmd-creds [id^='rcmd-creds-']").each(function() {
|
||||
var credentialId = $(this).attr("id");
|
||||
var credentialValues = {
|
||||
user: $(this).find('[name="rcmd-cred-user"]').val(),
|
||||
pass: $(this).find('[name="rcmd-cred-pass"]').val()
|
||||
};
|
||||
|
||||
rcmd_credentials.push({
|
||||
id: credentialId,
|
||||
credential: credentialValues
|
||||
});
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
async: false,
|
||||
type: "POST",
|
||||
|
@ -1414,6 +1746,10 @@ class WelcomeWindow extends Wizard
|
|||
data: {
|
||||
create_net_scan: 1,
|
||||
ip_target: $('#text-ip_target_discovery').val(),
|
||||
snmp_version: 1,
|
||||
snmp_communities: $('#text-community').val(),
|
||||
wmi_credentials: wmi_credentials,
|
||||
rcmd_credentials: rcmd_credentials
|
||||
},
|
||||
success: function(data) {
|
||||
if (data !== 0) {
|
||||
|
|
|
@ -473,13 +473,90 @@ function create_module_packet_lost($id_agent, $id_group, $ip_target)
|
|||
* Create module packet lost and return module id.
|
||||
*
|
||||
* @param string $ip_target Ip and red mask.
|
||||
* @param string $snmp_communities SNMP Communities to use in recon task.
|
||||
* @param array $wmi_credentials WMI Credentials to use in recon task.
|
||||
* @param array $rcmd_credentials RCMD Credentials to use in recon task.
|
||||
*
|
||||
* @return interger Module id.
|
||||
*/
|
||||
function create_net_scan($ip_target)
|
||||
function create_net_scan($ip_target, $snmp_version, $snmp_communities, $wmi_credentials, $rcmd_credentials)
|
||||
{
|
||||
global $config;
|
||||
include_once $config['homedir'].'/godmode/wizards/HostDevices.class.php';
|
||||
|
||||
$id_group = 10;
|
||||
$auth_strings = [];
|
||||
|
||||
$default_templates = [
|
||||
io_safe_input('Linux System'),
|
||||
io_safe_input('Windows System'),
|
||||
io_safe_input('Windows Hardware'),
|
||||
io_safe_input('Network Management')
|
||||
];
|
||||
|
||||
$default_templates_ids = db_get_all_rows_sql('SELECT id_np
|
||||
FROM tnetwork_profile
|
||||
WHERE name IN ('.implode(',', array_map(function($template) {
|
||||
return "'" . $template . "'";
|
||||
}, $default_templates)).')
|
||||
ORDER BY name');
|
||||
|
||||
$id_base = 'autoDiscovery-WMI-';
|
||||
$id = 0;
|
||||
foreach($wmi_credentials as $wmi) {
|
||||
$id++;
|
||||
$identifier = $id_base . $id;
|
||||
while(db_get_value_sql(
|
||||
sprintf(
|
||||
'SELECT COUNT(*) AS count FROM tcredential_store WHERE identifier = "%s"',
|
||||
$identifier
|
||||
)
|
||||
) > 0) {
|
||||
$id++;
|
||||
$identifier = $id_base . $id;
|
||||
}
|
||||
|
||||
$storeKey = db_process_sql_insert('tcredential_store', [
|
||||
'identifier' => $identifier,
|
||||
'id_group' => $id_group,
|
||||
'product' => 'WMI',
|
||||
'username' => $wmi['credential']['user'],
|
||||
'password' => $wmi['credential']['pass'],
|
||||
'extra_1' => $wmi['credential']['namespace']
|
||||
]);
|
||||
|
||||
if($storeKey !== false) {
|
||||
$auth_strings[] = $identifier;
|
||||
}
|
||||
}
|
||||
$id_base = 'autoDiscovery-RCMD-';
|
||||
$id = 0;
|
||||
foreach($rcmd_credentials as $rcmd) {
|
||||
$id++;
|
||||
$identifier = $id_base . $id;
|
||||
while(db_get_value_sql(
|
||||
sprintf(
|
||||
'SELECT COUNT(*) AS count FROM tcredential_store WHERE identifier = "%s"',
|
||||
$identifier
|
||||
)
|
||||
) > 0) {
|
||||
$id++;
|
||||
$identifier = $id_base . $id;
|
||||
}
|
||||
|
||||
$storeKey = db_process_sql_insert('tcredential_store', [
|
||||
'identifier' => $identifier,
|
||||
'id_group' => $id_group,
|
||||
'product' => 'CUSTOM',
|
||||
'username' => $rcmd['credential']['user'],
|
||||
'password' => $rcmd['credential']['pass']
|
||||
]);
|
||||
|
||||
if($storeKey !== false) {
|
||||
$auth_strings[] = $identifier;
|
||||
}
|
||||
}
|
||||
|
||||
$HostDevices = new HostDevices(1);
|
||||
$id_recon_server = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_DISCOVERY], 'id_server')['id_server'];
|
||||
|
||||
|
@ -493,7 +570,7 @@ function create_net_scan($ip_target)
|
|||
'taskname' => __('Basic network'),
|
||||
'id_recon_server' => $id_recon_server,
|
||||
'network' => $ip_target,
|
||||
'id_group' => '8',
|
||||
'id_group' => $id_group,
|
||||
'comment' => __('Created on welcome'),
|
||||
];
|
||||
$task_created = $HostDevices->parseNetScan();
|
||||
|
@ -504,13 +581,13 @@ function create_net_scan($ip_target)
|
|||
'page' => '2',
|
||||
'recon_ports' => '',
|
||||
'auto_monitor' => 'on',
|
||||
'id_network_profile' => ['0' => '2'],
|
||||
'id_network_profile' => array_column($default_templates_ids, 'id_np'),
|
||||
'review_results' => 'on',
|
||||
'review_limited' => '0',
|
||||
'snmp_enabled' => 'on',
|
||||
'snmp_version' => '1',
|
||||
'snmp_version' => $snmp_version,
|
||||
'snmp_skip_non_enabled_ifs' => 'on',
|
||||
'community' => '',
|
||||
'community' => $snmp_communities,
|
||||
'snmp_context' => '',
|
||||
'snmp_auth_user' => '',
|
||||
'snmp_security_level' => 'authNoPriv',
|
||||
|
@ -523,6 +600,9 @@ function create_net_scan($ip_target)
|
|||
'parent_detection' => 'on',
|
||||
'parent_recursion' => 'on',
|
||||
'vlan_enabled' => 'on',
|
||||
'wmi_enabled' => 'on',
|
||||
'rcmd_enabled' => 'on',
|
||||
'auth_strings' => $auth_strings,
|
||||
];
|
||||
|
||||
$task_final_created = $HostDevicesFinal->parseNetScan();
|
||||
|
|
Loading…
Reference in New Issue