2014-05-01 16:59:01 -04:00
|
|
|
/*
|
|
|
|
* OOXML JSON Internals
|
2019-05-04 17:28:16 -04:00
|
|
|
*
|
2025-02-14 10:24:30 -05:00
|
|
|
* Copyright (C) 2014-2025 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
2019-05-04 17:28:16 -04:00
|
|
|
*
|
2014-05-01 16:59:01 -04:00
|
|
|
* Authors: Kevin Lin
|
2019-05-04 17:28:16 -04:00
|
|
|
*
|
2014-05-01 16:59:01 -04:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License version 2 as published by the
|
|
|
|
* Free Software Foundation.
|
2019-05-04 17:28:16 -04:00
|
|
|
*
|
2014-05-01 16:59:01 -04:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2019-05-04 17:28:16 -04:00
|
|
|
*
|
2014-05-01 16:59:01 -04:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-05-23 10:11:32 -04:00
|
|
|
#include "json.h"
|
2014-07-10 18:11:49 -04:00
|
|
|
|
2014-05-01 16:59:01 -04:00
|
|
|
#include <libxml/xmlreader.h>
|
|
|
|
|
Add CMake build tooling
This patch adds experimental-quality CMake build tooling.
The libmspack build required a modification to use "" instead of <> for
header #includes. This will hopefully be included in the libmspack
upstream project when adding CMake build tooling to libmspack.
Removed use of libltdl when using CMake.
Flex & Bison are now required to build.
If -DMAINTAINER_MODE, then GPERF is also required, though it currently
doesn't actually do anything. TODO!
I found that the autotools build system was generating the lexer output
but not actually compiling it, instead using previously generated (and
manually renamed) lexer c source. As a consequence, changes to the .l
and .y files weren't making it into the build. To resolve this, I
removed generated flex/bison files and fixed the tooling to use the
freshly generated files. Flex and bison are now required build tools.
On Windows, this adds a dependency on the winflexbison package,
which can be obtained using Chocolatey or may be manually installed.
CMake tooling only has partial support for building with external LLVM
library, and no support for the internal LLVM (to be removed in the
future). I.e. The CMake build currently only supports the bytecode
interpreter.
Many files used include paths relative to the top source directory or
relative to the current project, rather than relative to each build
target. Modern CMake support requires including internal dependency
headers the same way you would external dependency headers (albeit
with "" instead of <>). This meant correcting all header includes to
be relative to the build targets and not relative to the workspace.
For example, ...
```c
include "../libclamav/clamav.h"
include "clamd/clamd_others.h"
```
... becomes:
```c
// libclamav
include "clamav.h"
// clamd
include "clamd_others.h"
```
Fixes header name conflicts by renaming a few of the files.
Converted the "shared" code into a static library, which depends on
libclamav. The ironically named "shared" static library provides
features common to the ClamAV apps which are not required in
libclamav itself and are not intended for use by downstream projects.
This change was required for correct modern CMake practices but was
also required to use the automake "subdir-objects" option.
This eliminates warnings when running autoreconf which, in the next
version of autoconf & automake are likely to break the build.
libclamav used to build in multiple stages where an earlier stage is
a static library containing utils required by the "shared" code.
Linking clamdscan and clamdtop with this libclamav utils static lib
allowed these two apps to function without libclamav. While this is
nice in theory, the practical gains are minimal and it complicates
the build system. As such, the autotools and CMake tooling was
simplified for improved maintainability and this feature was thrown
out. clamdtop and clamdscan now require libclamav to function.
Removed the nopthreads version of the autotools
libclamav_internal_utils static library and added pthread linking to
a couple apps that may have issues building on some platforms without
it, with the intention of removing needless complexity from the
source. Kept the regular version of libclamav_internal_utils.la
though it is no longer used anywhere but in libclamav.
Added an experimental doxygen build option which attempts to build
clamav.h and libfreshclam doxygen html docs.
The CMake build tooling also may build the example program(s), which
isn't a feature in the Autotools build system.
Changed C standard to C90+ due to inline linking issues with socket.h
when linking libfreshclam.so on Linux.
Generate common.rc for win32.
Fix tabs/spaces in shared Makefile.am, and remove vestigial ifndef
from misc.c.
Add CMake files to the automake dist, so users can try the new
CMake tooling w/out having to build from a git clone.
clamonacc changes:
- Renamed FANOTIFY macro to HAVE_SYS_FANOTIFY_H to better match other
similar macros.
- Added a new clamav-clamonacc.service systemd unit file, based on
the work of ChadDevOps & Aaron Brighton.
- Added missing clamonacc man page.
Updates to clamdscan man page, add missing options.
Remove vestigial CL_NOLIBCLAMAV definitions (all apps now use
libclamav).
Rename Windows mspack.dll to libmspack.dll so all ClamAV-built
libraries have the lib-prefix with Visual Studio as with CMake.
2020-08-13 00:25:34 -07:00
|
|
|
#include "clamav.h"
|
|
|
|
#include "filetypes.h"
|
|
|
|
#include "others.h"
|
|
|
|
#include "unzip.h"
|
|
|
|
#include "json_api.h"
|
|
|
|
#include "msxml_parser.h"
|
|
|
|
#include "ooxml.h"
|
|
|
|
|
2018-12-03 12:37:58 -05:00
|
|
|
// clang-format off
|
|
|
|
|
2015-12-17 16:16:55 -05:00
|
|
|
/*** OOXML MSDOC ***/
|
2015-03-16 16:34:44 -04:00
|
|
|
static const struct key_entry ooxml_keys[] = {
|
2018-12-03 12:37:58 -05:00
|
|
|
{ "coreproperties", "CoreProperties", MSXML_JSON_ROOT | MSXML_JSON_ATTRIB },
|
|
|
|
{ "title", "Title", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "subject", "Subject", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "creator", "Author", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "keywords", "Keywords", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "comments", "Comments", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "description", "Description", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "lastmodifiedby", "LastAuthor", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "revision", "Revision", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "created", "Created", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "modified", "Modified", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "category", "Category", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "contentstatus", "ContentStatus", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "properties", "ExtendedProperties", MSXML_JSON_ROOT | MSXML_JSON_ATTRIB },
|
|
|
|
{ "application", "Application", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "appversion", "AppVersion", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "characters", "Characters", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
2015-03-16 16:34:44 -04:00
|
|
|
{ "characterswithspaces", "CharactersWithSpaces", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
2018-12-03 12:37:58 -05:00
|
|
|
{ "company", "Company", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "digsig", "DigSig", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "docsecurity", "DocSecurity", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
//{ "headingpairs", "HeadingPairs", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "hiddenslides", "HiddenSlides", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "hlinks", "HLinks", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "hyperlinkbase", "HyperlinkBase", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "hyperlinkschanged", "HyperlinksChanged", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "lines", "Lines", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "linksuptodate", "LinksUpToDate", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "manager", "Manager", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "mmclips", "MultimediaClips", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "notes", "Notes", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "pages", "Pages", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "paragraphs", "Paragraphs", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "presentationformat", "PresentationFormat", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
//{ "properties", "Properties", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "scalecrop", "ScaleCrop", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "shareddoc", "SharedDocs", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "slides", "Slides", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "template", "Template", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
//{ "titleofparts", "TitleOfParts", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "totaltime", "TotalTime", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "words", "Words", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
2015-03-16 16:34:44 -04:00
|
|
|
|
|
|
|
/* Should NOT Exist */
|
2018-12-03 12:37:58 -05:00
|
|
|
{ "bindata", "BinaryData", MSXML_SCAN_B64 | MSXML_JSON_COUNT | MSXML_JSON_ROOT }
|
2014-05-09 13:30:32 -04:00
|
|
|
};
|
2015-03-16 16:34:44 -04:00
|
|
|
static size_t num_ooxml_keys = sizeof(ooxml_keys) / sizeof(struct key_entry);
|
2014-05-09 13:30:32 -04:00
|
|
|
|
2018-12-03 12:37:58 -05:00
|
|
|
/*** OOXML HWP ***/
|
|
|
|
static const struct key_entry ooxml_hwp_keys[] = {
|
|
|
|
{ "hcfversion", "HCFVersion", MSXML_JSON_ROOT | MSXML_JSON_ATTRIB },
|
|
|
|
{ "package", "Properties", MSXML_JSON_ROOT | MSXML_JSON_ATTRIB },
|
|
|
|
{ "metadata", "Metadata", MSXML_JSON_WRKPTR | MSXML_JSON_ATTRIB },
|
|
|
|
{ "title", "Title", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "language", "Language", MSXML_JSON_WRKPTR | MSXML_JSON_VALUE },
|
|
|
|
{ "meta", "MetaFields", MSXML_JSON_WRKPTR | MSXML_JSON_ATTRIB | MSXML_JSON_VALUE | MSXML_JSON_COUNT | MSXML_JSON_MULTI },
|
|
|
|
{ "item", "Contents", MSXML_JSON_WRKPTR | MSXML_JSON_ATTRIB | MSXML_JSON_COUNT | MSXML_JSON_MULTI }
|
|
|
|
};
|
|
|
|
static size_t num_ooxml_hwp_keys = sizeof(ooxml_hwp_keys) / sizeof(struct key_entry);
|
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
|
2020-03-19 21:23:54 -04:00
|
|
|
static cl_error_t ooxml_updatelimits(int fd, cli_ctx *ctx)
|
2014-11-25 12:06:55 -05:00
|
|
|
{
|
|
|
|
STATBUF sb;
|
|
|
|
if (FSTAT(fd, &sb) == -1) {
|
|
|
|
cli_errmsg("ooxml_updatelimits: Can't fstat descriptor %d\n", fd);
|
|
|
|
return CL_ESTAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli_updatelimits(ctx, sb.st_size);
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:23:54 -04:00
|
|
|
static cl_error_t ooxml_parse_document(int fd, cli_ctx *ctx)
|
2014-05-09 13:30:32 -04:00
|
|
|
{
|
2020-07-24 08:32:47 -07:00
|
|
|
cl_error_t ret = CL_SUCCESS;
|
2014-05-09 13:30:32 -04:00
|
|
|
xmlTextReaderPtr reader = NULL;
|
|
|
|
|
|
|
|
cli_dbgmsg("in ooxml_parse_document\n");
|
|
|
|
|
2014-11-25 12:06:55 -05:00
|
|
|
/* perform engine limit checks in temporary tracking session */
|
|
|
|
ret = ooxml_updatelimits(fd, ctx);
|
|
|
|
if (ret != CL_CLEAN)
|
|
|
|
return ret;
|
|
|
|
|
2014-08-26 13:47:27 -04:00
|
|
|
reader = xmlReaderForFd(fd, "properties.xml", NULL, CLAMAV_MIN_XMLREADER_FLAGS);
|
2014-05-09 13:30:32 -04:00
|
|
|
if (reader == NULL) {
|
|
|
|
cli_dbgmsg("ooxml_parse_document: xmlReaderForFd error\n");
|
|
|
|
return CL_SUCCESS; // internal error from libxml2
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:54:56 -04:00
|
|
|
ret = cli_msxml_parse_document(ctx, reader, ooxml_keys, num_ooxml_keys, MSXML_FLAG_JSON, NULL);
|
2014-05-09 13:30:32 -04:00
|
|
|
|
2014-11-19 18:15:36 -05:00
|
|
|
if (ret != CL_SUCCESS && ret != CL_ETIMEOUT && ret != CL_BREAK)
|
2014-08-21 16:53:16 -04:00
|
|
|
cli_warnmsg("ooxml_parse_document: encountered issue in parsing properties document\n");
|
2014-07-01 13:21:44 -04:00
|
|
|
|
2014-05-09 13:30:32 -04:00
|
|
|
xmlTextReaderClose(reader);
|
|
|
|
xmlFreeTextReader(reader);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2022-03-09 22:26:40 -08:00
|
|
|
static cl_error_t ooxml_core_cb(int fd, const char *filepath, cli_ctx *ctx, const char *name, uint32_t attributes)
|
2014-05-01 16:59:01 -04:00
|
|
|
{
|
2020-03-19 21:23:54 -04:00
|
|
|
cl_error_t ret;
|
2014-11-19 18:15:36 -05:00
|
|
|
|
2019-05-04 17:28:16 -04:00
|
|
|
UNUSEDPARAM(filepath);
|
2020-03-19 21:23:54 -04:00
|
|
|
UNUSEDPARAM(name);
|
2022-03-09 22:26:40 -08:00
|
|
|
UNUSEDPARAM(attributes);
|
2019-05-04 17:28:16 -04:00
|
|
|
|
2014-05-01 16:59:01 -04:00
|
|
|
cli_dbgmsg("in ooxml_core_cb\n");
|
2014-11-19 18:15:36 -05:00
|
|
|
ret = ooxml_parse_document(fd, ctx);
|
|
|
|
if (ret == CL_EPARSE)
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_CORE_XMLPARSER");
|
2014-11-19 18:15:36 -05:00
|
|
|
else if (ret == CL_EFORMAT)
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_CORE_MALFORMED");
|
2014-11-19 18:15:36 -05:00
|
|
|
|
|
|
|
return ret;
|
2014-05-01 16:59:01 -04:00
|
|
|
}
|
|
|
|
|
2022-03-09 22:26:40 -08:00
|
|
|
static cl_error_t ooxml_extn_cb(int fd, const char *filepath, cli_ctx *ctx, const char *name, uint32_t attributes)
|
2014-05-01 16:59:01 -04:00
|
|
|
{
|
2020-03-19 21:23:54 -04:00
|
|
|
cl_error_t ret;
|
2014-11-19 18:15:36 -05:00
|
|
|
|
2019-05-04 17:28:16 -04:00
|
|
|
UNUSEDPARAM(filepath);
|
2020-03-19 21:23:54 -04:00
|
|
|
UNUSEDPARAM(name);
|
2022-03-09 22:26:40 -08:00
|
|
|
UNUSEDPARAM(attributes);
|
2019-05-04 17:28:16 -04:00
|
|
|
|
2014-05-01 16:59:01 -04:00
|
|
|
cli_dbgmsg("in ooxml_extn_cb\n");
|
2014-11-19 18:15:36 -05:00
|
|
|
ret = ooxml_parse_document(fd, ctx);
|
|
|
|
if (ret == CL_EPARSE)
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_EXTN_XMLPARSER");
|
2014-11-19 18:15:36 -05:00
|
|
|
else if (ret == CL_EFORMAT)
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_EXTN_MALFORMED");
|
2014-11-19 18:15:36 -05:00
|
|
|
|
|
|
|
return ret;
|
2014-05-01 16:59:01 -04:00
|
|
|
}
|
|
|
|
|
2022-03-09 22:26:40 -08:00
|
|
|
static cl_error_t ooxml_content_cb(int fd, const char *filepath, cli_ctx *ctx, const char *name, uint32_t attributes)
|
2014-05-01 16:59:01 -04:00
|
|
|
{
|
2020-03-19 21:23:54 -04:00
|
|
|
cl_error_t ret = CL_SUCCESS;
|
|
|
|
int tmp, toval = 0, state;
|
2018-12-03 12:40:13 -05:00
|
|
|
int core = 0, extn = 0, cust = 0, dsig = 0;
|
|
|
|
int mcore = 0, mextn = 0, mcust = 0;
|
2020-03-19 21:23:54 -04:00
|
|
|
const xmlChar *localname, *value, *CT, *PN;
|
2014-05-01 16:59:01 -04:00
|
|
|
xmlTextReaderPtr reader = NULL;
|
|
|
|
uint32_t loff;
|
|
|
|
|
2019-05-04 17:28:16 -04:00
|
|
|
UNUSEDPARAM(filepath);
|
2020-03-19 21:23:54 -04:00
|
|
|
UNUSEDPARAM(name);
|
2022-03-09 22:26:40 -08:00
|
|
|
UNUSEDPARAM(attributes);
|
2019-05-04 17:28:16 -04:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
unsigned long sav_scansize = ctx->scansize;
|
2014-11-25 12:06:55 -05:00
|
|
|
unsigned int sav_scannedfiles = ctx->scannedfiles;
|
|
|
|
|
2014-05-01 16:59:01 -04:00
|
|
|
cli_dbgmsg("in ooxml_content_cb\n");
|
|
|
|
|
2014-11-25 12:06:55 -05:00
|
|
|
/* perform engine limit checks in temporary tracking session */
|
|
|
|
ret = ooxml_updatelimits(fd, ctx);
|
|
|
|
if (ret != CL_CLEAN)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* apply a reader to the document */
|
2014-08-26 13:47:27 -04:00
|
|
|
reader = xmlReaderForFd(fd, "[Content_Types].xml", NULL, CLAMAV_MIN_XMLREADER_FLAGS);
|
2014-05-01 16:59:01 -04:00
|
|
|
if (reader == NULL) {
|
2018-12-03 12:40:13 -05:00
|
|
|
cli_dbgmsg("ooxml_content_cb: xmlReaderForFd error for "
|
|
|
|
"[Content_Types].xml"
|
|
|
|
"\n");
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_XML_READER_FD");
|
2014-11-25 12:06:55 -05:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
ctx->scansize = sav_scansize;
|
2014-11-25 12:06:55 -05:00
|
|
|
ctx->scannedfiles = sav_scannedfiles;
|
2014-05-01 16:59:01 -04:00
|
|
|
return CL_SUCCESS; // libxml2 failed!
|
|
|
|
}
|
|
|
|
|
2014-11-19 18:15:36 -05:00
|
|
|
/* locate core-properties, extended-properties, and custom-properties (optional) */
|
|
|
|
while ((state = xmlTextReaderRead(reader)) == 1) {
|
2014-06-25 13:08:18 -04:00
|
|
|
if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) {
|
|
|
|
ret = CL_ETIMEOUT;
|
|
|
|
goto ooxml_content_exit;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:23:54 -04:00
|
|
|
localname = xmlTextReaderConstLocalName(reader);
|
|
|
|
if (localname == NULL) continue;
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2020-03-19 21:23:54 -04:00
|
|
|
if (strcmp((const char *)localname, "Override")) continue;
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2014-09-02 14:56:34 -04:00
|
|
|
if (xmlTextReaderHasAttributes(reader) != 1) continue;
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2014-06-27 16:30:41 -04:00
|
|
|
CT = PN = NULL;
|
2014-05-01 16:59:01 -04:00
|
|
|
while (xmlTextReaderMoveToNextAttribute(reader) == 1) {
|
2020-07-24 08:32:47 -07:00
|
|
|
localname = xmlTextReaderConstLocalName(reader);
|
|
|
|
value = xmlTextReaderConstValue(reader);
|
2020-03-19 21:23:54 -04:00
|
|
|
if (localname == NULL || value == NULL) continue;
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2020-03-19 21:23:54 -04:00
|
|
|
if (!xmlStrcmp(localname, (const xmlChar *)"ContentType")) {
|
2014-05-01 16:59:01 -04:00
|
|
|
CT = value;
|
2020-03-19 21:23:54 -04:00
|
|
|
} else if (!xmlStrcmp(localname, (const xmlChar *)"PartName")) {
|
2014-05-01 16:59:01 -04:00
|
|
|
PN = value;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:23:54 -04:00
|
|
|
cli_dbgmsg("%s: %s\n", localname, value);
|
2014-05-01 16:59:01 -04:00
|
|
|
}
|
|
|
|
|
2021-09-15 15:51:53 -07:00
|
|
|
if (!CT || !PN) continue;
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2014-07-10 18:11:49 -04:00
|
|
|
if (!xmlStrcmp(CT, (const xmlChar *)"application/vnd.openxmlformats-package.core-properties+xml")) {
|
2014-11-19 18:15:36 -05:00
|
|
|
/* default: /docProps/core.xml*/
|
2018-12-03 12:40:13 -05:00
|
|
|
tmp = unzip_search_single(ctx, (const char *)(PN + 1), xmlStrlen(PN) - 1, &loff);
|
2014-11-19 18:15:36 -05:00
|
|
|
if (tmp == CL_ETIMEOUT) {
|
|
|
|
ret = tmp;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (tmp != CL_VIRUS) {
|
2014-11-19 18:15:36 -05:00
|
|
|
cli_dbgmsg("cli_process_ooxml: failed to find core properties file \"%s\"!\n", PN);
|
|
|
|
mcore++;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2014-11-19 18:15:36 -05:00
|
|
|
cli_dbgmsg("ooxml_content_cb: found core properties file \"%s\" @ %x\n", PN, loff);
|
|
|
|
if (!core) {
|
|
|
|
tmp = unzip_single_internal(ctx, loff, ooxml_core_cb);
|
|
|
|
if (tmp == CL_ETIMEOUT || tmp == CL_EMEM) {
|
|
|
|
ret = tmp;
|
|
|
|
}
|
2014-06-27 16:30:41 -04:00
|
|
|
}
|
2014-11-19 18:15:36 -05:00
|
|
|
core++;
|
2014-05-01 16:59:01 -04:00
|
|
|
}
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (!xmlStrcmp(CT, (const xmlChar *)"application/vnd.openxmlformats-officedocument.extended-properties+xml")) {
|
2014-11-19 18:15:36 -05:00
|
|
|
/* default: /docProps/app.xml */
|
2018-12-03 12:40:13 -05:00
|
|
|
tmp = unzip_search_single(ctx, (const char *)(PN + 1), xmlStrlen(PN) - 1, &loff);
|
2014-11-19 18:15:36 -05:00
|
|
|
if (tmp == CL_ETIMEOUT) {
|
|
|
|
ret = tmp;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (tmp != CL_VIRUS) {
|
2014-11-19 18:15:36 -05:00
|
|
|
cli_dbgmsg("cli_process_ooxml: failed to find extended properties file \"%s\"!\n", PN);
|
|
|
|
mextn++;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2014-11-19 18:15:36 -05:00
|
|
|
cli_dbgmsg("ooxml_content_cb: found extended properties file \"%s\" @ %x\n", PN, loff);
|
|
|
|
if (!extn) {
|
|
|
|
tmp = unzip_single_internal(ctx, loff, ooxml_extn_cb);
|
|
|
|
if (tmp == CL_ETIMEOUT || tmp == CL_EMEM) {
|
|
|
|
ret = tmp;
|
|
|
|
}
|
2014-06-27 16:30:41 -04:00
|
|
|
}
|
2014-11-19 18:15:36 -05:00
|
|
|
extn++;
|
2014-05-01 16:59:01 -04:00
|
|
|
}
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (!xmlStrcmp(CT, (const xmlChar *)"application/vnd.openxmlformats-officedocument.custom-properties+xml")) {
|
2014-11-19 18:15:36 -05:00
|
|
|
/* default: /docProps/custom.xml */
|
2018-12-03 12:40:13 -05:00
|
|
|
tmp = unzip_search_single(ctx, (const char *)(PN + 1), xmlStrlen(PN) - 1, &loff);
|
2014-11-19 18:15:36 -05:00
|
|
|
if (tmp == CL_ETIMEOUT) {
|
|
|
|
ret = tmp;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (tmp != CL_VIRUS) {
|
2014-11-19 18:15:36 -05:00
|
|
|
cli_dbgmsg("cli_process_ooxml: failed to find custom properties file \"%s\"!\n", PN);
|
|
|
|
mcust++;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2014-11-19 18:15:36 -05:00
|
|
|
cli_dbgmsg("ooxml_content_cb: found custom properties file \"%s\" @ %x\n", PN, loff);
|
|
|
|
/* custom properties are not parsed */
|
|
|
|
cust++;
|
2014-05-01 16:59:01 -04:00
|
|
|
}
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (!xmlStrcmp(CT, (const xmlChar *)"application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml")) {
|
2014-06-27 16:30:41 -04:00
|
|
|
dsig++;
|
2014-05-19 18:18:20 -04:00
|
|
|
}
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2014-11-19 18:15:36 -05:00
|
|
|
if (ret != CL_SUCCESS)
|
2014-05-01 16:59:01 -04:00
|
|
|
goto ooxml_content_exit;
|
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
ooxml_content_exit:
|
2014-11-19 18:15:36 -05:00
|
|
|
if (core) {
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_jsonint(ctx->this_layer_metadata_json, "CorePropertiesFileCount", core);
|
2014-11-19 18:15:36 -05:00
|
|
|
if (core > 1)
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_MULTIPLE_CORE_PROPFILES");
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (!mcore)
|
2014-05-01 16:59:01 -04:00
|
|
|
cli_dbgmsg("cli_process_ooxml: file does not contain core properties file\n");
|
2014-11-19 18:15:36 -05:00
|
|
|
if (mcore) {
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_jsonint(ctx->this_layer_metadata_json, "CorePropertiesMissingFileCount", mcore);
|
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_MISSING_CORE_PROPFILES");
|
2014-11-19 18:15:36 -05:00
|
|
|
}
|
2014-06-30 17:26:48 -04:00
|
|
|
|
2014-11-19 18:15:36 -05:00
|
|
|
if (extn) {
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_jsonint(ctx->this_layer_metadata_json, "ExtendedPropertiesFileCount", extn);
|
2014-11-19 18:15:36 -05:00
|
|
|
if (extn > 1)
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_MULTIPLE_EXTN_PROPFILES");
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (!mextn)
|
2014-05-01 16:59:01 -04:00
|
|
|
cli_dbgmsg("cli_process_ooxml: file does not contain extended properties file\n");
|
2014-11-19 18:15:36 -05:00
|
|
|
if (mextn) {
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_jsonint(ctx->this_layer_metadata_json, "ExtendedPropertiesMissingFileCount", mextn);
|
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_MISSING_EXTN_PROPFILES");
|
2014-11-19 18:15:36 -05:00
|
|
|
}
|
2014-06-30 17:26:48 -04:00
|
|
|
|
2014-11-19 18:15:36 -05:00
|
|
|
if (cust) {
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_jsonint(ctx->this_layer_metadata_json, "CustomPropertiesFileCount", cust);
|
2014-11-19 18:15:36 -05:00
|
|
|
if (cust > 1)
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_MULTIPLE_CUSTOM_PROPFILES");
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (!mcust)
|
2014-05-01 16:59:01 -04:00
|
|
|
cli_dbgmsg("cli_process_ooxml: file does not contain custom properties file\n");
|
2014-11-19 18:15:36 -05:00
|
|
|
if (mcust) {
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_jsonint(ctx->this_layer_metadata_json, "CustomPropertiesMissingFileCount", mcust);
|
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_MISSING_CUST_PROPFILES");
|
2014-11-19 18:15:36 -05:00
|
|
|
}
|
2014-06-30 17:26:48 -04:00
|
|
|
|
2014-06-27 16:30:41 -04:00
|
|
|
if (dsig) {
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_jsonint(ctx->this_layer_metadata_json, "DigitalSignaturesCount", dsig);
|
2014-06-27 16:30:41 -04:00
|
|
|
}
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2014-11-25 12:06:55 -05:00
|
|
|
/* restore the engine tracking limits; resets session limit tracking */
|
2018-12-03 12:40:13 -05:00
|
|
|
ctx->scansize = sav_scansize;
|
2014-11-25 12:06:55 -05:00
|
|
|
ctx->scannedfiles = sav_scannedfiles;
|
|
|
|
|
2014-05-01 16:59:01 -04:00
|
|
|
xmlTextReaderClose(reader);
|
|
|
|
xmlFreeTextReader(reader);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-12-17 16:16:55 -05:00
|
|
|
|
2022-03-09 22:26:40 -08:00
|
|
|
static cl_error_t ooxml_hwp_cb(int fd, const char *filepath, cli_ctx *ctx, const char *name, uint32_t attributes)
|
2015-12-17 16:16:55 -05:00
|
|
|
{
|
2020-03-19 21:23:54 -04:00
|
|
|
cl_error_t ret = CL_SUCCESS;
|
2015-12-17 16:16:55 -05:00
|
|
|
xmlTextReaderPtr reader = NULL;
|
|
|
|
|
2019-05-04 17:28:16 -04:00
|
|
|
UNUSEDPARAM(filepath);
|
2020-03-19 21:23:54 -04:00
|
|
|
UNUSEDPARAM(name);
|
2022-03-09 22:26:40 -08:00
|
|
|
UNUSEDPARAM(attributes);
|
2019-05-04 17:28:16 -04:00
|
|
|
|
2015-12-17 16:16:55 -05:00
|
|
|
cli_dbgmsg("in ooxml_hwp_cb\n");
|
|
|
|
|
|
|
|
/* perform engine limit checks in temporary tracking session */
|
|
|
|
ret = ooxml_updatelimits(fd, ctx);
|
|
|
|
if (ret != CL_CLEAN)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
reader = xmlReaderForFd(fd, "ooxml_hwp.xml", NULL, CLAMAV_MIN_XMLREADER_FLAGS);
|
|
|
|
if (reader == NULL) {
|
|
|
|
cli_dbgmsg("ooxml_hwp_cb: xmlReaderForFd error\n");
|
|
|
|
return CL_SUCCESS; // internal error from libxml2
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:54:56 -04:00
|
|
|
ret = cli_msxml_parse_document(ctx, reader, ooxml_hwp_keys, num_ooxml_hwp_keys, MSXML_FLAG_JSON, NULL);
|
2015-12-17 16:16:55 -05:00
|
|
|
|
|
|
|
if (ret != CL_SUCCESS && ret != CL_ETIMEOUT && ret != CL_BREAK)
|
|
|
|
cli_warnmsg("ooxml_hwp_cb: encountered issue in parsing properties document\n");
|
|
|
|
|
|
|
|
xmlTextReaderClose(reader);
|
|
|
|
xmlFreeTextReader(reader);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2025-08-14 21:17:46 -04:00
|
|
|
cli_file_t cli_ooxml_filetype(cli_ctx *ctx)
|
2014-10-14 17:15:18 -04:00
|
|
|
{
|
|
|
|
struct zip_requests requests;
|
2020-03-19 21:23:54 -04:00
|
|
|
cl_error_t ret;
|
2014-10-14 17:15:18 -04:00
|
|
|
|
|
|
|
memset(&requests, 0, sizeof(struct zip_requests));
|
|
|
|
|
|
|
|
if ((ret = unzip_search_add(&requests, "xl/", 3)) != CL_SUCCESS) {
|
2020-03-19 21:23:54 -04:00
|
|
|
return CL_TYPE_ANY;
|
2014-10-14 17:15:18 -04:00
|
|
|
}
|
|
|
|
if ((ret = unzip_search_add(&requests, "ppt/", 4)) != CL_SUCCESS) {
|
2020-03-19 21:23:54 -04:00
|
|
|
return CL_TYPE_ANY;
|
2014-10-14 17:15:18 -04:00
|
|
|
}
|
|
|
|
if ((ret = unzip_search_add(&requests, "word/", 5)) != CL_SUCCESS) {
|
2020-03-19 21:23:54 -04:00
|
|
|
return CL_TYPE_ANY;
|
2014-10-14 17:15:18 -04:00
|
|
|
}
|
2016-01-13 14:56:46 -05:00
|
|
|
if ((ret = unzip_search_add(&requests, "Contents/content.hpf", 22)) != CL_SUCCESS) {
|
2020-03-19 21:23:54 -04:00
|
|
|
return CL_TYPE_ANY;
|
2016-01-13 14:56:46 -05:00
|
|
|
}
|
2014-10-14 17:15:18 -04:00
|
|
|
|
2025-08-14 21:17:46 -04:00
|
|
|
if ((ret = unzip_search(ctx, &requests)) == CL_VIRUS) {
|
2014-10-14 17:15:18 -04:00
|
|
|
switch (requests.found) {
|
2018-12-03 12:40:13 -05:00
|
|
|
case 0:
|
|
|
|
return CL_TYPE_OOXML_XL;
|
|
|
|
case 1:
|
|
|
|
return CL_TYPE_OOXML_PPT;
|
|
|
|
case 2:
|
|
|
|
return CL_TYPE_OOXML_WORD;
|
|
|
|
case 3:
|
|
|
|
return CL_TYPE_OOXML_HWP;
|
|
|
|
default:
|
2020-03-19 21:23:54 -04:00
|
|
|
return CL_TYPE_ANY;
|
2014-10-14 17:15:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:23:54 -04:00
|
|
|
return CL_TYPE_ANY;
|
2014-10-14 17:15:18 -04:00
|
|
|
}
|
|
|
|
|
2020-03-19 21:23:54 -04:00
|
|
|
cl_error_t cli_process_ooxml(cli_ctx *ctx, int type)
|
2014-05-01 16:59:01 -04:00
|
|
|
{
|
2020-07-24 08:32:47 -07:00
|
|
|
uint32_t loff = 0;
|
|
|
|
cl_error_t ret = CL_SUCCESS;
|
2014-05-01 16:59:01 -04:00
|
|
|
|
2015-03-10 15:33:32 -04:00
|
|
|
cli_dbgmsg("in cli_process_ooxml\n");
|
2014-05-01 16:59:01 -04:00
|
|
|
if (!ctx) {
|
|
|
|
return CL_ENULLARG;
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:16:55 -05:00
|
|
|
if (type == CL_TYPE_OOXML_HWP) {
|
|
|
|
/* two files: version.xml and Contents/content.hpf */
|
|
|
|
ret = unzip_search_single(ctx, "version.xml", 11, &loff);
|
|
|
|
if (ret == CL_ETIMEOUT) {
|
|
|
|
return CL_ETIMEOUT;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (ret != CL_VIRUS) {
|
|
|
|
cli_dbgmsg("cli_process_ooxml: failed to find "
|
|
|
|
"version.xml"
|
|
|
|
"!\n");
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_NO_HWP_VERSION");
|
2015-12-17 16:16:55 -05:00
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
|
|
|
ret = unzip_single_internal(ctx, loff, ooxml_hwp_cb);
|
|
|
|
|
|
|
|
if (ret == CL_SUCCESS) {
|
|
|
|
ret = unzip_search_single(ctx, "Contents/content.hpf", 20, &loff);
|
|
|
|
if (ret == CL_ETIMEOUT) {
|
|
|
|
return CL_ETIMEOUT;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (ret != CL_VIRUS) {
|
|
|
|
cli_dbgmsg("cli_process_ooxml: failed to find "
|
|
|
|
"Contents/content.hpf"
|
|
|
|
"!\n");
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_NO_HWP_CONTENT");
|
2015-12-17 16:16:55 -05:00
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
|
|
|
ret = unzip_single_internal(ctx, loff, ooxml_hwp_cb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* find "[Content Types].xml" */
|
|
|
|
ret = unzip_search_single(ctx, "[Content_Types].xml", 19, &loff);
|
|
|
|
if (ret == CL_ETIMEOUT) {
|
|
|
|
return CL_ETIMEOUT;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (ret != CL_VIRUS) {
|
|
|
|
cli_dbgmsg("cli_process_ooxml: failed to find "
|
|
|
|
"[Content_Types].xml"
|
|
|
|
"!\n");
|
2025-06-08 01:12:33 -04:00
|
|
|
cli_json_parse_error(ctx->this_layer_metadata_json, "OOXML_ERROR_NO_CONTENT_TYPES");
|
2015-12-17 16:16:55 -05:00
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
2018-12-03 12:40:13 -05:00
|
|
|
cli_dbgmsg("cli_process_ooxml: found "
|
|
|
|
"[Content_Types].xml"
|
|
|
|
" @ %x\n",
|
|
|
|
loff);
|
2015-12-17 16:16:55 -05:00
|
|
|
|
|
|
|
ret = unzip_single_internal(ctx, loff, ooxml_content_cb);
|
2014-05-01 16:59:01 -04:00
|
|
|
}
|
|
|
|
|
2015-12-17 16:16:55 -05:00
|
|
|
return ret;
|
2014-05-01 16:59:01 -04:00
|
|
|
}
|