| 80 | |
| 81 | |
| 82 | def search_exploit_online(ctx: Context, query: str, limit: int) -> Iterable[Mapping[str, Any]]: |
| 83 | resp = ctx.client.post( |
| 84 | "v3/search/lucene/", |
| 85 | json={ |
| 86 | "query": f"bulletinFamily:exploit AND ({query})", |
| 87 | "size": limit, |
| 88 | "fields": ["id", "type", "title", "description", "sourceData", "published"], |
| 89 | }, |
| 90 | ) |
| 91 | resp.raise_for_status() |
| 92 | data = resp.json()["data"] |
| 93 | if data.get("exactMatch"): |
| 94 | results = [data["exactMatch"]] |
| 95 | elif data.get("search"): |
| 96 | results = data["search"] |
| 97 | else: |
| 98 | results = [] |
| 99 | for item in results: |
| 100 | d = item["_source"] |
| 101 | yield { |
| 102 | "id": d["id"], |
| 103 | "title": d["title"], |
| 104 | "description": d["description"], |
| 105 | "sourceData": d.get("sourceData", ""), |
| 106 | "published": d["published"], |
| 107 | "vhref": f"https://vulners.com/{d['type']}/{d['id']}", |
| 108 | } |
| 109 | |
| 110 | |
| 111 | def slugify(value: str) -> str: |