[Add] Obfuscate executable file content.
This commit is contained in:
		
							parent
							
								
									9b6106f8aa
								
							
						
					
					
						commit
						233dd384f6
					
				@ -7,6 +7,7 @@
 | 
			
		||||
#include "session.h"
 | 
			
		||||
#include "machine.h"
 | 
			
		||||
#include "vfs.h"
 | 
			
		||||
#include "util.h"
 | 
			
		||||
 | 
			
		||||
namespace api {
 | 
			
		||||
 | 
			
		||||
@ -117,7 +118,7 @@ std::string create_executable(Session& context, const std::string& path,
 | 
			
		||||
    parent_dir->children.erase(it);
 | 
			
		||||
  }
 | 
			
		||||
  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;
 | 
			
		||||
  return "";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@
 | 
			
		||||
#include "machine_manager.h"
 | 
			
		||||
#include "machine.h"
 | 
			
		||||
#include "vfs.h"
 | 
			
		||||
#include "util.h"
 | 
			
		||||
 | 
			
		||||
vfs_node* copy_vfs_node(vfs_node* original, vfs_node* new_parent) {
 | 
			
		||||
  if(!original) {
 | 
			
		||||
@ -42,7 +43,7 @@ MachineManager::MachineManager(DatabaseManager* db_manager) :
 | 
			
		||||
      std::string filename_with_ext = entry.path().filename().string();
 | 
			
		||||
      std::string filename = filename_with_ext.substr(0, filename_with_ext.find_last_of('.'));
 | 
			
		||||
      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;
 | 
			
		||||
      fprintf(stderr, "Loaded executable: /bin/%s\n", filename.c_str());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,7 @@
 | 
			
		||||
#include "lua_processor.h"
 | 
			
		||||
#include "machine.h"
 | 
			
		||||
#include "vfs.h"
 | 
			
		||||
 | 
			
		||||
#include "util.h"
 | 
			
		||||
 | 
			
		||||
vfs_node* find_node_by_id(vfs_node* root, long long id) {
 | 
			
		||||
  if(root->id == id) {
 | 
			
		||||
@ -113,7 +113,8 @@ std::string Session::process_command(const std::string& command) {
 | 
			
		||||
  if(command_node) {
 | 
			
		||||
    if(command_node->type == EXEC_NODE) {
 | 
			
		||||
      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>()
 | 
			
		||||
                                      : "[Script returned non-string value]";
 | 
			
		||||
    } else if(command_node->type == DIR_NODE) {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								common/src/util.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								common/src/util.cpp
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										6
									
								
								common/src/util.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace util {
 | 
			
		||||
  std::string xor_string(const std::string& data);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user