2018-11-20 17:09:52 +01:00
|
|
|
/**
|
|
|
|
* @author bwhitn [brian.m.whitney@gmail.com]
|
2018-11-21 13:28:19 +01:00
|
|
|
* @copyright Crown Copyright 2018
|
2018-11-20 17:09:52 +01:00
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Operation from "../Operation";
|
2018-11-21 13:28:19 +01:00
|
|
|
import OperationError from "../errors/OperationError";
|
2018-11-20 17:09:52 +01:00
|
|
|
import cptable from "../vendor/js-codepage/cptable.js";
|
|
|
|
|
|
|
|
/**
|
2018-11-21 13:28:19 +01:00
|
|
|
* Citrix CTX1 Decode operation
|
2018-11-20 17:09:52 +01:00
|
|
|
*/
|
2018-11-21 13:28:19 +01:00
|
|
|
class CitrixCTX1Decode extends Operation {
|
2018-11-20 17:09:52 +01:00
|
|
|
|
|
|
|
/**
|
2018-11-21 13:28:19 +01:00
|
|
|
* CitrixCTX1Decode constructor
|
2018-11-20 17:09:52 +01:00
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Citrix CTX1 Decode";
|
2018-11-21 13:28:19 +01:00
|
|
|
this.module = "Encodings";
|
2018-11-20 17:09:52 +01:00
|
|
|
this.description = "Decodes strings in a Citrix CTX1 password format to plaintext.";
|
|
|
|
this.infoURL = "https://www.reddit.com/r/AskNetsec/comments/1s3r6y/citrix_ctx1_hash_decoding/";
|
|
|
|
this.inputType = "byteArray";
|
|
|
|
this.outputType = "string";
|
|
|
|
this.args = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {byteArray} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
2018-11-20 17:24:50 +01:00
|
|
|
if (input.length % 4 !== 0) {
|
2018-11-21 13:28:19 +01:00
|
|
|
throw new OperationError("Incorrect hash length");
|
2018-11-20 17:09:52 +01:00
|
|
|
}
|
2018-11-20 17:24:50 +01:00
|
|
|
const revinput = input.reverse();
|
|
|
|
const result = [];
|
2018-11-20 17:09:52 +01:00
|
|
|
let temp = 0;
|
2018-11-21 13:28:19 +01:00
|
|
|
for (let i = 0; i < revinput.length; i += 2) {
|
|
|
|
if (i + 2 >= revinput.length) {
|
2018-11-20 17:09:52 +01:00
|
|
|
temp = 0;
|
|
|
|
} else {
|
|
|
|
temp = ((revinput[i + 2] - 0x41) & 0xf) ^ (((revinput[i + 3]- 0x41) << 4) & 0xf0);
|
|
|
|
}
|
|
|
|
temp = (((revinput[i] - 0x41) & 0xf) ^ (((revinput[i + 1] - 0x41) << 4) & 0xf0)) ^ 0xa5 ^ temp;
|
|
|
|
result.push(temp);
|
|
|
|
}
|
|
|
|
// Decodes a utf-16le string
|
|
|
|
return cptable.utils.decode(1200, result.reverse());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-21 13:28:19 +01:00
|
|
|
export default CitrixCTX1Decode;
|