Skip to content

Commit e7b0326

Browse files
committed
Patch wrong UNICODE_STRING in [MS-NRPC] (reported)
1 parent 2bd5265 commit e7b0326

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/midl-to-scapy/idl/win/ms-nrpc.idl b/midl-to-scapy/idl/win/ms-nrpc.idl
2+
index b00daf8..84bc88e 100644
3+
--- a/midl-to-scapy/idl/win/ms-nrpc.idl
4+
+++ b/midl-to-scapy/idl/win/ms-nrpc.idl
5+
@@ -18,7 +18,7 @@
6+
typedef struct _UNICODE_STRING {
7+
USHORT Length;
8+
USHORT MaximumLength;
9+
- PWSTR Buffer;
10+
+ [size_is(MaximumLength/2), length_is(Length/2)] PWSTR Buffer;
11+
} UNICODE_STRING, * PUNICODE_STRING;
12+
13+
typedef struct _OLD_LARGE_INTEGER {

midl-to-scapy/idl/win/ms-nrpc.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
typedef struct _UNICODE_STRING {
1919
USHORT Length;
2020
USHORT MaximumLength;
21-
PWSTR Buffer;
21+
[size_is(MaximumLength/2), length_is(Length/2)] PWSTR Buffer;
2222
} UNICODE_STRING, * PUNICODE_STRING;
2323

2424
typedef struct _OLD_LARGE_INTEGER {

scapy-rpc/msrpcs/ms_nrpc.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
NDRConfPacketListField,
2424
NDRConfStrLenField,
2525
NDRConfVarStrLenField,
26+
NDRConfVarStrLenFieldUtf16,
2627
NDRConfVarStrNullField,
2728
NDRConfVarStrNullFieldUtf16,
2829
NDRFieldListField,
@@ -131,9 +132,18 @@ class NETLOGON_LOGON_INFO_CLASS(IntEnum):
131132
class UNICODE_STRING(NDRPacket):
132133
ALIGNMENT = (4, 8)
133134
fields_desc = [
134-
NDRShortField("Length", 0),
135-
NDRShortField("MaximumLength", 0),
136-
NDRFullEmbPointerField(NDRShortField("Buffer", 0)),
135+
NDRShortField("Length", None, size_of="Buffer", adjust=lambda _, x: (x * 2)),
136+
NDRShortField(
137+
"MaximumLength", None, size_of="Buffer", adjust=lambda _, x: (x * 2)
138+
),
139+
NDRFullEmbPointerField(
140+
NDRConfVarStrLenFieldUtf16(
141+
"Buffer",
142+
"",
143+
size_is=lambda pkt: (pkt.MaximumLength // 2),
144+
length_is=lambda pkt: (pkt.Length // 2),
145+
)
146+
),
137147
]
138148

139149

@@ -1455,9 +1465,18 @@ class PNETLOGON_DELTA_POLICY(NDRPacket):
14551465
class PUNICODE_STRING(NDRPacket):
14561466
ALIGNMENT = (4, 8)
14571467
fields_desc = [
1458-
NDRShortField("Length", 0),
1459-
NDRShortField("MaximumLength", 0),
1460-
NDRFullEmbPointerField(NDRShortField("Buffer", 0)),
1468+
NDRShortField("Length", None, size_of="Buffer", adjust=lambda _, x: (x * 2)),
1469+
NDRShortField(
1470+
"MaximumLength", None, size_of="Buffer", adjust=lambda _, x: (x * 2)
1471+
),
1472+
NDRFullEmbPointerField(
1473+
NDRConfVarStrLenFieldUtf16(
1474+
"Buffer",
1475+
"",
1476+
size_is=lambda pkt: (pkt.MaximumLength // 2),
1477+
length_is=lambda pkt: (pkt.Length // 2),
1478+
)
1479+
),
14611480
]
14621481

14631482

0 commit comments

Comments
 (0)