aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/suricata/src/app-layer-dcerpc-udp.c
blob: 58d714d040f4b1320787439697fe16ab4b432900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
/*
 * Copyright (c) 2009, 2010 Open Information Security Foundation
 *
 * \author Kirby Kuehl <kkuehl@gmail.com>
 *
 * \todo Updated by AS: Inspect the possibilities of sending junk start at the
 *       start of udp session to avoid alproto detection.
 */

#include "suricata-common.h"
#include "suricata.h"

#include "debug.h"
#include "decode.h"

#include "flow-util.h"

#include "threads.h"

#include "util-print.h"
#include "util-pool.h"
#include "util-debug.h"

#include "stream-tcp-private.h"
#include "stream-tcp-reassemble.h"
#include "stream-tcp.h"
#include "stream.h"

#include "app-layer-protos.h"
#include "app-layer-parser.h"
#include "app-layer.h"

#include "util-spm.h"
#include "util-unittest.h"

#include "app-layer-dcerpc-udp.h"

enum {
	DCERPC_FIELD_NONE = 0,
	DCERPC_PARSE_DCERPC_HEADER,
	DCERPC_PARSE_DCERPC_BIND,
	DCERPC_PARSE_DCERPC_BIND_ACK,
	DCERPC_PARSE_DCERPC_REQUEST,
	/* must be last */
	DCERPC_FIELD_MAX,
};

/** \internal
 *  \retval stub_len or 0 in case of error */
static uint32_t FragmentDataParser(Flow *f, void *dcerpcudp_state,
                                   AppLayerParserState *pstate,
                                   uint8_t *input, uint32_t input_len)
{
	SCEnter();
	DCERPCUDPState *sstate = (DCERPCUDPState *) dcerpcudp_state;
    uint8_t **stub_data_buffer = NULL;
    uint32_t *stub_data_buffer_len = NULL;
    uint8_t *stub_data_fresh = NULL;
    uint16_t stub_len = 0;
    void *ptmp;

    /* request PDU.  Retrieve the request stub buffer */
    if (sstate->dcerpc.dcerpchdrudp.type == REQUEST) {
        stub_data_buffer = &sstate->dcerpc.dcerpcrequest.stub_data_buffer;
        stub_data_buffer_len = &sstate->dcerpc.dcerpcrequest.stub_data_buffer_len;
        stub_data_fresh = &sstate->dcerpc.dcerpcrequest.stub_data_fresh;

    /* response PDU.  Retrieve the response stub buffer */
    } else {
        stub_data_buffer = &sstate->dcerpc.dcerpcresponse.stub_data_buffer;
        stub_data_buffer_len = &sstate->dcerpc.dcerpcresponse.stub_data_buffer_len;
        stub_data_fresh = &sstate->dcerpc.dcerpcresponse.stub_data_fresh;
    }

    stub_len = (sstate->dcerpc.fraglenleft < input_len) ? sstate->dcerpc.fraglenleft : input_len;

    if (stub_len == 0) {
        SCReturnUInt(0);
    }
    /* if the frag is the the first frag irrespective of it being a part of
     * a multi frag PDU or not, it indicates the previous PDU's stub would
     * have been buffered and processed and we can use the buffer to hold
     * frags from a fresh request/response */
    if (sstate->dcerpc.dcerpchdrudp.flags1 & PFC_FIRST_FRAG) {
        *stub_data_buffer_len = 0;
    }

    ptmp = SCRealloc(*stub_data_buffer, *stub_data_buffer_len + stub_len);
    if (ptmp == NULL) {
        SCFree(*stub_data_buffer);
        *stub_data_buffer = NULL;
        SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
        SCReturnUInt(0);
    }

    *stub_data_buffer = ptmp;
    memcpy(*stub_data_buffer + *stub_data_buffer_len, input, stub_len);

    *stub_data_fresh = 1;
    /* length of the buffered stub */
    *stub_data_buffer_len += stub_len;

   sstate->dcerpc.fraglenleft -= stub_len;
   sstate->dcerpc.bytesprocessed += stub_len;

#ifdef DEBUG
    if (SCLogDebugEnabled()) {
        int i = 0;
        for (i = 0; i < stub_len; i++) {
            SCLogDebug("0x%02x ", input[i]);
        }
    }
#endif

    SCReturnUInt((uint32_t)stub_len);
}

/**
 * \brief DCERPCParseHeader parses the 16 byte DCERPC header
 * A fast path for normal decoding is used when there is enough bytes
 * present to parse the entire header. A slow path is used to parse
 * fragmented packets.
 */
