MaltegoTech / maltego-trx

Maltego Transform library for Python
MIT License
218 stars 45 forks source link

Exception thrown when Properties not defined (maltego.py) #22

Closed MaltegoThinus closed 2 years ago

MaltegoThinus commented 3 years ago

If an Entity does not have Properties, calling the "getProperty" method causes an exception, since "Properties" is not defined.

This is in "maltego.py":

def getProperty(self, key):
    return self.Properties.get(key)

I suggest initializing an Empty "Properties" variable.

phdowling commented 3 years ago

Hi @MaltegoThinus, could you add some steps for reproducing this issue? Are you running on the latest version?

In server mode, Properties already gets initialized in the way you are proposing: https://github.com/paterva/maltego-trx/blob/master/maltego_trx/maltego.py#L259 In local transform mode, there is a code-path during which this does not happen, but it seems like an unlikely/impossible path if I am not mistaken: https://github.com/paterva/maltego-trx/blob/master/maltego_trx/maltego.py#L287 In any case it is probably worth fixing the problem in the local transform case - I could see how an entity with no defined properties at all could trigger this bug in a local setting.

MaltegoThinus commented 3 years ago

Hi @phdowling, yes: it's a local Transform only thing. If there are no additional arguments, then this error occurs because the "if len(LocalArgs) > 1" loop (line 287 in "maltego.py") is never executed, and the TransformSettings in line 297 is never initialized.

I think this is only possible when testing the Transform from the cmdline, since I don't duplicate properties when specifying the main value only. I think (not sure) that when the Local Transform is run from Maltego, it will add the "value" argument as well as a property for the main property.

To reproduce this, you can add a line to the GreetPerson example: "request.getProperty("randomstuffhere")", and then run the Transfrom from the terminal "python project.py local greetperson Thinus".

I test Transforms this way all the time, before wiring them into Maltego. Not sure if it's a common workflow.

felixatmaltego commented 2 years ago

Fixed in PR #27

crest42 commented 2 years ago

Close with reference to #27