#include <NVT.h>
Inheritance diagram for TCP_NVT:


Public Member Functions | |
| TCP_NVT (TCP_Endpoint *endp, int is_NUL_sensitive, int skip_partial, int CR_LF_as_EOL=LF_as_EOL) | |
| ~TCP_NVT () | |
| TelnetOption * | FindOption (unsigned int code) |
| TelnetOption * | FindPeerOption (unsigned int code) |
| void | AuthenticationAccepted () |
| void | AuthenticationRejected () |
| void | SetTerminal (const u_char *terminal, int len) |
| void | SetBinaryMode (int mode) |
| void | SetEncrypting (int mode) |
| void | SetAuthName (char *arg_auth_name) |
| void | SetPeer (TCP_NVT *arg_peer) |
| const char * | AuthName () const |
| int | AuthenticationHasBeenAccepted () const |
Protected Member Functions | |
| TCP_NVT () | |
| void | DoDeliver (double t, int seq, int len, u_char *data) |
| void | ScanOption (double t, int seq, int len, u_char *data) |
| virtual void | SawOption (unsigned int code) |
| virtual void | SawOption (unsigned int code, unsigned int subcode) |
| virtual void | SawSubOption (const char *opt, int len) |
| virtual void | BadOptionTermination (unsigned int code) |
| const char * | PeerAuthName () const |
Protected Attributes | |
| TCP_NVT * | peer |
| int | pending_IAC |
| int | IAC_pos |
| int | is_suboption |
| int | last_was_IAC |
| int | binary_mode |
| int | encrypting_mode |
| int | authentication_has_been_accepted |
| char * | auth_name |
| TelnetOption * | options [NUM_TELNET_OPTIONS] |
| int | num_options |
|
||||||||||||||||||||
|
Definition at line 380 of file NVT.cc. References auth_name, authentication_has_been_accepted, binary_mode, encrypting_mode, IAC_pos, is_suboption, last_was_IAC, num_options, peer, and pending_IAC.
00382 : TCP_ContentLine(arg_endp, arg_is_NUL_sensitive, 00383 arg_skip_partial, CRLF_as_EOL) 00384 { 00385 is_suboption = last_was_IAC = pending_IAC = 0; 00386 IAC_pos = 0; 00387 num_options = 0; 00388 authentication_has_been_accepted = encrypting_mode = binary_mode = 0; 00389 auth_name = 0; 00390 peer = 0; 00391 } |
|
|
Definition at line 393 of file NVT.cc. References auth_name, num_options, and options.
00394 {
00395 for ( int i = 0; i < num_options; ++i )
00396 delete options[i];
00397
00398 delete auth_name;
00399 }
|
|
|
Definition at line 168 of file NVT.h.
00168 {}
|
|
|
Definition at line 454 of file NVT.cc. References authentication_has_been_accepted, TCP_Contents::Conn(), Connection::Event(), and PeerAuthName(). Referenced by TelnetAuthenticateOption::RecvSubOption().
00455 {
00456 authentication_has_been_accepted = 1;
00457 Conn()->Event(authentication_accepted, PeerAuthName());
00458 }
|
|
|
Definition at line 164 of file NVT.h. References authentication_has_been_accepted. Referenced by TelnetEncryptOption::RecvSubOption().
00165 { return authentication_has_been_accepted; }
|
|
|
Definition at line 460 of file NVT.cc. References authentication_has_been_accepted, TCP_Contents::Conn(), Connection::Event(), and PeerAuthName(). Referenced by TelnetAuthenticateOption::RecvSubOption().
00461 {
00462 authentication_has_been_accepted = 0;
00463 Conn()->Event(authentication_rejected, PeerAuthName());
00464 }
|
|
|
Definition at line 163 of file NVT.h. References auth_name. Referenced by PeerAuthName().
00163 { return auth_name; }
|
|
|
Definition at line 719 of file NVT.cc. References TCP_Contents::Conn(), and Connection::Event(). Referenced by ScanOption().
|
|
||||||||||||||||||||
|
Reimplemented from TCP_ContentLine. Definition at line 494 of file NVT.cc. References binary_mode, TCP_ContentLine::CheckNUL(), TCP_Contents::Conn(), CR_as_EOL, EMIT_LINE, Connection::FlagEvent(), IAC_pos, TCP_ContentLine::Init(), is_suboption, LF_as_EOL, pending_IAC, ScanOption(), SINGULAR_CR, SINGULAR_LF, TELNET_IAC, and Connection::Weird().
00495 {
00496 // This code is very similar to that for TCP_ContentLine. We
00497 // don't virtualize out the differences because some of them
00498 // would require per-character function calls, too expensive.
00499 if ( pending_IAC )
00500 {
00501 ScanOption(t, seq, len, data);
00502 return;
00503 }
00504
00505 // Add data up to IAC or end.
00506 for ( ; len > 0; --len, ++data )
00507 {
00508 if ( offset >= buf_len )
00509 Init(buf_len * 2);
00510
00511 int c = data[0];
00512
00513 if ( binary_mode && c != TELNET_IAC )
00514 c &= 0x7f;
00515
00516 #define EMIT_LINE \
00517 { \
00518 buf[offset] = '\0'; \
00519 Conn()->NewLine(this, offset, buf); \
00520 offset = 0; \
00521 }
00522
00523 switch ( c ) {
00524 case '\r':
00525 if ( CR_LF_as_EOL & CR_as_EOL )
00526 EMIT_LINE
00527 else
00528 buf[offset++] = c;
00529 break;
00530
00531 case '\n':
00532 if ( last_char == '\r' )
00533 {
00534 --offset; // remove '\r'
00535 EMIT_LINE
00536 }
00537 else if ( CR_LF_as_EOL & LF_as_EOL )
00538 EMIT_LINE
00539 else
00540 {
00541 if ( Conn()->FlagEvent(SINGULAR_LF) )
00542 Conn()->Weird("line_terminated_with_single_LF");
00543 buf[offset++] = c;
00544 }
00545 break;
00546
00547 case '\0':
00548 if ( last_char == '\r' )
00549 // Allow a NUL just after a \r - Solaris
00550 // Telnet servers generate these, and they
00551 // appear harmless.
00552 ;
00553
00554 else if ( flag_NULs )
00555 CheckNUL();
00556
00557 else
00558 buf[offset++] = c;
00559 break;
00560
00561 case TELNET_IAC:
00562 pending_IAC = 1;
00563 IAC_pos = offset;
00564 is_suboption = 0;
00565 buf[offset++] = c;
00566 ScanOption(t, seq, len - 1, data + 1);
00567 return;
00568
00569 default:
00570 buf[offset++] = c;
00571 break;
00572 }
00573
00574 if ( ! (CR_LF_as_EOL & CR_as_EOL) &&
00575 last_char == '\r' && c != '\n' && c != '\0' )
00576 {
00577 if ( Conn()->FlagEvent(SINGULAR_CR) )
00578 Conn()->Weird("line_terminated_with_single_CR");
00579 }
00580
00581 last_char = c;
00582 }
00583 }
|
|
|
Definition at line 401 of file NVT.cc. References TelnetOption::Code(), num_options, NUM_TELNET_OPTIONS, options, peer, TELNET_OPTION_AUTHENTICATE, TELNET_OPTION_BINARY, TELNET_OPTION_ENCRYPT, TELNET_OPTION_ENVIRON, and TELNET_OPTION_TERMINAL. Referenced by FindPeerOption(), SawOption(), and SawSubOption().
00402 {
00403 if ( ! peer )
00404 // We can't do option processing if our peer doesn't
00405 // keep track of connection contents, as then we can't
00406 // see what's ack'd and what isn't.
00407 return 0;
00408
00409 int i;
00410 for ( i = 0; i < num_options; ++i )
00411 if ( options[i]->Code() == code )
00412 return options[i];
00413
00414 TelnetOption* opt = 0;
00415 if ( i < NUM_TELNET_OPTIONS )
00416 { // Maybe we haven't created this option yet.
00417 switch ( code ) {
00418 case TELNET_OPTION_BINARY:
00419 opt = new TelnetBinaryOption(this);
00420 break;
00421
00422 case TELNET_OPTION_TERMINAL:
00423 opt = new TelnetTerminalOption(this);
00424 break;
00425
00426 case TELNET_OPTION_ENCRYPT:
00427 opt = new TelnetEncryptOption(this);
00428 break;
00429
00430 case TELNET_OPTION_AUTHENTICATE:
00431 opt = new TelnetAuthenticateOption(this);
00432 break;
00433
00434 case TELNET_OPTION_ENVIRON:
00435 opt = new TelnetEnvironmentOption(this);
00436 break;
00437 }
00438 }
00439
00440 if ( opt )
00441 options[num_options++] = opt;
00442
00443 return opt;
00444 }
|
|
|
Definition at line 446 of file NVT.cc. References FindOption(), and peer. Referenced by TelnetOption::RecvOption(), TelnetAuthenticateOption::RecvSubOption(), and TelnetEncryptOption::RecvSubOption().
00447 {
00448 if ( peer )
00449 return peer->FindOption(code);
00450 else
00451 return 0;
00452 }
|
|
|
Definition at line 466 of file NVT.cc. References AuthName(), and peer. Referenced by AuthenticationAccepted(), and AuthenticationRejected().
|
|
||||||||||||
|
Definition at line 700 of file NVT.cc. References FindOption(), and TelnetOption::RecvOption().
00701 {
00702 TelnetOption* opt = FindOption(subcode);
00703 if ( opt )
00704 opt->RecvOption(code);
00705 }
|
|
|
Definition at line 696 of file NVT.cc. Referenced by ScanOption().
00697 {
00698 }
|
|
||||||||||||
|
Definition at line 707 of file NVT.cc. References FindOption(), and TelnetOption::RecvSubOption(). Referenced by ScanOption().
00708 {
00709 unsigned int subcode = u_char(subopt[0]);
00710
00711 ++subopt;
00712 --len;
00713
00714 TelnetOption* opt = FindOption(subcode);
00715 if ( opt )
00716 opt->RecvSubOption((u_char*) subopt, len);
00717 }
|
|
||||||||||||||||||||
|
Definition at line 585 of file NVT.cc. References BadOptionTermination(), TCP_ContentLine::Deliver(), IAC_pos, IS_3_BYTE_OPTION, is_suboption, last_was_IAC, pending_IAC, SawOption(), SawSubOption(), TELNET_IAC, TELNET_OPT_SB, and TELNET_OPT_SE. Referenced by DoDeliver().
00586 {
00587 if ( len <= 0 )
00588 return;
00589
00590 if ( IAC_pos == offset - 1 )
00591 { // All we've seen so far is the IAC.
00592 unsigned int code = data[0];
00593
00594 if ( code == TELNET_IAC )
00595 {
00596 // An escaped 255, throw away the second
00597 // instance and drop the IAC state.
00598 pending_IAC = 0;
00599 last_char = code;
00600 }
00601
00602 else if ( code == TELNET_OPT_SB )
00603 {
00604 is_suboption = 1;
00605 last_was_IAC = 0;
00606 buf[offset++] = code;
00607 }
00608
00609 else if ( IS_3_BYTE_OPTION(code) )
00610 {
00611 is_suboption = 0;
00612 buf[offset++] = code;
00613 }
00614
00615 else
00616 {
00617 // We've got the whole 2-byte option.
00618 SawOption(code);
00619
00620 // Throw it and the IAC away.
00621 --offset;
00622 pending_IAC = 0;
00623 }
00624
00625 // Recurse to munch on the remainder.
00626 Deliver(t, seq, len - 1, data + 1);
00627 return;
00628 }
00629
00630 if ( ! is_suboption )
00631 {
00632 // We now have the full 3-byte option.
00633 SawOption(u_char(buf[offset-1]), data[0]);
00634
00635 // Delete the option.
00636 offset -= 2; // code + IAC
00637 pending_IAC = 0;
00638
00639 Deliver(t, seq, len - 1, data + 1);
00640 return;
00641 }
00642
00643 // A suboption. Spin looking for end.
00644 for ( ; len > 0; --len, ++data )
00645 {
00646 unsigned int code = data[0];
00647
00648 if ( last_was_IAC )
00649 {
00650 last_was_IAC = 0;
00651
00652 if ( code == TELNET_IAC )
00653 {
00654 // This is an escaped IAC, eat
00655 // the second copy.
00656 continue;
00657 }
00658
00659 if ( code != TELNET_OPT_SE )
00660 // BSD Telnet treats this case as terminating
00661 // the suboption, so that's what we do here
00662 // too. Below we make sure to munch on the
00663 // new IAC.
00664 BadOptionTermination(code);
00665
00666 int opt_start = IAC_pos + 2;
00667 int opt_stop = offset - 1;
00668 int opt_len = opt_stop - opt_start;
00669 SawSubOption(&buf[opt_start], opt_len);
00670
00671 // Delete suboption.
00672 offset = IAC_pos;
00673 pending_IAC = is_suboption = 0;
00674
00675 if ( code == TELNET_OPT_SE )
00676 Deliver(t, seq, len - 1, data + 1);
00677 else
00678 {
00679 // Munch on the new (broken) option.
00680 pending_IAC = 1;
00681 IAC_pos = offset;
00682 buf[offset++] = TELNET_IAC;
00683 Deliver(t, seq, len, data);
00684 }
00685 return;
00686 }
00687
00688 else
00689 {
00690 buf[offset++] = code;
00691 last_was_IAC = (code == TELNET_IAC);
00692 }
00693 }
00694 }
|
|
|
Definition at line 159 of file NVT.h. References auth_name. Referenced by TelnetAuthenticateOption::RecvSubOption().
00159 { auth_name = arg_auth_name; }
|
|
|
Definition at line 157 of file NVT.h. References binary_mode. Referenced by TelnetBinaryOption::SetActive().
00157 { binary_mode = mode; }
|
|
|
Definition at line 485 of file NVT.cc. References TCP_Contents::Conn(), encrypting_mode, and Connection::Event(). Referenced by TelnetEncryptOption::RecvSubOption().
00486 {
00487 skip_deliveries = encrypting_mode = mode;
00488 if ( mode )
00489 Conn()->Event(activating_encryption);
00490 }
|
|
|
Definition at line 161 of file NVT.h. References peer. Referenced by TelnetConn::BuildEndpoints(), and FTP_Conn::BuildEndpoints().
00161 { peer = arg_peer; }
|
|
||||||||||||
|
Definition at line 473 of file NVT.cc. References BroString, TCP_Contents::Conn(), and Connection::ConnectionEvent(). Referenced by TelnetTerminalOption::RecvSubOption().
00474 {
00475 if ( login_terminal )
00476 {
00477 val_list* vl = new val_list;
00478 vl->append(Conn()->BuildConnVal());
00479 vl->append(new StringVal(new BroString(terminal, len, 0)));
00480
00481 Conn()->ConnectionEvent(login_terminal, vl);
00482 }
00483 }
|
|
|
Definition at line 190 of file NVT.h. Referenced by AuthName(), SetAuthName(), TCP_NVT(), and ~TCP_NVT(). |
|
|
Definition at line 189 of file NVT.h. Referenced by AuthenticationAccepted(), AuthenticationHasBeenAccepted(), AuthenticationRejected(), and TCP_NVT(). |
|
|
Definition at line 188 of file NVT.h. Referenced by DoDeliver(), SetBinaryMode(), and TCP_NVT(). |
|
|
Definition at line 188 of file NVT.h. Referenced by SetEncrypting(), and TCP_NVT(). |
|
|
Definition at line 184 of file NVT.h. Referenced by DoDeliver(), ScanOption(), and TCP_NVT(). |
|
|
Definition at line 185 of file NVT.h. Referenced by DoDeliver(), ScanOption(), and TCP_NVT(). |
|
|
Definition at line 186 of file NVT.h. Referenced by ScanOption(), and TCP_NVT(). |
|
|
Definition at line 193 of file NVT.h. Referenced by FindOption(), TCP_NVT(), and ~TCP_NVT(). |
|
|
Definition at line 192 of file NVT.h. Referenced by FindOption(), and ~TCP_NVT(). |
|
|
Definition at line 181 of file NVT.h. Referenced by FindOption(), FindPeerOption(), PeerAuthName(), SetPeer(), and TCP_NVT(). |
|
|
Definition at line 183 of file NVT.h. Referenced by DoDeliver(), ScanOption(), and TCP_NVT(). |
1.3.6