Go to the source code of this file.
◆ MD4_DIGEST_LENGTH
| #define MD4_DIGEST_LENGTH 16 |
◆ nasl_cipher_des()
◆ nasl_get_password()
◆ nasl_get_sign()
Definition at line 244 of file nasl_crypto.c.
250 if (mac_key == NULL || buf == NULL || buflen == -1 || seq_num <= -1)
252 nasl_perror (lexic,
"Syntax : get_signature(key:<k>, buf:<b>, "
253 "buflen:<bl>, seq_number:<s>)\n");
256 uint8_t calc_md5_mac[16];
259 memcpy (buf + 18, calc_md5_mac, 8);
260 char *ret = g_malloc0 (buflen);
261 memcpy (ret, buf, buflen);
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.
◆ nasl_get_smb2_sign()
◆ nasl_hmac_dss()
◆ nasl_hmac_md2()
◆ nasl_hmac_md5()
◆ nasl_hmac_ripemd160()
◆ nasl_hmac_sha1()
◆ nasl_hmac_sha256()
Definition at line 270 of file nasl_crypto.c.
272 void *key, *data, *signature;
280 if (!key || !data || keylen <= 0 || datalen <= 0)
282 nasl_perror (lexic,
"Syntax : hmac_sha256(data:<b>, key:<k>)\n");
285 signature =
hmac_sha256 (key, keylen, data, datalen);
289 retc->
x.
str_val = (
char *) signature;
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.
◆ nasl_hmac_sha384()
◆ nasl_hmac_sha512()
◆ nasl_insert_hexzeros()
Definition at line 740 of file nasl_crypto.c.
749 if (in_len < 0 || in == NULL)
751 nasl_perror (lexic,
"Syntax : insert_hexzeros(in:<i>)\n");
755 byte_len =
sizeof (
smb_ucs2_t) * (strlen ((
char *) in) + 1);
756 out = g_malloc0 (byte_len);
760 for (i = 0; i < in_len; i++)
771 byte_len = byte_len - 2;
774 retc->
size = byte_len;
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.
◆ nasl_keyexchg()
Definition at line 630 of file nasl_crypto.c.
634 unsigned char *nt_hash =
637 if (cryptkey == NULL || session_key == NULL || nt_hash == NULL)
641 "Syntax : key_exchange(cryptkey:<c>, session_key:<s>, nt_hash:<n> )\n");
644 uint8_t new_sess_key[16];
646 uint8_t *encrypted_session_key = NULL;
648 session_key, cryptkey, nt_hash, (uint8_t *) &new_sess_key);
650 char *ret = g_malloc0 (
len);
651 memcpy (ret, new_sess_key, 16);
652 memcpy (ret + 16, encrypted_session_key, 16);
References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), len, nasl_perror(), ntlmssp_genauth_keyexchg(), TC::size, TC::str_val, and TC::x.
◆ nasl_lm_owf_gen()
Definition at line 711 of file nasl_crypto.c.
720 if (pass_len < 0 || pass == NULL)
722 nasl_perror (lexic,
"Syntax : nt_lm_gen(password:<p>)\n");
726 bzero (pwd,
sizeof (pwd));
727 strncpy ((
char *) pwd, pass,
sizeof (pwd) - 1);
728 for (i = 0; i <
sizeof (pwd); i++)
729 pwd[i] = toupper (pwd[i]);
735 retc->
x.
str_val = g_memdup2 (p16, 16);
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.
◆ nasl_md2()
◆ nasl_md4()
◆ nasl_md5()
◆ nasl_nt_owf_gen()
◆ nasl_ntlm2_response()
Definition at line 557 of file nasl_crypto.c.
565 if (!cryptkey || !password || !nt_hash || hash_len < 16)
567 nasl_perror (lexic,
"Syntax : ntlm2_response(cryptkey:<c>, password:<p>, "
568 "nt_hash:<n[16]>)\n");
572 uint8_t lm_response[24];
573 uint8_t nt_response[24];
574 uint8_t session_key[16];
578 session_key, cryptkey, nt_hash);
579 int len =
sizeof (lm_response) +
sizeof (nt_response) +
sizeof (session_key);
580 char *ret = g_malloc0 (
len);
581 memcpy (ret, lm_response,
sizeof (lm_response));
582 memcpy (ret +
sizeof (lm_response), nt_response,
sizeof (nt_response));
583 memcpy (ret +
sizeof (lm_response) +
sizeof (nt_response), session_key,
584 sizeof (session_key));
References alloc_typed_cell(), CONST_DATA, get_str_var_by_name(), get_var_size_by_name(), len, nasl_perror(), ntlmssp_genauth_ntlm2(), TC::size, TC::str_val, and TC::x.
◆ nasl_ntlm_response()
Definition at line 592 of file nasl_crypto.c.
601 if (!cryptkey || !password || !nt_hash || hash_len < 16 || neg_flags < 0)
603 nasl_perror (lexic,
"Syntax : ntlm_response(cryptkey:<c>, password:<p>, "
604 "nt_hash:<n[16]>, neg_flags:<nf>)\n");
608 uint8_t lm_response[24];
609 uint8_t nt_response[24];
610 uint8_t session_key[16];
615 session_key, cryptkey, nt_hash, neg_flags);
617 int len =
sizeof (lm_response) +
sizeof (nt_response) +
sizeof (session_key);
618 char *ret = g_malloc0 (
len);
619 memcpy (ret, lm_response,
sizeof (lm_response));
620 memcpy (ret +
sizeof (lm_response), nt_response,
sizeof (nt_response));
621 memcpy (ret +
sizeof (lm_response) +
sizeof (nt_response), session_key,
622 sizeof (session_key));
References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), len, nasl_perror(), ntlmssp_genauth_ntlm(), TC::size, TC::str_val, and TC::x.
◆ nasl_ntlmv1_hash()
Definition at line 660 of file nasl_crypto.c.
665 unsigned char p21[21];
669 if (cryptkey == NULL || password == NULL)
671 nasl_perror (lexic,
"Syntax : ntlmv1_hash(cryptkey:<c>, passhash:<p>)\n");
678 bzero (p21,
sizeof (p21));
679 memcpy (p21, password, pass_len);
681 ret = g_malloc0 (24);
683 E_P24 (p21, cryptkey, ret);
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.
◆ nasl_ntlmv2_hash()
Definition at line 868 of file nasl_crypto.c.
876 unsigned char ntlmv2_response[16];
877 unsigned char *ntlmv2_client_data = NULL;
878 unsigned char *final_response;
881 if (sc_len < 0 || server_chal == NULL || hash_len < 0 || ntlm_v2_hash == NULL
882 || client_chal_length < 0)
886 "Syntax : ntlmv2_hash(cryptkey:<c>, passhash:<p>, length:<l>)\n");
893 ntlmv2_client_data = g_malloc0 (client_chal_length);
894 for (i = 0; i < client_chal_length; i++)
895 ntlmv2_client_data[i] = rand () % 256;
897 assert (hash_len == 16);
900 client_chal_length, ntlmv2_response);
903 final_response = g_malloc0 (client_chal_length +
sizeof (ntlmv2_response));
904 memcpy (final_response, ntlmv2_response,
sizeof (ntlmv2_response));
907 memcpy (final_response +
sizeof (ntlmv2_response), ntlmv2_client_data,
910 g_free (ntlmv2_client_data);
913 retc->
size = client_chal_length +
sizeof (ntlmv2_response);
914 retc->
x.
str_val = (
char *) final_response;
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.
◆ nasl_ntlmv2_response()
Definition at line 513 of file nasl_crypto.c.
518 unsigned char *ntlmv2_hash =
523 if (cryptkey == NULL || user == NULL || domain == NULL || ntlmv2_hash == NULL
524 || address_list == NULL || address_list_len < 0)
527 lexic,
"Syntax : ntlmv2_response(cryptkey:<c>, user:<u>, domain:<d>, "
528 "ntlmv2_hash:<n>, address_list:<a>, address_list_len:<len>)\n");
531 uint8_t lm_response[24];
532 uint8_t nt_response[16 + 28 + address_list_len];
533 uint8_t session_key[16];
534 bzero (lm_response,
sizeof (lm_response));
535 bzero (nt_response,
sizeof (nt_response));
536 bzero (session_key,
sizeof (session_key));
539 cryptkey, lm_response, nt_response, session_key,
542 int lm_response_len = 24;
543 int nt_response_len = 16 + 28 + address_list_len;
544 int len = lm_response_len + nt_response_len +
sizeof (session_key);
545 char *ret = g_malloc0 (
len);
546 memcpy (ret, lm_response, lm_response_len);
547 memcpy (ret + lm_response_len, session_key,
sizeof (session_key));
548 memcpy (ret + lm_response_len +
sizeof (session_key), nt_response,
References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), len, nasl_perror(), ntlmssp_genauth_ntlmv2(), TC::size, TC::str_val, and TC::x.
◆ nasl_ntv2_owf_gen()
Definition at line 781 of file nasl_crypto.c.
789 char *src_user, *src_domain;
793 size_t user_byte_len;
794 size_t domain_byte_len;
799 if (owf_in_len < 0 || owf_in == NULL || user_in_len < 0 || user_in == NULL
800 || domain_len < 0 || domain_in == NULL)
803 "Syntax : ntv2_owf_gen(owf:<o>, login:<l>, domain:<d>)\n");
807 assert (owf_in_len == 16);
809 user_byte_len =
sizeof (
smb_ucs2_t) * (strlen (user_in) + 1);
810 user = g_malloc0 (user_byte_len);
814 for (i = 0; i < user_in_len; i++)
816 val_user = *src_user;
817 *dst_user = val_user;
824 domain_byte_len =
sizeof (
smb_ucs2_t) * (strlen (domain_in) + 1);
825 domain = g_malloc0 (domain_byte_len);
827 src_domain = domain_in;
829 for (i = 0; i < domain_len; i++)
831 val_domain = *src_domain;
832 *dst_domain = val_domain;
843 assert (user_byte_len >= 2);
844 assert (domain_byte_len >= 2);
847 user_byte_len = user_byte_len - 2;
848 domain_byte_len = domain_byte_len - 2;
850 kr_buf = g_malloc0 (16);
854 hmac_md5_update ((
const unsigned char *) domain, domain_byte_len, &ctx);
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.
◆ nasl_prf_sha256()
◆ nasl_prf_sha384()
◆ nasl_ripemd160()
◆ nasl_sha()
◆ nasl_sha1()
◆ nasl_sha256()
◆ nasl_sha512()
◆ nasl_smb_cmac_aes_sign()
◆ nasl_smb_gmac_aes_sign()
◆ nasl_tls1_prf()
void E_P24(const uchar *p21, const uchar *c8, uchar *p24)
int get_var_size_by_name(lex_ctxt *, const char *)
tree_cell * nasl_smb_sign(const int algo, lex_ctxt *lexic)
static tree_cell * nasl_cipher(int algorithm, void *data, size_t dlen, void *key, size_t klen)
uint8_t * ntlmssp_genauth_keyexchg(uint8_t *session_key, char *challenge_data, unsigned char *nt_hash, uint8_t *new_sess_key)
void SMBOWFencrypt_ntv2_ntlmssp(const uchar *kr, const uint8_t *srv_chal, int srv_chal_len, const uint8_t *cli_chal, int cli_chal_len, uchar resp_buf[16])
void E_P16(uchar *p14, uchar *p16)
char * get_str_var_by_name(lex_ctxt *, const char *)
void hmac_md5_init_limK_to_64(const uchar *key, int key_len, HMACMD5Context *ctx)
The microsoft version of hmac_md5 initialisation.
void nasl_perror(lex_ctxt *lexic, char *msg,...)
static tree_cell * nasl_hash(lex_ctxt *lexic, int algorithm)
void * hmac_sha256(const void *key, int keylen, const void *buf, int buflen)
int strupper_w(smb_ucs2_t *s)
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
long int get_int_var_by_name(lex_ctxt *, const char *, int)
char * get_str_var_by_num(lex_ctxt *, int)
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)
static tree_cell * nasl_gcrypt_hash(lex_ctxt *lexic, int algorithm, void *data, size_t datalen, void *key, size_t keylen)
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)
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
int get_var_size_by_num(lex_ctxt *, int)
void simple_packet_signature_ntlmssp(uint8_t *mac_key, const uchar *buf, uint32 seq_number, unsigned char *calc_md5_mac)
static tree_cell * nasl_prf(lex_ctxt *lexic, int hmac)
static tree_cell * nasl_hmac(lex_ctxt *lexic, int algorithm)
tree_cell * alloc_typed_cell(int typ)
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)