19#include "base/hosts.h"
24#include <gvm/base/logging.h>
25#include <gvm/base/networking.h>
26#include <netinet/in.h>
30#include <sys/socket.h>
33#define IMPORT(var) char *var = get_str_var_by_name (lexic, #var)
39#define G_LOG_DOMAIN "lib nasl"
61 retc->
size = strlen (version);
91 if ((
host == NULL) || (username == NULL) || (password == NULL)
94 g_message (
"nasl_smb_connect: Invalid input arguments");
98 ip = addr6_as_str (
host);
99 if ((strlen (password) == 0) || (strlen (username) == 0) || (strlen (ip) == 0)
100 || (strlen (share) == 0))
102 g_message (
"nasl_smb_connect: Invalid input arguments");
108 value =
smb_connect (ip, share, username, password, &handle);
113 g_message (
"nasl_smb_connect: SMB Connect failed");
170 g_message (
"smb_file_SDDL failed: Invalid filename");
176 g_message (
"smb_file_SDDL failed: Invalid smb_handle");
189 retc->
size = strlen (buffer);
213 g_message (
"smb_file_owner_sid failed: Invalid filename");
219 g_message (
"smb_file_owner_sid failed: Invalid smb_handle");
232 retc->
size = strlen (buffer);
256 g_message (
"smb_file_group_sid failed: Invalid filename");
262 g_message (
"smb_file_group_sid failed: Invalid smb_handle");
275 retc->
size = strlen (buffer);
299 g_message (
"smb_file_trustee_rights failed: Invalid filename");
305 g_message (
"smb_file_trustee_rights failed: Invalid smb_handle");
318 retc->
size = strlen (buffer);
341 gvm_host_t *gvm_host = NULL;
342 char *argv[7], *unicode, target[2048], *c;
344 GString *
string = NULL;
348 bool calculate_host =
false;
349 char first_kdc[INET6_ADDRSTRLEN] = {0};
350 const char *delimiter;
361 if ((username == NULL) || (password == NULL) || (cmd == NULL))
363 g_message (
"win_cmd_exec: Invalid input arguments");
369 calculate_host =
true;
370 host = addr6_as_str (host_ip);
373 gvm_host = gvm_host_from_str (
host);
375 host = gvm_host_reverse_lookup (gvm_host);
381 g_message (
"win_cmd_exec: host must not be empty.");
384 if ((strlen (password) == 0) || (strlen (username) == 0)
385 || strlen (
host) == 0)
387 g_message (
"win_cmd_exec: Invalid input arguments");
394 if ((c = strchr (username,
'\\')))
396 if (strchr (username,
'/') == NULL)
398 snprintf (target,
sizeof (target),
"%s/%s:%s@%s", realm, username,
403 snprintf (target,
sizeof (target),
"%s:%s@%s", username, password,
host);
408 argv[0] =
"impacket-wmiexec";
417 delimiter = strchr (kdc,
',');
418 if (delimiter != NULL)
420 strncpy (first_kdc, kdc, delimiter - kdc);
424 strncpy (first_kdc, kdc,
sizeof (first_kdc) - 1);
433 ret = g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
434 NULL, NULL, NULL, &sout, NULL, &err);
437 g_warning (
"win_cmd_exec: %s", err ? err->message :
"Error");
443 string = g_string_new (
"");
449 bytes = read (sout, buf,
sizeof (buf));
453 g_string_append_len (
string, buf, bytes);
456 g_warning (
"win_cmd_exec: %s", strerror (errno));
457 g_string_free (
string, TRUE);
464 if (g_str_has_prefix (
string->str,
"[-]"))
466 g_warning (
"win_cmd_exec: %s",
string->str);
467 g_string_free (
string, TRUE);
470 else if ((unicode = strstr (
string->str,
"\xff\xfe")))
477 diff = unicode -
string->str + 1;
478 tmp = g_convert (unicode + 2,
string->
len - diff,
"UTF-8",
"UTF-16", NULL,
482 g_warning (
"win_cmd_exec: %s", err->message);
483 g_string_free (
string, TRUE);
494 retc->
size =
string->len;
struct struct_lex_ctxt lex_ctxt
char * get_str_var_by_name(lex_ctxt *, const char *)
long int get_int_var_by_name(lex_ctxt *, const char *, int)
tree_cell * nasl_smb_file_owner_sid(lex_ctxt *lexic)
Obtain File Owner SID.
tree_cell * nasl_smb_file_SDDL(lex_ctxt *lexic)
Obtain Security Descriptor in SDDL format.
tree_cell * nasl_smb_file_trustee_rights(lex_ctxt *lexic)
Obtain File Trustee SID with Access Mask.
tree_cell * nasl_smb_versioninfo(lex_ctxt *lexic)
Get a version string of the SMB implementation.
tree_cell * nasl_smb_close(lex_ctxt *lexic)
Close SMB service handle.
tree_cell * nasl_smb_connect(lex_ctxt *lexic)
Connect to SMB service and return a handle for it.
tree_cell * nasl_smb_file_group_sid(lex_ctxt *lexic)
Obtain File Group SID.
tree_cell * nasl_win_cmd_exec(lex_ctxt *lexic)
Execute the command in windows.
tree_cell * alloc_typed_cell(int typ)
API protos describing the interface of a smb interface implementation.
int smb_close(SMB_HANDLE)
Close the connection handle for SMB service.
char * smb_file_GroupSID(SMB_HANDLE, const char *)
Obtain the SID of the Group for a given file/path.
char * smb_versioninfo(void)
Return version info for SMB implementation.
char * smb_file_OwnerSID(SMB_HANDLE, const char *)
Obtain the SID of the Owner for a given file/path.
int smb_connect(const char *, const char *, const char *, const char *, SMB_HANDLE *)
Establish connection to a SMB service.
char * smb_file_TrusteeRights(SMB_HANDLE, const char *)
Obtain the Trustee SID and their rights for a given file/path.
char * smb_file_SDDL(SMB_HANDLE, const char *)
Obtain Windows file rights in SDDL format.
struct in6_addr * plug_get_host_ip(struct script_infos *args)
Header file for module plugutils.
union TC::@332262321161220155002104006201360276211317150140 x
Host information, implemented as doubly linked list.
Define a string struct for storing the response.
struct script_infos * script_infos