RC4Drop.mjs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @author n1474335 [n1474335@gmail.com]
  3. * @copyright Crown Copyright 2016
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation";
  7. import { format } from "../lib/Ciphers";
  8. import CryptoJS from "crypto-js";
  9. /**
  10. * RC4 Drop operation
  11. */
  12. class RC4Drop extends Operation {
  13. /**
  14. * RC4Drop constructor
  15. */
  16. constructor() {
  17. super();
  18. this.name = "RC4 Drop";
  19. this.module = "Ciphers";
  20. this.description = "It was discovered that the first few bytes of the RC4 keystream are strongly non-random and leak information about the key. We can defend against this attack by discarding the initial portion of the keystream. This modified algorithm is traditionally called RC4-drop.";
  21. this.inputType = "string";
  22. this.outputType = "string";
  23. this.args = [
  24. {
  25. "name": "Passphrase",
  26. "type": "toggleString",
  27. "value": "",
  28. "toggleValues": ["UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1", "Hex", "Base64"]
  29. },
  30. {
  31. "name": "Input format",
  32. "type": "option",
  33. "value": ["Latin1", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Hex", "Base64"]
  34. },
  35. {
  36. "name": "Output format",
  37. "type": "option",
  38. "value": ["Latin1", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Hex", "Base64"]
  39. },
  40. {
  41. "name": "Number of bytes to drop",
  42. "type": "number",
  43. "value": 768
  44. }
  45. ];
  46. }
  47. /**
  48. * @param {string} input
  49. * @param {Object[]} args
  50. * @returns {string}
  51. */
  52. run(input, args) {
  53. const message = format[args[1]].parse(input),
  54. passphrase = format[args[0].option].parse(args[0].string),
  55. drop = args[3],
  56. encrypted = CryptoJS.RC4Drop.encrypt(message, passphrase, { drop: drop });
  57. return encrypted.ciphertext.toString(format[args[2]]);
  58. }
  59. /**
  60. * Highlight RC4 Drop
  61. *
  62. * @param {Object[]} pos
  63. * @param {number} pos[].start
  64. * @param {number} pos[].end
  65. * @param {Object[]} args
  66. * @returns {Object[]} pos
  67. */
  68. highlight(pos, args) {
  69. return pos;
  70. }
  71. /**
  72. * Highlight RC4 Drop in reverse
  73. *
  74. * @param {Object[]} pos
  75. * @param {number} pos[].start
  76. * @param {number} pos[].end
  77. * @param {Object[]} args
  78. * @returns {Object[]} pos
  79. */
  80. highlightReverse(pos, args) {
  81. return pos;
  82. }
  83. }
  84. export default RC4Drop;