OpenVAS Scanner  7.0.1~git
nasl_crypto.h File Reference
#include "nasl_lex_ctxt.h"
Include dependency graph for nasl_crypto.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MD4_DIGEST_LENGTH   16
 

Functions

tree_cellnasl_md2 (lex_ctxt *)
 
tree_cellnasl_md4 (lex_ctxt *)
 
tree_cellnasl_md5 (lex_ctxt *)
 
tree_cellnasl_sha (lex_ctxt *)
 
tree_cellnasl_sha1 (lex_ctxt *)
 
tree_cellnasl_sha256 (lex_ctxt *)
 
tree_cellnasl_ripemd160 (lex_ctxt *)
 
tree_cellnasl_hmac_md2 (lex_ctxt *)
 
tree_cellnasl_hmac_md5 (lex_ctxt *)
 
tree_cellnasl_hmac_sha1 (lex_ctxt *)
 
tree_cellnasl_hmac_sha256 (lex_ctxt *)
 
tree_cellnasl_hmac_sha384 (lex_ctxt *)
 
tree_cellnasl_hmac_sha512 (lex_ctxt *)
 
tree_cellnasl_hmac_dss (lex_ctxt *)
 
tree_cellnasl_hmac_ripemd160 (lex_ctxt *)
 
tree_cellnasl_prf_sha256 (lex_ctxt *)
 
tree_cellnasl_prf_sha384 (lex_ctxt *)
 
tree_cellnasl_tls1_prf (lex_ctxt *)
 
tree_cellnasl_ntlmv1_hash (lex_ctxt *)
 
tree_cellnasl_nt_owf_gen (lex_ctxt *)
 
tree_cellnasl_lm_owf_gen (lex_ctxt *)
 
tree_cellnasl_ntv2_owf_gen (lex_ctxt *)
 
tree_cellnasl_ntlmv2_hash (lex_ctxt *)
 
tree_cellnasl_ntlmv2_response (lex_ctxt *lexic)
 
tree_cellnasl_ntlm2_response (lex_ctxt *lexic)
 
tree_cellnasl_ntlm_response (lex_ctxt *lexic)
 
tree_cellnasl_keyexchg (lex_ctxt *lexic)
 
tree_cellnasl_insert_hexzeros (lex_ctxt *lexic)
 
tree_cellnasl_get_password (lex_ctxt *lexic)
 
tree_cellnasl_get_sign (lex_ctxt *lexic)
 
tree_cellnasl_get_smb2_sign (lex_ctxt *lexic)
 
tree_cellnasl_cipher_des (lex_ctxt *)
 

Macro Definition Documentation

◆ MD4_DIGEST_LENGTH

#define MD4_DIGEST_LENGTH   16

Definition at line 28 of file nasl_crypto.h.

Function Documentation

◆ nasl_cipher_des()

tree_cell* nasl_cipher_des ( lex_ctxt )

Definition at line 189 of file nasl_crypto.c.

References get_str_var_by_num(), get_var_size_by_num(), and nasl_cipher().

190 {
191  char *data, *key;
192  size_t dlen, klen;
193 
194  data = get_str_var_by_num (lexic, 0);
195  dlen = get_var_size_by_num (lexic, 0);
196  key = get_str_var_by_num (lexic, 1);
197  klen = get_var_size_by_num (lexic, 1);
198  return nasl_cipher (GCRY_CIPHER_DES, data, dlen, key, klen);
199 }
static tree_cell * nasl_cipher(int algorithm, void *data, size_t dlen, void *key, size_t klen)
Definition: nasl_crypto.c:157
int get_var_size_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1154
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1120
Here is the call graph for this function:

◆ nasl_get_password()

tree_cell* nasl_get_password ( lex_ctxt lexic)

◆ nasl_get_sign()

tree_cell* nasl_get_sign ( lex_ctxt lexic)

Definition at line 246 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), nasl_perror(), simple_packet_signature_ntlmssp(), TC::size, TC::str_val, and TC::x.

