ternary
This tag is based on a old Hackvertor tag I wrote years ago. It does random expressions and obfuscates via ternary operations.
Created by: hackvertor
Installed 1 times
Category: XSS
Created on: Monday, December 9, 2024 at 12:54:50 PM
Updated on: Wednesday, December 11, 2024 at 1:41:02 PM
Tag arguments
[]
Code
class ternary {
constructor() {
this.operators = [">", "<", "==", "!="];
this.chars = "abcdefghijklmnopqrstuvwxyz";
}
getRandom(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
encode(input) {
const operator = this.operators[this.getRandom(0, this.operators.length)];
const statement = `${this.getRandom(0, 9)} ${operator} ${this.getRandom(0, 9)}`;
const randstring = Array.from(
{ length: this.getRandom(0, input.length) },
() =>
Math.random() > 0.5
? this.chars.charAt(this.getRandom(0, this.chars.length))
: this.chars
.charAt(this.getRandom(0, this.chars.length))
.toUpperCase(),
).join("");
let vector = `${statement} ${eval(statement) ? "? '$vector' : '$randstring'" : "? '$randstring' : '$vector'"}`;
vector = vector.replace("$randstring", randstring);
const concatString = Array.from(
input,
(char) => `(${vector.replace("$vector", char.replace(/'/g, "\\'"))})`,
);
return `eval(${concatString.join("+")})`;
}
}