PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/epan/dissectors/packet-dcom-remunkn.c

https://gitlab.com/jvelando/wireshark
C | 371 lines | 243 code | 79 blank | 49 comment | 22 complexity | 1704c997b732feb02123d871f116fc4a MD5 | raw file
  1. /* packet-dcom-remunkn.c
  2. * Routines for the IRemUnknown interface
  3. * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
  4. *
  5. * Wireshark - Network traffic analyzer
  6. * By Gerald Combs <gerald@wireshark.org>
  7. * Copyright 1998 Gerald Combs
  8. *
  9. * SPDX-License-Identifier: GPL-2.0-or-later
  10. */
  11. /* see packet-dcom.c for details about DCOM */
  12. #include "config.h"
  13. #include <epan/packet.h>
  14. #include "packet-dcerpc.h"
  15. #include "packet-dcom.h"
  16. void proto_register_remunk(void);
  17. void proto_reg_handoff_remunk(void);
  18. static int hf_remunk_opnum = -1;
  19. static int hf_remunk_refs = -1;
  20. static int hf_remunk_iids = -1;
  21. /* static int hf_remunk_flags = -1; */
  22. static int hf_remunk_qiresult = -1;
  23. static gint ett_remunk_reminterfaceref = -1;
  24. static int hf_remunk_reminterfaceref = -1;
  25. static int hf_remunk_interface_refs = -1;
  26. static int hf_remunk_public_refs = -1;
  27. static int hf_remunk_private_refs = -1;
  28. static gint ett_remunk_rqi_result = -1;
  29. static gint ett_remunk = -1;
  30. static e_guid_t uuid_remunk = { 0x00000131, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
  31. static guint16 ver_remunk = 0;
  32. static int proto_remunk = -1;
  33. static e_guid_t ipid_remunk = { 0x00000131, 0x1234, 0x5678, { 0xCA, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
  34. /* There is a little bit confusion about the IRemUnknown2 interface UUIDs */
  35. /* DCOM documentation tells us: 0x00000142 (7 methods) */
  36. /* win2000 registry tells us: 0x00000142 IRemoteQI (4 methods) */
  37. /* win2000 registry tells us: 0x00000143 IRemUnknown2 (7 methods) */
  38. /* There is some evidence, that the DCOM documentation is wrong, so using 143 for IRemUnknown2 now. */
  39. static gint ett_remunk2 = -1;
  40. static e_guid_t uuid_remunk2 = { 0x00000143, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
  41. static guint16 ver_remunk2 = 0;
  42. static int proto_remunk2 = -1;
  43. typedef struct remunk_remqueryinterface_call_s {
  44. guint iid_count;
  45. e_guid_t *iids;
  46. } remunk_remqueryinterface_call_t;
  47. static int
  48. dissect_remunk_remqueryinterface_rqst(tvbuff_t *tvb, int offset,
  49. packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)
  50. {
  51. e_guid_t ipid;
  52. guint32 u32Refs;
  53. guint16 u16IIDs;
  54. guint32 u32ArraySize;
  55. guint32 u32ItemIdx;
  56. e_guid_t iid;
  57. remunk_remqueryinterface_call_t *call;
  58. offset = dissect_dcom_this(tvb, offset, pinfo, tree, di, drep);
  59. offset = dissect_dcom_UUID(tvb, offset, pinfo, tree, di, drep,
  60. hf_dcom_ipid, &ipid);
  61. offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, di, drep,
  62. hf_remunk_refs, &u32Refs);
  63. offset = dissect_dcom_WORD(tvb, offset, pinfo, tree, di, drep,
  64. hf_remunk_iids, &u16IIDs);
  65. offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, di, drep,
  66. &u32ArraySize);
  67. /* limit the allocation to a reasonable size */
  68. if(u32ArraySize < 100) {
  69. call = (remunk_remqueryinterface_call_t *)wmem_alloc0(wmem_file_scope(), sizeof(remunk_remqueryinterface_call_t) + u32ArraySize * sizeof(e_guid_t));
  70. call->iid_count = u32ArraySize;
  71. call->iids = (e_guid_t *) (call+1);
  72. di->call_data->private_data = call;
  73. } else {
  74. call = NULL;
  75. }
  76. for (u32ItemIdx = 0; u32ArraySize--; u32ItemIdx++) {
  77. offset = dissect_dcom_append_UUID(tvb, offset, pinfo, tree, di, drep,
  78. hf_dcom_iid, u32ItemIdx+1, &iid);
  79. if(call != NULL) {
  80. call->iids[u32ItemIdx] = iid;
  81. }
  82. }
  83. return offset;
  84. }
  85. static int
  86. dissect_remunk_remqueryinterface_resp(tvbuff_t *tvb, int offset,
  87. packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)
  88. {
  89. guint32 u32Pointer;
  90. guint32 u32ArraySize;
  91. guint32 u32ItemIdx;
  92. proto_item *sub_item;
  93. proto_tree *sub_tree;
  94. guint32 u32HResult;
  95. guint32 u32SubStart;
  96. e_guid_t iid;
  97. e_guid_t iid_null = DCERPC_UUID_NULL;
  98. remunk_remqueryinterface_call_t *call = (remunk_remqueryinterface_call_t *)di->call_data->private_data;
  99. guint64 oxid;
  100. guint64 oid;
  101. e_guid_t ipid;
  102. offset = dissect_dcom_that(tvb, offset, pinfo, tree, di, drep);
  103. offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, di, drep,
  104. &u32Pointer);
  105. offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, di, drep,
  106. &u32ArraySize);
  107. u32ItemIdx = 1;
  108. while (u32ArraySize--) {
  109. /* add subtree */
  110. sub_item = proto_tree_add_item(tree, hf_remunk_qiresult, tvb, offset, 0, ENC_NA);
  111. sub_tree = proto_item_add_subtree(sub_item, ett_remunk_rqi_result);
  112. /* REMQIRESULT */
  113. offset = dissect_dcom_HRESULT(tvb, offset, pinfo, sub_tree, di, drep,
  114. &u32HResult);
  115. u32SubStart = offset - 4;
  116. offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, sub_tree, di, drep,
  117. &u32Pointer);
  118. /* try to read the iid from the request */
  119. if(call != NULL && u32ItemIdx <= call->iid_count) {
  120. iid = call->iids[u32ItemIdx-1];
  121. } else {
  122. iid = iid_null;
  123. }
  124. /* XXX - this doesn't seem to be dependent on the pointer above?!? */
  125. /*if (u32Pointer) {*/
  126. offset = dissect_dcom_STDOBJREF(tvb, offset, pinfo, sub_tree, di, drep, 0 /* hfindex */,
  127. &oxid, &oid, &ipid);
  128. /*}*/
  129. /* add interface instance to database (we currently only handle IPv4) */
  130. if(pinfo->net_src.type == AT_IPv4) {
  131. dcom_interface_new(pinfo,
  132. &pinfo->net_src,
  133. &iid, oxid, oid, &ipid);
  134. }
  135. /* update subtree */
  136. proto_item_append_text(sub_item, "[%u]: %s",
  137. u32ItemIdx,
  138. val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)") );
  139. proto_item_set_len(sub_item, offset - u32SubStart);
  140. /* update column info now */
  141. col_append_fstr(pinfo->cinfo, COL_INFO, " %s[%u]",
  142. val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)"),
  143. u32ItemIdx);
  144. u32ItemIdx++;
  145. }
  146. /* HRESULT of call */
  147. offset = dissect_dcom_HRESULT(tvb, offset, pinfo, tree, di, drep,
  148. &u32HResult);
  149. /* update column info now */
  150. col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s",
  151. val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)"));
  152. return offset;
  153. }
  154. static int
  155. dissect_remunk_remrelease_rqst(tvbuff_t *tvb, int offset,
  156. packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)
  157. {
  158. guint32 u32Pointer;
  159. guint32 u32IntRefs;
  160. guint32 u32ItemIdx;
  161. e_guid_t ipid;
  162. guint32 u32PublicRefs;
  163. guint32 u32PrivateRefs;
  164. const gchar *pszFormat;
  165. proto_item *sub_item;
  166. proto_tree *sub_tree;
  167. guint32 u32SubStart;
  168. offset = dissect_dcom_this(tvb, offset, pinfo, tree, di, drep);
  169. offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, di, drep,
  170. &u32Pointer);
  171. offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, di, drep,
  172. hf_remunk_interface_refs, &u32IntRefs);
  173. /* update column info now */
  174. if (u32IntRefs) {
  175. col_append_fstr(pinfo->cinfo, COL_INFO, " Cnt=%u Refs=", u32IntRefs);
  176. } else {
  177. col_append_str(pinfo->cinfo, COL_INFO, " Cnt=0");
  178. }
  179. u32ItemIdx = 1;
  180. while (u32IntRefs--) {
  181. /* add subtree */
  182. sub_item = proto_tree_add_item(tree, hf_remunk_reminterfaceref, tvb, offset, 0, ENC_NA);
  183. sub_tree = proto_item_add_subtree(sub_item, ett_remunk_reminterfaceref);
  184. u32SubStart = offset;
  185. offset = dissect_dcom_UUID(tvb, offset, pinfo, sub_tree, di, drep,
  186. hf_dcom_ipid, &ipid);
  187. offset = dissect_dcom_DWORD(tvb, offset, pinfo, sub_tree, di, drep,
  188. hf_remunk_public_refs, &u32PublicRefs);
  189. offset = dissect_dcom_DWORD(tvb, offset, pinfo, sub_tree, di, drep,
  190. hf_remunk_private_refs, &u32PrivateRefs);
  191. /* update subtree */
  192. proto_item_append_text(sub_item, "[%u]: IPID=%s, PublicRefs=%u, PrivateRefs=%u",
  193. u32ItemIdx,
  194. guids_resolve_guid_to_str(&ipid, pinfo->pool),
  195. u32PublicRefs, u32PrivateRefs);
  196. proto_item_set_len(sub_item, offset - u32SubStart);
  197. /* update column info now */
  198. pszFormat = "";
  199. if (u32ItemIdx == 1) {
  200. pszFormat = "%u-%u";
  201. } else if (u32ItemIdx < 10) {
  202. pszFormat = ",%u-%u";
  203. } else if (u32ItemIdx == 10) {
  204. pszFormat = ",...";
  205. }
  206. col_append_fstr(pinfo->cinfo, COL_INFO, pszFormat, u32PublicRefs, u32PrivateRefs);
  207. u32ItemIdx++;
  208. }
  209. return offset;
  210. }
  211. /* sub dissector table of IRemUnknown interface */
  212. static dcerpc_sub_dissector remunk_dissectors[] = {
  213. { 0, "QueryInterface", NULL, NULL },
  214. { 1, "AddRef", NULL, NULL },
  215. { 2, "Release", NULL, NULL },
  216. { 3, "RemQueryInterface", dissect_remunk_remqueryinterface_rqst, dissect_remunk_remqueryinterface_resp },
  217. { 4, "RemAddRef", NULL, NULL },
  218. { 5, "RemRelease", dissect_remunk_remrelease_rqst, dissect_dcom_simple_resp },
  219. { 0, NULL, NULL, NULL }
  220. };
  221. /* sub dissector table of IRemUnknown2 interface */
  222. static dcerpc_sub_dissector remunk2_dissectors[] = {
  223. { 0, "QueryInterface", NULL, NULL },
  224. { 1, "AddRef", NULL, NULL },
  225. { 2, "Release", NULL, NULL },
  226. { 3, "RemQueryInterface", dissect_remunk_remqueryinterface_rqst, dissect_remunk_remqueryinterface_resp },
  227. { 4, "RemAddRef", NULL, NULL },
  228. { 5, "RemRelease", dissect_remunk_remrelease_rqst, dissect_dcom_simple_resp },
  229. { 6, "RemQueryInterface2", NULL, NULL },
  230. { 0, NULL, NULL, NULL }
  231. };
  232. void
  233. proto_register_remunk (void)
  234. {
  235. static hf_register_info hf_remunk_rqi_array[] = {
  236. { &hf_remunk_opnum,
  237. { "Operation", "remunk.opnum", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
  238. { &hf_remunk_refs,
  239. { "Refs", "remunk.refs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
  240. { &hf_remunk_iids,
  241. { "IIDs", "remunk.iids", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
  242. { &hf_remunk_qiresult,
  243. { "QIResult", "remunk.qiresult", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
  244. #if 0
  245. { &hf_remunk_flags,
  246. { "Flags", "remunk.flags", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
  247. #endif
  248. { &hf_remunk_public_refs,
  249. { "PublicRefs", "remunk.public_refs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
  250. { &hf_remunk_reminterfaceref,
  251. { "RemInterfaceRef", "remunk.reminterfaceref", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
  252. { &hf_remunk_interface_refs,
  253. { "InterfaceRefs", "remunk.int_refs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
  254. { &hf_remunk_private_refs,
  255. { "PrivateRefs", "remunk.private_refs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }}
  256. };
  257. static gint *ett_remunk_array[] = {
  258. &ett_remunk,
  259. &ett_remunk_rqi_result,
  260. &ett_remunk2,
  261. &ett_remunk_reminterfaceref
  262. };
  263. proto_remunk = proto_register_protocol ("IRemUnknown", "IRemUnknown", "remunk");
  264. proto_register_field_array (proto_remunk, hf_remunk_rqi_array, array_length (hf_remunk_rqi_array));
  265. proto_remunk2 = proto_register_protocol ("IRemUnknown2", "IRemUnknown2", "remunk2");
  266. proto_register_subtree_array (ett_remunk_array, array_length (ett_remunk_array));
  267. }
  268. void
  269. proto_reg_handoff_remunk (void)
  270. {
  271. /* Register the IPID */
  272. guids_add_uuid(&ipid_remunk, "IPID-IRemUnknown");
  273. /* Register the interfaces */
  274. dcerpc_init_uuid(proto_remunk, ett_remunk,
  275. &uuid_remunk, ver_remunk,
  276. remunk_dissectors, hf_remunk_opnum);
  277. dcerpc_init_uuid(proto_remunk2, ett_remunk2,
  278. &uuid_remunk2, ver_remunk2,
  279. remunk2_dissectors, hf_remunk_opnum);
  280. }
  281. /*
  282. * Editor modelines - https://www.wireshark.org/tools/modelines.html
  283. *
  284. * Local variables:
  285. * c-basic-offset: 4
  286. * tab-width: 8
  287. * indent-tabs-mode: nil
  288. * End:
  289. *
  290. * vi: set shiftwidth=4 tabstop=8 expandtab:
  291. * :indentSize=4:tabSize=8:noTabs=true:
  292. */