Skip to content

Commit 5836b7c

Browse files
authored
Merge pull request #14 from SimonCahill/feat/detailed-reports-bugfix
Feat/detailed reports bugfix
2 parents cc1295f + c735628 commit 5836b7c

File tree

4 files changed

+116
-78
lines changed

4 files changed

+116
-78
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ unique_ids
3232
*.exe
3333
*.out
3434
*.app
35+
endlessh-report
36+
endlessh-report-debug
37+
38+
# Documentation
39+
html/
40+
41+
# VS Code logs
42+
.vscode/*.log

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
###############################################
2+
## Simple Makefile for Endlessh Report Gen ##
3+
## ©️ Simon Cahill 2022 ##
4+
###############################################
5+
6+
.PHONY: endlessh-report all clean install docs
7+
.SILENT: debug clean docs
8+
9+
endlessh-report: main.cpp
10+
${CXX} -s -O2 -o $@ $^
11+
12+
endlessh-report-debug: main.cpp
13+
${CXX} -O0 -ggdb -o $@ $^
14+
15+
debug: endlessh-report-debug
16+
ls -lah $^
17+
18+
release: endlessh-report
19+
ls -lah $^
20+
21+
all: endlessh-report endlessh-report-debug docs
22+
23+
clean:
24+
rm -Rfv *.o endlessh-report endlessh-report-debug
25+
26+
docs:
27+
doxygen Doxyfile
28+
29+
install: endlessh-report
30+
cp -v $^ /usr/local/bin/

README.md

Lines changed: 72 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,41 @@
22
(Very) simple and rudimentary C++ program that reads /var/log/syslog, filters out endlessh logs and determines basic stats, such as unique IDs, total accepted and closed connections.
33

44
# Building
5-
As a one-file project, I didn't see the need to create a Makefile. <br >
65
This will only work on Linux systems.
76

87
```bash
9-
g++ -std=c++17 -o endlessh-report main.cpp
8+
# build docs
9+
make docs
10+
11+
# build debug
12+
make debug
13+
14+
# build release
15+
make
16+
17+
# build all
18+
make all
19+
20+
# clean repo
21+
make clean
1022
```
1123

1224
# Installing
1325
After building the software, either move or copy it to /usr/local/bin, or add the build path to your local $PATH environment variable.
1426

27+
## System-wide installation
28+
```bash
29+
# install to /usr/local/bin
30+
sudo make install
31+
```
32+
33+
## User-specific install
1534
```bash
16-
sudo cp endlessh-report /usr/local/bin/endlessh-report # copy to global path
17-
sudo mv endlessh-report /usr/local/bin/endlessh-report # move to global path
35+
# ensure local bin-dir exists
36+
mkdir -p ~/.local/bin || >&2 echo "Failed to create local bin dir!"
37+
cp -v endlessh-report ~/.local/bin/
1838

19-
# in ~/.bashrc:
20-
export PATH="/path/to/repo:$PATH"
39+
echo "export PATH=\"$(realpath ~)/.local/bin:\$PATH\"" | tee -a ~/.bashrc
2140
```
2241

2342
# Usage
@@ -26,6 +45,8 @@ After building, simply call:
2645

2746
```bash
2847
./endlessh-report
48+
# or
49+
endlessh-report
2950
```
3051

3152
## Arguments
@@ -41,6 +62,7 @@ Switches:
4162
--stdin Read logs from stdin
4263
--abuse-ipdb, -a Enable AbuseIPDB-compatible CSV output
4364
--no-ad, -n No advertising please!
65+
--detailed, -d Provide detailed information.
4466
--help, -h Prints this message and exits
4567
Arguments:
4668
--syslog </path/to> Override default syslog path (/var/log/syslog)
@@ -88,41 +110,6 @@ Resulting in:
88110
| ::ffff:112.85.42.88 | 14 | 14 |
89111
| ::ffff:122.194.229.40 | 20 | 20 |
90112
| ::ffff:122.194.229.45 | 19 | 19 |
91-
| ::ffff:141.98.10.63 | 32 | 32 |
92-
| ::ffff:141.98.11.16 | 28 | 28 |
93-
| ::ffff:198.98.62.88 | 1 | 0 |
94-
| ::ffff:209.141.43.186 | 13 | 13 |
95-
| ::ffff:221.131.165.33 | 12 | 12 |
96-
| ::ffff:221.131.165.50 | 12 | 12 |
97-
| ::ffff:221.131.165.56 | 16 | 16 |
98-
| ::ffff:221.131.165.62 | 12 | 12 |
99-
| ::ffff:221.131.165.65 | 10 | 10 |
100-
| ::ffff:221.131.165.75 | 26 | 25 |
101-
| ::ffff:221.181.185.111 | 14 | 14 |
102-
| ::ffff:221.181.185.143 | 25 | 25 |
103-
| ::ffff:221.181.185.151 | 10 | 9 |
104-
| ::ffff:221.181.185.159 | 33 | 32 |
105-
| ::ffff:221.181.185.94 | 9 | 9 |
106-
| ::ffff:222.121.190.122 | 2 | 2 |
107-
| ::ffff:222.186.180.130 | 13 | 13 |
108-
| ::ffff:222.186.30.112 | 33 | 33 |
109-
| ::ffff:222.186.42.7 | 20 | 20 |
110-
| ::ffff:222.187.232.39 | 10 | 10 |
111-
| ::ffff:222.187.238.58 | 12 | 12 |
112-
| ::ffff:222.187.254.41 | 22 | 22 |
113-
| ::ffff:45.141.84.10 | 1 | 0 |
114-
| ::ffff:45.154.255.147 | 1 | 1 |
115-
| ::ffff:45.155.204.161 | 62 | 62 |
116-
| ::ffff:45.67.14.25 | 1 | 1 |
117-
| ::ffff:45.67.14.29 | 2 | 2 |
118-
| ::ffff:46.19.139.18 | 22 | 22 |
119-
| ::ffff:49.235.112.157 | 2 | 2 |
120-
| ::ffff:49.88.112.77 | 97 | 97 |
121-
| ::ffff:62.233.50.53 | 17 | 17 |
122-
| ::ffff:92.255.85.135 | 232 | 232 |
123-
| ::ffff:92.255.85.146 | 30 | 30 |
124-
| ::ffff:92.255.85.237 | 107 | 107 |
125-
| ::ffff:92.255.85.28 | 28 | 28 |
126113
```
127114

128115
Resulting in:
@@ -136,38 +123,47 @@ Resulting in:
136123
| ::ffff:112.85.42.88 | 14 | 14 |
137124
| ::ffff:122.194.229.40 | 20 | 20 |
138125
| ::ffff:122.194.229.45 | 19 | 19 |
139-
| ::ffff:141.98.10.63 | 32 | 32 |
140-
| ::ffff:141.98.11.16 | 28 | 28 |
141-
| ::ffff:198.98.62.88 | 1 | 0 |
142-
| ::ffff:209.141.43.186 | 13 | 13 |
143-
| ::ffff:221.131.165.33 | 12 | 12 |
144-
| ::ffff:221.131.165.50 | 12 | 12 |
145-
| ::ffff:221.131.165.56 | 16 | 16 |
146-
| ::ffff:221.131.165.62 | 12 | 12 |
147-
| ::ffff:221.131.165.65 | 10 | 10 |
148-
| ::ffff:221.131.165.75 | 26 | 25 |
149-
| ::ffff:221.181.185.111 | 14 | 14 |
150-
| ::ffff:221.181.185.143 | 25 | 25 |
151-
| ::ffff:221.181.185.151 | 10 | 9 |
152-
| ::ffff:221.181.185.159 | 33 | 32 |
153-
| ::ffff:221.181.185.94 | 9 | 9 |
154-
| ::ffff:222.121.190.122 | 2 | 2 |
155-
| ::ffff:222.186.180.130 | 13 | 13 |
156-
| ::ffff:222.186.30.112 | 33 | 33 |
157-
| ::ffff:222.186.42.7 | 20 | 20 |
158-
| ::ffff:222.187.232.39 | 10 | 10 |
159-
| ::ffff:222.187.238.58 | 12 | 12 |
160-
| ::ffff:222.187.254.41 | 22 | 22 |
161-
| ::ffff:45.141.84.10 | 1 | 0 |
162-
| ::ffff:45.154.255.147 | 1 | 1 |
163-
| ::ffff:45.155.204.161 | 62 | 62 |
164-
| ::ffff:45.67.14.25 | 1 | 1 |
165-
| ::ffff:45.67.14.29 | 2 | 2 |
166-
| ::ffff:46.19.139.18 | 22 | 22 |
167-
| ::ffff:49.235.112.157 | 2 | 2 |
168-
| ::ffff:49.88.112.77 | 97 | 97 |
169-
| ::ffff:62.233.50.53 | 17 | 17 |
170-
| ::ffff:92.255.85.135 | 232 | 232 |
171-
| ::ffff:92.255.85.146 | 30 | 30 |
172-
| ::ffff:92.255.85.237 | 107 | 107 |
173-
| ::ffff:92.255.85.28 | 28 | 28 |
126+
127+
# Detailed Statistics
128+
Since version v1.1.0 endlessh-report now allows for more detailed reports to be generated.
129+
These include factors such as bot time wasted, and total bytes sent.
130+
131+
Examples are:
132+
133+
## Detailed IP Statistics
134+
135+
```markdown
136+
# Statistics per IP
137+
| Host | Accepted | Closed | Total Time (s) | Total Bytes |
138+
|------------------------|----------|--------|----------------|-------------|
139+
| 218.92.0.206 | 3552 | 3547 | 2202334.810000 | 262224KiB |
140+
| 61.177.172.108 | 8 | 8 | 5282.840000 | 653KiB |
141+
| 61.177.173.46 | 8 | 8 | 7328.230000 | 909KiB |
142+
```
143+
144+
## Detailed Connection Statistics
145+
```markdown
146+
# Connection Statistics
147+
| Total Unique IPs | Total Accepted Connections | Total Closed Connections | Total Alive Connections | Total Bot Time Wasted | Total Bytes Sent |
148+
|------------------|----------------------------|--------------------------|-------------------------|-----------------------|------------------|
149+
| 99 | 0 | 0 | 0 | 4743646.220000 | 595462069 |
150+
```
151+
152+
## Detailed AbuseIPDB CSV format
153+
```csv
154+
IP,Categories,ReportDate,Comment
155+
218.92.0.206,"18,14,22,15",2022-06-14T21:40:58Z,"218.92.0.206 fell into Endlessh tarpit; opened 3561, closed 3569 connections. Total time wasted: 2.21585e+06s. Total bytes sent by tarpit: 269973303B (Report generated by Endlessh Report Generator)"
156+
61.177.172.108,"18,14,22,15",2022-06-14T21:40:58Z,"61.177.172.108 fell into Endlessh tarpit; opened 8, closed 8 connections. Total time wasted: 5282.83s. Total bytes sent by tarpit: 669662B (Report generated by Endlessh Report Generator)"
157+
61.177.173.46,"18,14,22,15",2022-06-14T21:40:58Z,"61.177.173.46 fell into Endlessh tarpit; opened 8, closed 8 connections. Total time wasted: 7328.23s. Total bytes sent by tarpit: 931388B (Report generated by Endlessh Report Generator)"
158+
136.144.41.181,"18,14,22,15",2022-06-14T21:40:58Z,"136.144.41.181 fell into Endlessh tarpit; opened 1, closed 1 connections. Total time wasted: 116.022s. Total bytes sent by tarpit: 13799B (Report generated by Endlessh Report Generator)"
159+
61.177.173.50,"18,14,22,15",2022-06-14T21:40:58Z,"61.177.173.50 fell into Endlessh tarpit; opened 12, closed 12 connections. Total time wasted: 9732.31s. Total bytes sent by tarpit: 1255507B (Report generated by Endlessh Report Generator)"
160+
45.61.188.110,"18,14,22,15",2022-06-14T21:40:58Z,"45.61.188.110 fell into Endlessh tarpit; opened 5, closed 5 connections. Total time wasted: 15.004s. Total bytes sent by tarpit: 1154B (Report generated by Endlessh Report Generator)"
161+
61.177.173.35,"18,14,22,15",2022-06-14T21:40:58Z,"61.177.173.35 fell into Endlessh tarpit; opened 10, closed 10 connections. Total time wasted: 6529.89s. Total bytes sent by tarpit: 831889B (Report generated by Endlessh Report Generator)"
162+
61.177.172.98,"18,14,22,15",2022-06-14T21:40:58Z,"61.177.172.98 fell into Endlessh tarpit; opened 9, closed 9 connections. Total time wasted: 4610.36s. Total bytes sent by tarpit: 592071B (Report generated by Endlessh Report Generator)"
163+
223.71.167.164,"18,14,22,15",2022-06-14T21:40:58Z,"223.71.167.164 fell into Endlessh tarpit; opened 3, closed 3 connections. Total time wasted: 8.001s. Total bytes sent by tarpit: 598B (Report generated by Endlessh Report Generator)"
164+
45.61.185.160,"18,14,22,15",2022-06-14T21:40:58Z,"45.61.185.160 fell into Endlessh tarpit; opened 3, closed 3 connections. Total time wasted: 9.004s. Total bytes sent by tarpit: 955B (Report generated by Endlessh Report Generator)"
165+
78.142.18.204,"18,14,22,15",2022-06-14T21:40:58Z,"78.142.18.204 fell into Endlessh tarpit; opened 28, closed 28 connections. Total time wasted: 103.027s. Total bytes sent by tarpit: 9708B (Report generated by Endlessh Report Generator)"
166+
61.177.173.51,"18,14,22,15",2022-06-14T21:40:58Z,"61.177.173.51 fell into Endlessh tarpit; opened 7, closed 7 connections. Total time wasted: 3609.56s. Total bytes sent by tarpit: 463135B (Report generated by Endlessh Report Generator)"
167+
67.207.83.91,"18,14,22,15",2022-06-14T21:40:58Z,"67.207.83.91 fell into Endlessh tarpit; opened 1, closed 1 connections. Total time wasted: 6.002s. Total bytes sent by tarpit: 644B (Report generated by Endlessh Report Generator)"
168+
45.61.184.111,"18,14,22,15",2022-06-14T21:40:58Z,"45.61.184.111 fell into Endlessh tarpit; opened 7, closed 7 connections. Total time wasted: 21.004s. Total bytes sent by tarpit: 2096B (Report generated by Endlessh Report Generator)"
169+
```

main.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,13 @@ void printConnectionStatistics(const uint32_t uniqueAddresses, const uint32_t to
395395
cout << "|" << uniqueIps << "|" << acceptedConns << "|" << closedConns << "|" << aliveConns << "|";
396396

397397
if (totalTimeWasted > 0) {
398-
cout << totalTimeWasted << "|";
398+
auto flooredSeconds = std::to_string(roundNumber(totalTimeWasted, 2));
399+
tmp = getSpacerString(23, flooredSeconds.size());
400+
cout << tmp << flooredSeconds << string(23 - flooredSeconds.size() - tmp.size(), ' ') << '|';
399401
} if (totalBytesSent > 0) {
400-
cout << totalBytesSent << "|";
402+
auto totalBytes = std::to_string(totalBytesSent);
403+
tmp = getSpacerString(18, totalBytes.size());
404+
cout << tmp << totalBytes << string(18 - totalBytes.size() - tmp.size(), ' ') << '|';
401405
}
402406

403407
cout << endl;

0 commit comments

Comments
 (0)