static int DCERPCUDPParseHeader(Flow *f, void *dcerpcudp_state,
                                AppLayerParserState *pstate,
                                uint8_t *input, uint32_t input_len)
{
	SCEnter();
	uint8_t *p = input;
	DCERPCUDPState *sstate = (DCERPCUDPState *) dcerpcudp_state;
	if (input_len) {
		switch (sstate->bytesprocessed) {
		case 0:
            // fallthrough
            /* above statement to prevent coverity FPs from the switch
             * fall through */
			if (input_len >= DCERPC_UDP_HDR_LEN) {
				sstate->dcerpc.dcerpchdrudp.rpc_vers = *p;
				if (sstate->dcerpc.dcerpchdrudp.rpc_vers != 4) {
					SCLogDebug("DCERPC UDP Header did not validate");
					SCReturnInt(-1);
				}
				sstate->dcerpc.dcerpchdrudp.type = *(p + 1);
				sstate->dcerpc.dcerpchdrudp.flags1 = *(p + 2);
				sstate->dcerpc.dcerpchdrudp.flags2 = *(p + 3);
				sstate->dcerpc.dcerpchdrudp.drep[0] = *(p + 4);
				sstate->dcerpc.dcerpchdrudp.drep[1] = *(p + 5);
				sstate->dcerpc.dcerpchdrudp.drep[2] = *(p + 6);
				sstate->dcerpc.dcerpchdrudp.serial_hi = *(p + 7);
				sstate->dcerpc.dcerpchdrudp.objectuuid[3] = *(p + 8);
				sstate->dcerpc.dcerpchdrudp.objectuuid[2] = *(p + 9);
				sstate->dcerpc.dcerpchdrudp.objectuuid[1] = *(p + 10);
				sstate->dcerpc.dcerpchdrudp.objectuuid[0] = *(p + 11);
				sstate->dcerpc.dcerpchdrudp.objectuuid[5] = *(p + 12);
				sstate->dcerpc.dcerpchdrudp.objectuuid[4] = *(p + 13);
				sstate->dcerpc.dcerpchdrudp.objectuuid[7] = *(p + 14);
				sstate->dcerpc.dcerpchdrudp.objectuuid[6] = *(p + 15);
				sstate->dcerpc.dcerpchdrudp.objectuuid[8] = *(p + 16);
				sstate->dcerpc.dcerpchdrudp.objectuuid[9] = *(p + 17);
				sstate->dcerpc.dcerpchdrudp.objectuuid[10] = *(p + 18);
				sstate->dcerpc.dcerpchdrudp.objectuuid[11] = *(p + 19);
				sstate->dcerpc.dcerpchdrudp.objectuuid[12] = *(p + 20);
				sstate->dcerpc.dcerpchdrudp.objectuuid[13] = *(p + 21);
				sstate->dcerpc.dcerpchdrudp.objectuuid[14] = *(p + 22);
				sstate->dcerpc.dcerpchdrudp.objectuuid[15] = *(p + 23);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[3] = *(p + 24);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[2] = *(p + 25);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[1] = *(p + 26);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[0] = *(p + 27);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[5] = *(p + 28);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[4] = *(p + 29);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[7] = *(p + 30);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[6] = *(p + 31);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[8] = *(p + 32);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[9] = *(p + 33);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[10] = *(p + 34);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[11] = *(p + 35);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[12] = *(p + 36);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[13] = *(p + 37);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[14] = *(p + 38);
				sstate->dcerpc.dcerpchdrudp.interfaceuuid[15] = *(p + 39);
				sstate->dcerpc.dcerpchdrudp.activityuuid[3] = *(p + 40);
				sstate->dcerpc.dcerpchdrudp.activityuuid[2] = *(p + 41);
				sstate->dcerpc.dcerpchdrudp.activityuuid[1] = *(p + 42);
				sstate->dcerpc.dcerpchdrudp.activityuuid[0] = *(p + 43);
				sstate->dcerpc.dcerpchdrudp.activityuuid[5] = *(p + 44);
				sstate->dcerpc.dcerpchdrudp.activityuuid[4] = *(p + 45);
				sstate->dcerpc.dcerpchdrudp.activityuuid[7] = *(p + 46);
				sstate->dcerpc.dcerpchdrudp.activityuuid[6] = *(p + 47);
				sstate->dcerpc.dcerpchdrudp.activityuuid[8] = *(p + 48);
				sstate->dcerpc.dcerpchdrudp.activityuuid[9] = *(p + 49);
				sstate->dcerpc.dcerpchdrudp.activityuuid[10] = *(p + 50);
				sstate->dcerpc.dcerpchdrudp.activityuuid[11] = *(p + 51);
				sstate->dcerpc.dcerpchdrudp.activityuuid[12] = *(p + 52);
				sstate->dcerpc.dcerpchdrudp.activityuuid[13] = *(p + 53);
				sstate->dcerpc.dcerpchdrudp.activityuuid[14] = *(p + 54);
				sstate->dcerpc.dcerpchdrudp.activityuuid[15] = *(p + 55);
				if (sstate->dcerpc.dcerpchdrudp.drep[0] == 0x10) {
					sstate->dcerpc.dcerpchdrudp.server_boot = *(p + 56);
					sstate->dcerpc.dcerpchdrudp.server_boot |= *(p + 57) << 8;
					sstate->dcerpc.dcerpchdrudp.server_boot |= *(p + 58) << 16;
					sstate->dcerpc.dcerpchdrudp.server_boot |= *(p + 59) << 24;
					sstate->dcerpc.dcerpchdrudp.if_vers = *(p + 60);
					sstate->dcerpc.dcerpchdrudp.if_vers |= *(p + 61) << 8;
					sstate->dcerpc.dcerpchdrudp.if_vers |= *(p + 62) << 16;
					sstate->dcerpc.dcerpchdrudp.if_vers |= *(p + 63) << 24;
					sstate->dcerpc.dcerpchdrudp.seqnum = *(p + 64);
					sstate->dcerpc.dcerpchdrudp.seqnum |= *(p + 65) << 8;
					sstate->dcerpc.dcerpchdrudp.seqnum |= *(p + 66) << 16;
					sstate->dcerpc.dcerpchdrudp.seqnum |= *(p + 67) << 24;
					sstate->dcerpc.dcerpchdrudp.opnum = *(p + 68);
					sstate->dcerpc.dcerpchdrudp.opnum |= *(p + 69) << 8;
					sstate->dcerpc.dcerpchdrudp.ihint = *(p + 70);
					sstate->dcerpc.dcerpchdrudp.ihint |= *(p + 71) << 8;
					sstate->dcerpc.dcerpchdrudp.ahint = *(p + 72);
					sstate->dcerpc.dcerpchdrudp.ahint |= *(p + 73) << 8;
					sstate->dcerpc.dcerpchdrudp.fraglen = *(p + 74);
					sstate->dcerpc.dcerpchdrudp.fraglen |= *(p + 75) << 8;
					sstate->dcerpc.dcerpchdrudp.fragnum = *(p + 76);
					sstate->dcerpc.dcerpchdrudp.fragnum |= *(p + 77) << 8;
				} else {
					sstate->dcerpc.dcerpchdrudp.server_boot = *(p + 56) << 24;
					sstate->dcerpc.dcerpchdrudp.server_boot |= *(p + 57) << 16;
					sstate->dcerpc.dcerpchdrudp.server_boot |= *(p + 58) << 8;
					sstate->dcerpc.dcerpchdrudp.server_boot |= *(p + 59);
					sstate->dcerpc.dcerpchdrudp.if_vers = *(p + 60) << 24;
					sstate->dcerpc.dcerpchdrudp.if_vers |= *(p + 61) << 16;
					sstate->dcerpc.dcerpchdrudp.if_vers |= *(p + 62) << 8;
					sstate->dcerpc.dcerpchdrudp.if_vers |= *(p + 63);
					sstate->dcerpc.dcerpchdrudp.seqnum = *(p + 64) << 24;
					sstate->dcerpc.dcerpchdrudp.seqnum |= *(p + 65) << 16;
					sstate->dcerpc.dcerpchdrudp.seqnum |= *(p + 66) << 8;
					sstate->dcerpc.dcerpchdrudp.seqnum |= *(p + 67);
					sstate->dcerpc.dcerpchdrudp.opnum = *(p + 68) << 24;
					sstate->dcerpc.dcerpchdrudp.opnum |= *(p + 69) << 16;
					sstate->dcerpc.dcerpchdrudp.ihint = *(p + 70) << 8;
					sstate->dcerpc.dcerpchdrudp.ihint |= *(p + 71);
					sstate->dcerpc.dcerpchdrudp.ahint = *(p + 72) << 8;
					sstate->dcerpc.dcerpchdrudp.ahint |= *(p + 73);
					sstate->dcerpc.dcerpchdrudp.fraglen = *(p + 74) << 8;
					sstate->dcerpc.dcerpchdrudp.fraglen |= *(p + 75);
					sstate->dcerpc.dcerpchdrudp.fragnum = *(p + 76) << 8;
					sstate->dcerpc.dcerpchdrudp.fragnum |= *(p + 77);
				}
				sstate->fraglenleft = sstate->dcerpc.dcerpchdrudp.fraglen;
				sstate->dcerpc.dcerpchdrudp.auth_proto = *(p + 78);
				sstate->dcerpc.dcerpchdrudp.serial_lo = *(p + 79);
				sstate->bytesprocessed = DCERPC_UDP_HDR_LEN;
				sstate->uuid_entry = (DCERPCUuidEntry *) SCCalloc(1,
						sizeof(DCERPCUuidEntry));
				if (sstate->uuid_entry == NULL) {
					SCReturnUInt(-1);
				} else {
					memcpy(sstate->uuid_entry->uuid,
							sstate->dcerpc.dcerpchdrudp.activityuuid,
							sizeof(sstate->dcerpc.dcerpchdrudp.activityuuid));
					TAILQ_INSERT_HEAD(&sstate->uuid_list, sstate->uuid_entry,
							next);
#ifdef UNITTESTS
					if (RunmodeIsUnittests()) {
						printUUID("DCERPC UDP", sstate->uuid_entry);

					}
#endif
				}
				SCReturnUInt(80);
				break;
			} else {
				sstate->dcerpc.dcerpchdrudp.rpc_vers = *(p++);
				if (sstate->dcerpc.dcerpchdrudp.rpc_vers != 4) {
					SCLogDebug("DCERPC UDP Header did not validate");
					SCReturnInt(-1);
				}
				if (!(--input_len))
					break;
                /* We fall through to the next case if we still have input.
                 * Same applies for other cases as well */
			}
            /* fall through */
		case 1:
			sstate->dcerpc.dcerpchdrudp.type = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 2:
			sstate->dcerpc.dcerpchdrudp.flags1 = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 3:
			sstate->dcerpc.dcerpchdrudp.flags2 = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 4:
			sstate->dcerpc.dcerpchdrudp.drep[0] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 5:
			sstate->dcerpc.dcerpchdrudp.drep[1] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 6:
			sstate->dcerpc.dcerpchdrudp.drep[2] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 7:
			sstate->dcerpc.dcerpchdrudp.serial_hi = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 8:
			sstate->dcerpc.dcerpchdrudp.objectuuid[3] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 9:
			sstate->dcerpc.dcerpchdrudp.objectuuid[2] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 10:
			sstate->dcerpc.dcerpchdrudp.objectuuid[1] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 11:
			sstate->dcerpc.dcerpchdrudp.objectuuid[0] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 12:
			sstate->dcerpc.dcerpchdrudp.objectuuid[5] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 13:
			sstate->dcerpc.dcerpchdrudp.objectuuid[4] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 14:
			sstate->dcerpc.dcerpchdrudp.objectuuid[7] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 15:
			sstate->dcerpc.dcerpchdrudp.objectuuid[6] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 16:
			sstate->dcerpc.dcerpchdrudp.objectuuid[8] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 17:
			sstate->dcerpc.dcerpchdrudp.objectuuid[9] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 18:
			sstate->dcerpc.dcerpchdrudp.objectuuid[10] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 19:
			sstate->dcerpc.dcerpchdrudp.objectuuid[11] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 20:
			sstate->dcerpc.dcerpchdrudp.objectuuid[12] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 21:
			sstate->dcerpc.dcerpchdrudp.objectuuid[13] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 22:
			sstate->dcerpc.dcerpchdrudp.objectuuid[14] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 23:
			sstate->dcerpc.dcerpchdrudp.objectuuid[15] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 24:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[3] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 25:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[2] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 26:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[1] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 27:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[0] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 28:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[5] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 29:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[4] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 30:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[7] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 31:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[6] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 32:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[8] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 33:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[9] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 34:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[10] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 35:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[11] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 36:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[12] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 37:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[13] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 38:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[14] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 39:
			sstate->dcerpc.dcerpchdrudp.interfaceuuid[15] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 40:
			sstate->dcerpc.dcerpchdrudp.activityuuid[3] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 41:
			sstate->dcerpc.dcerpchdrudp.activityuuid[2] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 42:
			sstate->dcerpc.dcerpchdrudp.activityuuid[1] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 43:
			sstate->dcerpc.dcerpchdrudp.activityuuid[0] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 44:
			sstate->dcerpc.dcerpchdrudp.activityuuid[5] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 45:
			sstate->dcerpc.dcerpchdrudp.activityuuid[4] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 46:
			sstate->dcerpc.dcerpchdrudp.activityuuid[7] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 47:
			sstate->dcerpc.dcerpchdrudp.activityuuid[6] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 48:
			sstate->dcerpc.dcerpchdrudp.activityuuid[8] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 49:
			sstate->dcerpc.dcerpchdrudp.activityuuid[9] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 50:
			sstate->dcerpc.dcerpchdrudp.activityuuid[10] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 51:
			sstate->dcerpc.dcerpchdrudp.activityuuid[11] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 52:
			sstate->dcerpc.dcerpchdrudp.activityuuid[12] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 53:
			sstate->dcerpc.dcerpchdrudp.activityuuid[13] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 54:
			sstate->dcerpc.dcerpchdrudp.activityuuid[14] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 55:
			sstate->dcerpc.dcerpchdrudp.activityuuid[15] = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 56:
			sstate->dcerpc.dcerpchdrudp.server_boot = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 57:
			sstate->dcerpc.dcerpchdrudp.server_boot |= *(p++) << 8;
			if (!(--input_len))
				break;
            /* fall through */
		case 58:
			sstate->dcerpc.dcerpchdrudp.server_boot |= *(p++) << 16;
			if (!(--input_len))
				break;
            /* fall through */
		case 59:
			sstate->dcerpc.dcerpchdrudp.server_boot |= *(p++) << 24;
			if (!(--input_len))
				break;
            /* fall through */
		case 60:
			sstate->dcerpc.dcerpchdrudp.if_vers = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 61:
			sstate->dcerpc.dcerpchdrudp.if_vers |= *(p++) << 8;
			if (!(--input_len))
				break;
            /* fall through */
		case 62:
			sstate->dcerpc.dcerpchdrudp.if_vers |= *(p++) << 16;
			if (!(--input_len))
				break;
            /* fall through */
		case 63:
			sstate->dcerpc.dcerpchdrudp.if_vers |= *(p++) << 24;
			if (!(--input_len))
				break;
            /* fall through */
		case 64:
			sstate->dcerpc.dcerpchdrudp.seqnum = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 65:
			sstate->dcerpc.dcerpchdrudp.seqnum |= *(p++) << 8;
			if (!(--input_len))
				break;
            /* fall through */
		case 66:
			sstate->dcerpc.dcerpchdrudp.seqnum |= *(p++) << 16;
			if (!(--input_len))
				break;
            /* fall through */
		case 67:
			sstate->dcerpc.dcerpchdrudp.seqnum |= *(p++) << 24;
			if (!(--input_len))
				break;
            /* fall through */
		case 68:
			sstate->dcerpc.dcerpchdrudp.opnum = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 69:
			sstate->dcerpc.dcerpchdrudp.opnum |= *(p++) << 8;
			if (!(--input_len))
				break;
            /* fall through */
		case 70:
			sstate->dcerpc.dcerpchdrudp.ihint = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 71:
			sstate->dcerpc.dcerpchdrudp.ihint |= *(p++) << 8;
			if (!(--input_len))
				break;
            /* fall through */
		case 72:
			sstate->dcerpc.dcerpchdrudp.ahint = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 73:
			sstate->dcerpc.dcerpchdrudp.ahint |= *(p++) << 8;
			if (!(--input_len))
				break;
            /* fall through */
		case 74:
			sstate->dcerpc.dcerpchdrudp.fraglen = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 75:
			sstate->dcerpc.dcerpchdrudp.fraglen |= *(p++) << 8;
			if (!(--input_len))
				break;
            /* fall through */
		case 76:
			sstate->dcerpc.dcerpchdrudp.fragnum = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 77:
			sstate->dcerpc.dcerpchdrudp.fragnum |= *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 78:
			sstate->dcerpc.dcerpchdrudp.auth_proto = *(p++);
			if (!(--input_len))
				break;
            /* fall through */
		case 79:
			sstate->dcerpc.dcerpchdrudp.serial_lo = *(p++);
			if (sstate->dcerpc.dcerpchdrudp.drep[0] != 0x10) {
				sstate->dcerpc.dcerpchdrudp.server_boot = SCByteSwap32(sstate->dcerpc.dcerpchdrudp.server_boot);
				sstate->dcerpc.dcerpchdrudp.if_vers= SCByteSwap32(sstate->dcerpc.dcerpchdrudp.if_vers);
				sstate->dcerpc.dcerpchdrudp.seqnum= SCByteSwap32(sstate->dcerpc.dcerpchdrudp.seqnum);
				sstate->dcerpc.dcerpchdrudp.opnum = SCByteSwap16(sstate->dcerpc.dcerpchdrudp.opnum);
				sstate->dcerpc.dcerpchdrudp.ihint= SCByteSwap16(sstate->dcerpc.dcerpchdrudp.ihint);
				sstate->dcerpc.dcerpchdrudp.ahint = SCByteSwap16(sstate->dcerpc.dcerpchdrudp.ahint);
				sstate->dcerpc.dcerpchdrudp.fraglen = SCByteSwap16(sstate->dcerpc.dcerpchdrudp.fraglen);
				sstate->dcerpc.dcerpchdrudp.fragnum = SCByteSwap16(sstate->dcerpc.dcerpchdrudp.fragnum);
			}
			sstate->fraglenleft = sstate->dcerpc.dcerpchdrudp.fraglen;
			sstate->uuid_entry = (DCERPCUuidEntry *) SCCalloc(1,
					sizeof(DCERPCUuidEntry));
			if (sstate->uuid_entry == NULL) {
				SCReturnUInt(-1);
			} else {
				memcpy(sstate->uuid_entry->uuid,
						sstate->dcerpc.dcerpchdrudp.activityuuid,
						sizeof(sstate->dcerpc.dcerpchdrudp.activityuuid));
				TAILQ_INSERT_HEAD(&sstate->uuid_list, sstate->uuid_entry,
						next);
#ifdef UNITTESTS
				if (RunmodeIsUnittests()) {
					printUUID("DCERPC UDP", sstate->uuid_entry);
				}
#endif
			}
			--input_len;
			break;
		}
	}
	sstate->bytesprocessed += (p - input);
	SCReturnInt((p - input));
}

