Retrieve the rules as JSON object :param product: set a certain product that all rules must support :param max_version: set a maximum YARA version that your product supports :param modules: set a list of modules that your product supports :param with_crypto:
(self, product="", max_version="", modules=[], with_crypto=True, tags=[], score=0, search="")
| 188 | return json.loads(r.text) |
| 189 | |
| 190 | def get_rules_json(self, product="", max_version="", modules=[], with_crypto=True, tags=[], score=0, search=""): |
| 191 | """ |
| 192 | Retrieve the rules as JSON object |
| 193 | :param product: set a certain product that all rules must support |
| 194 | :param max_version: set a maximum YARA version that your product supports |
| 195 | :param modules: set a list of modules that your product supports |
| 196 | :param with_crypto: set False if a product's YARA has not been built with OpenSSL (--without-crypto) |
| 197 | :param tags: set a list of tags that you want to retrieve |
| 198 | :param score: minimum score for rules to include in the output |
| 199 | :return: |
| 200 | """ |
| 201 | # API Request |
| 202 | r = requests.post("%s/api/%s/get" % (self.base_url, self.api_version), |
| 203 | data={ |
| 204 | "apikey": self.api_key, |
| 205 | "format": "json", |
| 206 | }, |
| 207 | proxies=self.proxies, |
| 208 | headers=self.headers) |
| 209 | # Load JSON |
| 210 | rules_response = json.loads(r.text) |
| 211 | |
| 212 | # Filter ------------------------------------------------------ |
| 213 | # Product filtering |
| 214 | if product: |
| 215 | (max_version, modules, with_crypto) = get_product_requirements(product=product) |
| 216 | # Tag filtering |
| 217 | if len(tags) > 0: |
| 218 | rules_response['rules'] = filter_tags(rules_response['rules'], tags=tags) |
| 219 | # Score |
| 220 | if score > 0: |
| 221 | rules_response['rules'] = filter_score(rules_response['rules'], minimum_score=score) |
| 222 | # Search string |
| 223 | if search: |
| 224 | rules_response['rules'] = filter_search(rules_response['rules'], query=search) |
| 225 | # Custom filtering |
| 226 | if max_version or len(modules) > 0 or with_crypto is not True: |
| 227 | rules_response['rules'] = filter_requirements(rules_response['rules'], |
| 228 | sup_ver_string=max_version, |
| 229 | sup_modules=modules, |
| 230 | with_crypto=with_crypto) |
| 231 | # Return filtered set |
| 232 | return rules_response |
| 233 | |
| 234 | def get_rules_text(self, product="", max_version="", modules=[], with_crypto=True, tags=[], score=0, search=""): |
| 235 | """ |