Module Installation - Inno-SVQ/RedOps GitHub Wiki

Module Installation

The RedOps modules are made in Python 3.

  1. First of all, it's necessary to have downloaded the repository and installed the agent. To do this, you can follow the following link: wiki/Agent-installation.

  2. Then you must import BaseModule. This module has the main basis for any module that you want to create. Where you can find the parameters that you pass for a communication with the agent. Thus, for the correct import of the module, it will be carried out as follows:from modules.Generics.BaseModule import BaseModule.

  3. On the other hand, it is necessary to implement the type of object that will be sent to the agent, it must be imported in the same way as BaseModule. An example can be the following:from modules.Generics.Domain import Domain. On the other hand, if you need to create a new type of object it is recommended to Create Own Object.

  4. Finally, a basic structure for sending data needs to be applied. To do this, it is recommended to review the Basic Skeleton section for a module.

Create Own Object

By the established standards, it is necessary to add the file created in the directory agent/modules/Generics. The skeleton to follow is:

class OwnObject:
    def __init__(self, id, param1, param2, paramN):
        self.id = id
        self.param1 = param1
        self.param2 = param2
        self.paramN = paramN

    def toDict(self):
        return {
            "type": "__ownobject__",
            "id": self.id,
            "param1": self.ip,
            "param2": self.param2,
            "paramN": self.paramN
        }

    def __repr__(self):
        return str(self.toDict())

Where def __init__(): has following mandatory parameters: self, id. On the other hand, def toDict(self): it's necessary to implement like the example, just like def __repr__(self):. Each 'param' corresponds to the developer's own parameters.

Basic Skeleton Module

The basic skeleton to be implemented is as follows:

from modules.Generics.BaseModule import BaseModule
from modules.Generics.OwnObject import OwnObject

class Module(BaseModule):

    def run(self, callback):
        app=nameClassObject(callback)

        data = self.params["data"]

        for index, domain in enumerate(data):
            # TODO call a function || res=function ... 
            jsonStr=[]
            for i in res:
                jsonStr.append(OwnObject(param1,param2,paramN))

            # In the last loop we want to finish the task in the server
            if(index < len(self.params) - 1):
                callback.update(jsonStr)

            callback.finish(jsonStr)

This class is necessary for the correct operation class Module(BaseModule):. It should be noted that through callback.finish(jsonStr) the information is sent to the agent.

Finally, you need to add the next initial part:

class SearchDomain:

    def __init__(self, callback):
        self.callback = callback

The parameter callback, It can also be used to debug the module. For instance: self.callback.debug(printSomething).