OpenVAS Libraries  9.0.3
nasl_crypto.h File Reference
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 23 of file nasl_crypto.h.

Function Documentation

◆ nasl_cipher_des()

tree_cell* nasl_cipher_des ( lex_ctxt )

Definition at line 184 of file nasl_crypto.c.

References get_str_var_by_num(), and get_var_size_by_num().

185 {
186  char *data, *key;
187  size_t dlen, klen;
188 
189  data = get_str_var_by_num (lexic, 0);
190  dlen = get_var_size_by_num (lexic, 0);
191  key = get_str_var_by_num (lexic, 1);
192  klen = get_var_size_by_num (lexic, 1);
193  return nasl_cipher (GCRY_CIPHER_DES, data, dlen, key, klen);
194 }
int get_var_size_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1305
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
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 243 of file nasl_crypto.c.

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

244 {
245  char *mac_key = (char *) get_str_var_by_name (lexic, "key");
246  uint8_t *buf = (uint8_t *) get_str_var_by_name (lexic, "buf");
247  int buflen = get_int_var_by_name (lexic, "buflen", -1);
248  uint32 seq_num = get_int_var_by_name (lexic, "seq_number", -1);
249  if (mac_key == NULL || buf == NULL || buflen == -1 || seq_num == -1)
250  {
251  nasl_perror (lexic,
252  "Syntax : get_sign(key:<k>, buf:<b>, buflen:<bl>, seq_number:<s>)\n");
253  return NULL;
254  }
255  uint8_t calc_md5_mac[16];
256  simple_packet_signature_ntlmssp ((uint8_t *) mac_key, buf, seq_num, calc_md5_mac);
257  memcpy (buf + 18, calc_md5_mac, 8);
258  char *ret = g_malloc0 (buflen);
259  memcpy (ret, buf, buflen);
260  tree_cell *retc;
261  retc = alloc_tree_cell (0, NULL);
262  retc->type = CONST_DATA;
263  retc->size = buflen;
264  retc->x.str_val = (char *) ret;
265  return retc;
266 }
#define uint32
Definition: genrand.c:49
void simple_packet_signature_ntlmssp(uint8_t *mac_key, const uchar *buf, uint32 seq_number, unsigned char *calc_md5_mac)
Definition: smb_signing.c:27
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1233
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_get_smb2_sign()

tree_cell* nasl_get_smb2_sign ( lex_ctxt lexic)

Definition at line 572 of file nasl_crypto.c.

References get_str_var_by_name(), get_var_size_by_name(), and nasl_perror().