static int DCERPCUDPParse(Flow *f, void *dcerpc_state,
                          AppLayerParserState *pstate,
                          uint8_t *input, uint32_t input_len,
                          void *local_data)
{
	uint32_t retval = 0;
	uint32_t parsed = 0;
	int hdrretval = 0;
	SCEnter();

    if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
        SCReturnInt(1);
    } else if (input == NULL || input_len == 0) {
        SCReturnInt(-1);
    }

	DCERPCUDPState *sstate = (DCERPCUDPState *) dcerpc_state;
	while (sstate->bytesprocessed < DCERPC_UDP_HDR_LEN && input_len) {
		hdrretval = DCERPCUDPParseHeader(f, dcerpc_state, pstate, input,
                                         input_len);
		if (hdrretval == -1 || hdrretval > (int32_t)input_len) {
			sstate->bytesprocessed = 0;
			SCReturnInt(hdrretval);
		} else {
			parsed += hdrretval;
			input_len -= hdrretval;
		}
	}

#if 0
	printf("Done with DCERPCUDPParseHeader bytesprocessed %u/%u left %u\n",
			sstate->bytesprocessed, sstate->dcerpc.dcerpchdrudp.fraglen, input_len);
	printf("\nDCERPC Version:\t%u\n", sstate->dcerpc.dcerpchdrudp.rpc_vers);
	printf("DCERPC Type:\t%u\n", sstate->dcerpc.dcerpchdrudp.ptype);
	printf("DCERPC Flags1:\t0x%02x\n", sstate->dcerpc.dcerpchdrudp.flags1);
	printf("DCERPC Flags2:\t0x%02x\n", sstate->dcerpc.dcerpchdrudp.flags2);
	printf("DCERPC Packed Drep:\t%02x %02x %02x\n",
			sstate->dcerpc.dcerpchdrudp.drep[0], sstate->dcerpc.dcerpchdrudp.drep[1],
			sstate->dcerpc.dcerpchdrudp.drep[2]);
	printf("DCERPC Frag Length:\t0x%04x %u\n", sstate->dcerpc.dcerpchdrudp.fraglen,
			sstate->dcerpc.dcerpchdrudp.fraglen);
	printf("DCERPC Frag Number:\t0x%04x\n", sstate->dcerpc.dcerpchdrudp.fragnum);
	printf("DCERPC OpNum:\t0x%04x\n", sstate->dcerpc.dcerpchdrudp.opnum);
