Skip to content

Commit bcab2ee

Browse files
authored
Merge pull request #26 from olgaKiseleva/master
Support of Vulners API v.2
2 parents 9d60f4c + a4c724e commit bcab2ee

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# getsploit
22

33
[![Current Release](https://img.shields.io/github/release/vulnersCom/getsploit.svg "Current Release")](https://github.com/vulnersCom/getsploit/releases/latest)
4-
[![Downloads](https://img.shields.io/github/downloads/vulnersCom/getsploit/total.svg "Downloads")](https://github.com/vulnersCom/getsploit/releases) [![PayPal](https://img.shields.io/badge/donate-PayPal-green.svg)](https://paypal.me/videns)
4+
[![Downloads](https://img.shields.io/github/downloads/vulnersCom/getsploit/total.svg "Downloads")](https://github.com/vulnersCom/getsploit/releases)
55

66
# Description
77
Inspired by [searchsploit](https://github.com/offensive-security/exploit-database/blob/master/searchsploit), it combines two features: command line search and download tool.
88
It allows you to search online for the exploits across all the most popular collections: *Exploit-DB*, *Metasploit*, *Packetstorm* and others.
99
The most powerful feature is immediate *exploit source download* right in your working path.
1010

1111
# Python version
12-
Utility was tested on *python2.6*, *python2.7*, *python3.6* with SQLite FTS4 support. If you have found any bugs, don't hesitate to create an issue
12+
Utility was tested on *python2.7*, *python3.8+* with SQLite FTS4 support. If you have found any bugs, don't hesitate to create an issue
1313

1414
# How to use
1515

getsploit/getsploit.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33
from __future__ import division
44

5-
__version__ = "0.3.3"
5+
__version__ = "1.0.0"
66

77
import json
88
import vulners
@@ -49,16 +49,25 @@
4949
LOCAL_SEARCH_AVAILABLE = False
5050

5151

52-
class sploitVulners(vulners.Vulners):
52+
class sploitVulners(vulners.VulnersApi):
5353

54-
api_endpoints = {
55-
'search': "/api/v3/search/lucene/",
56-
'software': "/api/v3/burp/software/",
57-
'apiKey': "/api/v3/apiKey/valid/",
58-
'searchsploitdb': "/api/v3/archive/getsploit/"
59-
}
54+
default_fields = (
55+
"id",
56+
"title",
57+
"description",
58+
"type",
59+
"bulletinFamily",
60+
"cvss",
61+
"published",
62+
"modified",
63+
"lastseen",
64+
"href",
65+
"sourceHref",
66+
"sourceData",
67+
"cvelist",
68+
)
6069

61-
def searchExploit(self, query, lookup_fields=None, limit=500, offset=0, fields=None):
70+
def searchExploit(self, query, lookup_fields=None, limit=500, offset=0, fields=default_fields):
6271

6372
if lookup_fields:
6473
if not isinstance(lookup_fields, (list, set, tuple)) or not all(isinstance(item, string_types) for item in lookup_fields):
@@ -68,27 +77,16 @@ def searchExploit(self, query, lookup_fields=None, limit=500, offset=0, fields=N
6877
else:
6978
searchQuery = "bulletinFamily:exploit AND %s" % query
7079

71-
total_bulletins = limit or self._Vulners__search(searchQuery, 0, 0, ['id']).get('total')
72-
total = 0
73-
dataDocs = []
80+
dataDocs = self.find_all(searchQuery, offset=offset, limit=limit, fields=fields)
7481

75-
for skip in range(offset, total_bulletins, min(self.search_size, limit or self.search_size)):
76-
results = self._Vulners__search(searchQuery, skip, min(self.search_size, limit or self.search_size), fields or self.default_fields + ['sourceData'])
77-
total = max(results.get('total'), total)
78-
for element in results.get('search'):
79-
dataDocs.append(element.get('_source'))
8082
return searchQuery, dataDocs
8183

8284
def downloadGetsploitDb(self, full_path):
8385
print("Downloading getsploit database archive. Please wait, it may take time. Usually around 5-10 minutes.")
84-
# {'apiKey':self._Vulners__api_key}
85-
download_request = self._Vulners__opener.get(self.vulners_urls['searchsploitdb'], stream = True)
86+
87+
download_request = self.getsploit()
8688
with open(full_path, 'wb') as f:
87-
total_length = int(download_request.headers.get('content-length'))
88-
for chunk in progress.bar(download_request.iter_content(chunk_size=1024), expected_size=(total_length / 1024) + 1):
89-
if chunk:
90-
f.write(chunk)
91-
f.flush()
89+
f.write(download_request)
9290
print("\nUnpacking database.")
9391
zip_ref = zipfile.ZipFile(full_path, 'r')
9492
zip_ref.extractall(DBPATH)
@@ -192,8 +190,6 @@ def main():
192190
os.unlink(KEYFILE)
193191
raise exc
194192

195-
vulners_lib._Vulners__opener.headers.update({'User-Agent': 'Vulners Getsploit %s' % __version__})
196-
197193
with open(KEYFILE, 'w') as key_file:
198194
key_file.write(api_key)
199195

0 commit comments

Comments
 (0)