18#include "../misc/plugutils.h"
23#include <gvm/base/logging.h>
24#include <gvm/base/networking.h>
25#include <netinet/in.h>
28#include <sys/socket.h>
31#define IMPORT(var) char *var = get_str_var_by_name (lexic, #var)
37#define G_LOG_DOMAIN "lib nasl"
59 retc->
size = strlen (version);
89 if ((
host == NULL) || (username == NULL) || (password == NULL)
92 g_message (
"nasl_smb_connect: Invalid input arguments");
96 ip = addr6_as_str (
host);
97 if ((strlen (password) == 0) || (strlen (username) == 0) || (strlen (ip) == 0)
98 || (strlen (share) == 0))
100 g_message (
"nasl_smb_connect: Invalid input arguments");
106 value =
smb_connect (ip, share, username, password, &handle);
111 g_message (
"nasl_smb_connect: SMB Connect failed");
168 g_message (
"smb_file_SDDL failed: Invalid filename");
174 g_message (
"smb_file_SDDL failed: Invalid smb_handle");
187 retc->
size = strlen (buffer);
211 g_message (
"smb_file_owner_sid failed: Invalid filename");
217 g_message (
"smb_file_owner_sid failed: Invalid smb_handle");
230 retc->
size = strlen (buffer);
254 g_message (
"smb_file_group_sid failed: Invalid filename");
260 g_message (
"smb_file_group_sid failed: Invalid smb_handle");
273 retc->
size = strlen (buffer);
297 g_message (
"smb_file_trustee_rights failed: Invalid filename");
303 g_message (
"smb_file_trustee_rights failed: Invalid smb_handle");
316 retc->
size = strlen (buffer);
339 char *ip, *argv[4], *unicode, target[2048], *c;
341 GString *
string = NULL;
349 if ((
host == NULL) || (username == NULL) || (password == NULL)
352 g_message (
"win_cmd_exec: Invalid input arguments");
356 ip = addr6_as_str (
host);
357 if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
359 g_message (
"win_cmd_exec: Invalid input arguments");
365 if ((c = strchr (username,
'\\')))
367 argv[0] =
"impacket-wmiexec";
368 snprintf (target,
sizeof (target),
"%s:%s@%s", username, password, ip);
372 ret = g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
373 NULL, NULL, NULL, &sout, NULL, &err);
377 g_warning (
"win_cmd_exec: %s", err ? err->message :
"Error");
383 string = g_string_new (
"");
389 bytes = read (sout, buf,
sizeof (buf));
393 g_string_append_len (
string, buf, bytes);
396 g_warning (
"win_cmd_exec: %s", strerror (errno));
397 g_string_free (
string, TRUE);
404 if (g_str_has_prefix (string->str,
"[-]"))
406 g_warning (
"win_cmd_exec: %s", string->str);
407 g_string_free (
string, TRUE);
410 else if ((unicode = strstr (string->str,
"\xff\xfe")))
417 diff = unicode -
string->str + 1;
418 tmp = g_convert (unicode + 2, string->len - diff,
"UTF-8",
"UTF-16", NULL,
422 g_warning (
"win_cmd_exec: %s", err->message);
423 g_string_free (
string, TRUE);
427 g_free (string->str);
434 retc->
size =
string->len;
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)
Host information, implemented as doubly linked list.
struct script_infos * script_infos