-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-visualization-scripts-only.R
311 lines (256 loc) · 10.8 KB
/
data-visualization-scripts-only.R
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
# install.packages("stringi")
# install.packages("stringr")
# install.packages("lattice")
# install.packages("ggplot2")
# install.packages("ggExtra")
# install.packages("hrbrthemes")
# install.packages("rgl")
# install.packages("GGally")
library("stringi")
library("stringr")
library("lattice")
library("ggplot2")
library("ggExtra")
library("hrbrthemes")
library("rgl")
library("GGally")
source("modules/split-url.r")
source("modules/url-ambiguity.r")
source("modules/url-lengths.r")
source("modules/url-special-symbol-count.r")
# Mendeley Data : Dataset of Malicious and Benign Webpages
dfm <- read.csv("data/Webpages_Classification_10k.csv", row.names = "X")
# Aalto University : PhishStorm - phishing / legitimate URL dataset
dfp <- read.csv("data/PhishStorm_urlset_96k.csv")
dfm[c("content", "url_len", "ip_add")] <- NULL
dfm$label <- factor(dfm$label)
head(dfm)
colnames(dfp)[1] <- "url"
dfp[c("card_rem", "ratio_Rrem", "ratio_Arem",
"jaccard_RR", "jaccard_RA", "jaccard_AR",
"jaccard_AA", "jaccard_ARrd", "jaccard_ARrem")] <- NULL
dfp$label <- factor(dfp$label)
levels(dfp$label) <- c("good", "bad")
dfp$mld_res <- factor(dfp$mld_res)
dfp$mld.ps_res <- factor(dfp$mld.ps_res)
levels(dfp$mld_res) <- c("no", "yes")
levels(dfp$mld.ps_res) <- c("no", "yes")
head(dfp)
split_res <- clean_split_url(dfp$url)
lengths_res <- url_lengths(split_res)
ldl_res <- letter_digit_letter(split_res)
dld_res <- digit_letter_digit(split_res)
xyx_res <- combined_url_ambiguity(split_res)
ldsc_res <- lett_dig_symb_count(split_res)
split_res_2 <- clean_split_url(dfm$url)
lengths_res_2 <- url_lengths(split_res_2)
ldl_res_2 <- letter_digit_letter(split_res_2)
dld_res_2 <- digit_letter_digit(split_res_2)
xyx_res_2 <- combined_url_ambiguity(split_res_2)
ldsc_res_2 <- lett_dig_symb_count(split_res_2)
params_df <- as.data.frame(cbind(
lengths_res,
ldl_res,
dld_res,
xyx_res,
ldsc_res
))
params_df_2 <- as.data.frame(cbind(
lengths_res_2,
ldl_res_2,
dld_res_2,
xyx_res_2,
ldsc_res_2
))
params_df[, c("protocol", "protocol_l", "ldl_protocol",
"dld_protocol", "xyx_protocol", "lett_protocol",
"dig_protocol", "symb_protocol")] <- NULL
params_df_2[, c("protocol", "protocol_l", "ldl_protocol",
"dld_protocol", "xyx_protocol", "lett_protocol",
"dig_protocol", "symb_protocol")] <- NULL
fdfp <- cbind(dfp, params_df)
fdfm <- cbind(dfm, params_df_2)
cat("First DataFrame dimensions (dfdp): \n", dim(fdfp),
"\nSecond DataFrame dimensions (dfdm):\n", dim(fdfm), "\n")
cat(c(colnames(fdfp), "\n\n\n", colnames(fdfm)), sep = ", ")
fdfm[fdfm$label == "bad", "color"] <- '#6dd38c'
fdfm[fdfm$label == "good", "color"] <- '#f3aca7'
fdfp[fdfp$label == "bad", "color"] <- '#6dd38c'
fdfp[fdfp$label == "good", "color"] <- '#f3aca7'
data_distribution_df <- data.frame(counts = c(sum(fdfp$label == "good"), sum(fdfp$label == "bad")),
labels = c("good", "bad"))
ggplot(data_distribution_df, aes(x = "", y = counts, fill = labels)) +
geom_bar(stat = "identity", width = 1, color = "white") +
coord_polar("y", start = 0) +
theme_void() + ggtitle("Porównanie bezpieczeństwa domen w zbiorze danych \"PhishStorm\".") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12)) +
labs(fill = "Etykieta", color = "Etykieta")
data_distribution_df2 <- data.frame(counts = c(sum(fdfm$label == "good"), sum(fdfm$label == "bad")),
labels = c("good", "bad"))
ggplot(data_distribution_df2, aes(x = "", y = counts, fill = labels)) +
geom_bar(stat = "identity", width = 1, color = "white") +
coord_polar("y", start = 0) +
theme_void() +
ggtitle("Porównanie bezpieczeństwa domen w poprzednio przygotowanym\nzbiorze danych \"Mendeley Data\".") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12)) +
labs(fill = "Etykieta", color = "Etykieta")
ggplot(fdfp[fdfp$url_l < 500, ], aes(x = label, y = url_l, group = label, fill = label)) +
geom_violin() +
ylab("Długość linku") +
xlab("Etykieta") +
ggtitle("Porównanie długości adresów URL.") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12),
rect = element_rect(fill = "#d8d7c4"),
#plot.background = element_rect(fill = "#d8d7c4"),
panel.background = element_rect(fill = "#f0bc5e", colour = "black")
) +
labs(color = "Etykieta")
splom(~data.frame(xyx_host, lett_host, dig_host, symb_host),
data = fdfp[sample(nrow(fdfp), 1000),],
pch = 1,
main = "Rozkład symboli w hoście adresu URL.",
groups = label,
# xlab = c("A", "B", "C", "D"),
# xlab = "", # czymś takim można usunąńć ten napis "Scatter Plot Matrix"
# ylab = c("A", "B", "C", "D"),
pscales = 0,
auto.key = list(columns = 2),
varnames = c("Ilość ciągów\npostaci XYX", "Ilość liter",
"Ilość cyfr", "Liczba znaków\ninterpunkcyjnych")
)
ggpairs(fdfp[fdfp$url_l < 500 & sample(nrow(fdfp), 1000), ],
aes(color = color,
alpha = .5),
columns = c("xyx_host", "lett_host", "dig_host", "symb_host"),
columnLabels = c("Ilość ciągów\npostaci XYX",
"Ilość liter",
"Ilość cyfr",
"Liczba znaków\ninterpunkcyjnych")) +
ggtitle("Rozkład symboli w hoscie adresu URL.") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12),
#panel.background = element_rect(fill = "#f0bc5e", colour = "black"),
rect = element_rect(fill = "#d8d7c4")
) +
labs(color = "Etykieta")
histogram(~ symb_url | label ,
data = fdfp[sample(nrow(fdfp), 2000),],
main = "Porównanie ilości znaków interpunkcyjnych\nw dobrych i złych domenach.",
xlab = "Ilość symboli w adresie URL",
ylab = "Procent całości",
layout = c(1, 2),
nint = 20,
xlim = c(0, 50)
)
ggplot(fdfp[fdfp$url_l < 500, ], aes(x = symb_url, fill = label)) +
geom_histogram(binwidth = 2, alpha = 0.6, position = 'identity') +
ylab("Ilość wystąpień") +
xlab("Ilość symboli w adresie URL") +
ggtitle("Porównanie ilości znaków interpunkcyjnych\nw dobrych i złych domenach.") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12),
#panel.background = element_rect(fill = "#f0bc5e", colour = "black"),
rect = element_rect(fill = "#d8d7c4")
) +
scale_fill_manual(values = c("#6dd38c", "#f3aca7")) +
labs(fill = "Etykieta", color = "Etykieta")
ggplot(data = fdfm, aes(x = js_len, group = label, fill = label)) +
geom_density(adjust = 1, alpha = .4) +
ylab("Gęstość") +
xlab("Długość kodu JavaScript") +
ggtitle("Gęstość długości kodu JavaScript na stronach internetowych.") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12),
#panel.background = element_rect(fill = "#f0bc5e", colour = "black"),
rect = element_rect(fill = "#d8d7c4")
) +
scale_fill_manual(values = c("#f3aca7", "#6dd38c")) +
labs(fill = "Etykieta", color = "Etykieta")
p <- ggplot(fdfp[fdfp$url_l < 1000, ], aes(x = xyx_query, y = xyx_url, color = label)) +
geom_point(alpha = .7, na.rm = TRUE) +
theme(legend.position = "left") +
ylab("Letter-Digit-Letter lub Digit-Letter-Digit w całym adresie URL") +
xlab("Letter-Digit-Letter lub Digit-Letter-Digit w zapytaniu") +
ggtitle("Porównanie podejrzanych ciągów w adresach URL.") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12)) +
labs(fill = "Etykieta", color = "label")
ggMarginal(p, type = "histogram")
splom(~data.frame(host_l, path_l, query_l, fragment_l, xyx_host, xyx_path, xyx_query),
data = fdfp[sample(nrow(fdfp), 2000),],
pch = 1,
main = "Rozkład znaków w domenach",
groups = label,
pscales = 0,
auto.key = list(columns = 2),
varnames = c("Długość\nhosta", "Długość\nścieżki", "Długość\nzapytania",
"Długość\nfragmentu", "XYX\nhost", "XYX\nścieżka",
"XYX\nzapytanie")
)
ggplot(data = fdfp[fdfp$url_l < 200, ], aes(x = symb_url, group = label, fill = label)) +
geom_density(adjust = 5, alpha = .4) +
ylab("Gęstość") +
xlab("Ilość znaków interpunkcyjnych w linku") +
ggtitle("Gęstość ilości znaków interpunkcyjnych w linkach") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12),
#panel.background = element_rect(fill = "#f0bc5e", colour = "black"),
rect = element_rect(fill = "#d8d7c4")
) +
scale_fill_manual(values = c("#6dd38c", "#f3aca7")) +
labs(fill = "Etykieta", color = "Etykieta")
ggplot(data = fdfm, aes(x = js_len, y = js_obf_len, color = label) ) +
geom_point() +
ylab("Długość zaciemnionego kodu JavaScript.") +
xlab("Długość kodu JavaScript") +
ggtitle("Związek pomiędzy długością kodu JavaScript\na bezpieczeństwem domen") +
theme(plot.title = element_text(family = "",
face = 'bold',
colour = 'black',
size = 12),
#panel.background = element_rect(fill = "#f0bc5e", colour = "black"),
rect = element_rect(fill = "#d8d7c4")
) +
scale_fill_manual(values = c("#6dd38c", "#f3aca7")) +
labs(fill = "Etykieta", color = "Etykieta")
# ggsave(
# "images/plot_8.png",
# plot = last_plot(),
# device = "png",
# path = NULL,
# scale = 1,
# # width = 300,
# # height = 300,
# # units = "mm",
# dpi = 400,
# bg = "transparent"
# )
# 3D plot
par(mar = c(0,0,0,0))
plot3d(
x = fdfm$js_len, y = fdfm$js_obf_len, z = fdfm$url_len,
col = fdfm$color,
type = 's',
radius = 30,
xlab = "URL", ylab = "JS ", zlab = "JS obf")
rgl.bg( sphere = FALSE, fogtype = "none", color = c("#d8d7c4", "black"),
back = "lines", fogScale = 1)