573 {
574  void *key, *buf, *signature, *ret;
575  int keylen, buflen;
576  tree_cell *retc;
577 
578  key = get_str_var_by_name (lexic, "key");
579  buf = get_str_var_by_name (lexic, "buf");
580  keylen = get_var_size_by_name (lexic, "key");
581  buflen = get_var_size_by_name (lexic, "buf");
582  if (!key || !buf || keylen <= 0)
583  {
584  nasl_perror (lexic,
585  "Syntax : get_smb2_sign(buf:<b>, key:<k>)");
586  return NULL;
587  }
588  if (buflen < 64)
589  {
590  nasl_perror (lexic, "get_smb2_sign: Buffer length < 64");
591  return NULL;
592  }
593 
594  /* Zero the SMB2 signature field, then calculate signature */
595  memset(buf + 48, 0, 16);
596  signature = hmac_sha256 (key, keylen, buf, buflen);
597 
598  /* Return the header with signature included. */
599  ret = g_malloc0 (buflen);
600  memcpy (ret, buf, buflen);
601  memcpy (ret + 48, signature, 16);
602  g_free (signature);
603  retc = alloc_tree_cell (0, NULL);
604  retc->type = CONST_DATA;
605  retc->size = buflen;
606  retc->x.str_val = (char *) ret;
607  return retc;
608 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
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 212 of file nasl_crypto.c.

213 {
214  return nasl_hmac (lexic, GCRY_MD_MD2);
215 }

◆ nasl_hmac_md5()

tree_cell* nasl_hmac_md5 ( lex_ctxt )

Definition at line 218 of file nasl_crypto.c.

219 {
220  return nasl_hmac (lexic, GCRY_MD_MD5);
221 }

◆ nasl_hmac_ripemd160()

tree_cell* nasl_hmac_ripemd160 ( lex_ctxt )

Definition at line 236 of file nasl_crypto.c.

237 {
238  return nasl_hmac (lexic, GCRY_MD_RMD160);
239 }

◆ nasl_hmac_sha1()

tree_cell* nasl_hmac_sha1 ( lex_ctxt )

Definition at line 224 of file nasl_crypto.c.

225 {
226  return nasl_hmac (lexic, GCRY_MD_SHA1);
227 }

◆ nasl_hmac_sha256()

tree_cell* nasl_hmac_sha256 ( lex_ctxt )

Definition at line 346 of file nasl_crypto.c.

References get_local_var_size_by_name(), get_str_var_by_name(), and nasl_perror().

347 {
348  void *key, *data, *signature;
349  int keylen, datalen;
350  tree_cell *retc;
351 
352  key = get_str_var_by_name (lexic, "key");
353  data = get_str_var_by_name (lexic, "data");
354  datalen = get_local_var_size_by_name (lexic, "data");
355  keylen = get_local_var_size_by_name (lexic, "key");
356  if (!key || !data || keylen <= 0 || datalen <= 0)
357  {
358  nasl_perror (lexic,
359  "Syntax : hmac_sha256(data:<b>, key:<k>)\n");
360  return NULL;
361  }
362  signature = hmac_sha256 (key, keylen, data, datalen);
363 
364  retc = alloc_tree_cell (0, NULL);
365  retc->type = CONST_DATA;
366  retc->size = 32;
367  retc->x.str_val = (char *) signature;
368  return retc;
369 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
int get_local_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1298
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_hmac_sha384()

tree_cell* nasl_hmac_sha384 ( lex_ctxt )

Definition at line 230 of file nasl_crypto.c.

231 {
232  return nasl_hmac (lexic, GCRY_MD_SHA384);
233 }

◆ nasl_hmac_sha512()

tree_cell* nasl_hmac_sha512 ( lex_ctxt )

Definition at line 566 of file nasl_crypto.c.

567 {
568  return nasl_hmac (lexic, GCRY_MD_SHA512);
569 }

◆ nasl_insert_hexzeros()

tree_cell* nasl_insert_hexzeros ( lex_ctxt lexic)

Definition at line 843 of file nasl_crypto.c.

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

844 {
845  const uchar *in = (uchar *) get_str_var_by_name (lexic, "in");
846  int in_len = get_var_size_by_name (lexic, "in");
847  char *src;
848  smb_ucs2_t *out, *dst, val;
849  int i;
850  size_t byte_len;
851  tree_cell *retc;
852  if (in_len < 0 || in == NULL)
853  {
854  nasl_perror (lexic, "Syntax : insert_hexzeros(in:<i>)\n");
855  return NULL;
856  }
857 
858  byte_len = sizeof (smb_ucs2_t) * (strlen ((char *) in) + 1);
859  out = g_malloc0 (byte_len);
860  dst = out;
861  src = (char *) in;
862 
863  for (i = 0; i < in_len; i++)
864  {
865  val = *src;
866  *dst = val;
867  dst++;
868  src++;
869  if (val == 0)
870  break;
871  }
872 
873 
874  /* We don't want null termination */
875  byte_len = byte_len - 2;
876 
877  retc = alloc_tree_cell (0, NULL);
878  retc->type = CONST_DATA;
879  retc->size = byte_len;
880  retc->x.str_val = (char *) out;
881  return retc;
882 }
#define uchar
Definition: hmacmd5.h:28
const char * val
Definition: nasl_init.c:525
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
uint16 smb_ucs2_t
Definition: hmacmd5.h:68
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_keyexchg()

tree_cell* nasl_keyexchg ( lex_ctxt lexic)

Definition at line 730 of file nasl_crypto.c.

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

731 {
732  char *cryptkey = (char *) get_str_var_by_name (lexic, "cryptkey");
733  uint8_t *session_key = (uint8_t *) get_str_var_by_name (lexic, "session_key");
734  unsigned char *nt_hash =
735  (unsigned char *) get_str_var_by_name (lexic, "nt_hash");
736 
737  if (cryptkey == NULL || session_key == NULL || nt_hash == NULL)
738  {
739  nasl_perror (lexic,
740  "Syntax : keyexchg(cryptkey:<c>, session_key:<s>, nt_hash:<n> )\n");
741  return NULL;
742  }
743  uint8_t new_sess_key[16];
744  tree_cell *retc;
745  uint8_t *encrypted_session_key = NULL;
746  encrypted_session_key =
747  ntlmssp_genauth_keyexchg (session_key, cryptkey, nt_hash,
748  (uint8_t *) & new_sess_key);
749  int len = 16 + 16;
750  char *ret = g_malloc0 (len);
751  memcpy (ret, new_sess_key, 16);
752  memcpy (ret + 16, encrypted_session_key, 16);
753  retc = alloc_tree_cell (0, NULL);
754  retc->type = CONST_DATA;
755  retc->size = len;
756  retc->x.str_val = ret;
757  return retc;
758 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
uint8_t * ntlmssp_genauth_keyexchg(uint8_t *session_key, char *challenge_data, unsigned char *nt_hash, uint8_t *new_sess_key)
Definition: ntlmssp.c:95
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_lm_owf_gen()

tree_cell* nasl_lm_owf_gen ( lex_ctxt )

Definition at line 813 of file nasl_crypto.c.

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

814 {
815  char *pass = get_str_var_by_num (lexic, 0);
816  int pass_len = get_var_size_by_num (lexic, 0);
817  tree_cell *retc;
818  uchar pwd[15];
819  uchar p16[16];
820  int i;
821 
822  if (pass_len < 0 || pass == NULL)
823  {
824  nasl_perror (lexic, "Syntax : nt_lm_gen(password:<p>)\n");
825  return NULL;
826  }
827 
828  bzero (pwd, sizeof (pwd));
829  strncpy ((char *) pwd, pass, sizeof (pwd) - 1);
830  for (i = 0; i < sizeof (pwd); i++)
831  pwd[i] = toupper (pwd[i]);
832 
833  E_P16 (pwd, p16);
834 
835  retc = alloc_tree_cell (0, NULL);
836  retc->type = CONST_DATA;
837  retc->size = 16;
838  retc->x.str_val = g_memdup (p16, 16);
839  return retc;
840 }
#define uchar
Definition: hmacmd5.h:28
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
void E_P16(uchar *p14, uchar *p16)
Definition: smb_crypt.c:323
union TC::@7 x
Definition: nasl_tree.h:105
int get_var_size_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1305
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_md2()

tree_cell* nasl_md2 ( lex_ctxt )

Definition at line 115 of file nasl_crypto.c.

116 {
117  return nasl_hash (lexic, GCRY_MD_MD2);
118 }

◆ nasl_md4()

tree_cell* nasl_md4 ( lex_ctxt )

Definition at line 121 of file nasl_crypto.c.

122 {
123  return nasl_hash (lexic, GCRY_MD_MD4);
124 }

◆ nasl_md5()

tree_cell* nasl_md5 ( lex_ctxt )

Definition at line 127 of file nasl_crypto.c.

128 {
129  return nasl_hash (lexic, GCRY_MD_MD5);
130 }

◆ nasl_nt_owf_gen()

tree_cell* nasl_nt_owf_gen ( lex_ctxt )

Definition at line 794 of file nasl_crypto.c.

References get_str_var_by_num(), and nasl_perror().

795 {
796  char *pass = get_str_var_by_num (lexic, 0);
797  gunichar2 *upass;
798  glong upass_len;
799  tree_cell *ret;
800 
801  if (!pass)
802  {
803  nasl_perror (lexic, "Syntax : nt_owf_gen(password:<p>)\n");
804  return NULL;
805  }
806  upass = g_utf8_to_utf16 (pass, -1, NULL, &upass_len, NULL);
807  ret = nasl_gcrypt_hash (lexic, GCRY_MD_MD4, upass, upass_len * 2, NULL, 0);
808  g_free (upass);
809  return ret;
810 }
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
Here is the call graph for this function:

◆ nasl_ntlm2_response()

tree_cell* nasl_ntlm2_response ( lex_ctxt lexic)

Definition at line 655 of file nasl_crypto.c.

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

656 {
657  char *cryptkey = (char *) get_str_var_by_name (lexic, "cryptkey");
658  char *password = get_str_var_by_name (lexic, "password");
659  uint8_t pass_len = get_var_size_by_name (lexic, "password");
660  void *nt_hash = get_str_var_by_name (lexic, "nt_hash");
661  int hash_len = get_var_size_by_name (lexic, "nt_hash");
662 
663  if (!cryptkey || !password || !nt_hash || hash_len < 16)
664  {
666  (lexic, "Syntax : ntlm2_response(cryptkey:<c>, password:<p>, nt_hash:<n[16]>)\n");
667  return NULL;
668  }
669 
670  uint8_t lm_response[24];
671  uint8_t nt_response[24];
672  uint8_t session_key[16];
673 
674  tree_cell *retc;
675  ntlmssp_genauth_ntlm2 (password, pass_len, lm_response, nt_response, session_key,
676  cryptkey, nt_hash);
677  int len = sizeof (lm_response) + sizeof (nt_response) + sizeof (session_key);
678  char *ret = g_malloc0 (len);
679  memcpy (ret, lm_response, sizeof (lm_response));
680  memcpy (ret + sizeof (lm_response), nt_response, sizeof (nt_response));
681  memcpy (ret + sizeof (lm_response) + sizeof (nt_response), session_key,
682  sizeof (session_key));
683  retc = alloc_tree_cell (0, NULL);
684  retc->type = CONST_DATA;
685  retc->size = len;
686  retc->x.str_val = ret;
687  return retc;
688 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
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:43
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_ntlm_response()

tree_cell* nasl_ntlm_response ( lex_ctxt lexic)

Definition at line 691 of file nasl_crypto.c.

References alloc_tree_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, TC::type, and TC::x.

692 {
693  char *cryptkey = (char *) get_str_var_by_name (lexic, "cryptkey");
694  char *password = get_str_var_by_name (lexic, "password");
695  uint8_t pass_len = (uint8_t) get_var_size_by_name (lexic, "password");
696  void *nt_hash = get_str_var_by_name (lexic, "nt_hash");
697  int hash_len = get_var_size_by_name (lexic, "nt_hash");
698  int neg_flags = get_int_var_by_name (lexic, "neg_flags", -1);
699 
700  if (!cryptkey || !password || !nt_hash || hash_len < 16 || neg_flags < 0)
701  {
702  nasl_perror (lexic,
703  "Syntax : ntlm_response(cryptkey:<c>, password:<p>, nt_hash:<n[16]>, neg_flags:<nf>)\n");
704  return NULL;
705  }
706 
707  uint8_t lm_response[24];
708  uint8_t nt_response[24];
709  uint8_t session_key[16];
710 
711  tree_cell *retc;
712 
713  ntlmssp_genauth_ntlm (password, pass_len, lm_response, nt_response, session_key,
714  cryptkey, nt_hash, neg_flags);
715 
716  int len = sizeof (lm_response) + sizeof (nt_response) + sizeof (session_key);
717  char *ret = g_malloc0 (len);
718  memcpy (ret, lm_response, sizeof (lm_response));
719  memcpy (ret + sizeof (lm_response), nt_response, sizeof (nt_response));
720  memcpy (ret + sizeof (lm_response) + sizeof (nt_response), session_key,
721  sizeof (session_key));
722  retc = alloc_tree_cell (0, NULL);
723  retc->type = CONST_DATA;
724  retc->size = len;
725  retc->x.str_val = ret;
726  return retc;
727 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1233
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:76
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_ntlmv1_hash()

tree_cell* nasl_ntlmv1_hash ( lex_ctxt )

Definition at line 761 of file nasl_crypto.c.

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

762 {
763  const uchar *cryptkey = (uchar *) get_str_var_by_name (lexic, "cryptkey");
764  char *password = get_str_var_by_name (lexic, "passhash");
765  int pass_len = get_var_size_by_name (lexic, "passhash");
766  unsigned char p21[21];
767  tree_cell *retc;
768  uchar *ret;
769 
770  if (cryptkey == NULL || password == NULL)
771  {
772  nasl_perror (lexic, "Syntax : ntlmv1_hash(cryptkey:<c>, passhash:<p>)\n");
773  return NULL;
774  }
775 
776  if (pass_len < 16)
777  pass_len = 16;
778 
779  bzero (p21, sizeof (p21));
780  memcpy (p21, password, pass_len);
781 
782  ret = g_malloc0 (24);
783 
784  E_P24 (p21, cryptkey, ret);
785  retc = alloc_tree_cell (0, NULL);
786  retc->type = CONST_DATA;
787  retc->size = 24;
788  retc->x.str_val = (char *) ret;
789 
790  return retc;
791 }
#define uchar
Definition: hmacmd5.h:28
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
void E_P24(const uchar *p21, const uchar *c8, uchar *p24)
Definition: smb_crypt.c:330
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_ntlmv2_hash()

tree_cell* nasl_ntlmv2_hash ( lex_ctxt )

Definition at line 974 of file nasl_crypto.c.

References alloc_tree_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, TC::type, uchar, and TC::x.

975 {
976  const uchar *server_chal = (uchar *) get_str_var_by_name (lexic, "cryptkey");
977  int sc_len = get_var_size_by_name (lexic, "cryptkey");
978  const uchar *ntlm_v2_hash = (uchar *) get_str_var_by_name (lexic, "passhash");
979  int hash_len = get_var_size_by_name (lexic, "passhash");
980  int client_chal_length = get_int_var_by_name (lexic, "length", -1);
981  tree_cell *retc;
982  unsigned char ntlmv2_response[16];
983  unsigned char *ntlmv2_client_data = NULL;
984  unsigned char *final_response;
985  int i;
986 
987  if (sc_len < 0 || server_chal == NULL || hash_len < 0 || ntlm_v2_hash == NULL
988  || client_chal_length < 0)
989  {
990  nasl_perror (lexic,
991  "Syntax : ntlmv2_hash(cryptkey:<c>, passhash:<p>, length:<l>)\n");
992  return NULL;
993  }
994 
995  /* NTLMv2 */
996 
997  /* We also get to specify some random data */
998  ntlmv2_client_data = g_malloc0 (client_chal_length);
999  for (i = 0; i < client_chal_length; i++)
1000  ntlmv2_client_data[i] = rand () % 256;
1001 
1002 
1003 
1004  assert (hash_len == 16);
1005  /* Given that data, and the challenge from the server, generate a response */
1006  SMBOWFencrypt_ntv2_ntlmssp(ntlm_v2_hash, server_chal, 8, ntlmv2_client_data,
1007  client_chal_length, ntlmv2_response);
1008 
1009  /* put it into nt_response, for the code below to put into the packet */
1010  final_response = g_malloc0 (client_chal_length + sizeof (ntlmv2_response));
1011  memcpy (final_response, ntlmv2_response, sizeof (ntlmv2_response));
1012  /* after the first 16 bytes is the random data we generated above, so the server can verify us with it */
1013  memcpy (final_response + sizeof (ntlmv2_response), ntlmv2_client_data,
1014  client_chal_length);
1015 
1016  g_free (ntlmv2_client_data);
1017 
1018  retc = alloc_tree_cell (0, NULL);
1019  retc->type = CONST_DATA;
1020  retc->size = client_chal_length + sizeof (ntlmv2_response);
1021  retc->x.str_val = (char *) final_response;
1022 
1023  return retc;
1024 }
#define uchar
Definition: hmacmd5.h:28
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
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:94
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1233
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_ntlmv2_response()

tree_cell* nasl_ntlmv2_response ( lex_ctxt lexic)

Definition at line 611 of file nasl_crypto.c.

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

612 {
613  char *cryptkey = (char *) get_str_var_by_name (lexic, "cryptkey");
614  char *user = (char *) get_str_var_by_name (lexic, "user");
615  char *domain = (char *) get_str_var_by_name (lexic, "domain");
616  unsigned char *ntlmv2_hash =
617  (unsigned char *) get_str_var_by_name (lexic, "ntlmv2_hash");
618  char *address_list = get_str_var_by_name (lexic, "address_list");
619  int address_list_len = get_int_var_by_name (lexic, "address_list_len", -1);
620 
621  if (cryptkey == NULL || user == NULL || domain == NULL || ntlmv2_hash == NULL
622  || address_list == NULL || address_list_len < 0)
623  {
624  nasl_perror (lexic,
625  "Syntax : ntlmv2_response(cryptkey:<c>, user:<u>, domain:<d>, ntlmv2_hash:<n>, address_list:<a>, address_list_len:<len>)\n");
626  return NULL;
627  }
628  uint8_t lm_response[24];
629  uint8_t nt_response[16 + 28 + address_list_len];
630  uint8_t session_key[16];
631  bzero (lm_response, sizeof (lm_response));
632  bzero (nt_response, sizeof (nt_response));
633  bzero (session_key, sizeof (session_key));
634 
635  ntlmssp_genauth_ntlmv2 (user, domain, address_list, address_list_len,
636  cryptkey, lm_response, nt_response, session_key,
637  ntlmv2_hash);
638  tree_cell *retc;
639  int lm_response_len = 24;
640  int nt_response_len = 16 + 28 + address_list_len;
641  int len = lm_response_len + nt_response_len + sizeof (session_key);
642  char *ret = g_malloc0 (len);
643  memcpy (ret, lm_response, lm_response_len);
644  memcpy (ret + lm_response_len, session_key, sizeof (session_key));
645  memcpy (ret + lm_response_len + sizeof (session_key), nt_response,
646  nt_response_len);
647  retc = alloc_tree_cell (0, NULL);
648  retc->type = CONST_DATA;
649  retc->size = len;
650  retc->x.str_val = ret;
651  return retc;
652 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1233
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
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:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_ntv2_owf_gen()

tree_cell* nasl_ntv2_owf_gen ( lex_ctxt )

Definition at line 886 of file nasl_crypto.c.

References alloc_tree_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(), TC::type, uchar, and TC::x.

887 {
888  const uchar *owf_in = (uchar *) get_str_var_by_name (lexic, "owf");
889  int owf_in_len = get_var_size_by_name (lexic, "owf");
890  char *user_in = get_str_var_by_name (lexic, "login");
891  int user_in_len = get_var_size_by_name (lexic, "login");
892  char *domain_in = get_str_var_by_name (lexic, "domain");
893  int domain_len = get_var_size_by_name (lexic, "domain");
894  char *src_user, *src_domain;
895  smb_ucs2_t *user, *dst_user, val_user;
896  smb_ucs2_t *domain, *dst_domain, val_domain;
897  int i;
898  size_t user_byte_len;
899  size_t domain_byte_len;
900  tree_cell *retc;
901  uchar *kr_buf;
902  HMACMD5Context ctx;
903 
904  if (owf_in_len < 0 || owf_in == NULL || user_in_len < 0 || user_in == NULL
905  || domain_len < 0 || domain_in == NULL)
906  {
907  nasl_perror (lexic,
908  "Syntax : ntv2_owf_gen(owf:<o>, login:<l>, domain:<d>)\n");
909  return NULL;
910  }
911 
912  assert (owf_in_len == 16);
913 
914  user_byte_len = sizeof (smb_ucs2_t) * (strlen (user_in) + 1);
915  user = g_malloc0 (user_byte_len);
916  dst_user = user;
917  src_user = user_in;
918 
919  for (i = 0; i < user_in_len; i++)
920  {
921  val_user = *src_user;
922  *dst_user = val_user;
923  dst_user++;
924  src_user++;
925  if (val_user == 0)
926  break;
927  }
928 
929  domain_byte_len = sizeof (smb_ucs2_t) * (strlen (domain_in) + 1);
930  domain = g_malloc0 (domain_byte_len);
931  dst_domain = domain;
932  src_domain = domain_in;
933 
934  for (i = 0; i < domain_len; i++)
935  {
936  val_domain = *src_domain;
937  *dst_domain = val_domain;
938 
939  dst_domain++;
940  src_domain++;
941  if (val_domain == 0)
942  break;
943  }
944 
945  strupper_w (user);
946  strupper_w (domain);
947 
948  assert (user_byte_len >= 2);
949  assert (domain_byte_len >= 2);
950 
951  /* We don't want null termination */
952  user_byte_len = user_byte_len - 2;
953  domain_byte_len = domain_byte_len - 2;
954 
955  kr_buf = g_malloc0 (16);
956 
957  hmac_md5_init_limK_to_64 (owf_in, 16, &ctx);
958  hmac_md5_update ((const unsigned char *) user, user_byte_len, &ctx);
959  hmac_md5_update ((const unsigned char *) domain, domain_byte_len, &ctx);
960  hmac_md5_final (kr_buf, &ctx);
961 
962  g_free (user);
963  g_free (domain);
964 
965  retc = alloc_tree_cell (0, NULL);
966  retc->type = CONST_DATA;
967  retc->size = 16;
968  retc->x.str_val = (char *) kr_buf;
969 
970  return retc;
971 }
#define uchar
Definition: hmacmd5.h:28
int strupper_w(smb_ucs2_t *s)
Definition: smb_crypt2.c:42
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
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:33
Definition: nasl_tree.h:105
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
Definition: hmacmd5.c:71
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
Definition: hmacmd5.c:63
uint16 smb_ucs2_t
Definition: hmacmd5.h:68
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_prf_sha256()

tree_cell* nasl_prf_sha256 ( lex_ctxt )

Definition at line 548 of file nasl_crypto.c.

549 {
550  return nasl_prf (lexic, 0);
551 }

◆ nasl_prf_sha384()

tree_cell* nasl_prf_sha384 ( lex_ctxt )

Definition at line 554 of file nasl_crypto.c.

555 {
556  return nasl_prf (lexic, 1);
557 }

◆ nasl_ripemd160()

tree_cell* nasl_ripemd160 ( lex_ctxt )

Definition at line 145 of file nasl_crypto.c.

146 {
147  return nasl_hash (lexic, GCRY_MD_RMD160);
148 }

◆ nasl_sha()

tree_cell* nasl_sha ( lex_ctxt )

◆ nasl_sha1()

tree_cell* nasl_sha1 ( lex_ctxt )

Definition at line 133 of file nasl_crypto.c.

134 {
135  return nasl_hash (lexic, GCRY_MD_SHA1);
136 }

◆ nasl_sha256()

tree_cell* nasl_sha256 ( lex_ctxt )

Definition at line 139 of file nasl_crypto.c.

140 {
141  return nasl_hash (lexic, GCRY_MD_SHA256);
142 }

◆ nasl_tls1_prf()

tree_cell* nasl_tls1_prf ( lex_ctxt )

Definition at line 560 of file nasl_crypto.c.

561 {
562  return nasl_prf (lexic, 2);
563 }