#endif

	while (sstate->bytesprocessed >= DCERPC_UDP_HDR_LEN
			&& sstate->bytesprocessed < sstate->dcerpc.dcerpchdrudp.fraglen
			&& input_len) {
		retval = FragmentDataParser(f, dcerpc_state, pstate, input + parsed,
                                    input_len);
		if (retval || retval > input_len) {
			parsed += retval;
			input_len -= retval;
		} else if (input_len) {
			SCLogDebug("Error parsing DCERPC UDP Fragment Data");
			parsed -= input_len;
			input_len = 0;
			sstate->bytesprocessed = 0;
		}
	}

	if (sstate->bytesprocessed == sstate->dcerpc.dcerpchdrudp.fraglen) {
		sstate->bytesprocessed = 0;
	}
	if (pstate == NULL)
		SCReturnInt(-1);

	SCReturnInt(1);
}

static void *DCERPCUDPStateAlloc(void)
{
	void *s = SCMalloc(sizeof(DCERPCUDPState));
	if (unlikely(s == NULL))
		return NULL;

	memset(s, 0, sizeof(DCERPCUDPState));
	return s;
}

static void DCERPCUDPStateFree(void *s)
{
	DCERPCUDPState *sstate = (DCERPCUDPState *) s;

	DCERPCUuidEntry *item;

	while ((item = TAILQ_FIRST(&sstate->uuid_list))) {
		//printUUID("Free", item);
		TAILQ_REMOVE(&sstate->uuid_list, item, next);
		SCFree(item);
	}
    if (sstate->dcerpc.dcerpcrequest.stub_data_buffer != NULL) {
        SCFree(sstate->dcerpc.dcerpcrequest.stub_data_buffer);
        sstate->dcerpc.dcerpcrequest.stub_data_buffer = NULL;
        sstate->dcerpc.dcerpcrequest.stub_data_buffer_len = 0;
    }
    if (sstate->dcerpc.dcerpcresponse.stub_data_buffer != NULL) {
        SCFree(sstate->dcerpc.dcerpcresponse.stub_data_buffer);
        sstate->dcerpc.dcerpcresponse.stub_data_buffer = NULL;
        sstate->dcerpc.dcerpcresponse.stub_data_buffer_len = 0;
    }
    SCFree(s);
}

