weblogchecker 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- weblogchecker/__init__.py +11 -0
- weblogchecker/__main__.py +114 -0
- weblogchecker/analyze.py +822 -0
- weblogchecker/data/log_iocs.json +42 -0
- weblogchecker/indicators.py +213 -0
- weblogchecker/render.py +100 -0
- weblogchecker-0.2.2.dist-info/METADATA +177 -0
- weblogchecker-0.2.2.dist-info/RECORD +12 -0
- weblogchecker-0.2.2.dist-info/WHEEL +5 -0
- weblogchecker-0.2.2.dist-info/entry_points.txt +2 -0
- weblogchecker-0.2.2.dist-info/licenses/LICENSE +23 -0
- weblogchecker-0.2.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""weblogchecker - access-log compromise analyzer.
|
|
2
|
+
|
|
3
|
+
Reads Apache / nginx access logs the user owns and reports
|
|
4
|
+
compromise indicators (webshell interactions, exploitation
|
|
5
|
+
patterns, brute-force bursts) with severity, confidence and
|
|
6
|
+
remediation for every finding class. Strictly read-only:
|
|
7
|
+
weblogchecker never opens a network connection and never modifies
|
|
8
|
+
the logs it analyzes.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "0.2.2"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Command-line interface for weblogchecker.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
weblogchecker analyze <access.log> [--since YYYY-MM-DD]
|
|
5
|
+
[--baseline <older.log>]
|
|
6
|
+
[--format text|json]
|
|
7
|
+
|
|
8
|
+
Exit codes: 0 = no indicators found, 1 = indicators found,
|
|
9
|
+
2 = usage error (bad arguments, unreadable file).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import json
|
|
14
|
+
import sys
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
|
|
17
|
+
from . import __version__
|
|
18
|
+
from .analyze import Analyzer, collect_baseline, open_log
|
|
19
|
+
from .render import render_text
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _parse_since(text):
|
|
23
|
+
try:
|
|
24
|
+
return datetime.strptime(text, "%Y-%m-%d").date()
|
|
25
|
+
except ValueError:
|
|
26
|
+
raise argparse.ArgumentTypeError(
|
|
27
|
+
"--since must be a date as YYYY-MM-DD, got %r" % text)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def build_parser():
|
|
31
|
+
parser = argparse.ArgumentParser(
|
|
32
|
+
prog="weblogchecker",
|
|
33
|
+
description="Analyze web server access logs you own for "
|
|
34
|
+
"compromise indicators (webshell interactions, "
|
|
35
|
+
"exploitation patterns, brute-force bursts). "
|
|
36
|
+
"Read-only; reports indicators with confidence "
|
|
37
|
+
"levels, never verdicts of compromise.")
|
|
38
|
+
parser.add_argument("--version", action="version",
|
|
39
|
+
version="%(prog)s " + __version__)
|
|
40
|
+
sub = parser.add_subparsers(dest="command")
|
|
41
|
+
analyze = sub.add_parser(
|
|
42
|
+
"analyze", help="analyze an access log file ('-' for stdin, "
|
|
43
|
+
".gz files are decompressed automatically)")
|
|
44
|
+
analyze.add_argument("logfile")
|
|
45
|
+
analyze.add_argument("--since", type=_parse_since, default=None,
|
|
46
|
+
metavar="YYYY-MM-DD",
|
|
47
|
+
help="only analyze entries on/after this date")
|
|
48
|
+
analyze.add_argument("--baseline", default=None,
|
|
49
|
+
metavar="LOGFILE",
|
|
50
|
+
help="trusted older access log: report "
|
|
51
|
+
"executable paths that appear for the "
|
|
52
|
+
"first time versus it, scored on "
|
|
53
|
+
"stacked weak signals")
|
|
54
|
+
analyze.add_argument("--format", choices=("text", "json"),
|
|
55
|
+
default="text")
|
|
56
|
+
return parser
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def main(argv=None):
|
|
60
|
+
parser = build_parser()
|
|
61
|
+
args = parser.parse_args(argv)
|
|
62
|
+
if args.command != "analyze":
|
|
63
|
+
parser.print_help(sys.stderr)
|
|
64
|
+
return 2
|
|
65
|
+
baseline_paths = None
|
|
66
|
+
if args.baseline is not None:
|
|
67
|
+
if args.baseline == "-" and args.logfile == "-":
|
|
68
|
+
print("weblogchecker: --baseline and the analyzed log "
|
|
69
|
+
"cannot both be stdin", file=sys.stderr)
|
|
70
|
+
return 2
|
|
71
|
+
try:
|
|
72
|
+
baseline_stream = open_log(args.baseline)
|
|
73
|
+
except OSError as exc:
|
|
74
|
+
print("weblogchecker: cannot open baseline %s: %s"
|
|
75
|
+
% (args.baseline, exc), file=sys.stderr)
|
|
76
|
+
return 2
|
|
77
|
+
try:
|
|
78
|
+
with baseline_stream:
|
|
79
|
+
baseline_paths, _ = collect_baseline(baseline_stream)
|
|
80
|
+
except OSError as exc:
|
|
81
|
+
print("weblogchecker: error reading baseline %s: %s"
|
|
82
|
+
% (args.baseline, exc), file=sys.stderr)
|
|
83
|
+
return 2
|
|
84
|
+
try:
|
|
85
|
+
stream = open_log(args.logfile)
|
|
86
|
+
except OSError as exc:
|
|
87
|
+
print("weblogchecker: cannot open %s: %s"
|
|
88
|
+
% (args.logfile, exc), file=sys.stderr)
|
|
89
|
+
return 2
|
|
90
|
+
analyzer = Analyzer(since=args.since,
|
|
91
|
+
baseline_paths=baseline_paths,
|
|
92
|
+
baseline_name=args.baseline)
|
|
93
|
+
try:
|
|
94
|
+
with stream:
|
|
95
|
+
analyzer.run(stream)
|
|
96
|
+
except OSError as exc:
|
|
97
|
+
print("weblogchecker: error reading %s: %s"
|
|
98
|
+
% (args.logfile, exc), file=sys.stderr)
|
|
99
|
+
return 2
|
|
100
|
+
report = analyzer.report(args.logfile, __version__)
|
|
101
|
+
if args.format == "json":
|
|
102
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
103
|
+
else:
|
|
104
|
+
sys.stdout.write(render_text(report))
|
|
105
|
+
return 1 if report["findings"] else 0
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def cli():
|
|
109
|
+
"""Console-script entry point."""
|
|
110
|
+
sys.exit(main())
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if __name__ == "__main__":
|
|
114
|
+
cli()
|