censor1.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Packet-censoring code for SSH-1, used to identify sensitive fields
  3. * like passwords so that the logging system can avoid writing them
  4. * into log files.
  5. */
  6. #include <assert.h>
  7. #include "putty.h"
  8. #include "ssh.h"
  9. int ssh1_censor_packet(
  10. const PacketLogSettings *pls, int type, bool sender_is_client,
  11. ptrlen pkt, logblank_t *blanks)
  12. {
  13. int nblanks = 0;
  14. ptrlen str;
  15. BinarySource src[1];
  16. BinarySource_BARE_INIT_PL(src, pkt);
  17. if (pls->omit_data &&
  18. (type == SSH1_SMSG_STDOUT_DATA ||
  19. type == SSH1_SMSG_STDERR_DATA ||
  20. type == SSH1_CMSG_STDIN_DATA ||
  21. type == SSH1_MSG_CHANNEL_DATA)) {
  22. /* "Session data" packets - omit the data string. */
  23. if (type == SSH1_MSG_CHANNEL_DATA)
  24. get_uint32(src); /* skip channel id */
  25. str = get_string(src);
  26. if (!get_err(src)) {
  27. assert(nblanks < MAX_BLANKS);
  28. blanks[nblanks].offset = src->pos - str.len;
  29. blanks[nblanks].type = PKTLOG_OMIT;
  30. blanks[nblanks].len = str.len;
  31. nblanks++;
  32. }
  33. }
  34. if (sender_is_client && pls->omit_passwords) {
  35. if (type == SSH1_CMSG_AUTH_PASSWORD ||
  36. type == SSH1_CMSG_AUTH_TIS_RESPONSE ||
  37. type == SSH1_CMSG_AUTH_CCARD_RESPONSE) {
  38. /* If this is a password or similar packet, blank the
  39. * password(s). */
  40. assert(nblanks < MAX_BLANKS);
  41. blanks[nblanks].offset = 0;
  42. blanks[nblanks].len = pkt.len;
  43. blanks[nblanks].type = PKTLOG_BLANK;
  44. nblanks++;
  45. } else if (type == SSH1_CMSG_X11_REQUEST_FORWARDING) {
  46. /*
  47. * If this is an X forwarding request packet, blank the
  48. * fake auth data.
  49. *
  50. * Note that while we blank the X authentication data
  51. * here, we don't take any special action to blank the
  52. * start of an X11 channel, so using MIT-MAGIC-COOKIE-1
  53. * and actually opening an X connection without having
  54. * session blanking enabled is likely to leak your cookie
  55. * into the log.
  56. */
  57. get_string(src); /* skip protocol name */
  58. str = get_string(src);
  59. if (!get_err(src)) {
  60. assert(nblanks < MAX_BLANKS);
  61. blanks[nblanks].offset = src->pos - str.len;
  62. blanks[nblanks].type = PKTLOG_BLANK;
  63. blanks[nblanks].len = str.len;
  64. nblanks++;
  65. }
  66. }
  67. }
  68. return nblanks;
  69. }