Refactor copyparty and npm analyzers to use updated imports and remove utils module
Update whois cache with additional IP ranges
This commit is contained in:
1 parent
0e2c69579a
commit
40212d84f7
4 files changed
+36
-258
No files matched your search
@@ -12,8 +12,12 @@ import os
|
||||
import re
|
||||
from collections import Counter
|
||||
|
||||
import utils
|
||||
from utils import Request
|
||||
from analyzer import Analyzer
|
||||
from files import write_csv
|
||||
from flags import flag_scanners
|
||||
from models import Request
|
||||
from utils import arg_parser
|
||||
|
||||
|
||||
DEFAULT_LOG_PATH = os.environ.get("NPM_LOG_PATH", r"Y:\npm\logs")
|
||||
DEFAULT_REPORT_DIR = os.path.join(
|
||||
@@ -40,7 +44,7 @@ LINE_RE = re.compile(
|
||||
)
|
||||
|
||||
|
||||
class NpmAnalyzer(utils.Analyzer):
|
||||
class NpmAnalyzer(Analyzer):
|
||||
name = "npm"
|
||||
title = "Nginx Proxy Manager log analysis report"
|
||||
log_suffixes = (".log", ".gz")
|
||||
@@ -112,8 +116,8 @@ class NpmAnalyzer(utils.Analyzer):
|
||||
# --- flagging ----------------------------------------------------------
|
||||
|
||||
def flag(self, stats):
|
||||
return utils.flag_scanners(stats, min_errors=self.min_errors,
|
||||
min_ratio=self.min_ratio)
|
||||
return flag_scanners(stats, min_errors=self.min_errors,
|
||||
min_ratio=self.min_ratio)
|
||||
|
||||
# --- extras ------------------------------------------------------------
|
||||
|
||||
@@ -131,15 +135,15 @@ class NpmAnalyzer(utils.Analyzer):
|
||||
uas = Counter(r.ua for r in self.requests if r.ua and r.ua != "-")
|
||||
hosts = Counter(r.host for r in self.requests if r.host)
|
||||
return [
|
||||
utils.write_csv(os.path.join(data_dir, "ua_summary.csv"),
|
||||
["user_agent", "count"], uas.most_common()),
|
||||
utils.write_csv(os.path.join(data_dir, "host_summary.csv"),
|
||||
["host", "count"], hosts.most_common()),
|
||||
write_csv(os.path.join(data_dir, "ua_summary.csv"),
|
||||
["user_agent", "count"], uas.most_common()),
|
||||
write_csv(os.path.join(data_dir, "host_summary.csv"),
|
||||
["host", "count"], hosts.most_common()),
|
||||
]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = utils.arg_parser(
|
||||
parser = arg_parser(
|
||||
"analyze NPM proxy logs, flag scanner IPs, export MikroTik rules",
|
||||
DEFAULT_LOG_PATH, DEFAULT_REPORT_DIR)
|
||||
parser.add_argument("--min-errors", type=int, default=5,
|
||||
|
||||
Reference in new issue
Block a user