Contents
Log Scanner Guide
The Log Scanner utility is a command-line application that allows you to send data to Feed Service for checking against feeds. You can check hashes, IP addresses, or URLs one by one or in batch mode, that is, by sending Feed Service files that contain data to check.
This chapter explains how to use the Log Scanner utility.
Command-line options
In Linux, the Log Scanner utility is launched from the command line as follows:
./log_scanner [-h|--help] [-r|--report] [-c|--config] [[-p|--path]|[-s|--hash]|[-u|--url]|[-i|--ip]] [value]
In Windows, the Log Scanner utility is launched from the command line as follows:
log_scanner.exe [-h|--help] [-r|--report] [-c|--config] [[-p|--path]|[-s|--hash]|[-u|--url]|[-i|--ip]] [value]
The following table explains the command-line options.
Command-line options of Log Scanner
Option |
Description |
|
Prints the usage message to the screen. If this option is specified, all other options are ignored. |
|
If this option is specified, Feed Service will return the response to Log Scanner in the same socket in which the request was sent, and Log Scanner will save the result in a text file. The output file is named If a URL, IP address, or hash is found in Kaspersky Threat Data Feeds, its category and context information is written to the output. After the entire input is processed, the following information is written to the output:
If this option is specified, make sure that the value of the |
|
Path to the configuration file. It can be either an absolute or a relative path. A relative path is calculated relative to the directory from which you run Log Scanner. By default, Log Scanner uses the log_scanner.conf configuration file that is placed in the directory from which you run Log Scanner. |
|
Path to a directory or text file that contains URLs, IP addresses, and hashes to check against Kaspersky Threat Data Feeds. It can be an absolute or a relative path. A relative path is calculated relative to the directory that contains the Log Scanner binary file. If the path to a directory is specified, all files contained in it and all its all-level subdirectories are processed. Each line of each processed file is sent to Feed Service as the data to be checked. No further formatting is applied. Feed Service will parse the lines by using the regular expressions set in its configuration file. You can specify several paths; in this case, use the
|
|
Hashes to be checked against Kaspersky Threat Data Feeds. They can be MD5 hashes, SHA1 hashes, or SHA256 hashes; Log Scanner determines the type of a hash on the basis of its length. If several hashes are specified, they must be separated by space symbols. For example:
|
|
IP addresses to be checked against Kaspersky Threat Data Feeds. If several IP addresses are specified, they must be separated by space symbols. For example:
|
|
URLs to be checked against Kaspersky Threat Data Feeds. If several URLs are specified, they must be separated by space symbols. For example:
Do not use the |
If you specify none of the -p
, -s
, -u
, or -i
options, and specify only the value to check, this value will be treated as the path to the file or directory to be scanned.
The Log Scanner utility uses the current locale of the operating system.
Page topExamples of usage scenarios
This section contains examples of using Log Scanner in some situations.
Checking several log files
All log files that you pass for scanning must be in UTF-8 encoding. If your log files have a different encoding, make sure to convert them to UTF-8.
If you have feeds that are not compiled and a directory containing log files, you can check the log files by performing the following procedure.
To check several log files:
- In the Feed Service configuration file kl_feed_service.conf specify the feeds to be used, normalizing rules to process events in the log files, and regular expressions to parse events.
- Start Feed Service:
systemctl start cybertrace.service
(in LInux)%service_dir%\bin\kl_control.bat start
(in Windows) - Run the Log Scanner utility and specify the directory that contains log files. For example:
./log_scanner -r –p ../logs
(in Linux)log_scanner.exe -r –p ..\logs
(in Windows) - Stop Feed Service by running the following command:
systemctl stop cybertrace.service
%service_dir%\bin\kl_control.bat stop
(in Windows)
After Log Scanner finishes its work, the directory specified by the OutputDir
element of the log_scanner.conf configuration file will contain a report about the URLs and hashes detected by Feed Service.
Checking several URLs and hashes
If you have to check several URLs and hashes, perform the following procedure.
To check several URLs and hashes:
- Start Feed Service by running the following command:
systemctl start cybertrace.service
(in LInux)%service_dir%\bin\kl_control.bat start
(in Windows) - Run Log Scanner and specify the hashes to be checked. For example:
./log_scanner -r -s A72C5B99F2706B00718279C9533A3648 -s 6AA0321FA9D82D652AB53882D7CF9E592B4439B8
(in LInux)log_scanner.exe -r -s A72C5B99F2706B00718279C9533A3648 -s 6AA0321FA9D82D652AB53882D7CF9E592B4439B8
(in Windows) - Run Log Scanner and specify the URLs to be checked. For example:
./log_scanner -r –u test.mav.example.com?bad_url=1 -u test.phishing.example.com/psh/test?p=1&p=2
(in LInux)log_scanner.exe -r –u test.mav.example.com?bad_url=1 -u test.phishing.example.com/psh/test?p=1&p=2
(in Windows) - Stop Feed Service by running the following command:
systemctl stop cybertrace.service
(in LInux)%service_dir%\bin\kl_control.bat stop
(in Windows)
After Log Scanner finishes its work, the directory specified by the OutputDir
element of the log_scanner.conf configuration file will contain a report about the URLs detected by Feed Service and a report about the detected hashes.
Configuration file (Log Scanner)
The Log Scanner configuration file is an XML file that contains parameters described in the table below. If this file is not present in the directory or some parameters are not present in the file, the default values are used for the missing parameters.
Configuration file parameters
Parameter |
Description |
|
Affects the Log Scanner output to the console. If the value contained in the |
|
Maximum number of threads that Log Scanner can use when processing input data. By default, up to 8 threads are used. |
|
Directory that will contain the output file. It can be either an absolute or a relative path. A relative path is calculated relative to the directory that contains the Log Scanner binary file. If the |
|
The utility sends requests to Feed Service in the format specified in the
|
|
Specifies the IP address and port (or the Windows-named pipe, or UNIX socket) to which Log Scanner will send the received data.
|
|
Number of seconds that Log Scanner waits for the socket or pipe specified in the If the value of this parameter is The maximum value of this parameter that you can set is By default, the timeout is 15 seconds. |
Configuration file example
<Settings> <Verbose>0</Verbose> <ThreadsCount>8</ThreadsCount> <OutputDir>../log_scanner_reports</OutputDir> <Pattern>ip=%IP% md5=%MD5% sha1=%SHA1% sha256=%SHA256% url=%URL%</Pattern> <Connection>127.0.0.1:9999</Connection> <SocketTimeout>15</SocketTimeout> </Settings> |
Recommendations on using Log Scanner
We recommend that you use Feed Service together with Log Scanner in the following cases:
- You have to check some log files and save the check result to a file.
It can be useful while investigating information security incidents, when the SIEM solution you use is unavailable, or if you do not use any SIEM solution.
- You have to check some log files and send the check results to the SIEM solution used.
Configuring Feed Service and Log Scanner
Feed Service and Log Scanner must interact correctly, so their corresponding parameters must be set according to each other as follows:
- The port set in the
Settings > Connection
element of the Log Scanner configuration file must accord with the port specified in theInputSettings > ConnectionString
element of the Feed Service configuration file. - The number of threads specified in the
Settings > ThreadsCount
element of the Log Scanner configuration file must not be greater than that specified in theServiceSettings > ScannersCount
element of the Feed Service configuration file. If Feed Service runs in watchdog mode, the number of threads specified in theSettings > ThreadsCount
element of the Log Scanner configuration file must be less than that specified in theServiceSettings > ScannersCount
element of the Feed Service configuration file. - The data sent by Log Scanner to Feed Service—either lines of log files or strings created on the basis of the
Settings > Pattern
element of the Log Scanner configuration file—must be parseable by regular expressions specified in theConfiguration > InputSettings > RegExps
element of the Feed Service configuration file.
Configuration files examples
The following is an excerpt from a sample Feed Service configuration file.
<Configuration> <InputSettings> <RegExps> <Source id="default"> <!--You can use them in the OutputSettings->EventFormat string with the pattern %REGEXPNAME%--> ... <RE_MD5>md5=(.*?)(?:$|\s)</RE_MD5> <RE_SHA1>sha1=(.*?)(?:$|\s)</RE_SHA1> <RE_SHA256>sha256=(.*?)(?:$|\s)</RE_SHA256> <RE_URL>url=(.*?)(?:$|\s)</RE_URL> <RE_IP>ip=(.*?)(?:$|\s)</RE_IP> </Source> </RegExps> <ConnectionString>127.0.0.1:9999</ConnectionString> <!-- <ip>:<port>. Threat Feed Service listens for <ip>:<port>. <port> must be available --> </InputSettings>
<Feeds per_scan_detect_limit="10000">...</Feeds>
<OutputSettings> ... <FinishedEventFormat>LookupFinished</FinishedEventFormat> </OutputSettings>
<ServiceSettings> ... <ScannersCount>9</ScannersCount> <!-- 1 tcp connection = 1 scanner --> </ServiceSettings> </Configuration> |
The following is an excerpt from a Log Scanner configuration file that corresponds to the Feed Service configuration file provided above.
<Settings> ... <ThreadsCount>8</ThreadsCount> <Pattern>ip=%IP% md5=%MD5% sha1=%SHA1% sha256=%SHA256% url=%URL%</Pattern> <Connection>127.0.0.1:9999</Connection> </Settings> |
When using these configuration files, Log Scanner sends the requests to the IP address 127.0.0.1 and port 9999, and Feed Service listens on port 9999 for data to check. Both Log Scanner and Feed Service use up to 8 threads for transferring and processing data, and one thread is used by the watchdog module (in LInux) or watchdog service (in Windows). If correct URLs, IP addresses, and hashes are sent to Feed Service for checking, they will be successfully parsed by using the regular expressions specified in the Feed Service configuration file.
Managing check results
After data is checked by Feed Service, you can either send the check results to event target software or save them to a file:
- For sending check results to event target software, set the correct value of the
"OutputSettings
>ConnectionString"
element of the Feed Service configuration file. - For saving check results to a file, pass the
-r
option when running Log Scanner from the command line as follows:./log_scanner -r -p file_to_check
(in Linux)log_scanner.exe -r -p file_to_check
(in Windows)The value of the
enable
attribute of theOutputSettings > FinishedEventFormat
element in the Feed Service configuration file must not befalse
.
Report example
The report content depends on the value of the OutputSettings
> EventFormat
element of the Feed Service configuration file.
The following is an example of a report sent by Feed Service to Log Scanner.
- KL_Data_Feed_Service_v1 LEEF:1.0|Kaspersky Lab|SIEM Service|1.0|KL_Malicious_URL|url=malicious_domain_21.com/folder/load.php?| IP=91.202.63.117, 196.254.10.200, 194.190.253.19, 185.56.137.11, 178.62.5.157, 173.194.222.211, 159.253.145.183, 87.250.250.135, 82.145.209.252, 74.125.205.211 first_seen=11.01.2016 07:17 geo=ru, ua, kz, by, de, ro, az, cz, uz, md id=9491494 last_seen=14.01.2016 13:36 mask=malicious_domain_21.com/folder/load.php?* popularity=5 type=21 Total number of objects sent to KTFS: 1 Total number of detects received from KTFS: 1 Total scan time: 00:00:01.032 |