247 {
248  char *mac_key = (char *) get_str_var_by_name (lexic, "key");
249  uint8_t *buf = (uint8_t *) get_str_var_by_name (lexic, "buf");
250  int buflen = get_int_var_by_name (lexic, "buflen", -1);
251  int seq_num = get_int_var_by_name (lexic, "seq_number", -1);
252  if (mac_key == NULL || buf == NULL || buflen == -1 || seq_num <= -1)
253  {
254  nasl_perror (lexic, "Syntax : get_signature(key:<k>, buf:<b>, "
255  "buflen:<bl>, seq_number:<s>)\n");
256  return NULL;
257  }
258  uint8_t calc_md5_mac[16];
259  simple_packet_signature_ntlmssp ((uint8_t *) mac_key, buf, seq_num,
260  calc_md5_mac);
261  memcpy (buf + 18, calc_md5_mac, 8);
262  char *ret = g_malloc0 (buflen);
263  memcpy (ret, buf, buflen);
264  tree_cell *retc;
265  retc = alloc_typed_cell (CONST_DATA);
266  retc->size = buflen;
267  retc->x.str_val = (char *) ret;
268  return retc;
269 }
void simple_packet_signature_ntlmssp(uint8_t *mac_key, const uchar *buf, uint32 seq_number, unsigned char *calc_md5_mac)
Definition: smb_signing.c:36
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_get_smb2_sign()

tree_cell* nasl_get_smb2_sign ( lex_ctxt lexic)

Definition at line 571 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), get_var_size_by_name(), hmac_sha256(), nasl_perror(), TC::size, TC::str_val, and TC::x.

572 {
573  void *key, *buf, *signature, *ret;
574  int keylen, buflen;
575  tree_cell *retc;
576 
577  key = get_str_var_by_name (lexic, "key");
578  buf = get_str_var_by_name (lexic, "buf");
579  keylen = get_var_size_by_name (lexic, "key");
580  buflen = get_var_size_by_name (lexic, "buf");
581  if (!key || !buf || keylen <= 0)
582  {
583  nasl_perror (lexic, "Syntax : get_smb2_signature(buf:<b>, key:<k>)");
584  return NULL;
585  }
586  if (buflen < 64)
587  {
588  nasl_perror (lexic, "get_smb2_sign: Buffer length < 64");
589  return NULL;
590  }
591 
592  /* Zero the SMB2 signature field, then calculate signature */
593  memset ((char *) buf + 48, 0, 16);
594  signature = hmac_sha256 (key, keylen, buf, buflen);
595 
596  /* Return the header with signature included. */
597  ret = g_malloc0 (buflen);
598  memcpy (ret, buf, buflen);
599  memcpy ((char *) ret + 48, signature, 16);
600  g_free (signature);
601  retc = alloc_typed_cell (CONST_DATA);
602  retc->size = buflen;
603  retc->x.str_val = (char *) ret;
604  return retc;
605 }
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
static void * hmac_sha256(const void *key, int keylen, const void *buf, int buflen)
Definition: nasl_crypto.c:300
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_hmac_dss()

tree_cell* nasl_hmac_dss ( lex_ctxt )

◆ nasl_hmac_md2()

tree_cell* nasl_hmac_md2 ( lex_ctxt )

Definition at line 215 of file nasl_crypto.c.

References nasl_hmac().

