Skip to content

Instantly share code, notes, and snippets.

@WKL-Sec
Created March 7, 2024 15:49
Show Gist options
  • Save WKL-Sec/e24830ebfafabc283bd9329e79f71164 to your computer and use it in GitHub Desktop.
Save WKL-Sec/e24830ebfafabc283bd9329e79f71164 to your computer and use it in GitHub Desktop.
This code snippet demonstrates a simple yet effective string obfuscation technique using a combination of XOR, NOT, and ADD operations.
// White Knight Labs - Offensive Development Course
// String Obfuscation
#include <iostream>
#include <string>
// Function to apply XOR, then NOT, and finally ADD 1 for obfuscation
std::string obfuscateString(const std::string& input) {
std::string output = input;
for (char& c : output) {
c = ~((c ^ 0xAA) + 1); // Obfuscate: XOR with 0xAA, ADD 1, then NOT
}
return output;
}
// Function to reverse the obfuscation process
std::string deobfuscateString(const std::string& input) {
std::string output = input;
for (char& c : output) {
c = ((~c) - 1) ^ 0xAA; // Deobfuscate: NOT, then SUBTRACT 1, finally XOR with 0xAA
}
return output;
}
int main() {
const std::string secretName = "OpenProcess";
// Obfuscating the string
std::string obfuscatedSecretName = obfuscateString(secretName);
std::cout << "Obfuscated: " << obfuscatedSecretName << std::endl;
// Deobfuscating the string
std::string deobfuscatedSecretName = deobfuscateString(obfuscatedSecretName);
std::cout << "Deobfuscated: " << deobfuscatedSecretName << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment