Commit graph

55 commits

Author SHA1 Message Date
Micah Snyder
c110392780 Change permission for new tmp files from RWX to RW 2020-06-03 11:00:53 -04:00
Micah Snyder
11ef77007b Improve tmp sub-directory names
At present many parsers create tmp subdirectories to store extracted
files.  For parsers like the vba parser, this is required as the
directory is later scanned.  For other parsers, these subdirectories are
probably not helpful now that we provide recursive sub-dirs when
--leave-temps is enabled.  It's not quite as simple as removing the extra
subdirectories, however.  Certain parsers, like autoit, don't create very
unique filenames and would result in file name collisions when
--leave-temps is not enabled.

The best thing to do would be to make sure each parser uses unique
filenames and doesn't rely on cli_magic_scan_dir() to scan extracted
content before removing the extra subdirectory.  In the meantime, this
commit gives the extra subdirectories meaningful names to improve
readability.

This commit also:

- Provides the 'bmp' prefix for extracted PE icons.

- Removes empty tmp subdirs when extracting rtf files, to eliminate
  clutter.

- The PDF parser sometimes creates tmp files when decompressing streams
  before it knows if there is actually any content to decompress.  This
  resulted in a large number of empty files.  While it would be best to
  avoid creating empty files in the first place, that's not quite as
  as it sounds.  This commit does the next best thing and deletes the
  tmp files if nothing was actually extracted, even if --leave-temps is
  enabled.

- Removes the "scantemp" prefix for unnamed fmaps scanned with
  cli_magic_scan().  The 5-character hashes given to tmp files with
  prefixes resulted in occasional file name collisions when extracting
  certain file types with thousands of embedded files.

- The VBA and TAR parsers mistakenly used NAME_MAX instead of PATH_MAX,
  resulting in truncated file paths and failed extraction  when
  --leave-temps is enabled and a lot of recursion is in play.  This commit
  switches them from NAME_MAX to PATH_MAX.
2020-06-03 11:00:53 -04:00
Micah Snyder
9b9999d778 Rename core scanning functions
Many of the core scanning functions' names no longer represent their
specific purpose or arguments. This commit aims to make the names more
intuitive. Names are now prefixed with "magic" if they involve
file-typing and file-type parsing. In addition, each function now
includes the type of input being scanned whether its "desc", "fmap", or
"buff". Some of the APIs also now specify "type" to indicate that a type
other than "ANY" may be passed in to select the type rather than use
file type magic for type recognition.

| current name              | new name                          |
| ------------------------- | --------------------------------- |
| magic_scandesc()          | cli_magic_scan()                  |
| cli_magic_scandesc_type() | <delete>                          |
| cli_magic_scandesc()      | cli_magic_scan_desc()             |
| cli_base_scandesc()       | cli_magic_scan_desc_type()        |
| cli_partition_scandesc()  | <delete>                          |
| cli_map_scandesc()        | magic_scan_nested_fmap_type()     |
| cli_map_scan()            | cli_magic_scan_nested_fmap_type() |
| cli_mem_scandesc()        | cli_magic_scan_buff()             |
| cli_scanbuff()            | cli_scan_buff()                   |
| cli_scandesc()            | cli_scan_desc()                   |
| cli_fmap_scandesc()       | cli_scan_fmap()                   |
| cli_scanfile()            | cli_magic_scan_file()             |
| cli_scandir()             | cli_magic_scan_dir()              |
| cli_filetype2()           | cli_determine_fmap_type()         |
| cli_filetype()            | cli_compare_ftm_file()            |
| cli_partitiontype()       | cli_compare_ftm_partition()       |
| cli_scanraw()             | scanraw()                         |
2020-06-03 11:00:40 -04:00
Micah Snyder
005cbf5a37 Record names of extracted files
A way is needed to record scanned file names for two purposes:

1. File names (and extensions) must be stored in the json metadata
properties recorded when using the --gen-json clamscan option. Future
work may use this to compare file extensions with detected file types.

2. File names are useful when interpretting tmp directory output when
using the --leave-temps option.

This commit enables file name retention for later use by storing file
names in the fmap header structure, if a file name exists.

To store the names in fmaps, an optional name argument has been added to
any internal scan API's that create fmaps and every call to these APIs
has been modified to pass a file name or NULL if a file name is not
required.  The zip and gpt parsers required some modification to record
file names.  The NSIS and XAR parsers fail to collect file names at all
and will require future work to support file name extraction.

