OpenVAS Scanner 23.32.3
smb_signing.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Greenbone AG
2 * SPDX-FileCopyrightText: 2003 Jeremy Allison
3 * SPDX-FileCopyrightText: 2002-2003 Andrew Bartlett <abartlet@samba.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
12
13/*
14 Modified by Preeti Subramanian <spreeti@secpod.com> for OpenVAS:
15 simple packet signature function argument struct smb_basic_signing_context
16 *data to uint8_t* mac_key and henceforth used mac_key in the
17 implementation
18*/
19
20#include "smb_signing.h"
21
22void
23simple_packet_signature_ntlmssp (uint8_t *mac_key, const uchar *buf,
24 uint32 seq_number, unsigned char *calc_md5_mac)
25{
26 const size_t offset_end_of_sig = (smb_ss_field + 8);
27 unsigned char sequence_buf[8];
28 struct MD5Context md5_ctx;
29
30 /*
31 * Firstly put the sequence number into the first 4 bytes.
32 * and zero out the next 4 bytes.
33 *
34 * We do this here, to avoid modifying the packet.
35 */
36
37 SIVAL (sequence_buf, 0, seq_number);
38 SIVAL (sequence_buf, 4, 0);
39
40 /* Calculate the 16 byte MAC - but don't alter the data in the
41 incoming packet.
42
43 This makes for a bit of fussing about, but it's not too bad.
44 */
45 MD5Init (&md5_ctx);
46
47 /* initialise with the key */
48 MD5Update (&md5_ctx, mac_key, 16);
49
50 /* copy in the first bit of the SMB header */
51 MD5Update (&md5_ctx, buf + 4, smb_ss_field - 4);
52
53 /* copy in the sequence number, instead of the signature */
54 MD5Update (&md5_ctx, sequence_buf, sizeof (sequence_buf));
55
56 /* copy in the rest of the packet in, skipping the signature */
57 MD5Update (&md5_ctx, buf + offset_end_of_sig,
58 smb_len (buf) - (offset_end_of_sig - 4));
59
60 /* calculate the MD5 sig */
61 MD5Final (calc_md5_mac, &md5_ctx);
62}
#define SIVAL(buf, pos, val)
Definition byteorder.h:117
#define uint32
Definition genrand.c:40
#define uchar
Definition hmacmd5.h:22
void MD5Init(struct MD5Context *ctx)
Definition md5.c:55
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
Definition md5.c:123
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
Definition md5.c:71
#define smb_len(buf)
Definition smb.h:183
#define smb_ss_field
Definition smb.h:47
void simple_packet_signature_ntlmssp(uint8_t *mac_key, const uchar *buf, uint32 seq_number, unsigned char *calc_md5_mac)
Definition smb_signing.c:23
Unix SMB/CIFS implementation. SMB Signing Code.
uint32 buf[4]
Definition md5.h:53