badpacket.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <unistd.h>
  15. #include <iostream>
  16. #include <config.h>
  17. #include <exceptions/exceptions.h>
  18. #include "command_options.h"
  19. #include "scan.h"
  20. /// \brief Perform Bad Packet Scan
  21. ///
  22. /// Scans the server by sending a sequence of (potentially) bad packets and
  23. /// printing the packet settings and the response received. The principle
  24. /// raison d'etre for this is to check if a bad packet will cause a crash.
  25. ///
  26. /// This particular version of the code allows a set of ranges to be set for
  27. /// each field in the "flags" word (the third and fourth bytes) of a DNS
  28. /// message. (Most of the flags are single-bit values, so the range is just 0-1.
  29. /// The OPCODE and RCODE are both four bits wide, so the range is 0-15.) The
  30. /// program then sends packets containing each combination of values.
  31. ///
  32. /// TODO: Extend the program to other bad values.
  33. /// Examples of this would be to make the count fields invalid, to add data
  34. /// to sections that should be empty, and to deliberately mangle the names in
  35. /// these sections.
  36. using namespace isc::badpacket;
  37. /// \brief Main Program
  38. int main(int argc, char* argv[]) {
  39. try {
  40. CommandOptions options;
  41. options.parse(argc, argv);
  42. // Construct the scan object and perform the scan.
  43. Scan scanner;
  44. scanner.scan(options);
  45. } catch (isc::Exception& e) {
  46. std::cout << "ERROR: " << e.what() << "\n";
  47. return 1;
  48. }
  49. return 0;
  50. }