syslog2cef 0.1.0__tar.gz
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.
- syslog2cef-0.1.0/LICENSE +21 -0
- syslog2cef-0.1.0/PKG-INFO +202 -0
- syslog2cef-0.1.0/README.md +183 -0
- syslog2cef-0.1.0/pyproject.toml +42 -0
- syslog2cef-0.1.0/setup.cfg +4 -0
- syslog2cef-0.1.0/syslog2cef.egg-info/PKG-INFO +202 -0
- syslog2cef-0.1.0/syslog2cef.egg-info/SOURCES.txt +44 -0
- syslog2cef-0.1.0/syslog2cef.egg-info/dependency_links.txt +1 -0
- syslog2cef-0.1.0/syslog2cef.egg-info/entry_points.txt +2 -0
- syslog2cef-0.1.0/syslog2cef.egg-info/requires.txt +3 -0
- syslog2cef-0.1.0/syslog2cef.egg-info/top_level.txt +1 -0
- syslog2cef-0.1.0/syslogcef/__init__.py +19 -0
- syslog2cef-0.1.0/syslogcef/__main__.py +7 -0
- syslog2cef-0.1.0/syslogcef/api.py +127 -0
- syslog2cef-0.1.0/syslogcef/cef.py +103 -0
- syslog2cef-0.1.0/syslogcef/cli.py +136 -0
- syslog2cef-0.1.0/syslogcef/mappings/__init__.py +40 -0
- syslog2cef-0.1.0/syslogcef/mappings/cisco_asa.json +26 -0
- syslog2cef-0.1.0/syslogcef/mappings/cisco_ios.json +13 -0
- syslog2cef-0.1.0/syslogcef/mappings/f5.json +13 -0
- syslog2cef-0.1.0/syslogcef/mappings/linux.json +13 -0
- syslog2cef-0.1.0/syslogcef/mappings/vmware.json +12 -0
- syslog2cef-0.1.0/syslogcef/normalizer.py +106 -0
- syslog2cef-0.1.0/syslogcef/parsers.py +380 -0
- syslog2cef-0.1.0/syslogcef/utils.py +144 -0
- syslog2cef-0.1.0/tests/test_cef.py +64 -0
- syslog2cef-0.1.0/tests/test_cli.py +45 -0
- syslog2cef-0.1.0/tests/test_normalizer.py +49 -0
- syslog2cef-0.1.0/tests/test_parsers.py +56 -0
- syslog2cef-0.1.0/tests/test_parsers_extra.py +75 -0
- syslog2cef-0.1.0/tests/test_pipeline.py +52 -0
- syslog2cef-0.1.0/tests/test_utils.py +70 -0
syslog2cef-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Tamir Suliman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: syslog2cef
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Convert RFC3164/RFC5424 syslog lines into ArcSight CEF
|
|
5
|
+
Author-email: Tamir Suliman <allamiro@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/allamiro/syslogcef
|
|
7
|
+
Project-URL: Issues, https://github.com/allamiro/syslogcef/issues
|
|
8
|
+
Keywords: syslog,cef,logging,security
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Topic :: System :: Logging
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# syslogcef
|
|
21
|
+
|
|
22
|
+
syslogcef converts syslog events into ArcSight Common Event Format (CEF). It
|
|
23
|
+
is a small, dependency-free Python package with a command line interface,
|
|
24
|
+
built for feeding syslog data from network devices and Linux hosts into SIEM
|
|
25
|
+
platforms that consume CEF.
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- Automatic detection and parsing of multiple syslog dialects:
|
|
30
|
+
RFC3164 (BSD), RFC5424 (including structured data), rsyslog JSON and
|
|
31
|
+
file formats, and systemd journal exports (JSON, short, and ISO formats).
|
|
32
|
+
- Deterministic vendor/product mappings bundled for Cisco ASA, Cisco IOS,
|
|
33
|
+
F5 BIG-IP, generic Linux, and VMware ESXi, with automatic mapping
|
|
34
|
+
selection based on message content.
|
|
35
|
+
- Custom mappings supplied as JSON files or Python dictionaries.
|
|
36
|
+
- Escaping of untrusted log content in both CEF header and extension
|
|
37
|
+
fields, so crafted messages cannot forge header fields or split records.
|
|
38
|
+
- Streaming CLI with stdin/file input, tail (follow) mode across multiple
|
|
39
|
+
files, optional multiprocessing, and no runtime dependencies.
|
|
40
|
+
- Malformed lines never abort a stream: unparseable input falls back to a
|
|
41
|
+
raw-message event.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
From PyPI (the distribution is named `syslog2cef` because the `syslogcef`
|
|
46
|
+
name on PyPI belongs to an unrelated project; the import package and CLI
|
|
47
|
+
are still `syslogcef`):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install syslog2cef
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
From source:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/allamiro/syslogcef.git
|
|
57
|
+
cd syslogcef
|
|
58
|
+
pip install .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
An RPM package with a systemd service is also available from the GitHub
|
|
62
|
+
releases page; see "Running as a service" below.
|
|
63
|
+
|
|
64
|
+
## Command Line Usage
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Read from stdin, write CEF to stdout
|
|
68
|
+
syslogcef < /var/log/syslog
|
|
69
|
+
|
|
70
|
+
# Convert one or more files and write to an output file
|
|
71
|
+
syslogcef /var/log/messages /var/log/secure --output events.cef
|
|
72
|
+
|
|
73
|
+
# Follow files in real time (all files are tailed concurrently)
|
|
74
|
+
syslogcef /var/log/asa.log /var/log/messages --tail
|
|
75
|
+
|
|
76
|
+
# Force a parser and mapping instead of auto-detection
|
|
77
|
+
syslogcef asa.log --mode rfc3164 --mapping syslogcef/mappings/cisco_asa.json
|
|
78
|
+
|
|
79
|
+
# Use multiprocessing for high-volume batch conversion
|
|
80
|
+
syslogcef big.log --multiprocess --pool-size 4
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Options:
|
|
84
|
+
|
|
85
|
+
| Option | Description |
|
|
86
|
+
| ------ | ----------- |
|
|
87
|
+
| `paths` | Input files; stdin is used when omitted. |
|
|
88
|
+
| `-o, --output FILE` | Write CEF lines to a file instead of stdout. |
|
|
89
|
+
| `--mode MODE` | Parser override: `rfc3164`, `rfc5424`, `rsyslog_json`, `rsyslog_file`, `journald_json`, `journald_short`, `journald_iso`. Auto-detected when omitted. |
|
|
90
|
+
| `--mapping FILE` | Mapping JSON file. Auto-selected from message content when omitted. |
|
|
91
|
+
| `--tail` | Follow input files like `tail -f`. |
|
|
92
|
+
| `--multiprocess` | Convert lines using a process pool. |
|
|
93
|
+
| `--pool-size N` | Worker count for `--multiprocess` (default: CPU count minus one). |
|
|
94
|
+
| `--log-level LEVEL` | Python logging level (default `WARNING`). |
|
|
95
|
+
|
|
96
|
+
`python -m syslogcef` is equivalent to the `syslogcef` entry point.
|
|
97
|
+
|
|
98
|
+
## Python API
|
|
99
|
+
|
|
100
|
+
High-level, one call per line:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from syslogcef import convert_line
|
|
104
|
+
|
|
105
|
+
line = "<166>Jan 1 12:34:56 fw01 %ASA-6-302013: Built inbound TCP connection src=10.0.0.1 dst=10.0.0.2"
|
|
106
|
+
print(convert_line(line))
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Lower-level pipeline when granular control is required:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from syslogcef import parse_syslog, normalize_event, to_cef
|
|
113
|
+
|
|
114
|
+
parsed = parse_syslog(line) # ParsedEvent: pri, timestamp, host, app, msg, ...
|
|
115
|
+
normalized = normalize_event(parsed) # adds key/value pairs, event codes, derived fields
|
|
116
|
+
cef = to_cef(normalized, mapping="my_mapping.json")
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Bundled mappings are importable from `syslogcef.mappings` (`CISCO_ASA`,
|
|
120
|
+
`CISCO_IOS`, `F5`, `LINUX`, `VMWARE`, or `load_mapping(name)`).
|
|
121
|
+
|
|
122
|
+
## Mapping Files
|
|
123
|
+
|
|
124
|
+
A mapping is a JSON object that controls the CEF header and extension
|
|
125
|
+
fields. Values are Python %-format templates resolved against the
|
|
126
|
+
normalized event's fields:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"deviceVendor": "Cisco",
|
|
131
|
+
"deviceProduct": "ASA",
|
|
132
|
+
"deviceVersion": "auto",
|
|
133
|
+
"eventClassId": "asa.%(event_code)s",
|
|
134
|
+
"name": "%(message_short)s",
|
|
135
|
+
"severity_map": { "6": "2", "3": "6" },
|
|
136
|
+
"extensions": {
|
|
137
|
+
"src": "%(src)s",
|
|
138
|
+
"dst": "%(dst)s",
|
|
139
|
+
"cs1Label": "rawEvent",
|
|
140
|
+
"cs1": "%(raw_kv)s"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- Header keys: `deviceVendor`, `deviceProduct`, `deviceVersion`,
|
|
146
|
+
`eventClassId`, `name`.
|
|
147
|
+
- `severity_map` translates syslog severity (0-7) to CEF severity (0-10);
|
|
148
|
+
unmapped values pass through.
|
|
149
|
+
- `extensions` maps CEF extension keys to templates. Extensions that
|
|
150
|
+
resolve to an empty value are omitted.
|
|
151
|
+
- Available template fields include `host`, `app`, `pid`, `msgid`, `msg`,
|
|
152
|
+
`message_short` (first 120 characters), `raw`, `raw_kv`, `event_code`,
|
|
153
|
+
`facility`, `severity`, `ts`, plus every key=value pair extracted from
|
|
154
|
+
the message and any RFC5424 structured-data or journald fields.
|
|
155
|
+
|
|
156
|
+
Field templates that reference missing keys resolve to an empty string
|
|
157
|
+
rather than failing the event. See [docs/cef_fields.md](docs/cef_fields.md)
|
|
158
|
+
for the full CEF extension dictionary.
|
|
159
|
+
|
|
160
|
+
## Running as a Service
|
|
161
|
+
|
|
162
|
+
The RPM package installs a systemd unit and an environment file:
|
|
163
|
+
|
|
164
|
+
- `/etc/syslogcef/syslogcef.conf` — input file, output file, and extra
|
|
165
|
+
arguments for the converter.
|
|
166
|
+
- `syslogcef.service` — runs `syslogcef --tail` against the configured
|
|
167
|
+
input and appends CEF to the configured output.
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
sudo dnf install syslogcef-*.rpm
|
|
171
|
+
sudo vi /etc/syslogcef/syslogcef.conf
|
|
172
|
+
sudo systemctl enable --now syslogcef
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
See [packaging/rpm/](packaging/rpm/) for the spec file and build
|
|
176
|
+
instructions, including GPG signing of the RPM.
|
|
177
|
+
|
|
178
|
+
## Security
|
|
179
|
+
|
|
180
|
+
Log content is treated as untrusted input. Header and extension values are
|
|
181
|
+
escaped per the CEF specification before rendering, and CR/LF are removed
|
|
182
|
+
from header fields so records cannot be split or spoofed. To report a
|
|
183
|
+
vulnerability, see [SECURITY.md](SECURITY.md) — please do not open public
|
|
184
|
+
issues for security reports.
|
|
185
|
+
|
|
186
|
+
## Development
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
git clone https://github.com/allamiro/syslogcef.git
|
|
190
|
+
cd syslogcef
|
|
191
|
+
python -m venv .venv
|
|
192
|
+
source .venv/bin/activate
|
|
193
|
+
pip install -e .[test]
|
|
194
|
+
pytest
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Notable
|
|
198
|
+
changes are tracked in [CHANGELOG.md](CHANGELOG.md).
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT — see [LICENSE](LICENSE). Copyright (c) Tamir Suliman.
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# syslogcef
|
|
2
|
+
|
|
3
|
+
syslogcef converts syslog events into ArcSight Common Event Format (CEF). It
|
|
4
|
+
is a small, dependency-free Python package with a command line interface,
|
|
5
|
+
built for feeding syslog data from network devices and Linux hosts into SIEM
|
|
6
|
+
platforms that consume CEF.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Automatic detection and parsing of multiple syslog dialects:
|
|
11
|
+
RFC3164 (BSD), RFC5424 (including structured data), rsyslog JSON and
|
|
12
|
+
file formats, and systemd journal exports (JSON, short, and ISO formats).
|
|
13
|
+
- Deterministic vendor/product mappings bundled for Cisco ASA, Cisco IOS,
|
|
14
|
+
F5 BIG-IP, generic Linux, and VMware ESXi, with automatic mapping
|
|
15
|
+
selection based on message content.
|
|
16
|
+
- Custom mappings supplied as JSON files or Python dictionaries.
|
|
17
|
+
- Escaping of untrusted log content in both CEF header and extension
|
|
18
|
+
fields, so crafted messages cannot forge header fields or split records.
|
|
19
|
+
- Streaming CLI with stdin/file input, tail (follow) mode across multiple
|
|
20
|
+
files, optional multiprocessing, and no runtime dependencies.
|
|
21
|
+
- Malformed lines never abort a stream: unparseable input falls back to a
|
|
22
|
+
raw-message event.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
From PyPI (the distribution is named `syslog2cef` because the `syslogcef`
|
|
27
|
+
name on PyPI belongs to an unrelated project; the import package and CLI
|
|
28
|
+
are still `syslogcef`):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install syslog2cef
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
From source:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/allamiro/syslogcef.git
|
|
38
|
+
cd syslogcef
|
|
39
|
+
pip install .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
An RPM package with a systemd service is also available from the GitHub
|
|
43
|
+
releases page; see "Running as a service" below.
|
|
44
|
+
|
|
45
|
+
## Command Line Usage
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Read from stdin, write CEF to stdout
|
|
49
|
+
syslogcef < /var/log/syslog
|
|
50
|
+
|
|
51
|
+
# Convert one or more files and write to an output file
|
|
52
|
+
syslogcef /var/log/messages /var/log/secure --output events.cef
|
|
53
|
+
|
|
54
|
+
# Follow files in real time (all files are tailed concurrently)
|
|
55
|
+
syslogcef /var/log/asa.log /var/log/messages --tail
|
|
56
|
+
|
|
57
|
+
# Force a parser and mapping instead of auto-detection
|
|
58
|
+
syslogcef asa.log --mode rfc3164 --mapping syslogcef/mappings/cisco_asa.json
|
|
59
|
+
|
|
60
|
+
# Use multiprocessing for high-volume batch conversion
|
|
61
|
+
syslogcef big.log --multiprocess --pool-size 4
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Options:
|
|
65
|
+
|
|
66
|
+
| Option | Description |
|
|
67
|
+
| ------ | ----------- |
|
|
68
|
+
| `paths` | Input files; stdin is used when omitted. |
|
|
69
|
+
| `-o, --output FILE` | Write CEF lines to a file instead of stdout. |
|
|
70
|
+
| `--mode MODE` | Parser override: `rfc3164`, `rfc5424`, `rsyslog_json`, `rsyslog_file`, `journald_json`, `journald_short`, `journald_iso`. Auto-detected when omitted. |
|
|
71
|
+
| `--mapping FILE` | Mapping JSON file. Auto-selected from message content when omitted. |
|
|
72
|
+
| `--tail` | Follow input files like `tail -f`. |
|
|
73
|
+
| `--multiprocess` | Convert lines using a process pool. |
|
|
74
|
+
| `--pool-size N` | Worker count for `--multiprocess` (default: CPU count minus one). |
|
|
75
|
+
| `--log-level LEVEL` | Python logging level (default `WARNING`). |
|
|
76
|
+
|
|
77
|
+
`python -m syslogcef` is equivalent to the `syslogcef` entry point.
|
|
78
|
+
|
|
79
|
+
## Python API
|
|
80
|
+
|
|
81
|
+
High-level, one call per line:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from syslogcef import convert_line
|
|
85
|
+
|
|
86
|
+
line = "<166>Jan 1 12:34:56 fw01 %ASA-6-302013: Built inbound TCP connection src=10.0.0.1 dst=10.0.0.2"
|
|
87
|
+
print(convert_line(line))
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Lower-level pipeline when granular control is required:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from syslogcef import parse_syslog, normalize_event, to_cef
|
|
94
|
+
|
|
95
|
+
parsed = parse_syslog(line) # ParsedEvent: pri, timestamp, host, app, msg, ...
|
|
96
|
+
normalized = normalize_event(parsed) # adds key/value pairs, event codes, derived fields
|
|
97
|
+
cef = to_cef(normalized, mapping="my_mapping.json")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Bundled mappings are importable from `syslogcef.mappings` (`CISCO_ASA`,
|
|
101
|
+
`CISCO_IOS`, `F5`, `LINUX`, `VMWARE`, or `load_mapping(name)`).
|
|
102
|
+
|
|
103
|
+
## Mapping Files
|
|
104
|
+
|
|
105
|
+
A mapping is a JSON object that controls the CEF header and extension
|
|
106
|
+
fields. Values are Python %-format templates resolved against the
|
|
107
|
+
normalized event's fields:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"deviceVendor": "Cisco",
|
|
112
|
+
"deviceProduct": "ASA",
|
|
113
|
+
"deviceVersion": "auto",
|
|
114
|
+
"eventClassId": "asa.%(event_code)s",
|
|
115
|
+
"name": "%(message_short)s",
|
|
116
|
+
"severity_map": { "6": "2", "3": "6" },
|
|
117
|
+
"extensions": {
|
|
118
|
+
"src": "%(src)s",
|
|
119
|
+
"dst": "%(dst)s",
|
|
120
|
+
"cs1Label": "rawEvent",
|
|
121
|
+
"cs1": "%(raw_kv)s"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- Header keys: `deviceVendor`, `deviceProduct`, `deviceVersion`,
|
|
127
|
+
`eventClassId`, `name`.
|
|
128
|
+
- `severity_map` translates syslog severity (0-7) to CEF severity (0-10);
|
|
129
|
+
unmapped values pass through.
|
|
130
|
+
- `extensions` maps CEF extension keys to templates. Extensions that
|
|
131
|
+
resolve to an empty value are omitted.
|
|
132
|
+
- Available template fields include `host`, `app`, `pid`, `msgid`, `msg`,
|
|
133
|
+
`message_short` (first 120 characters), `raw`, `raw_kv`, `event_code`,
|
|
134
|
+
`facility`, `severity`, `ts`, plus every key=value pair extracted from
|
|
135
|
+
the message and any RFC5424 structured-data or journald fields.
|
|
136
|
+
|
|
137
|
+
Field templates that reference missing keys resolve to an empty string
|
|
138
|
+
rather than failing the event. See [docs/cef_fields.md](docs/cef_fields.md)
|
|
139
|
+
for the full CEF extension dictionary.
|
|
140
|
+
|
|
141
|
+
## Running as a Service
|
|
142
|
+
|
|
143
|
+
The RPM package installs a systemd unit and an environment file:
|
|
144
|
+
|
|
145
|
+
- `/etc/syslogcef/syslogcef.conf` — input file, output file, and extra
|
|
146
|
+
arguments for the converter.
|
|
147
|
+
- `syslogcef.service` — runs `syslogcef --tail` against the configured
|
|
148
|
+
input and appends CEF to the configured output.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
sudo dnf install syslogcef-*.rpm
|
|
152
|
+
sudo vi /etc/syslogcef/syslogcef.conf
|
|
153
|
+
sudo systemctl enable --now syslogcef
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
See [packaging/rpm/](packaging/rpm/) for the spec file and build
|
|
157
|
+
instructions, including GPG signing of the RPM.
|
|
158
|
+
|
|
159
|
+
## Security
|
|
160
|
+
|
|
161
|
+
Log content is treated as untrusted input. Header and extension values are
|
|
162
|
+
escaped per the CEF specification before rendering, and CR/LF are removed
|
|
163
|
+
from header fields so records cannot be split or spoofed. To report a
|
|
164
|
+
vulnerability, see [SECURITY.md](SECURITY.md) — please do not open public
|
|
165
|
+
issues for security reports.
|
|
166
|
+
|
|
167
|
+
## Development
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
git clone https://github.com/allamiro/syslogcef.git
|
|
171
|
+
cd syslogcef
|
|
172
|
+
python -m venv .venv
|
|
173
|
+
source .venv/bin/activate
|
|
174
|
+
pip install -e .[test]
|
|
175
|
+
pytest
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Notable
|
|
179
|
+
changes are tracked in [CHANGELOG.md](CHANGELOG.md).
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT — see [LICENSE](LICENSE). Copyright (c) Tamir Suliman.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=65", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "syslog2cef"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Convert RFC3164/RFC5424 syslog lines into ArcSight CEF"
|
|
9
|
+
authors = [{name = "Tamir Suliman", email = "allamiro@gmail.com"}]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Topic :: System :: Logging",
|
|
17
|
+
]
|
|
18
|
+
keywords = ["syslog", "cef", "logging", "security"]
|
|
19
|
+
dependencies = []
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/allamiro/syslogcef"
|
|
23
|
+
Issues = "https://github.com/allamiro/syslogcef/issues"
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
test = [
|
|
27
|
+
"pytest>=7",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
syslogcef = "syslogcef.cli:main"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools]
|
|
34
|
+
package-dir = {"" = "."}
|
|
35
|
+
packages = ["syslogcef", "syslogcef.mappings"]
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.package-data]
|
|
38
|
+
syslogcef = ["mappings/*.json"]
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
addopts = "-ra"
|
|
42
|
+
pythonpath = ["."]
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: syslog2cef
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Convert RFC3164/RFC5424 syslog lines into ArcSight CEF
|
|
5
|
+
Author-email: Tamir Suliman <allamiro@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/allamiro/syslogcef
|
|
7
|
+
Project-URL: Issues, https://github.com/allamiro/syslogcef/issues
|
|
8
|
+
Keywords: syslog,cef,logging,security
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Topic :: System :: Logging
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# syslogcef
|
|
21
|
+
|
|
22
|
+
syslogcef converts syslog events into ArcSight Common Event Format (CEF). It
|
|
23
|
+
is a small, dependency-free Python package with a command line interface,
|
|
24
|
+
built for feeding syslog data from network devices and Linux hosts into SIEM
|
|
25
|
+
platforms that consume CEF.
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- Automatic detection and parsing of multiple syslog dialects:
|
|
30
|
+
RFC3164 (BSD), RFC5424 (including structured data), rsyslog JSON and
|
|
31
|
+
file formats, and systemd journal exports (JSON, short, and ISO formats).
|
|
32
|
+
- Deterministic vendor/product mappings bundled for Cisco ASA, Cisco IOS,
|
|
33
|
+
F5 BIG-IP, generic Linux, and VMware ESXi, with automatic mapping
|
|
34
|
+
selection based on message content.
|
|
35
|
+
- Custom mappings supplied as JSON files or Python dictionaries.
|
|
36
|
+
- Escaping of untrusted log content in both CEF header and extension
|
|
37
|
+
fields, so crafted messages cannot forge header fields or split records.
|
|
38
|
+
- Streaming CLI with stdin/file input, tail (follow) mode across multiple
|
|
39
|
+
files, optional multiprocessing, and no runtime dependencies.
|
|
40
|
+
- Malformed lines never abort a stream: unparseable input falls back to a
|
|
41
|
+
raw-message event.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
From PyPI (the distribution is named `syslog2cef` because the `syslogcef`
|
|
46
|
+
name on PyPI belongs to an unrelated project; the import package and CLI
|
|
47
|
+
are still `syslogcef`):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install syslog2cef
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
From source:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/allamiro/syslogcef.git
|
|
57
|
+
cd syslogcef
|
|
58
|
+
pip install .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
An RPM package with a systemd service is also available from the GitHub
|
|
62
|
+
releases page; see "Running as a service" below.
|
|
63
|
+
|
|
64
|
+
## Command Line Usage
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Read from stdin, write CEF to stdout
|
|
68
|
+
syslogcef < /var/log/syslog
|
|
69
|
+
|
|
70
|
+
# Convert one or more files and write to an output file
|
|
71
|
+
syslogcef /var/log/messages /var/log/secure --output events.cef
|
|
72
|
+
|
|
73
|
+
# Follow files in real time (all files are tailed concurrently)
|
|
74
|
+
syslogcef /var/log/asa.log /var/log/messages --tail
|
|
75
|
+
|
|
76
|
+
# Force a parser and mapping instead of auto-detection
|
|
77
|
+
syslogcef asa.log --mode rfc3164 --mapping syslogcef/mappings/cisco_asa.json
|
|
78
|
+
|
|
79
|
+
# Use multiprocessing for high-volume batch conversion
|
|
80
|
+
syslogcef big.log --multiprocess --pool-size 4
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Options:
|
|
84
|
+
|
|
85
|
+
| Option | Description |
|
|
86
|
+
| ------ | ----------- |
|
|
87
|
+
| `paths` | Input files; stdin is used when omitted. |
|
|
88
|
+
| `-o, --output FILE` | Write CEF lines to a file instead of stdout. |
|
|
89
|
+
| `--mode MODE` | Parser override: `rfc3164`, `rfc5424`, `rsyslog_json`, `rsyslog_file`, `journald_json`, `journald_short`, `journald_iso`. Auto-detected when omitted. |
|
|
90
|
+
| `--mapping FILE` | Mapping JSON file. Auto-selected from message content when omitted. |
|
|
91
|
+
| `--tail` | Follow input files like `tail -f`. |
|
|
92
|
+
| `--multiprocess` | Convert lines using a process pool. |
|
|
93
|
+
| `--pool-size N` | Worker count for `--multiprocess` (default: CPU count minus one). |
|
|
94
|
+
| `--log-level LEVEL` | Python logging level (default `WARNING`). |
|
|
95
|
+
|
|
96
|
+
`python -m syslogcef` is equivalent to the `syslogcef` entry point.
|
|
97
|
+
|
|
98
|
+
## Python API
|
|
99
|
+
|
|
100
|
+
High-level, one call per line:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from syslogcef import convert_line
|
|
104
|
+
|
|
105
|
+
line = "<166>Jan 1 12:34:56 fw01 %ASA-6-302013: Built inbound TCP connection src=10.0.0.1 dst=10.0.0.2"
|
|
106
|
+
print(convert_line(line))
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Lower-level pipeline when granular control is required:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from syslogcef import parse_syslog, normalize_event, to_cef
|
|
113
|
+
|
|
114
|
+
parsed = parse_syslog(line) # ParsedEvent: pri, timestamp, host, app, msg, ...
|
|
115
|
+
normalized = normalize_event(parsed) # adds key/value pairs, event codes, derived fields
|
|
116
|
+
cef = to_cef(normalized, mapping="my_mapping.json")
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Bundled mappings are importable from `syslogcef.mappings` (`CISCO_ASA`,
|
|
120
|
+
`CISCO_IOS`, `F5`, `LINUX`, `VMWARE`, or `load_mapping(name)`).
|
|
121
|
+
|
|
122
|
+
## Mapping Files
|
|
123
|
+
|
|
124
|
+
A mapping is a JSON object that controls the CEF header and extension
|
|
125
|
+
fields. Values are Python %-format templates resolved against the
|
|
126
|
+
normalized event's fields:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"deviceVendor": "Cisco",
|
|
131
|
+
"deviceProduct": "ASA",
|
|
132
|
+
"deviceVersion": "auto",
|
|
133
|
+
"eventClassId": "asa.%(event_code)s",
|
|
134
|
+
"name": "%(message_short)s",
|
|
135
|
+
"severity_map": { "6": "2", "3": "6" },
|
|
136
|
+
"extensions": {
|
|
137
|
+
"src": "%(src)s",
|
|
138
|
+
"dst": "%(dst)s",
|
|
139
|
+
"cs1Label": "rawEvent",
|
|
140
|
+
"cs1": "%(raw_kv)s"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- Header keys: `deviceVendor`, `deviceProduct`, `deviceVersion`,
|
|
146
|
+
`eventClassId`, `name`.
|
|
147
|
+
- `severity_map` translates syslog severity (0-7) to CEF severity (0-10);
|
|
148
|
+
unmapped values pass through.
|
|
149
|
+
- `extensions` maps CEF extension keys to templates. Extensions that
|
|
150
|
+
resolve to an empty value are omitted.
|
|
151
|
+
- Available template fields include `host`, `app`, `pid`, `msgid`, `msg`,
|
|
152
|
+
`message_short` (first 120 characters), `raw`, `raw_kv`, `event_code`,
|
|
153
|
+
`facility`, `severity`, `ts`, plus every key=value pair extracted from
|
|
154
|
+
the message and any RFC5424 structured-data or journald fields.
|
|
155
|
+
|
|
156
|
+
Field templates that reference missing keys resolve to an empty string
|
|
157
|
+
rather than failing the event. See [docs/cef_fields.md](docs/cef_fields.md)
|
|
158
|
+
for the full CEF extension dictionary.
|
|
159
|
+
|
|
160
|
+
## Running as a Service
|
|
161
|
+
|
|
162
|
+
The RPM package installs a systemd unit and an environment file:
|
|
163
|
+
|
|
164
|
+
- `/etc/syslogcef/syslogcef.conf` — input file, output file, and extra
|
|
165
|
+
arguments for the converter.
|
|
166
|
+
- `syslogcef.service` — runs `syslogcef --tail` against the configured
|
|
167
|
+
input and appends CEF to the configured output.
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
sudo dnf install syslogcef-*.rpm
|
|
171
|
+
sudo vi /etc/syslogcef/syslogcef.conf
|
|
172
|
+
sudo systemctl enable --now syslogcef
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
See [packaging/rpm/](packaging/rpm/) for the spec file and build
|
|
176
|
+
instructions, including GPG signing of the RPM.
|
|
177
|
+
|
|
178
|
+
## Security
|
|
179
|
+
|
|
180
|
+
Log content is treated as untrusted input. Header and extension values are
|
|
181
|
+
escaped per the CEF specification before rendering, and CR/LF are removed
|
|
182
|
+
from header fields so records cannot be split or spoofed. To report a
|
|
183
|
+
vulnerability, see [SECURITY.md](SECURITY.md) — please do not open public
|
|
184
|
+
issues for security reports.
|
|
185
|
+
|
|
186
|
+
## Development
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
git clone https://github.com/allamiro/syslogcef.git
|
|
190
|
+
cd syslogcef
|
|
191
|
+
python -m venv .venv
|
|
192
|
+
source .venv/bin/activate
|
|
193
|
+
pip install -e .[test]
|
|
194
|
+
pytest
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Notable
|
|
198
|
+
changes are tracked in [CHANGELOG.md](CHANGELOG.md).
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT — see [LICENSE](LICENSE). Copyright (c) Tamir Suliman.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
./syslogcef/__init__.py
|
|
5
|
+
./syslogcef/__main__.py
|
|
6
|
+
./syslogcef/api.py
|
|
7
|
+
./syslogcef/cef.py
|
|
8
|
+
./syslogcef/cli.py
|
|
9
|
+
./syslogcef/normalizer.py
|
|
10
|
+
./syslogcef/parsers.py
|
|
11
|
+
./syslogcef/utils.py
|
|
12
|
+
./syslogcef/mappings/__init__.py
|
|
13
|
+
./syslogcef/mappings/cisco_asa.json
|
|
14
|
+
./syslogcef/mappings/cisco_ios.json
|
|
15
|
+
./syslogcef/mappings/f5.json
|
|
16
|
+
./syslogcef/mappings/linux.json
|
|
17
|
+
./syslogcef/mappings/vmware.json
|
|
18
|
+
syslog2cef.egg-info/PKG-INFO
|
|
19
|
+
syslog2cef.egg-info/SOURCES.txt
|
|
20
|
+
syslog2cef.egg-info/dependency_links.txt
|
|
21
|
+
syslog2cef.egg-info/entry_points.txt
|
|
22
|
+
syslog2cef.egg-info/requires.txt
|
|
23
|
+
syslog2cef.egg-info/top_level.txt
|
|
24
|
+
syslogcef/__init__.py
|
|
25
|
+
syslogcef/__main__.py
|
|
26
|
+
syslogcef/api.py
|
|
27
|
+
syslogcef/cef.py
|
|
28
|
+
syslogcef/cli.py
|
|
29
|
+
syslogcef/normalizer.py
|
|
30
|
+
syslogcef/parsers.py
|
|
31
|
+
syslogcef/utils.py
|
|
32
|
+
syslogcef/mappings/__init__.py
|
|
33
|
+
syslogcef/mappings/cisco_asa.json
|
|
34
|
+
syslogcef/mappings/cisco_ios.json
|
|
35
|
+
syslogcef/mappings/f5.json
|
|
36
|
+
syslogcef/mappings/linux.json
|
|
37
|
+
syslogcef/mappings/vmware.json
|
|
38
|
+
tests/test_cef.py
|
|
39
|
+
tests/test_cli.py
|
|
40
|
+
tests/test_normalizer.py
|
|
41
|
+
tests/test_parsers.py
|
|
42
|
+
tests/test_parsers_extra.py
|
|
43
|
+
tests/test_pipeline.py
|
|
44
|
+
tests/test_utils.py
|