Expanding Neto capabilities: how to develop new analysis plugins
A system of plugins to gain flexibility
$ pip3 install neto --user --upgrade
But first, we will give you a brief description of how Neto works. Each extension is represented in Python in an object that loads the official analysis methods that we have included in
neto/plugins/analysis.
Neto will automatically execute the function defined as
runAnalysis
in which we will receive two different parameters that we can use according to our needs:
-
extensionFile
The local path in which the compressed file of the extension is located. -
unzippedFiles
A list in which the keys are the relative path of the unzipped file which is found in the extension and the absolute path value where it has been unzipped in the system. By default, this is a temporary route.
{ "manifest.json": "/tmp/extension/manifest.json" … }
unzippedFiles
but if we want to analyze the file itself we can use
extensionFile
. It depends on our needs. What we have to take into account is that you should always return a list in which the key is the name we give to our procedure and the value of the results. Thus, this new attribute will be added to the rest of the elements already obtained.
~/.config/ElevenPaths/Neto/plugins/.
The characteristics of these user modules are identical to those of the official modules only that will be loaded upon request.
Creating our first plugin for Neto
~/.config/ElevenPaths/Neto/plugins/template.py.sample
It is easy to start developing from this screen and in order to see it we will make a simple
plugin, which will count the number of files which the extension contains.
def runAnalysis(**kwargs): """ Method that runs an analysis This method is dinamically loaded by neto.lib.extensions.Extension objects to conduct an analysis. The analyst can choose to perform the analysis on kwargs["extensionFile"] or on kwargs["unzippedFiles"]. It SHOULD return a dictionary with the results of the analysis that will be updated to the features property of the Extension. Args: ----- kwargs: It currently contains: - extensionFile: A string to the local path of the extension. - unzippedFiles: A dictionary where the key is the relative path to the file and the the value the absolute path to the extension. { "manifest.json": "/tmp/extension/manifest.json" … } Returns: -------- A dictionary where the key is the name given to the analysis and the value is the result of the analysis. This result can be of any format. """ results = {} # Iterate through all the files in the folder for f, realPath in kwargs["unzippedFiles"].items(): if os.path.isfile(realPath): # TODO: Your code here for each file pass return {__name__: results}
kwargs["unzippedFiles"]
and we will reutilize the loop which we already have to count those elements which are files increasing the variable
myCounter,
which we initiated at the start of the method.
myCounter = 0 # Iterate through all the files in the folder for f, realPath in kwargs["unzippedFiles"].items(): if os.path.isfile(realPath): # TODO: Your code here for each file myCounter += 1 return {"num_files": myCounter}
~/.config/ElevenPaths/Neto/plugins/hello_world.py
for example. All that's left to do is start Neto with a new extension (for example, with the CLI) and to check the exit:
$ neto analyser -e ./my_demo.xpi $ cat /home/USER/.config/ElevenPaths/Neto/data/analysis/854…78f.json | grep num_files "num_files": 151,
$ git clone https://github.com/USER/neto $ cd neto
~/.config/ElevenPaths/Neto/plugins/hello_world.py
and copy it into the file of
neto/plugins/analysis
.
$ cp ~/.config/ElevenPaths/Neto/plugins/hello_world.py neto/plugins/analysis
$ git add neto/plugins/analyser $ git commit -m "Add hello_world plugin following the tutorial" $ git push origin master
setup.py
so that they satisfy the corresponding dependencies. Even so, you will not be in the process alone. Do you fancy trying it out?