Giter VIP home page Giter VIP logo

Comments (9)

rholloway avatar rholloway commented on June 13, 2024

Hi Tom. This is likely also related to #12 as the rebuilt rule comes from the parsed rule data. I'm not sure that is actually a blocker for this though. Will take a look.

from plyara.

rshipp avatar rshipp commented on June 13, 2024

This should be fixed in plyara v1.2.4 with @Taskr's changes (#18).

Thanks for the issue, and let us know if you find any more problems.

from plyara.

tlansec avatar tlansec commented on June 13, 2024

Hi,

Yep - this fixes it.

Thanks for the fast turn around!

Tom

from plyara.

tlansec avatar tlansec commented on June 13, 2024

Hey,

I found an edge case (possibly more than one) where the current fix will not correctly parse a rule, for example:

rule test
{
meta:
    field = "1"
    field = "2"
condition:
    false

}

Will fail on this check with a TypeError:

# Check for and handle correctly quoting string metadata
for k, v in rule['metadata'].items():
    try:
        if v in ('true', 'false') or int(v):
             pass
        except ValueError:
             v = '"{}"'.format(v)

An extra try/except would resolve the issue, like this:

except TypeError:
     if isinstance(v, list):
         v = '"{}"'.format(v)

Cheers,
Tom

from plyara.

rshipp avatar rshipp commented on June 13, 2024

Interesting... is a list what you'd expect these fields to be parsed as? This is what our dict looks like now:

    "metadata": {
        "field": [
            "1", 
            "2"
        ]
    }, 

Which means if all we do is v = '"{}"'.format(v), we'd end up with rebuild output like this:

field = "[1, 2]"

At the least we'd need to handle splitting that back into

field = 1
field = 2

But more than that, I'm not sure it makes sense to represent this as a list in the parsed dict object. What's the general use case for this? I haven't seen duplicate meta fields used before.

from plyara.

tlansec avatar tlansec commented on June 13, 2024

Hi,

Yea good point.

I have a large repository of rules from multiple contributors, some contributors have included a list of hashes in their rules, and define each hash in the metadata using:

hash = "$hash1"
hash = "$hash2"

That's how I came across this case.

I agree it makes more sense to split them back into each line as the original rule had them to stay in the spirit of rebuilding the original rule as it was.

Cheers,
Tom

from plyara.

rshipp avatar rshipp commented on June 13, 2024

Got it. In that case, it sounds like using a list internally is OK, since it's meant to be a list of reference hashes.

@Taskr do you want to handle this piece? Or I can probably get to it sometime this week.

from plyara.

Taskr avatar Taskr commented on June 13, 2024

@rshipp @tlansec New pull should fix the issue. I completely blanked on the list of same metadata entries. Thanks for the input @tlansec. Also added to test case to verify working correctly. Minimal changes to just the rebuild rule method so it won't impact any other part :)

from plyara.

rshipp avatar rshipp commented on June 13, 2024

Pushed as v1.2.5, let us know if you find anything else!

from plyara.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.