Better HTML example
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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
diff --git a/examples.js b/examples.js
index 83bc228..02897d3 100644
--- a/examples.js
+++ b/examples.js
@@ -85,7 +85,6 @@ function fileExists(filepath) {
return true;
}
}
- //return false;
return true;
});
}
diff --git a/examples/prism-bro.html b/examples/prism-bro.html
index ee9d899..c8a7f18 100644
--- a/examples/prism-bro.html
+++ b/examples/prism-bro.html
@@ -14,11 +14,6 @@
<pre><code>123
123.456
-123.456
-.3f
-1.3e9d
-0xaf
-0xAF
-0xFF.AEP-4
</code></pre>
<h2>Full example</h2>
@@ -646,459 +641,9 @@ event bro_done()
}
</code></pre>
-<p></p>
-<pre>
-<code>
-# $Id: conn.bro 6782 2009-06-28 02:19:03Z vern $
-
-@load notice
-@load hot
-@load port-name
-@load netstats
-@load conn-id
-
-redef enum Notice += {
- SensitiveConnection, # connection marked "hot"
-};
-
-const conn_closed = { TCP_CLOSED, TCP_RESET };
-
-global have_FTP = F; # if true, we've loaded ftp.bro
-global have_SMTP = F; # if true, we've loaded smtp.bro
-global is_ftp_data_conn: function(c: connection): bool;
-
-# Whether to include connection state history in the logs generated
-# by record_connection.
-const record_state_history = F &redef;
-
-# Whether to translate the local address in SensitiveConnection notices
-# to a hostname. Meant as a demonstration of the "when" construct.
-const xlate_hot_local_addr = F &redef;
-
-# Whether to use DPD for generating the service field in the summaries.
-# Default off, because it changes the format of conn.log in a way
-# potentially incompatible with existing scripts.
-const dpd_conn_logs = F &redef;
-
-# Maps a given port on a given server's address to an RPC service.
-# If we haven't loaded portmapper.bro, then it will be empty
-# (and, ideally, queries to it would be optimized away ...).
-global RPC_server_map: table[addr, port] of string;
-
-const conn_file = open_log_file("conn") &redef;
-
-function conn_state(c: connection, trans: transport_proto): string
- {
- local os = c$orig$state;
- local rs = c$resp$state;
-
- local o_inactive = os == TCP_INACTIVE || os == TCP_PARTIAL;
- local r_inactive = rs == TCP_INACTIVE || rs == TCP_PARTIAL;
-
- if ( trans == tcp )
- {
- if ( rs == TCP_RESET )
- {
- if ( os == TCP_SYN_SENT || os == TCP_SYN_ACK_SENT ||
- (os == TCP_RESET &&
- c$orig$size == 0 && c$resp$size == 0) )
- return "REJ";
- else if ( o_inactive )
- return "RSTRH";
- else
- return "RSTR";
- }
- else if ( os == TCP_RESET )
- return r_inactive ? "RSTOS0" : "RSTO";
- else if ( rs == TCP_CLOSED && os == TCP_CLOSED )
- return "SF";
- else if ( os == TCP_CLOSED )
- return r_inactive ? "SH" : "S2";
- else if ( rs == TCP_CLOSED )
- return o_inactive ? "SHR" : "S3";
- else if ( os == TCP_SYN_SENT && rs == TCP_INACTIVE )
- return "S0";
- else if ( os == TCP_ESTABLISHED && rs == TCP_ESTABLISHED )
- return "S1";
- else
- return "OTH";
- }
-
- else if ( trans == udp )
- {
- if ( os == UDP_ACTIVE )
- return rs == UDP_ACTIVE ? "SF" : "S0";
- else
- return rs == UDP_ACTIVE ? "SHR" : "OTH";
- }
-
- else
- return "OTH";
- }
-
-function conn_size(e: endpoint, trans: transport_proto): string
- {
- if ( e$size > 0 || (trans == tcp && e$state == TCP_CLOSED) )
- return fmt("%d", e$size);
- else
- ### should return 0 for TCP_RESET that went through TCP_CLOSED
- return "?";
- }
-
-function service_name(c: connection): string
- {
- local p = c$id$resp_p;
-
- if ( p in port_names )
- return port_names[p];
- else
- return "other";
- }
-
-const state_graphic = {
- ["OTH"] = "?>?", ["REJ"] = "[",
- ["RSTO"] = ">]", ["RSTOS0"] = "}]", ["RSTR"] = ">[", ["RSTRH"] = "<[",
- ["S0"] = "}", ["S1"] = ">", ["S2"] = "}2", ["S3"] = "}3",
- ["SF"] = ">", ["SH"] = ">h", ["SHR"] = "<h",
-};
-
-function full_id_string(c: connection): string
- {
- local id = c$id;
- local trans = get_port_transport_proto(id$orig_p);
- local state = conn_state(c, trans);
- local state_gr = state_graphic[state];
- local service = service_name(c);
-
- if ( state == "S0" || state == "S1" || state == "REJ" )
- return fmt("%s %s %s/%s %s", id$orig_h, state_gr,
- id$resp_h, service, c$addl);
-
- else
- return fmt("%s %sb %s %s/%s %sb %.1fs %s",
- id$orig_h, conn_size(c$orig, trans),
- state_gr, id$resp_h, service,
- conn_size(c$resp, trans), c$duration, c$addl);
- }
-
-# The sets are indexed by the complete hot messages.
-global hot_conns_reported: table[conn_id] of set[string];
-
-# Low-level routine that generates the actual SensitiveConnection
-# notice associated with a "hot" connection.
-function do_hot_notice(c: connection, dir: string, host: string)
- {
- NOTICE([$note=SensitiveConnection, $conn=c,
- $msg=fmt("hot: %s %s local host: %s",
- full_id_string(c), dir, host)]);
- }
-
-# Generate a SensitiveConnection notice with the local hostname
-# translated. Mostly intended as a demonstration of using "when".
-function gen_hot_notice_with_hostnames(c: connection)
- {
- local id = c$id;
- local inbound = is_local_addr(id$resp_h);
- local dir = inbound ? "to" : "from";
- local local_addr = inbound ? id$orig_h : id$resp_h;
-
- add_notice_tag(c);
-
- when ( local hostname = lookup_addr(local_addr) )
- do_hot_notice(c, dir, hostname);
- timeout 5 sec
- { do_hot_notice(c, dir, fmt("%s", local_addr)); }
- }
-
-function log_hot_conn(c: connection)
- {
- if ( c$id !in hot_conns_reported )
- hot_conns_reported[c$id] = set() &mergeable;
-
- local msg = full_id_string(c);
-
- if ( msg !in hot_conns_reported[c$id] )
- {
- if ( xlate_hot_local_addr )
- gen_hot_notice_with_hostnames(c);
- else
- NOTICE([$note=SensitiveConnection, $conn=c,
- $msg=fmt("hot: %s", full_id_string(c))]);
-
- add hot_conns_reported[c$id][msg];
- }
- }
-
-function determine_service_non_DPD(c: connection) : string
- {
- if ( length(c$service) != 0 )
- {
- for ( i in c$service )
- return i; # return first;
- }
-
- else if ( have_FTP && is_ftp_data_conn(c) )
- return port_names[20/tcp];
-
- else if ( [c$id$resp_h, c$id$resp_p] in RPC_server_map )
- # Alternatively, perhaps this should be stored in $addl
- # rather than $service, so the port number remains
- # visible .... ?
- return RPC_server_map[c$id$resp_h, c$id$resp_p];
-
- else if ( c$orig$state == TCP_INACTIVE )
- {
- # We're seeing a half-established connection. Use the
- # service of the originator if it's well-known and the
- # responder isn't.
- if ( c$id$resp_p !in port_names && c$id$orig_p in port_names )
- return port_names[c$id$orig_p];
- }
-
- return service_name(c);
- }
-
-function determine_service(c: connection) : string
- {
- if ( ! dpd_conn_logs )
- return determine_service_non_DPD(c);
-
- if ( [c$id$resp_h, c$id$resp_p] in RPC_server_map )
- add c$service[RPC_server_map[c$id$resp_h, c$id$resp_p]];
-
- if ( length(c$service) == 0 )
- {
- # Empty service set. Use port as a hint.
- if ( c$orig$state == TCP_INACTIVE )
- {
- # We're seeing a half-established connection. Use the
- # service of the originator if it's well-known and the
- # responder isn't.
- if ( c$id$resp_p !in port_names &&
- c$id$orig_p in port_names )
- return fmt("%s?", port_names[c$id$orig_p]);
- }
-
- if ( c$id$resp_p in port_names )
- return fmt("%s?", port_names[c$id$resp_p]);
-
- return "other";
- }
-
- local service = "";
- for ( s in c$service )
- {
- if ( sub_bytes(s, 0, 1) != "-" )
- service = service == "" ? s : cat(service, ",", s);
- }
-
- return service != "" ? to_lower(service) : "other";
- }
-
-function record_connection(f: file, c: connection)
- {
- local id = c$id;
- local local_init = is_local_addr(id$orig_h);
-
- local local_addr = local_init ? id$orig_h : id$resp_h;
- local remote_addr = local_init ? id$resp_h : id$orig_h;
-
- local flags = local_init ? "L" : "X";
-
- local trans = get_port_transport_proto(id$orig_p);
- local duration: string;
-
- # Do this first so we see the tag in addl.
- if ( c$hot > 0 )
- log_hot_conn(c);
-
- if ( trans == tcp )
- {
- if ( c$orig$state in conn_closed || c$resp$state in conn_closed )
- duration = fmt("%.06f", c$duration);
- else
- duration = "?";
- }
- else
- duration = fmt("%.06f", c$duration);
-
- local addl = c$addl;
-
-@ifdef ( estimate_flow_size_and_remove )
- # Annotate connection with separately-estimated size, if present.
- local orig_est = estimate_flow_size_and_remove(id, T);
- local resp_est = estimate_flow_size_and_remove(id, F);
-
- if ( orig_est$have_est )
- addl = fmt("%s olower=%.0fMB oupper=%.0fMB oincon=%s", addl,
- orig_est$lower / 1e6, orig_est$upper / 1e6,
- orig_est$num_inconsistent);
-
- if ( resp_est$have_est )
- addl = fmt("%s rlower=%.0fMB rupper=%.0fMB rincon=%s", addl,
- resp_est$lower / 1e6, resp_est$upper / 1e6,
- resp_est$num_inconsistent);
-@endif
-
- local service = determine_service(c);
-
- local log_msg =
- fmt("%.6f %s %s %s %s %d %d %s %s %s %s %s",
- c$start_time, duration, id$orig_h, id$resp_h, service,
- id$orig_p, id$resp_p, trans,
- conn_size(c$orig, trans), conn_size(c$resp, trans),
- conn_state(c, trans), flags);
-
- if ( record_state_history )
- log_msg = fmt("%s %s", log_msg,
- c$history == "" ? "X" : c$history);
-
- if ( addl != "" )
- log_msg = fmt("%s %s", log_msg, addl);
-
- print f, log_msg;
- }
-
-event protocol_confirmation(c: connection, atype: count, aid: count)
- {
- if ( ! dpd_conn_logs )
- return;
-
- delete c$service[fmt("-%s",analyzer_name(atype))];
- add c$service[analyzer_name(atype)];
- }
-
-event protocol_violation(c: connection, atype: count, aid: count,
- reason: string) &priority = 10
- {
- if ( ! dpd_conn_logs )
- return;
-
- delete c$service[analyzer_name(atype)];
- add c$service[fmt("-%s",analyzer_name(atype))];
- }
-
-event connection_established(c: connection)
- {
- Hot::check_hot(c, Hot::CONN_ESTABLISHED);
-
- if ( c$hot > 0 )
- log_hot_conn(c);
- }
-
-event partial_connection(c: connection)
- {
- if ( c$orig$state == TCP_PARTIAL && c$resp$state == TCP_INACTIVE )
- # This appears to be a stealth scan. Don't do hot-checking
- # as there wasn't an established connection.
- ;
- else
- {
- Hot::check_hot(c, Hot::CONN_ESTABLISHED);
- Hot::check_hot(c, Hot::APPL_ESTABLISHED); # assume it's been established
- }
-
- if ( c$hot > 0 )
- log_hot_conn(c);
- }
-
-event connection_attempt(c: connection)
- {
- Hot::check_spoof(c);
- Hot::check_hot(c, Hot::CONN_ATTEMPTED);
- }
-
-event connection_finished(c: connection)
- {
- if ( c$orig$size == 0 || c$resp$size == 0 )
- # Hard to get excited about this - not worth logging again.
- c$hot = 0;
- else
- Hot::check_hot(c, Hot::CONN_FINISHED);
- }
-
-event connection_partial_close(c: connection)
- {
- if ( c$orig$size == 0 || c$resp$size == 0 )
- # Hard to get excited about this - not worth logging again.
- c$hot = 0;
- else
- Hot::check_hot(c, Hot::CONN_FINISHED);
- }
-
-event connection_half_finished(c: connection)
- {
- Hot::check_hot(c, Hot::CONN_ATTEMPTED);
- }
-
-event connection_rejected(c: connection)
- {
- Hot::check_hot(c, Hot::CONN_REJECTED);
- }
-
-event connection_reset(c: connection)
- {
- Hot::check_hot(c, Hot::CONN_FINISHED);
- }
-
-event connection_pending(c: connection)
- {
- if ( c$orig$state in conn_closed &&
- (c$resp$state == TCP_INACTIVE || c$resp$state == TCP_PARTIAL) )
- # This is a stray FIN or RST - don't bother reporting.
- return;
-
- if ( c$orig$state == TCP_RESET || c$resp$state == TCP_RESET )
- # We already reported this connection when the RST
- # occurred.
- return;
-
- Hot::check_hot(c, Hot::CONN_FINISHED);
- }
-
-function connection_gone(c: connection, gone_type: string)
- {
- if ( c$orig$size == 0 || c$resp$size == 0 )
- {
- if ( c$orig$state == TCP_RESET && c$resp$state == TCP_INACTIVE)
- # A bare RST, no other context. Ignore it.
- return;
-
- # Hard to get excited about this - not worth logging again,
- # per connection_finished().
- c$hot = 0;
- }
- else
- Hot::check_hot(c, Hot::CONN_TIMEOUT);
- }
-
-event connection_state_remove(c: connection) &priority = -10
- {
- local os = c$orig$state;
- local rs = c$resp$state;
-
- if ( os == TCP_ESTABLISHED && rs == TCP_ESTABLISHED )
- # It was still active, no summary generated.
- connection_gone(c, "remove");
-
- else if ( (os == TCP_CLOSED || rs == TCP_CLOSED) &&
- (os == TCP_ESTABLISHED || rs == TCP_ESTABLISHED) )
- # One side has closed, the other hasn't - it's in state S2
- # or S3, hasn't been reported yet.
- connection_gone(c, "remove");
-
- record_connection(conn_file, c);
-
- delete hot_conns_reported[c$id];
- }
-</code>
-</pre>
<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
There are always such cases in every regex-based syntax highlighter.
However, Prism dares to be open and honest about them.
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
-</p>
-
-<h3>Comment-like substrings</h3>
-<pre><code>"foo /* bar */ baz"; "foo // bar";</code></pre>
\ No newline at end of file
+</p>
\ No newline at end of file