static int DCERPCUDPRegisterPatternsForProtocolDetection(void)
{
    if (AppLayerProtoDetectPMRegisterPatternCS(IPPROTO_UDP, ALPROTO_DCERPC,
                                               "|04 00|", 2, 0, STREAM_TOSERVER) < 0)
    {
        return -1;
    }

    return 0;
}

void RegisterDCERPCUDPParsers(void)
{
    char *proto_name = "dcerpc";

    if (AppLayerProtoDetectConfProtoDetectionEnabled("udp", proto_name)) {
        AppLayerProtoDetectRegisterProtocol(ALPROTO_DCERPC, proto_name);
        if (DCERPCUDPRegisterPatternsForProtocolDetection() < 0)
            return;
    } else {
        SCLogInfo("Protocol detection and parser disabled for %s protocol.",
                  "dcerpc");
        return;
    }

    if (AppLayerParserConfParserEnabled("udp", "dcerpc")) {
        AppLayerParserRegisterParser(IPPROTO_UDP, ALPROTO_DCERPC, STREAM_TOSERVER,
                                     DCERPCUDPParse);
        AppLayerParserRegisterParser(IPPROTO_UDP, ALPROTO_DCERPC, STREAM_TOCLIENT,
                                     DCERPCUDPParse);
        AppLayerParserRegisterStateFuncs(IPPROTO_UDP, ALPROTO_DCERPC, DCERPCUDPStateAlloc,
                                         DCERPCUDPStateFree);
        AppLayerParserRegisterParserAcceptableDataDirection(IPPROTO_UDP, ALPROTO_DCERPC, STREAM_TOSERVER);
    } else {
        SCLogInfo("Parsed disabled for %s protocol. Protocol detection"
                  "still on.", "dcerpc");
    }
#ifdef UNITTESTS
    AppLayerParserRegisterProtocolUnittests(IPPROTO_UDP, ALPROTO_DCERPC, DCERPCUDPParserRegisterTests);
#endif

    return;
}