216 {
217  return nasl_hmac (lexic, GCRY_MD_MD2);
218 }
static tree_cell * nasl_hmac(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:204
Here is the call graph for this function:

◆ nasl_hmac_md5()

tree_cell* nasl_hmac_md5 ( lex_ctxt )

Definition at line 221 of file nasl_crypto.c.

References nasl_hmac().

222 {
223  return nasl_hmac (lexic, GCRY_MD_MD5);
224 }
static tree_cell * nasl_hmac(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:204
Here is the call graph for this function:

◆ nasl_hmac_ripemd160()

tree_cell* nasl_hmac_ripemd160 ( lex_ctxt )

Definition at line 239 of file nasl_crypto.c.

References nasl_hmac().

240 {
241  return nasl_hmac (lexic, GCRY_MD_RMD160);
242 }
static tree_cell * nasl_hmac(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:204
Here is the call graph for this function:

◆ nasl_hmac_sha1()

tree_cell* nasl_hmac_sha1 ( lex_ctxt )

Definition at line 227 of file nasl_crypto.c.

References nasl_hmac().

228 {
229  return nasl_hmac (lexic, GCRY_MD_SHA1);
230 }
static tree_cell * nasl_hmac(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:204
Here is the call graph for this function:

◆ nasl_hmac_sha256()

tree_cell* nasl_hmac_sha256 ( lex_ctxt )

Definition at line 349 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), get_var_size_by_name(), hmac_sha256(), nasl_perror(), TC::size, TC::str_val, and TC::x.

350 {
351  void *key, *data, *signature;
352  int keylen, datalen;
353  tree_cell *retc;
354 
355  key = get_str_var_by_name (lexic, "key");
356  data = get_str_var_by_name (lexic, "data");
357  datalen = get_var_size_by_name (lexic, "data");
358  keylen = get_var_size_by_name (lexic, "key");
359  if (!key || !data || keylen <= 0 || datalen <= 0)
360  {
361  nasl_perror (lexic, "Syntax : hmac_sha256(data:<b>, key:<k>)\n");
362  return NULL;
363  }
364  signature = hmac_sha256 (key, keylen, data, datalen);
365 
366  retc = alloc_typed_cell (CONST_DATA);
367  retc->size = 32;
368  retc->x.str_val = (char *) signature;
369  return retc;
370 }
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
static void * hmac_sha256(const void *key, int keylen, const void *buf, int buflen)
Definition: nasl_crypto.c:300
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_hmac_sha384()

tree_cell* nasl_hmac_sha384 ( lex_ctxt )

Definition at line 233 of file nasl_crypto.c.

References nasl_hmac().

234 {
235  return nasl_hmac (lexic, GCRY_MD_SHA384);
236 }
static tree_cell * nasl_hmac(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:204
Here is the call graph for this function:

◆ nasl_hmac_sha512()

tree_cell* nasl_hmac_sha512 ( lex_ctxt )

Definition at line 565 of file nasl_crypto.c.

References nasl_hmac().

566 {
567  return nasl_hmac (lexic, GCRY_MD_SHA512);
568 }
static tree_cell * nasl_hmac(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:204
Here is the call graph for this function:

◆ nasl_insert_hexzeros()

tree_cell* nasl_insert_hexzeros ( lex_ctxt lexic)

Definition at line 835 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), get_var_size_by_name(), nasl_perror(), TC::size, TC::str_val, uchar, val, and TC::x.

836 {
837  const uchar *in = (uchar *) get_str_var_by_name (lexic, "in");
838  int in_len = get_var_size_by_name (lexic, "in");
839  char *src;
840  smb_ucs2_t *out, *dst, val;
841  int i;
842  size_t byte_len;
843  tree_cell *retc;
844  if (in_len < 0 || in == NULL)
845  {
846  nasl_perror (lexic, "Syntax : insert_hexzeros(in:<i>)\n");
847  return NULL;
848  }
849 
850  byte_len = sizeof (smb_ucs2_t) * (strlen ((char *) in) + 1);
851  out = g_malloc0 (byte_len);
852  dst = out;
853  src = (char *) in;
854 
855  for (i = 0; i < in_len; i++)
856  {
857  val = *src;
858  *dst = val;
859  dst++;
860  src++;
861  if (val == 0)
862  break;
863  }
864 
865  /* We don't want null termination */
866  byte_len = byte_len - 2;
867 
868  retc = alloc_typed_cell (CONST_DATA);
869  retc->size = byte_len;
870  retc->x.str_val = (char *) out;
871  return retc;
872 }
#define uchar
Definition: hmacmd5.h:35
const char * val
Definition: nasl_init.c:378
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
uint16 smb_ucs2_t
Definition: hmacmd5.h:65
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_keyexchg()

tree_cell* nasl_keyexchg ( lex_ctxt lexic)

Definition at line 725 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), nasl_perror(), ntlmssp_genauth_keyexchg(), TC::size, TC::str_val, and TC::x.

726 {
727  char *cryptkey = (char *) get_str_var_by_name (lexic, "cryptkey");
728  uint8_t *session_key = (uint8_t *) get_str_var_by_name (lexic, "session_key");
729  unsigned char *nt_hash =
730  (unsigned char *) get_str_var_by_name (lexic, "nt_hash");
731 
732  if (cryptkey == NULL || session_key == NULL || nt_hash == NULL)
733  {
734  nasl_perror (
735  lexic,
736  "Syntax : key_exchange(cryptkey:<c>, session_key:<s>, nt_hash:<n> )\n");
737  return NULL;
738  }
739  uint8_t new_sess_key[16];
740  tree_cell *retc;
741  uint8_t *encrypted_session_key = NULL;
742  encrypted_session_key = ntlmssp_genauth_keyexchg (
743  session_key, cryptkey, nt_hash, (uint8_t *) &new_sess_key);
744  int len = 16 + 16;
745  char *ret = g_malloc0 (len);
746  memcpy (ret, new_sess_key, 16);
747  memcpy (ret + 16, encrypted_session_key, 16);
748  retc = alloc_typed_cell (CONST_DATA);
749  retc->size = len;
750  retc->x.str_val = ret;
751  return retc;
752 }
char * str_val
Definition: nasl_tree.h:112
uint8_t * ntlmssp_genauth_keyexchg(uint8_t *session_key, char *challenge_data, unsigned char *nt_hash, uint8_t *new_sess_key)
Definition: ntlmssp.c:99
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_lm_owf_gen()

tree_cell* nasl_lm_owf_gen ( lex_ctxt )

Definition at line 806 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, E_P16(), get_str_var_by_num(), get_var_size_by_num(), nasl_perror(), TC::size, TC::str_val, uchar, and TC::x.

807 {
808  char *pass = get_str_var_by_num (lexic, 0);
809  int pass_len = get_var_size_by_num (lexic, 0);
810  tree_cell *retc;
811  uchar pwd[15];
812  uchar p16[16];
813  unsigned int i;
814 
815  if (pass_len < 0 || pass == NULL)
816  {
817  nasl_perror (lexic, "Syntax : nt_lm_gen(password:<p>)\n");
818  return NULL;
819  }
820 
821  bzero (pwd, sizeof (pwd));
822  strncpy ((char *) pwd, pass, sizeof (pwd) - 1);
823  for (i = 0; i < sizeof (pwd); i++)
824  pwd[i] = toupper (pwd[i]);
825 
826  E_P16 (pwd, p16);
827 
828  retc = alloc_typed_cell (CONST_DATA);
829  retc->size = 16;
830  retc->x.str_val = g_memdup (p16, 16);
831  return retc;
832 }
#define uchar
Definition: hmacmd5.h:35
char * str_val
Definition: nasl_tree.h:112
void E_P16(uchar *p14, uchar *p16)
Definition: smb_crypt.c:315
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
int get_var_size_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1154
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1120
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_md2()

tree_cell* nasl_md2 ( lex_ctxt )

Definition at line 121 of file nasl_crypto.c.

References nasl_hash().

122 {
123  return nasl_hash (lexic, GCRY_MD_MD2);
124 }
static tree_cell * nasl_hash(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:112
Here is the call graph for this function:

◆ nasl_md4()

tree_cell* nasl_md4 ( lex_ctxt )

Definition at line 127 of file nasl_crypto.c.

References nasl_hash().

128 {
129  return nasl_hash (lexic, GCRY_MD_MD4);
130 }
static tree_cell * nasl_hash(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:112
Here is the call graph for this function:

◆ nasl_md5()

tree_cell* nasl_md5 ( lex_ctxt )

Definition at line 133 of file nasl_crypto.c.

References nasl_hash().

134 {
135  return nasl_hash (lexic, GCRY_MD_MD5);
136 }
static tree_cell * nasl_hash(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:112
Here is the call graph for this function:

◆ nasl_nt_owf_gen()

tree_cell* nasl_nt_owf_gen ( lex_ctxt )

Definition at line 787 of file nasl_crypto.c.

References get_str_var_by_num(), nasl_gcrypt_hash(), and nasl_perror().

788 {
789  char *pass = get_str_var_by_num (lexic, 0);
790  gunichar2 *upass;
791  glong upass_len;
792  tree_cell *ret;
793 
794  if (!pass)
795  {
796  nasl_perror (lexic, "Syntax : nt_owf_gen(<password>)\n");
797  return NULL;
798  }
799  upass = g_utf8_to_utf16 (pass, -1, NULL, &upass_len, NULL);
800  ret = nasl_gcrypt_hash (lexic, GCRY_MD_MD4, upass, upass_len * 2, NULL, 0);
801  g_free (upass);
802  return ret;
803 }
static tree_cell * nasl_gcrypt_hash(lex_ctxt *lexic, int algorithm, void *data, size_t datalen, void *key, size_t keylen)
Definition: nasl_crypto.c:68
Definition: nasl_tree.h:104
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1120
Here is the call graph for this function:

◆ nasl_ntlm2_response()

tree_cell* nasl_ntlm2_response ( lex_ctxt lexic)

Definition at line 652 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), get_var_size_by_name(), nasl_perror(), ntlmssp_genauth_ntlm2(), TC::size, TC::str_val, and TC::x.

653 {
654  char *cryptkey = (char *) get_str_var_by_name (lexic, "cryptkey");
655  char *password = get_str_var_by_name (lexic, "password");
656  uint8_t pass_len = get_var_size_by_name (lexic, "password");
657  void *nt_hash = get_str_var_by_name (lexic, "nt_hash");
658  int hash_len = get_var_size_by_name (lexic, "nt_hash");
659 
660  if (!cryptkey || !password || !nt_hash || hash_len < 16)
661  {
662  nasl_perror (lexic, "Syntax : ntlm2_response(cryptkey:<c>, password:<p>, "
663  "nt_hash:<n[16]>)\n");
664  return NULL;
665  }
666 
667  uint8_t lm_response[24];
668  uint8_t nt_response[24];
669  uint8_t session_key[16];
670 
671  tree_cell *retc;
672  ntlmssp_genauth_ntlm2 (password, pass_len, lm_response, nt_response,
673  session_key, cryptkey, nt_hash);
674  int len = sizeof (lm_response) + sizeof (nt_response) + sizeof (session_key);
675  char *ret = g_malloc0 (len);
676  memcpy (ret, lm_response, sizeof (lm_response));
677  memcpy (ret + sizeof (lm_response), nt_response, sizeof (nt_response));
678  memcpy (ret + sizeof (lm_response) + sizeof (nt_response), session_key,
679  sizeof (session_key));
680  retc = alloc_typed_cell (CONST_DATA);
681  retc->size = len;
682  retc->x.str_val = ret;
683  return retc;
684 }
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void ntlmssp_genauth_ntlm2(char *password, uint8_t pass_len, uint8_t *lm_response, uint8_t *nt_response, uint8_t *session_key, char *challenge_data, unsigned char *nt_hash)
Definition: ntlmssp.c:44
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_ntlm_response()

tree_cell* nasl_ntlm_response ( lex_ctxt lexic)

Definition at line 687 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), nasl_perror(), ntlmssp_genauth_ntlm(), TC::size, TC::str_val, and TC::x.

688 {
689  char *cryptkey = (char *) get_str_var_by_name (lexic, "cryptkey");
690  char *password = get_str_var_by_name (lexic, "password");
691  uint8_t pass_len = (uint8_t) get_var_size_by_name (lexic, "password");
692  void *nt_hash = get_str_var_by_name (lexic, "nt_hash");
693  int hash_len = get_var_size_by_name (lexic, "nt_hash");
694  int neg_flags = get_int_var_by_name (lexic, "neg_flags", -1);
695 
696  if (!cryptkey || !password || !nt_hash || hash_len < 16 || neg_flags < 0)
697  {
698  nasl_perror (lexic, "Syntax : ntlm_response(cryptkey:<c>, password:<p>, "
699  "nt_hash:<n[16]>, neg_flags:<nf>)\n");
700  return NULL;
701  }
702 
703  uint8_t lm_response[24];
704  uint8_t nt_response[24];
705  uint8_t session_key[16];
706 
707  tree_cell *retc;
708 
709  ntlmssp_genauth_ntlm (password, pass_len, lm_response, nt_response,
710  session_key, cryptkey, nt_hash, neg_flags);
711 
712  int len = sizeof (lm_response) + sizeof (nt_response) + sizeof (session_key);
713  char *ret = g_malloc0 (len);
714  memcpy (ret, lm_response, sizeof (lm_response));
715  memcpy (ret + sizeof (lm_response), nt_response, sizeof (nt_response));
716  memcpy (ret + sizeof (lm_response) + sizeof (nt_response), session_key,
717  sizeof (session_key));
718  retc = alloc_typed_cell (CONST_DATA);
719  retc->size = len;
720  retc->x.str_val = ret;
721  return retc;
722 }
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
void ntlmssp_genauth_ntlm(char *password, uint8_t pass_len, uint8_t *lm_response, uint8_t *nt_response, uint8_t *session_key, char *challenge_data, unsigned char *nt_hash, int neg_flags)
Definition: ntlmssp.c:75
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_ntlmv1_hash()

tree_cell* nasl_ntlmv1_hash ( lex_ctxt )

Definition at line 755 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, E_P24(), get_str_var_by_name(), get_var_size_by_name(), nasl_perror(), TC::size, TC::str_val, uchar, and TC::x.

756 {
757  const uchar *cryptkey = (uchar *) get_str_var_by_name (lexic, "cryptkey");
758  char *password = get_str_var_by_name (lexic, "passhash");
759  int pass_len = get_var_size_by_name (lexic, "passhash");
760  unsigned char p21[21];
761  tree_cell *retc;
762  uchar *ret;
763 
764  if (cryptkey == NULL || password == NULL)
765  {
766  nasl_perror (lexic, "Syntax : ntlmv1_hash(cryptkey:<c>, passhash:<p>)\n");
767  return NULL;
768  }
769 
770  if (pass_len < 16)
771  pass_len = 16;
772 
773  bzero (p21, sizeof (p21));
774  memcpy (p21, password, pass_len);
775 
776  ret = g_malloc0 (24);
777 
778  E_P24 (p21, cryptkey, ret);
779  retc = alloc_typed_cell (CONST_DATA);
780  retc->size = 24;
781  retc->x.str_val = (char *) ret;
782 
783  return retc;
784 }
#define uchar
Definition: hmacmd5.h:35
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
void E_P24(const uchar *p21, const uchar *c8, uchar *p24)
Definition: smb_crypt.c:323
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_ntlmv2_hash()

tree_cell* nasl_ntlmv2_hash ( lex_ctxt )

Definition at line 963 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), nasl_perror(), TC::size, SMBOWFencrypt_ntv2_ntlmssp(), TC::str_val, uchar, and TC::x.

964 {
965  const uchar *server_chal = (uchar *) get_str_var_by_name (lexic, "cryptkey");
966  int sc_len = get_var_size_by_name (lexic, "cryptkey");
967  const uchar *ntlm_v2_hash = (uchar *) get_str_var_by_name (lexic, "passhash");
968  int hash_len = get_var_size_by_name (lexic, "passhash");
969  int client_chal_length = get_int_var_by_name (lexic, "length", -1);
970  tree_cell *retc;
971  unsigned char ntlmv2_response[16];
972  unsigned char *ntlmv2_client_data = NULL;
973  unsigned char *final_response;
974  int i;
975 
976  if (sc_len < 0 || server_chal == NULL || hash_len < 0 || ntlm_v2_hash == NULL
977  || client_chal_length < 0)
978  {
979  nasl_perror (
980  lexic,
981  "Syntax : ntlmv2_hash(cryptkey:<c>, passhash:<p>, length:<l>)\n");
982  return NULL;
983  }
984 
985  /* NTLMv2 */
986 
987  /* We also get to specify some random data */
988  ntlmv2_client_data = g_malloc0 (client_chal_length);
989  for (i = 0; i < client_chal_length; i++)
990  ntlmv2_client_data[i] = rand () % 256;
991 
992  assert (hash_len == 16);
993  /* Given that data, and the challenge from the server, generate a response */
994  SMBOWFencrypt_ntv2_ntlmssp (ntlm_v2_hash, server_chal, 8, ntlmv2_client_data,
995  client_chal_length, ntlmv2_response);
996 
997  /* put it into nt_response, for the code below to put into the packet */
998  final_response = g_malloc0 (client_chal_length + sizeof (ntlmv2_response));
999  memcpy (final_response, ntlmv2_response, sizeof (ntlmv2_response));
1000  /* after the first 16 bytes is the random data we generated above, so the
1001  * server can verify us with it */
1002  memcpy (final_response + sizeof (ntlmv2_response), ntlmv2_client_data,
1003  client_chal_length);
1004 
1005  g_free (ntlmv2_client_data);
1006 
1007  retc = alloc_typed_cell (CONST_DATA);
1008  retc->size = client_chal_length + sizeof (ntlmv2_response);
1009  retc->x.str_val = (char *) final_response;
1010 
1011  return retc;
1012 }
#define uchar
Definition: hmacmd5.h:35
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void SMBOWFencrypt_ntv2_ntlmssp(const uchar kr[16], const uint8_t *srv_chal, int srv_chal_len, const uint8_t *cli_chal, int cli_chal_len, uchar resp_buf[16])
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_ntlmv2_response()

tree_cell* nasl_ntlmv2_response ( lex_ctxt lexic)

Definition at line 608 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), nasl_perror(), ntlmssp_genauth_ntlmv2(), TC::size, TC::str_val, and TC::x.

609 {
610  char *cryptkey = (char *) get_str_var_by_name (lexic, "cryptkey");
611  char *user = (char *) get_str_var_by_name (lexic, "user");
612  char *domain = (char *) get_str_var_by_name (lexic, "domain");
613  unsigned char *ntlmv2_hash =
614  (unsigned char *) get_str_var_by_name (lexic, "ntlmv2_hash");
615  char *address_list = get_str_var_by_name (lexic, "address_list");
616  int address_list_len = get_int_var_by_name (lexic, "address_list_len", -1);
617 
618  if (cryptkey == NULL || user == NULL || domain == NULL || ntlmv2_hash == NULL
619  || address_list == NULL || address_list_len < 0)
620  {
621  nasl_perror (
622  lexic, "Syntax : ntlmv2_response(cryptkey:<c>, user:<u>, domain:<d>, "
623  "ntlmv2_hash:<n>, address_list:<a>, address_list_len:<len>)\n");
624  return NULL;
625  }
626  uint8_t lm_response[24];
627  uint8_t nt_response[16 + 28 + address_list_len];
628  uint8_t session_key[16];
629  bzero (lm_response, sizeof (lm_response));
630  bzero (nt_response, sizeof (nt_response));
631  bzero (session_key, sizeof (session_key));
632 
633  ntlmssp_genauth_ntlmv2 (user, domain, address_list, address_list_len,
634  cryptkey, lm_response, nt_response, session_key,
635  ntlmv2_hash);
636  tree_cell *retc;
637  int lm_response_len = 24;
638  int nt_response_len = 16 + 28 + address_list_len;
639  int len = lm_response_len + nt_response_len + sizeof (session_key);
640  char *ret = g_malloc0 (len);
641  memcpy (ret, lm_response, lm_response_len);
642  memcpy (ret + lm_response_len, session_key, sizeof (session_key));
643  memcpy (ret + lm_response_len + sizeof (session_key), nt_response,
644  nt_response_len);
645  retc = alloc_typed_cell (CONST_DATA);
646  retc->size = len;
647  retc->x.str_val = ret;
648  return retc;
649 }
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
void ntlmssp_genauth_ntlmv2(char *user, char *domain, char *address_list, int address_list_len, char *challenge_data, uint8_t *lm_response, uint8_t *nt_response, uint8_t *session_key, unsigned char *ntlmv2_hash)
Definition: ntlmssp.c:33
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_ntv2_owf_gen()

tree_cell* nasl_ntv2_owf_gen ( lex_ctxt )

Definition at line 876 of file nasl_crypto.c.

References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), get_var_size_by_name(), hmac_md5_final(), hmac_md5_init_limK_to_64(), hmac_md5_update(), nasl_perror(), TC::size, TC::str_val, strupper_w(), uchar, and TC::x.

877 {
878  const uchar *owf_in = (uchar *) get_str_var_by_name (lexic, "owf");
879  int owf_in_len = get_var_size_by_name (lexic, "owf");
880  char *user_in = get_str_var_by_name (lexic, "login");
881  int user_in_len = get_var_size_by_name (lexic, "login");
882  char *domain_in = get_str_var_by_name (lexic, "domain");
883  int domain_len = get_var_size_by_name (lexic, "domain");
884  char *src_user, *src_domain;
885  smb_ucs2_t *user, *dst_user, val_user;
886  smb_ucs2_t *domain, *dst_domain, val_domain;
887  int i;
888  size_t user_byte_len;
889  size_t domain_byte_len;
890  tree_cell *retc;
891  uchar *kr_buf;
892  HMACMD5Context ctx;
893 
894  if (owf_in_len < 0 || owf_in == NULL || user_in_len < 0 || user_in == NULL
895  || domain_len < 0 || domain_in == NULL)
896  {
897  nasl_perror (lexic,
898  "Syntax : ntv2_owf_gen(owf:<o>, login:<l>, domain:<d>)\n");
899  return NULL;
900  }
901 
902  assert (owf_in_len == 16);
903 
904  user_byte_len = sizeof (smb_ucs2_t) * (strlen (user_in) + 1);
905  user = g_malloc0 (user_byte_len);
906  dst_user = user;
907  src_user = user_in;
908 
909  for (i = 0; i < user_in_len; i++)
910  {
911  val_user = *src_user;
912  *dst_user = val_user;
913  dst_user++;
914  src_user++;
915  if (val_user == 0)
916  break;
917  }
918 
919  domain_byte_len = sizeof (smb_ucs2_t) * (strlen (domain_in) + 1);
920  domain = g_malloc0 (domain_byte_len);
921  dst_domain = domain;
922  src_domain = domain_in;
923 
924  for (i = 0; i < domain_len; i++)
925  {
926  val_domain = *src_domain;
927  *dst_domain = val_domain;
928 
929  dst_domain++;
930  src_domain++;
931  if (val_domain == 0)
932  break;
933  }
934 
935  strupper_w (user);
936  strupper_w (domain);
937 
938  assert (user_byte_len >= 2);
939  assert (domain_byte_len >= 2);
940 
941  /* We don't want null termination */
942  user_byte_len = user_byte_len - 2;
943  domain_byte_len = domain_byte_len - 2;
944 
945  kr_buf = g_malloc0 (16);
946 
947  hmac_md5_init_limK_to_64 (owf_in, 16, &ctx);
948  hmac_md5_update ((const unsigned char *) user, user_byte_len, &ctx);
949  hmac_md5_update ((const unsigned char *) domain, domain_byte_len, &ctx);
950  hmac_md5_final (kr_buf, &ctx);
951 
952  g_free (user);
953  g_free (domain);
954 
955  retc = alloc_typed_cell (CONST_DATA);
956  retc->size = 16;
957  retc->x.str_val = (char *) kr_buf;
958 
959  return retc;
960 }
#define uchar
Definition: hmacmd5.h:35
int strupper_w(smb_ucs2_t *s)
Definition: smb_crypt2.c:48
char * str_val
Definition: nasl_tree.h:112
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
void hmac_md5_init_limK_to_64(const uchar *key, int key_len, HMACMD5Context *ctx)
The microsoft version of hmac_md5 initialisation.
Definition: hmacmd5.c:37
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
Definition: nasl_tree.h:104
union TC::@2 x
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
Definition: hmacmd5.c:77
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
Definition: hmacmd5.c:68
uint16 smb_ucs2_t
Definition: hmacmd5.h:65
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
int size
Definition: nasl_tree.h:109
Here is the call graph for this function:

◆ nasl_prf_sha256()

tree_cell* nasl_prf_sha256 ( lex_ctxt )

Definition at line 547 of file nasl_crypto.c.

References nasl_prf().

548 {
549  return nasl_prf (lexic, 0);
550 }
static tree_cell * nasl_prf(lex_ctxt *lexic, int hmac)
Definition: nasl_crypto.c:513
Here is the call graph for this function:

◆ nasl_prf_sha384()

tree_cell* nasl_prf_sha384 ( lex_ctxt )

Definition at line 553 of file nasl_crypto.c.

References nasl_prf().

554 {
555  return nasl_prf (lexic, 1);
556 }
static tree_cell * nasl_prf(lex_ctxt *lexic, int hmac)
Definition: nasl_crypto.c:513
Here is the call graph for this function:

◆ nasl_ripemd160()

tree_cell* nasl_ripemd160 ( lex_ctxt )

Definition at line 151 of file nasl_crypto.c.

References nasl_hash().

152 {
153  return nasl_hash (lexic, GCRY_MD_RMD160);
154 }
static tree_cell * nasl_hash(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:112
Here is the call graph for this function:

◆ nasl_sha()

tree_cell* nasl_sha ( lex_ctxt )

◆ nasl_sha1()

tree_cell* nasl_sha1 ( lex_ctxt )

Definition at line 139 of file nasl_crypto.c.

References nasl_hash().

140 {
141  return nasl_hash (lexic, GCRY_MD_SHA1);
142 }
static tree_cell * nasl_hash(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:112
Here is the call graph for this function:

◆ nasl_sha256()

tree_cell* nasl_sha256 ( lex_ctxt )

Definition at line 145 of file nasl_crypto.c.

References nasl_hash().

146 {
147  return nasl_hash (lexic, GCRY_MD_SHA256);
148 }
static tree_cell * nasl_hash(lex_ctxt *lexic, int algorithm)
Definition: nasl_crypto.c:112
Here is the call graph for this function:

◆ nasl_tls1_prf()

tree_cell* nasl_tls1_prf ( lex_ctxt )

Definition at line 559 of file nasl_crypto.c.

References nasl_prf().

560 {
561  return nasl_prf (lexic, 2);
562 }
static tree_cell * nasl_prf(lex_ctxt *lexic, int hmac)
Definition: nasl_crypto.c:513
Here is the call graph for this function: