[Add] Obfuscate executable file content.

This commit is contained in:
Ritchie Cunningham 2025-10-28 18:36:54 +00:00
parent 9b6106f8aa
commit 233dd384f6
5 changed files with 27 additions and 4 deletions

View File

@ -7,6 +7,7 @@
#include "session.h" #include "session.h"
#include "machine.h" #include "machine.h"
#include "vfs.h" #include "vfs.h"
#include "util.h"
namespace api { namespace api {
@ -117,7 +118,7 @@ std::string create_executable(Session& context, const std::string& path,
parent_dir->children.erase(it); parent_dir->children.erase(it);
} }
vfs_node* new_exec = new_node(filename, EXEC_NODE, parent_dir); vfs_node* new_exec = new_node(filename, EXEC_NODE, parent_dir);
new_exec->content = content; new_exec->content = util::xor_string(content);
parent_dir->children[filename] = new_exec; parent_dir->children[filename] = new_exec;
return ""; return "";
} }

View File

@ -7,6 +7,7 @@
#include "machine_manager.h" #include "machine_manager.h"
#include "machine.h" #include "machine.h"
#include "vfs.h" #include "vfs.h"
#include "util.h"
vfs_node* copy_vfs_node(vfs_node* original, vfs_node* new_parent) { vfs_node* copy_vfs_node(vfs_node* original, vfs_node* new_parent) {
if(!original) { if(!original) {
@ -42,7 +43,7 @@ MachineManager::MachineManager(DatabaseManager* db_manager) :
std::string filename_with_ext = entry.path().filename().string(); std::string filename_with_ext = entry.path().filename().string();
std::string filename = filename_with_ext.substr(0, filename_with_ext.find_last_of('.')); std::string filename = filename_with_ext.substr(0, filename_with_ext.find_last_of('.'));
vfs_node* script_node = new_node(filename, EXEC_NODE, bin); vfs_node* script_node = new_node(filename, EXEC_NODE, bin);
script_node->content = buffer.str(); script_node->content = util::xor_string(buffer.str());
bin->children[filename] = script_node; bin->children[filename] = script_node;
fprintf(stderr, "Loaded executable: /bin/%s\n", filename.c_str()); fprintf(stderr, "Loaded executable: /bin/%s\n", filename.c_str());
} }

View File

@ -8,7 +8,7 @@
#include "lua_processor.h" #include "lua_processor.h"
#include "machine.h" #include "machine.h"
#include "vfs.h" #include "vfs.h"
#include "util.h"
vfs_node* find_node_by_id(vfs_node* root, long long id) { vfs_node* find_node_by_id(vfs_node* root, long long id) {
if(root->id == id) { if(root->id == id) {
@ -113,7 +113,8 @@ std::string Session::process_command(const std::string& command) {
if(command_node) { if(command_node) {
if(command_node->type == EXEC_NODE) { if(command_node->type == EXEC_NODE) {
bool is_remote = (_session_machine != _home_machine); bool is_remote = (_session_machine != _home_machine);
sol::object result = lua.execute(command_node->content, *this, args, is_remote); std::string deobfuscated_content = util::xor_string(command_node->content);
sol::object result = lua.execute(deobfuscated_content, *this, args, is_remote);
return result.is<std::string>() ? result.as<std::string>() return result.is<std::string>() ? result.as<std::string>()
: "[Script returned non-string value]"; : "[Script returned non-string value]";
} else if(command_node->type == DIR_NODE) { } else if(command_node->type == DIR_NODE) {

14
common/src/util.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "util.h"
namespace util {
std::string xor_string(const std::string& data) {
std::string result = data;
char key = 'B';
for(size_t i = 0; i < data.size(); ++i) {
result[i] = data[i] ^ key;
}
return result;
}
}

6
common/src/util.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#include <string>
namespace util {
std::string xor_string(const std::string& data);
}