Browse code

* libclamav/special.c: Check Photoshop thumbnail images embedded in JPEG files. * sigtool/vba.c: Add more Word6 tokens.

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1386 77e5149b-7576-45b1-b177-96237e5ba77b

Trog authored on 2005/03/10 22:34:30
Showing 3 changed files
... ...
@@ -1,3 +1,9 @@
1
+Thu Mar 10 13:32:38 GMT 2005 (trog)
2
+-----------------------------------
3
+  * libclamav/special.c: Check Photoshop thumbnail images embedded in JPEG files.
4
+
5
+  * sigtool/vba.c: Add more Word6 tokens.
6
+
1 7
 Thu Mar 10 08:48:54 GMT 2005 (njh)
2 8
 ----------------------------------
3 9
   * clamav-milter:	--detect-forged-local-address no longer gives false
... ...
@@ -32,6 +32,27 @@
32 32
 #define FALSE (0)
33 33
 #define TRUE (1)
34 34
 
35
+/* NOTE: Photoshop stores data in BIG ENDIAN format, this is the opposite
36
+	to virtually everything else */
37
+#if WORDS_BIGENDIAN == 0
38
+static uint16_t special_endian_convert_16(uint16_t v)
39
+{
40
+        return ((v >> 8) + (v << 8));
41
+}
42
+#else
43
+#define special_endian_convert_16(v)       (v)
44
+#endif
45
+
46
+#if WORDS_BIGENDIAN == 0
47
+static uint32_t special_endian_convert_32(uint32_t v)
48
+{
49
+        return ((v >> 24) | ((v & 0x00FF0000) >> 8) |
50
+                ((v & 0x0000FF00) << 8) | (v << 24));
51
+}
52
+#else
53
+#define special_endian_convert_32(v)    (v)
54
+#endif
55
+
35 56
 int cli_check_mydoom_log(int desc, const char **virname)
36 57
 {
37 58
 	int32_t record[8], check;
... ...
@@ -69,6 +90,96 @@ int cli_check_mydoom_log(int desc, const char **virname)
69 69
     return retval;
70 70
 }
71 71
 
72
+static int jpeg_check_photoshop_8bim(int fd)
73
+{
74
+	unsigned char bim[5];
75
+	uint16_t id, nlength;
76
+	uint32_t size;
77
+	off_t offset;
78
+	int retval;
79
+
80
+	if (cli_readn(fd, bim, 4) != 4) {
81
+		cli_dbgmsg("read bim failed\n");
82
+		return -1;
83
+	}
84
+
85
+	if (memcmp(bim, "8BIM", 4) != 0) {
86
+		bim[4] = '\0';
87
+		cli_dbgmsg("missed 8bim: %s\n", bim);
88
+		return -1;
89
+	}
90
+
91
+	if (cli_readn(fd, &id, 2) != 2) {
92
+		return -1;
93
+	}
94
+	id = special_endian_convert_16(id);
95
+	cli_dbgmsg("ID: 0x%.4x\n", id);
96
+	if (cli_readn(fd, &nlength, 2) != 2) {
97
+		return -1;
98
+	}
99
+	nlength = special_endian_convert_16(nlength);
100
+	/* Seek past the name string */
101
+	if (nlength > 0) {
102
+		lseek(fd, nlength, SEEK_CUR);
103
+	}
104
+
105
+	if (cli_readn(fd, &size, 4) != 4) {
106
+		return -1;
107
+	}
108
+	size = special_endian_convert_32(size);
109
+	if (size == 0) {
110
+		return -1;
111
+	}
112
+	if ((size & 0x01) == 1) {
113
+		size++;
114
+	}
115
+	/* Is it a thumbnail image */
116
+	if ((id != 0x0409) && (id != 0x040c)) {
117
+		/* No - Seek past record */
118
+		lseek(fd, size, SEEK_CUR);
119
+		return 0;
120
+	}
121
+
122
+	cli_dbgmsg("found thumbnail\n");
123
+	/* Check for thumbmail image */
124
+	offset = lseek(fd, 0, SEEK_CUR);
125
+
126
+	/* Jump past header */
127
+	lseek(fd, 28, SEEK_CUR);
128
+
129
+	retval = cli_check_jpeg_exploit(fd);
130
+	if (retval == 1) {
131
+		cli_dbgmsg("Exploit found in thumbnail\n", retval);
132
+	}
133
+	lseek(fd, offset+size, SEEK_SET);
134
+
135
+	return retval;
136
+}
137
+
138
+static int jpeg_check_photoshop(int fd)
139
+{
140
+	int retval;
141
+	unsigned char buffer[14];
142
+
143
+	if (cli_readn(fd, buffer, 14) != 14) {
144
+		return 0;
145
+	}
146
+
147
+	if (memcmp(buffer, "Photoshop 3.0", 14) != 0) {
148
+		return 0;
149
+	}
150
+
151
+	cli_dbgmsg("Found Photoshop segment\n");
152
+	do {
153
+		retval = jpeg_check_photoshop_8bim(fd);
154
+	} while (retval == 0);
155
+
156
+	if (retval == -1) {
157
+		retval = 0;
158
+	}
159
+	return retval;
160
+}
161
+
72 162
 int cli_check_jpeg_exploit(int fd)
73 163
 {
74 164
 	unsigned char buffer[4];
... ...
@@ -85,6 +196,7 @@ int cli_check_jpeg_exploit(int fd)
85 85
 	if ((buffer[0] != 0xff) || (buffer[1] != 0xd8)) {
86 86
 		return 0;
87 87
 	}
88
+
88 89
 	for (;;) {
89 90
 		if ((retval=cli_readn(fd, buffer, 4)) != 4) {
90 91
 			return 0;
... ...
@@ -94,7 +206,7 @@ int cli_check_jpeg_exploit(int fd)
94 94
 			lseek(fd, -3, SEEK_CUR);
95 95
 			continue;
96 96
 		}
97
-		
97
+
98 98
 		if ((buffer[0] == 0xff) && (buffer[1] == 0xfe)) {
99 99
 			if (buffer[2] == 0x00) {
100 100
 				if ((buffer[3] == 0x00) || (buffer[3] == 0x01)) {
... ...
@@ -109,12 +221,21 @@ int cli_check_jpeg_exploit(int fd)
109 109
 			/* End of Image marker */
110 110
 			return 0;
111 111
 		}
112
+
112 113
 		offset = ((unsigned int) buffer[2] << 8) + buffer[3];
113 114
 		if (offset < 2) {
114 115
 			return 1;
115 116
 		}
116 117
 		offset -= 2;
117 118
 		offset += lseek(fd, 0, SEEK_CUR);
119
+
120
+		if (buffer[1] == 0xed) {
121
+			/* Possible Photoshop file */
122
+			if ((retval=jpeg_check_photoshop(fd)) != 0) {
123
+				return retval;
124
+			}
125
+		}
126
+
118 127
 		if (lseek(fd, offset, SEEK_SET) != offset) {
119 128
 			return -1;
120 129
 		}
... ...
@@ -180,7 +180,9 @@ void output_token67 (uint16_t token)
180 180
 	{0x0009, "HelpAbout"},
181 181
 	{0x000c, "ShrinkFont"},
182 182
 	{0x0016, "NextWindow"},
183
+	{0x0017, "PrevWindow"},
183 184
 	{0x001c, "DeleteWord"},
185
+	{0x001e, "EditClear"},
184 186
 	{0x0045, "GoBack"},
185 187
 	{0x0046, "SaveTemplate"},
186 188
 	{0x0048, "Cancel"},
... ...
@@ -205,6 +207,7 @@ void output_token67 (uint16_t token)
205 205
 	{0x007b, "EditAutoText"},
206 206
 	{0x0093, "ViewPage"},
207 207
 	{0x0098, "ToolsCustomize"},
208
+	{0x009b, "NormalViewHeaderArea"},
208 209
 	{0x009f, "InsertBreak"},
209 210
 	{0x00a2, "InsertSymbol"},
210 211
 	{0x00a4, "InsertFile"},
... ...
@@ -218,6 +221,7 @@ void output_token67 (uint16_t token)
218 218
 	{0x00cc, "ToolsOptionsView"},
219 219
 	{0x00cb, "ToolsOptionsGeneral"},
220 220
 	{0x00d1, "ToolsOptionsSave"},
221
+	{0x00d3, "ToolsOptionsSpelling"},
221 222
 	{0x00d5, "ToolsOptionsUserInfo"},
222 223
 	{0x00d7, "ToolsMacro"},
223 224
 	{0x00de, "Organizer"},
... ...
@@ -237,6 +241,8 @@ void output_token67 (uint16_t token)
237 237
 	{0x0179, "DrawRectangle"},
238 238
 	{0x017a, "ToolsAutoCorrect"},
239 239
 	{0x01a4, "Connect"},
240
+	{0x01a5, "WW2_EditFind"},
241
+	{0x01a6, "WW2_EditReplace"},
240 242
 	{0x01b0, "ToolsCustomizeKeyboard"},
241 243
 	{0x01b1, "ToolsCustomizeMenus"},
242 244
 	{0x01d2, "DrawBringToFront"},
... ...
@@ -291,12 +297,15 @@ void output_token67 (uint16_t token)
291 291
 	{0x8025, "FileName$"},
292 292
 	{0x8026, "CountFiles"},
293 293
 	{0x8027, "GetAutoText$"},
294
+	{0x8028, "CountAutoTextEntries"},
294 295
 	{0x802a, "SetAutoText"},
295 296
 	{0x802b, "MsgBox"},
296 297
 	{0x802c, "Beep"},
297 298
 	{0x802d, "Shell"},
299
+	{0x802f, "ResetPara"},
298 300
 	{0x8032, "DocMove"},
299 301
 	{0x8033, "DocSize"},
302
+	{0x8034, "VLine"},
300 303
 	{0x803a, "CountWindows"},
301 304
 	{0x803b, "WindowName$"},
302 305
 	{0x803e, "Window"},
... ...
@@ -324,14 +333,17 @@ void output_token67 (uint16_t token)
324 324
 	{0x8063, "AppActivate"},
325 325
 	{0x8064, "SendKeys"},
326 326
 	{0x806f, "ViewStatusBar"},
327
-	{0x8075, "ViewNormal"},
327
+	{0x8071, "ViewRibbon"},
328 328
 	{0x8073, "ViewPage"},
329
+	{0x8075, "ViewNormal"},
330
+	{0x8079, "Overtype"},
329 331
 	{0x807a, "Font$"},
330 332
 	{0x807b, "CountOfFonts"},
331 333
 	{0x807c, "Font"},
332 334
 	{0x807d, "FontSize"},
333 335
 	{0x8081, "WW6_EditClear"},
334 336
 	{0x8082, "FileList"},
337
+	{0x8083, "File1"},
335 338
 	{0x8098, "ExtendSelection"},
336 339
 	{0x809e, "DisableInput"},
337 340
 	{0x809f, "DocClose"},
... ...
@@ -358,6 +370,7 @@ void output_token67 (uint16_t token)
358 358
 	{0x80b9, "CountFoundFiles"},
359 359
 	{0x80ba, "FoundFileName$"},
360 360
 	{0x80be, "MacroDesc$"},
361
+	{0x80bf, "CountKeys"},
361 362
 	{0x80c1, "KeyMacro$"},
362 363
 	{0x80c2, "MacroCopy"},
363 364
 	{0x80c3, "IsExecuteOnly"},
... ...
@@ -393,6 +406,7 @@ void output_token67 (uint16_t token)
393 393
 	{0x80f9, "Year"},
394 394
 	{0x80fa, "DocWindowHeight"},
395 395
 	{0x80fb, "DocWindowWidth"},
396
+	{0x80fc, "DOSToWIN$"},
396 397
 	{0x80fd, "WinToDOS$"},
397 398
 	{0x80ff, "Second"},
398 399
 	{0x8100, "TimeValue"},
... ...
@@ -400,6 +414,8 @@ void output_token67 (uint16_t token)
400 400
 	{0x8103, "SetAttr"},
401 401
 	{0x8105, "DocMinimize"},
402 402
 	{0x8107, "AppActivate"},
403
+	{0x8108, "AppCount"},
404
+	{0x8109, "AppGetNames"},
403 405
 	{0x810a, "AppHide"},
404 406
 	{0x810b, "AppIsRunning"},
405 407
 	{0x810c, "GetSystemInfo$"},
... ...
@@ -411,11 +427,13 @@ void output_token67 (uint16_t token)
411 411
 	{0x8118, "IsTemplateDirty"},
412 412
 	{0x8119, "SetTemplateDirty"},
413 413
 	{0x811b, "DlgEnable"},
414
+	{0x811d, "DlgVisible"},
414 415
 	{0x811f, "DlgText$"},
415 416
 	{0x8121, "AppShow"},
416 417
 	{0x8122, "DlgListBoxArray"},
417 418
 	{0x8125, "Picture"},
418 419
 	{0x8126, "DlgSetPicture"},
420
+	{0x8131, "WW2_Files$"},
419 421
 	{0x8138, "DlgFocus"},
420 422
 	{0x813b, "BorderLineStyle"},
421 423
 	{0x813d, "MenuItemText$"},
... ...
@@ -441,26 +459,36 @@ void output_token67 (uint16_t token)
441 441
 	{0x8172, "GetText$"},
442 442
 	{0x8174, "DeleteButton"},
443 443
 	{0x8175, "AddButton"},
444
+	{0x8177, "DeleteAddIn"},
444 445
 	{0x8178, "AddAddIn"},
445 446
 	{0x8179, "GetAddInName$"},
446 447
 	{0x817c, "ResetButtonImage"},
447 448
 	{0x8180, "GetAddInId"},
448 449
 	{0x8181, "CountAddIns"},
450
+	{0x8182, "ClearAddIns"},
449 451
 	{0x8183, "AddInState"},
450 452
 	{0x818c, "DefaultDir$"},
451 453
 	{0x818d, "FileNameInfo$"},
452 454
 	{0x818e, "MacroFileName$"},
453 455
 	{0x818f, "ViewHeader"},
454 456
 	{0x8190, "ViewFooter"},
457
+	{0x8192, "CopyButtonImage"},
455 458
 	{0x8195, "CountToolbars"},
456 459
 	{0x8196, "ToolbarName$"},
457 460
 	{0x8198, "ChDefaultDir"},
458 461
 	{0x8199, "EditUndo"},
462
+	{0x81a0, "GetAutoCorrect$"},
459 463
 	{0x81a2, "FileQuit"},
460 464
 	{0x81a4, "FileConfirmConversions"},
465
+	{0x81d3, "SelectionFileName$"},
461 466
 	{0x81d9, "CountToolbarButtons"},
462 467
 	{0x81da, "ToolbarButtonMacro$"},
468
+	{0x81db, "WW2_Insert"},
463 469
 	{0x81dc, "AtEndOfDocument"},
470
+	{0x81fc, "GetDocumentProperty$"},
471
+	{0x81fd, "GetDocumentProperty"},
472
+	{0x8201, "DocumentPropertyName$"},
473
+	{0x820e, "SpellChecked"},
464 474
 	{0xb780, "CountMacros"},
465 475
 	{0xb880, "MacroName$"},
466 476
 	{0xc000, "CharLeft"},
... ...
@@ -506,6 +534,7 @@ void output_token73 (uint16_t token)
506 506
 	{0x0008, ".MenuText"},
507 507
 	{0x0009, ".APPUSERNAME"},
508 508
 	{0x000b, ".Delete"},
509
+	{0x000c, ".Sort"},
509 510
 	{0x0012, ".SavedBy"},
510 511
 	{0x0014, ".DateCreatedFrom"},
511 512
 	{0x0015, ".DateCreatedTo"},
... ...
@@ -519,6 +548,7 @@ void output_token73 (uint16_t token)
519 519
 	{0x0025, ".Italic"},
520 520
 	{0x0027, ".Hidden"},
521 521
 	{0x0028, ".Underline"},
522
+	{0x0029, ".Outline"},
522 523
 	{0x002b, ".Position"},
523 524
 	{0x002d, ".Spacing"},
524 525
 	{0x002f, ".Printer"},
... ...
@@ -533,6 +563,7 @@ void output_token73 (uint16_t token)
533 533
 	{0x003d, ".Hyphens"},
534 534
 	{0x003e, ".ShowAll"},
535 535
 	{0x0041, ".TextBoundaries"},
536
+	{0x0043, ".VScroll"},
536 537
 	{0x0046, ".PageWidth"},
537 538
 	{0x0047, ".PageHeight"},
538 539
 	{0x0049, ".TopMargin"},
... ...
@@ -562,17 +593,24 @@ void output_token73 (uint16_t token)
562 562
 	{0x0075, ".NewName"},
563 563
 	{0x0078, ".SmartQuotes"},
564 564
 	{0x007f, ".Source"},
565
+	{0x0080, ".Reference"},
565 566
 	{0x0085, ".Insert"},
566 567
 	{0x0086, ".Destination"},
567 568
 	{0x0087, ".Type"},
569
+	{0x0089, ".HeaderDistance"},
570
+	{0x008a, ".FooterDistance"},
571
+	{0x008b, ".FirstPage"},
572
+	{0x008c, ".OddAndEvenPages"},
568 573
 	{0x0091, ".Entry"},
569 574
 	{0x0092, ".Range"},
570 575
 	{0x0095, ".Link"},
571 576
 	{0x0098, ".Add"},
572 577
 	{0x009b, ".NewTemplate"},
578
+	{0x009f, ".ReadOnly"},
573 579
 	{0x00a1, ".LeftIndent"},
574 580
 	{0x00a2, ".RightIndent"},
575 581
 	{0x00a3, ".FirstIndent"},
582
+	{0x00a5, ".After"},
576 583
 	{0x00b9, ".NumCopies"},
577 584
 	{0x00ba, ".From"},
578 585
 	{0x00bb, ".To"},
... ...
@@ -583,6 +621,7 @@ void output_token73 (uint16_t token)
583 583
 	{0x00d7, ".CreateBackup"},
584 584
 	{0x00d8, ".LockAnnot"},
585 585
 	{0x00d9, ".Direction"},
586
+	{0x00ff, ".SuggestFromMainDictOnly"},
586 587
 	{0x012b, ".UpdateLinks"},
587 588
 	{0x012e, ".Update"},
588 589
 	{0x0131, ".Text"},
... ...
@@ -591,6 +630,7 @@ void output_token73 (uint16_t token)
591 591
 	{0x013b, ".AllCaps"},
592 592
 	{0x0148, ".Category"},
593 593
 	{0x0149, ".ConfirmConversions"},
594
+	{0x014c, ".StatusBar"},
594 595
 	{0x014d, ".PicturePlaceHolders"},
595 596
 	{0x014e, ".FieldCodes"},
596 597
 	{0x0150, ".Show"},
... ...
@@ -600,11 +640,18 @@ void output_token73 (uint16_t token)
600 600
 	{0x017d, ".Wrap"},
601 601
 	{0x0183, ".AutoFit"},
602 602
 	{0x0184, ".CharNum"},
603
+	{0x018b, ".View"},
604
+	{0x0190, ".Options"},
603 605
 	{0x0194, ".Find"},
604 606
 	{0x0196, ".Path"},
605 607
 	{0x01a8, ".Background"},
606 608
 	{0x01a9, ".SearchPath"},
609
+	{0x01ab, ".CustomDict1"},
610
+	{0x01ac, ".CustomDict2"},
611
+	{0x01ad, ".CustomDict3"},
612
+	{0x01ae, ".CustomDict4"},
607 613
 	{0x01b1, ".Collate"},
614
+	{0x01b2, ".Shadow"},
608 615
 	{0x01b4, ".Button"},
609 616
 	{0x01b9, ".Remove"},
610 617
 	{0x01ba, ".Protect"},
... ...
@@ -614,6 +661,7 @@ void output_token73 (uint16_t token)
614 614
 	{0x01df, ".Toolbar"},
615 615
 	{0x01e0, ".ReplaceAll"},
616 616
 	{0x01eb, ".Address"},
617
+	{0x01f4, ".SelectedFile"},
617 618
 	{0x01f5, ".Run"},
618 619
 	{0x01f6, ".Edit"},
619 620
 	{0x0218, ".LastSaved"},
... ...
@@ -625,7 +673,14 @@ void output_token73 (uint16_t token)
625 625
 	{0x0234, ".SetDesc"},
626 626
 	{0x023d, ".CountFootNodes"},
627 627
 	{0x0255, ".AddToMru"},
628
+	{0x0262, ".NoteTypes"},
628 629
 	{0x0272, ".With"},
630
+	{0x0275, ".CustoDict5"},
631
+	{0x0276, ".CustoDict6"},
632
+	{0x0277, ".CustoDict7"},
633
+	{0x0278, ".CustoDict8"},
634
+	{0x0279, ".CustoDict9"},
635
+	{0x027a, ".CustoDict10"},
629 636
 	{0x027e, ".ErrorBeeps"},
630 637
 	{0x0285, ".Goto"},
631 638
 	{0x0287, ".Copy"},
... ...
@@ -678,6 +733,7 @@ void output_token73 (uint16_t token)
678 678
 	{0x0355, ".TextFormat"},
679 679
 	{0x0366, ".SearchName"},
680 680
 	{0x0370, ".BlueScreen"},
681
+	{0x0377, ".ListBy"},
681 682
 	{0x0378, ".SubDir"},
682 683
 	{0x0388, ".HorizontalPos"},
683 684
 	{0x0389, ".HorizontalFrom"},
... ...
@@ -687,6 +743,7 @@ void output_token73 (uint16_t token)
687 687
 	{0x039a, ".Strikethrough"},
688 688
 	{0x039b, ".Face"},
689 689
 	{0x039d, ".NativePictureFormat"},
690
+	{0x039e, ".FileSize"},
690 691
 	{0x03a2, ".LineType"},
691 692
 	{0x03a4, ".DisplayIcon"},
692 693
 	{0x03a8, ".IconFilename"},