eth0izzle / shhgit

Ah shhgit! Find secrets in your code. Secrets detection for your GitHub, GitLab and Bitbucket repositories.
MIT License
3.84k stars 481 forks source link

Implement YARA rules #17

Open eth0izzle opened 5 years ago

eth0izzle commented 5 years ago

To replace the current yaml signatures. This will allow us to create mroe powerful rules. For example to find GitHub API keys we would regex on ([a-f\d]{40}), but currently that would produce a lot of false positives (it's a SHA1 hash). With a YARA rule we could do:

rule GitHubApikey
{
    strings:
        $re1 = /[a-f\d]{40}/
        $re2 = /Authorization: token/
        $re3 = /https://api.github.com/

    condition:
        $re1 and ($re2 or $re3)
}
audibleblink commented 4 years ago

@eth0izzle does your ideal implementation

  1. replace yaml with YARA?
  2. add yara as an option, leaving yaml?
  3. add yara as the new default, making yaml optional?

For 2 and 3, a cli option could be added to choose the default matching engine.

I'm all for number 1. Easier to maintain just 1 code path. But what do you see being more merge-able, from a maintainer's standpoint?

This would probably close out #10 too, yeah?

audibleblink commented 4 years ago

Could also potentially use both.

Since yara won't do filename or extension matching, perhaps we leave the yaml config file for the filename and extension parts. Eliminate contents as a part option from the config file and only use yara for pattern matching.

Or some variation of all of the above.

eth0izzle commented 4 years ago

Definitely the first option. I've already written the code for this and it seems to work well, just a little slow. I need to do further testing and cleanup. We can pass in YARA variables to check the extension, path and file name.

Have you made a start on this @audibleblink ?

audibleblink commented 4 years ago

I haven't @eth0izzle. Just spent some of today reading through the project, getting a feel for where I'd put the code for each option. Glad I checked!

eth0izzle commented 4 years ago

The main problem is it's a bit of a bitch to setup the libyara on a platform other than Linux. See https://github.com/hillu/go-yara#installation

I'm thinking the best way forward is running shhgit in a docker container. What do you think?

audibleblink commented 4 years ago

Would certainly make it easier. ... I started typing some other ideas, re-read them, and deleted them with extreme prejudice. It involved words like 'wrap with cgo', 'precompile', 'shellcode', and 'injection'.

Docker is fine.

eth0izzle commented 4 years ago

Hey @audibleblink I've just pushed the code to the v2 branch which includes the YARA rules and a lot of other stuff + code cleanup - definitely a WIP for now but would appreciate if you could test when you get a chance.

audibleblink commented 4 years ago

Oh awesome! Initial reports:

Runs great otherwise. Love the work on the rules. Works with the standalone yara binary as well (provided I define external vars). It's gonna take me a bit to dive deeper and give any meaningful feedback but I'm excited to spend some time on this.

edit: just noticed the TODOs. makes sense