forked from ikoniaris/honeyd-viz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
honeyd-viz-generator.php
executable file
·369 lines (304 loc) · 15 KB
/
honeyd-viz-generator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
#Package: Honeyd-Viz
#Version: 0.3
#Author: ikoniaris
#Website: bruteforce.gr/honeyd-viz
require_once('include/libchart/classes/libchart.php');
require_once('config.php');
require_once('include/rb.php');
//Let's connect to the database
R::setup('mysql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
//-----------------------------------------------------------------------------------------------------------------
//CONNECTIONS BY PROTOCOL
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT proto, COUNT(proto)
FROM connections
GROUP BY proto
ORDER BY COUNT(proto) DESC ";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new vertical bar chart and initialize the dataset
$chart = new VerticalBarChart(600, 300);
$pie_chart = new PieChart(600, 300);
$dataSet = new XYDataSet();
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row)
$dataSet->addPoint(new Point($row['proto'], $row['COUNT(proto)']));
//We set the bar chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Connections by protocol");
$chart->render("generated-graphs/connections_by_proto.png");
//We set the pie chart's dataset and render the graph
$pie_chart->setDataSet($dataSet);
$pie_chart->setTitle("Connections by protocol");
$pie_chart->render("generated-graphs/connections_by_proto_pie.png");
}
//-----------------------------------------------------------------------------------------------------------------
//CONNECTIONS BY DESTINATION IP
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT dest_ip, COUNT(dest_ip)
FROM connections
GROUP BY dest_ip
ORDER BY COUNT(dest_ip) DESC";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new vertical bar chart and initialize the dataset
$chart = new VerticalBarChart(600, 300);
$pie_chart = new PieChart(600, 300);
$dataSet = new XYDataSet();
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row)
$dataSet->addPoint(new Point($row['dest_ip'], $row['COUNT(dest_ip)']));
//We set the bar chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Connections by destination IP");
//For this particular graph we need to set the corrent padding
$chart->getPlot()->setGraphPadding(new Padding(5, 40, 75, 50)); //top, right, bottom, left | defaults: 5, 30, 50, 50
$chart->render("generated-graphs/connections_by_dest_ip.png");
//We set the pie chart's dataset and render the graph
$pie_chart->setDataSet($dataSet);
$pie_chart->setTitle("Connections by destination IP");
$pie_chart->render("generated-graphs/connections_by_dest_ip_pie.png");
}
//-----------------------------------------------------------------------------------------------------------------
//NUMBER OF CONNECTIONS PER IP
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT source_ip, COUNT(source_ip)
FROM connections
GROUP BY source_ip
ORDER BY COUNT(source_ip) DESC
LIMIT 10 ";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new vertical bar chart,a new pie chart and initialize the dataset
$chart = new VerticalBarChart(600, 300);
$pie_chart = new PieChart(600, 300);
$dataSet = new XYDataSet();
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row)
$dataSet->addPoint(new Point($row['source_ip'], $row['COUNT(source_ip)']));
//We set the bar chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Number of connections per unique IP (Top 10)");
//For this particular graph we need to set the corrent padding
$chart->getPlot()->setGraphPadding(new Padding(5, 40, 75, 50)); //top, right, bottom, left | defaults: 5, 30, 50, 50
$chart->render("generated-graphs/connections_per_ip.png");
//We set the pie chart's dataset and render the graph
$pie_chart->setDataSet($dataSet);
$pie_chart->setTitle("Number of connections per unique IP (Top 10)");
$pie_chart->render("generated-graphs/connections_per_ip_pie.png");
}
//-----------------------------------------------------------------------------------------------------------------
//TCP CONNECTIONS PER IP
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT source_ip, COUNT(source_ip)
FROM connections
WHERE proto = 'tcp'
GROUP BY source_ip
ORDER BY COUNT(source_ip) DESC
LIMIT 10";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new vertical bar chart,a new pie chart and initialize the dataset
$chart = new VerticalBarChart(600, 300);
$pie_chart = new PieChart(600, 300);
$dataSet = new XYDataSet();
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row)
$dataSet->addPoint(new Point($row['source_ip'], $row['COUNT(source_ip)']));
//We set the bar chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Number of TCP connections per unique IP (Top 10)");
//For this particular graph we need to set the corrent padding
$chart->getPlot()->setGraphPadding(new Padding(5, 40, 75, 50)); //top, right, bottom, left | defaults: 5, 30, 50, 50
$chart->render("generated-graphs/tcp_connections_per_ip.png");
//We set the pie chart's dataset and render the graph
$pie_chart->setDataSet($dataSet);
$pie_chart->setTitle("Number of TCP connections per unique IP (Top 10)");
$pie_chart->render("generated-graphs/tcp_connections_per_ip_pie.png");
}
//-----------------------------------------------------------------------------------------------------------------
//UDP CONNECTIONS PER IP
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT source_ip, COUNT(source_ip)
FROM connections
WHERE proto = 'udp'
GROUP BY source_ip
ORDER BY COUNT(source_ip) DESC
LIMIT 10 ";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new vertical bar chart,a new pie chart and initialize the dataset
$chart = new VerticalBarChart(600, 300);
$pie_chart = new PieChart(600, 300);
$dataSet = new XYDataSet();
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row)
$dataSet->addPoint(new Point($row['source_ip'], $row['COUNT(source_ip)']));
//We set the bar chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Number of UDP connections per unique IP (Top 10)");
//For this particular graph we need to set the corrent padding
$chart->getPlot()->setGraphPadding(new Padding(5, 40, 75, 50)); //top, right, bottom, left | defaults: 5, 30, 50, 50
$chart->render("generated-graphs/udp_connections_per_ip.png");
//We set the pie chart's dataset and render the graph
$pie_chart->setDataSet($dataSet);
$pie_chart->setTitle("Number of UDP connections per unique IP (Top 10)");
$pie_chart->render("generated-graphs/udp_connections_per_ip_pie.png");
}
//-----------------------------------------------------------------------------------------------------------------
//ICMP CONNECTIONS PER IP
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT source_ip, COUNT(source_ip)
FROM connections
WHERE proto = 'icmp'
GROUP BY source_ip
ORDER BY COUNT(source_ip) DESC
LIMIT 10 ";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new vertical bar chart,a new pie chart and initialize the dataset
$chart = new VerticalBarChart(600, 300);
$pie_chart = new PieChart(600, 300);
$dataSet = new XYDataSet();
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row)
$dataSet->addPoint(new Point($row['source_ip'], $row['COUNT(source_ip)']));
//We set the bar chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Number of ICMP connections per unique IP (Top 10)");
//For this particular graph we need to set the corrent padding
$chart->getPlot()->setGraphPadding(new Padding(5, 40, 75, 50)); //top, right, bottom, left | defaults: 5, 30, 50, 50
$chart->render("generated-graphs/icmp_connections_per_ip.png");
//We set the pie chart's dataset and render the graph
$pie_chart->setDataSet($dataSet);
$pie_chart->setTitle("Number of ICMP connections per unique IP (Top 10)");
$pie_chart->render("generated-graphs/icmp_connections_per_ip_pie.png");
}
//-----------------------------------------------------------------------------------------------------------------
//CONNECTIONS BY DESTINATION PORTS
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT dest_port, COUNT(dest_port), proto
FROM connections
GROUP BY dest_port
ORDER BY COUNT(dest_port) DESC ";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new vertical bar chart,a new pie chart and initialize the dataset
$chart = new VerticalBarChart(600, 300);
$pie_chart = new PieChart(600, 300);
$dataSet = new XYDataSet();
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row)
$dataSet->addPoint(new Point($row['dest_port'] . " / " . $row['proto'], $row['COUNT(dest_port)']));
//We set the bar chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Number of connections by destination port");
$chart->render("generated-graphs/connections_by_dest_port.png");
//We set the pie chart's dataset and render the graph
$pie_chart->setDataSet($dataSet);
$pie_chart->setTitle("Number of connections by destination port");
$pie_chart->render("generated-graphs/connections_by_dest_port_pie.png");
}
//-----------------------------------------------------------------------------------------------------------------
//MOST CONNECTIONS PER DAY
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT COUNT(*), date_time
FROM connections
GROUP BY DAYOFYEAR(date_time)
ORDER BY COUNT(*) DESC
LIMIT 20 ";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new horizontal bar chart and initialize the dataset
$chart = new HorizontalBarChart(600, 300);
$dataSet = new XYDataSet();
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row)
$dataSet->addPoint(new Point(date('d-m-Y', strtotime($row['date_time'])), $row['COUNT(*)']));
//$dataSet->addPoint(new Point(date('l, d-m-Y', strtotime($row['date_time'])), $row['COUNT(*)']));
//We set the horizontal chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Most connections per day (Top 20)");
$chart->getPlot()->setGraphPadding(new Padding(5, 30, 50, 75 /*140*/)); //top, right, bottom, left | defaults: 5, 30, 50, 50
$chart->render("generated-graphs/most_connections_per_day.png");
}
//-----------------------------------------------------------------------------------------------------------------
//CONNECTIONS PER DAY
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT COUNT(*), date_time
FROM connections
GROUP BY DAYOFYEAR(date_time)
ORDER BY date_time ASC";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new line chart and initialize the dataset
$chart = new LineChart(600, 300);
$dataSet = new XYDataSet();
//This graph gets messed up for large DBs, so here is a simple way to limit some of the input
$counter = 1;
//Display date legend only every $mod rows, 25 distinct values being the optimal for a graph
$mod = round(count($rows) / 25);
if ($mod == 0) $mod = 1; //otherwise a division by zero might happen below
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row) {
if ($counter % $mod == 0) {
$dataSet->addPoint(new Point(date('d-m-Y', strtotime($row['date_time'])), $row['COUNT(*)']));
} else {
$dataSet->addPoint(new Point('', $row['COUNT(*)']));
}
$counter++;
}
//We set the line chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Connections per day");
$chart->render("generated-graphs/connections_per_day.png");
}
//-----------------------------------------------------------------------------------------------------------------
//CONNECTIONS PER WEEK
//-----------------------------------------------------------------------------------------------------------------
$db_query = "SELECT COUNT(*), MAKEDATE(
CASE
WHEN WEEKOFYEAR(date_time) = 52
THEN YEAR(date_time)-1
ELSE YEAR(date_time)
END, (WEEKOFYEAR(date_time) * 7)-4) AS DateOfWeek_Value
FROM connections
GROUP BY WEEKOFYEAR(date_time)
ORDER BY date_time ASC";
$rows = R::getAll($db_query);
if (count($rows)) {
//We create a new line chart and initialize the dataset
$chart = new LineChart(600, 300);
$dataSet = new XYDataSet();
//This graph gets messed up for large DBs, so here is a simple way to limit some of the input
$counter = 1;
//Display date legend only every $mod rows, 25 distinct values being the optimal for a graph
$mod = round(count($rows) / 25);
if ($mod == 0) $mod = 1; //otherwise a division by zero might happen below
//For every row returned from the database we add a new point to the dataset
foreach ($rows as $row) {
if ($counter % $mod == 0) {
$dataSet->addPoint(new Point(date('d-m-Y', strtotime($row['DateOfWeek_Value'])), $row['COUNT(*)']));
} else {
$dataSet->addPoint(new Point('', $row['COUNT(*)']));
}
$counter++;
//We add 6 "empty" points to make a horizontal line representing a week
for ($i = 0; $i < 6; $i++) {
$dataSet->addPoint(new Point('', $row['COUNT(*)']));
}
}
//We set the line chart's dataset and render the graph
$chart->setDataSet($dataSet);
$chart->setTitle("Connections per week");
$chart->render("generated-graphs/connections_per_week.png");
}
//-----------------------------------------------------------------------------------------------------------------
//END
//-----------------------------------------------------------------------------------------------------------------
//We close the connection
R::close();
//And redirect to the graph presentation page
header('location:honeyd-viz.php');
?>