/* UNITTESTS */
#ifdef UNITTESTS
/** \test DCERPC UDP Header Parsing and UUID handling
 */

int DCERPCUDPParserTest01(void)
{
	int result = 1;
	Flow f;
	uint8_t dcerpcrequest[] = {
		0x04, 0x00, 0x2c, 0x00, 0x10, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
		0x3f, 0x98, 0xf0, 0x5c, 0xd9, 0x63, 0xcc, 0x46,
		0xc2, 0x74, 0x51, 0x6c, 0x8a, 0x53, 0x7d, 0x6f,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xff, 0xff,
		0xff, 0xff, 0x70, 0x05, 0x00, 0x00, 0x00, 0x00,
		0x05, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x32, 0x24, 0x58, 0xfd,
		0xcc, 0x45, 0x64, 0x49, 0xb0, 0x70, 0xdd, 0xae,
		0x74, 0x2c, 0x96, 0xd2, 0x60, 0x5e, 0x0d, 0x00,
		0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x70, 0x5e, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x00,
		0x7c, 0x5e, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x10, 0x00, 0x00, 0x00, 0x80, 0x96, 0xf1, 0xf1,
		0x2a, 0x4d, 0xce, 0x11, 0xa6, 0x6a, 0x00, 0x20,
		0xaf, 0x6e, 0x72, 0xf4, 0x0c, 0x00, 0x00, 0x00,
		0x4d, 0x41, 0x52, 0x42, 0x01, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x0d, 0xf0, 0xad, 0xba,
		0x00, 0x00, 0x00, 0x00, 0xa8, 0xf4, 0x0b, 0x00,
		0x10, 0x09, 0x00, 0x00, 0x10, 0x09, 0x00, 0x00,
		0x4d, 0x45, 0x4f, 0x57, 0x04, 0x00, 0x00, 0x00,
		0xa2, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
		0x38, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
		0x00, 0x00, 0x00, 0x00, 0xe0, 0x08, 0x00, 0x00,
		0xd8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x01, 0x10, 0x08, 0x00, 0xcc, 0xcc, 0xcc, 0xcc,
		0xc8, 0x00, 0x00, 0x00, 0x4d, 0x45, 0x4f, 0x57,
		0xd8, 0x08, 0x00, 0x00, 0xd8, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
		0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xc4, 0x28, 0xcd, 0x00,
		0x64, 0x29, 0xcd, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x07, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x46, 0xab, 0x01, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x46, 0xa5, 0x01, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x46, 0xa6, 0x01, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x46, 0xa4, 0x01, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x46, 0xad, 0x01, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x46, 0xaa, 0x01, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x46, 0x07, 0x00, 0x00, 0x00,
		0x60, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00,
		0x90, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
		0x20, 0x00, 0x00, 0x00, 0x28, 0x06, 0x00, 0x00,
		0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
		0x01, 0x10, 0x08, 0x00, 0xcc, 0xcc, 0xcc, 0xcc,
		0x50, 0x00, 0x00, 0x00, 0x4f, 0xb6, 0x88, 0x20,
		0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x01, 0x10, 0x08, 0x00, 0xcc, 0xcc, 0xcc, 0xcc,
		0x48, 0x00, 0x00, 0x00, 0x07, 0x00, 0x66, 0x00,
		0x06, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
		0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x78, 0x19, 0x0c, 0x00,
		0x58, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00,
		0x01, 0x00, 0x00, 0x00, 0x70, 0xd8, 0x98, 0x93,
		0x98, 0x4f, 0xd2, 0x11, 0xa9, 0x3d, 0xbe, 0x57,
		0xb2, 0x00, 0x00, 0x00, 0x32, 0x00, 0x31, 0x00,
		0x01, 0x10, 0x08, 0x00, 0xcc, 0xcc, 0xcc, 0xcc,
		0x80, 0x00, 0x00, 0x00, 0x0d, 0xf0, 0xad, 0xba,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x18, 0x43, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x60, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
		0x4d, 0x45, 0x4f, 0x57, 0x04, 0x00, 0x00, 0x00,
		0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
		0x3b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
		0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
		0x01, 0x00, 0x01, 0x00, 0x81, 0xc5, 0x17, 0x03,
		0x80, 0x0e, 0xe9, 0x4a, 0x99, 0x99, 0xf1, 0x8a,
		0x50, 0x6f, 0x7a, 0x85, 0x02, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
		0x01, 0x10, 0x08, 0x00, 0xcc, 0xcc, 0xcc, 0xcc,
		0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x6e, 0x00,
		0x00, 0x00, 0x00, 0x00, 0xd8, 0xda, 0x0d, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x20, 0x2f, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
		0x46, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x01, 0x10, 0x08, 0x00, 0xcc, 0xcc, 0xcc, 0xcc,
		0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x2e, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x01, 0x10, 0x08, 0x00, 0xcc, 0xcc, 0xcc, 0xcc,
		0x68, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xff, 0xff,
		0x68, 0x8b, 0x0b, 0x00, 0x02, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xfe, 0x02, 0x00, 0x00, 0x5c, 0x00, 0x5c, 0x00,
		0x31, 0x00, 0x31, 0x00, 0x31, 0x00, 0x31, 0x00,
		0x31, 0x00, 0x31, 0x00, 0x31, 0x00, 0x31, 0x00,
		0x31, 0x00, 0x31, 0x00, 0x31, 0x00, 0x31, 0x00,
		0x31, 0x00, 0x31, 0x00, 0x31, 0x00, 0x31, 0x00,
		0x31, 0x00, 0x31, 0x00, 0x9d, 0x13, 0x00, 0x01,
		0xcc, 0xe0, 0xfd, 0x7f, 0xcc, 0xe0, 0xfd, 0x7f,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
		0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90};
	uint32_t requestlen = sizeof(dcerpcrequest);

	TcpSession ssn;
	DCERPCUuidEntry *uuid_entry;
    AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();

	memset(&f, 0, sizeof(f));
	memset(&ssn, 0, sizeof(ssn));
    FLOW_INITIALIZE(&f);
	f.protoctx = (void *)&ssn;
    f.proto = IPPROTO_UDP;
    f.protomap = FlowGetProtoMapping(f.proto);

	StreamTcpInitConfig(TRUE);

	SCMutexLock(&f.m);
	int r = AppLayerParserParse(alp_tctx, &f, ALPROTO_DCERPC, STREAM_TOSERVER|STREAM_START, dcerpcrequest, requestlen);
	if (r != 0) {
		printf("dcerpc header check returned %" PRId32 ", expected 0: ", r);
		result = 0;
		SCMutexUnlock(&f.m);
		goto end;
	}
	SCMutexUnlock(&f.m);

	DCERPCUDPState *dcerpc_state = f.alstate;
	if (dcerpc_state == NULL) {
		printf("no dcerpc state: ");
		result = 0;
		goto end;
	}

	if (dcerpc_state->dcerpc.dcerpchdrudp.rpc_vers != 4) {
		printf("expected dcerpc version 0x04, got 0x%02x : ",
				dcerpc_state->dcerpc.dcerpchdrudp.rpc_vers);
		result = 0;
		goto end;
	}

	if (dcerpc_state->dcerpc.dcerpchdrudp.fraglen != 1392) {
		printf("expected dcerpc fraglen 0x%02x , got 0x%02x : ", 1392, dcerpc_state->dcerpc.dcerpchdrudp.fraglen);
		result = 0;
		goto end;
	}

	if (dcerpc_state->dcerpc.dcerpchdrudp.opnum != 4) {
		printf("expected dcerpc opnum 0x%02x , got 0x%02x : ", 4, dcerpc_state->dcerpc.dcerpchdrudp.opnum);
		result = 0;
		goto end;
	}

	TAILQ_FOREACH(uuid_entry, &dcerpc_state->uuid_list, next) {
		printUUID("REQUEST", uuid_entry);
	}

end:
    if (alp_tctx != NULL)
        AppLayerParserThreadCtxFree(alp_tctx);
	StreamTcpFreeConfig(TRUE);
	return result;
}

void DCERPCUDPParserRegisterTests(void)
{
	UtRegisterTest("DCERPCUDPParserTest01", DCERPCUDPParserTest01, 1);
}
#endif