Also:

- Added recursive extraction to the tmp directory when the
  --leave-temps option is enabled.  When not enabled, the tmp directory
  structure remains flat so as to prevent the likelihood of exceeding
  MAX_PATH.  The current tmp directory is stored in the scan context.

- Made the cli_scanfile() internal API non-static and added it to
  scanners.h so it would be accessible outside of scanners.c in order to
  remove code duplication within libmspack.c.

- Added function comments to scanners.h and matcher.h

- Converted a TDB-type macros and LSIG-type macros to enums for improved
  type safey.

- Converted more return status variables from `int` to `cl_error_t` for
  improved type safety, and corrected ooxml file typing functions so
  they use `cli_file_t` exclusively rather than mixing types with
  `cl_error_t`.

- Restructured the magic_scandesc() function to use goto's for error
  handling and removed the early_ret_from_magicscan() macro and
  magic_scandesc_cleanup() function.  This makes the code easier to
  read and made it easier to add the recursive tmp directory cleanup to
  magic_scandesc().

- Corrected zip, egg, rar filename extraction issues.

- Removed use of extra sub-directory layer for zip, egg, and rar file
  extraction.  For Zip, this also involved changing the extracted
  filenames to be randomly generated rather than using the "zip.###"
  file name scheme.
2020-06-03 10:39:18 -04:00
Andrew
4fd8cf0845 Add support for the 0x0 and 0x1 AutoIT opcodes
These opcodes specify a function or keyword by number
instead of by name.  The corresponding lookup tables
still have a few entries without names, but the majority
of them are been determined and verified.
2020-02-17 10:14:01 -08:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05:00
Andrew
1643b4a114 Support the ternary operators (AutoIt script extraction)
There are a few other unsupported op codes, but we'll need
to investigate more to determine what to do with them.
2019-10-02 16:08:26 -04:00
Micah Snyder
4524c398f3 Argument and return types for fmap_readn(), cli_writen(), cli_readn() converted to use size_t instead of int. 2019-10-02 16:08:25 -04:00
Micah Snyder
52cddcbcfd Updating and cleaning up copyright notices. 2019-10-02 16:08:18 -04:00
Micah Snyder
72fd33c8b2 clang-format'd using new .clang-format rules. 2019-10-02 16:08:16 -04:00
Micah Snyder
d39cb6581f Updating libclamunrar from legacy C implementation to modern unrar 5.6.5. API changes and supporting changes included to pass the filepath of the scanned file into libclamav through the cli_ctx structure, required by the unrar library to open archives. The filename argument may be optional for the scandesc scanning variant, but libclamav will make a best effort to identify the filename from the file descriptor if it was not provided. In addition, included the ability to prefix temp file and directory names with file basenames. 2018-12-02 23:06:59 -05:00
Micah Snyder
d7979d4ff7 Restructured scan options flags from a single bitflag field to a structure containing multiple bitflag fields. This also required adding a new function to the bytecode API to get scan options a la carte, and modifying the existing function to hand back scan options in the old/deprecated uint32_t bitflag format. Re-generated bytecode iface header files.
Updated libclamav documentation detailing new scan options structure.
Renamed references to 'algorithmic' detection to 'heuristic' detection. Renaming references to 'properties' to 'collect metadata'.
Renamed references to 'scan all' to 'scan all match'.
Renamed a couple of 'Hueristic.*' signature names as 'Heuristics.*' signatures (plural) to match majority of other heuristics.
2018-12-02 23:06:59 -05:00
Mickey Sola
7ee1af4ddd bb11446 - adding check for compressed input stream 2016-01-20 16:21:58 -05:00
Mickey Sola
3072cef1f9 bb11446 - fixing autoit OOB bufferread 2016-01-11 14:47:30 -05:00
Mickey Sola
46a35abe56 mass update of copyright headers 2015-09-17 13:41:26 -04:00
Kevin Lin
122a0d9116 autoit: additional all-match fixes 2015-09-03 12:54:05 -04:00
Kevin Lin
ffb0d291ae autoit: fixed an all-match scanning issue 2015-09-03 12:32:30 -04:00
Shawn Webb
60d8d2c352 Move all the crypto API to clamav.h 2014-07-01 19:38:01 -04:00
Shawn Webb
b2e7c931d0 Use OpenSSL for hashing. 2014-02-08 00:31:12 -05:00
Steven Morgan
6fdf5527c7 quick fix for autoit.c bad header. 2013-10-31 11:12:11 -07:00
Steven Morgan
4896ecf6b7 bb#5341 - Change floating point byte order check from compile time to run time. 2013-10-31 12:54:50 -04:00
Shawn Webb
9691454612 bb6091 - check lseek() return 2013-02-28 19:32:29 -05:00
David Raynor
bebd86a60b bb#5343 2012-06-22 16:55:29 -04:00
Török Edvin
f304dc688a fmapify: fix const-ness warnings 2012-01-05 14:16:09 +02:00
aCaB
52c5734e73 bb#3051 2011-07-19 18:32:07 +02:00
aCaB
6c6638b01e bb#2171 2010-08-06 13:50:35 +02:00
aCaB
dc0bf21281 fix variable declaration 2010-07-29 04:00:11 +02:00
aCaB
ac867aad67 use fmap in autoit 2010-07-29 02:41:15 +02:00
aCaB
58481352d5 win32 paths handling 2009-09-24 19:07:39 +02:00
aCaB
081f64735d win32#2 2009-09-24 16:24:07 +02:00
Tomasz Kojm
e78b518630 fix some debug format 2009-09-15 22:46:35 +02:00
Tomasz Kojm
871177cdd9 return codes cleanup (bb#1159)
git-svn: trunk@4749
2009-02-12 13:53:23 +00:00
Tomasz Kojm
33068e0973 libclamav: drop cl_settempdir(); use cl_engine_set() with CL_ENGINE_TMPDIR and CL_ENGINE_KEEPTMP instead
git-svn: trunk@4416
2008-11-14 22:23:39 +00:00
Török Edvin
5cd3f734a9 add lots of warnings flags to 'make distcheck',
and turn some warnings into errors (bb #1092)

git-svn: trunk@4129
2008-08-21 20:21:43 +00:00
aCaB
c75c99bf13 autoit updated, test files added
git-svn: trunk@4013
2008-07-29 00:39:49 +00:00
aCaB
997a0e0b86 hardfail on unlink failure
git-svn: trunk@3775
2008-04-08 17:45:05 +00:00
Tomasz Kojm
2023340a41 update copyrights and stick more files to GPLv2; move and add more credits to the AUTHORS file; add COPYING.BSD
git-svn: trunk@3749
2008-04-02 15:24:51 +00:00
aCaB
c0a95e0ce6 bb#384 - unlink
git-svn: trunk@3747
2008-04-02 11:13:16 +00:00
aCaB
fd747ed8cc fsyncs removed - bb#844
git-svn: trunk@3728
2008-03-20 20:45:37 +00:00
aCaB
d91ab809a2 initial rewrite of limits
git-svn-id: file:///var/lib/svn/clamav-devel/branches/newlimits@3591 77e5149b-7576-45b1-b177-96237e5ba77b
2008-02-06 21:19:10 +00:00
aCaB
b80ae27752 newlimits started
git-svn-id: file:///var/lib/svn/clamav-devel/branches/newlimits@3556 77e5149b-7576-45b1-b177-96237e5ba77b
2008-01-29 03:27:30 +00:00
aCaB
b5231f5f67 realign structs see bb#474
git-svn: trunk@3537
2008-01-24 13:24:02 +00:00
Tomasz Kojm
2b304af942 eliminate some warning msgs
git-svn: trunk@3386
2007-12-10 15:33:46 +00:00
aCaB
993503da60 autoit fix for arm
git-svn: trunk@3356
2007-11-03 14:28:10 +00:00
aCaB
f99a37a211 autoit final
git-svn: trunk@3354
2007-11-02 00:06:33 +00:00
aCaB
f1b4700daf correct utf16le check
git-svn: trunk@3353
2007-11-01 21:53:50 +00:00
aCaB
79e179b3ec fix error handling logic and reenable otf scan and recursion for ea06
git-svn: trunk@3351
2007-11-01 16:16:31 +00:00
aCaB
8a06eed18f autoit: add support for type10(int64) and some misc fixes
git-svn: trunk@3350
2007-11-01 16:04:53 +00:00
aCaB
e66912ad80 autoit u2a reworked - more to come
git-svn: trunk@3349
2007-11-01 03:40:22 +00:00
aCaB
dbeb3de272 autoit: more fixes
git-svn: trunk@3347
2007-10-31 16:26:37 +00:00