File: scrapers.py

package info (click to toggle)
pompem 0.2.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 188 kB
  • sloc: python: 481; makefile: 6
file content (280 lines) | stat: -rw-r--r-- 11,265 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/python3
# -*- coding: utf-8 -*-

from threading import Thread
import datetime
import re
from core.request_worker import RequestWorker, RequestWorkerHttpLib
import json


class Scraper(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.list_result = None
        self.list_req_workers = []

    def _parser(self):
        raise NotImplementedError()

    def join(self):
        Thread.join(self)
        return self.list_result

    def _get_results(self):
        for r_worker in self.list_req_workers:
            try:
                html = r_worker.join()
                self._parser(html)
            except Exception as e:
                import traceback
                traceback.print_exc()


class PacketStorm(Scraper):
    def __init__(self, key_word):
        Scraper.__init__(self)
        self.name_site = "Packet Storm Security"
        self.name_class = PacketStorm.__name__
        self.base_url = "https://packetstormsecurity.com"
        self.key_word = key_word
        self.url = "https://packetstormsecurity.com/search/files/page{0}/?q={1}"
        self.page_max = 2
        self.list_result = []
        self.regex_item = re.compile(r'(?ms)(<dl id="[^"]*?".*?<\/dl>)')
        self.regex_url = re.compile(r'href="(/files/\d+?\/[^"]*?)"')
        self.regex_date = re.compile(r'href="/files/date/(\d{4}-\d{2}-\d{2})')
        self.regex_name = re.compile(r'href="/files/\d+?\/[^"]*?".*?title.*?>([^<]*?)<')

    def run(self, ):
        for page in range(self.page_max):
            try:
                url_search = self.url.format(page + 1, self.key_word)
                req_worker = RequestWorker(url_search)
                req_worker.start()
                self.list_req_workers.append(req_worker)
            except Exception as e:
                import traceback
                traceback.print_exc()
        self._get_results()

    def _parser(self, html):
        for item in self.regex_item.finditer(html):
            item_html = item.group(0)
            dict_result = {}
            url_exploit = "{0}{1}".format(
                self.base_url,
                self.regex_url.search(item_html).group(1)
            )
            dict_result['url'] = url_exploit
            dict_result['date'] = self.regex_date.search(item_html).group(1)
            dict_result['name'] = self.regex_name.search(item_html).group(1)
            self.list_result.append(dict_result)


class CXSecurity(Scraper):
    def __init__(self, key_word):
        Scraper.__init__(self)
        self.name_site = "CXSecurity"
        self.name_class = CXSecurity.__name__
        self.key_word = key_word
        self.url = "https://cxsecurity.com/search/wlb/DESC/AND/{0}.1999.1.1/{1}/10/{3}/"
        self.page_max = 2
        self.list_result = []
        self.regex_item = re.compile(r'(?msi)<tr>.*?<td width="17".*?<td width="550".*?</tr>')
        self.regex_url = re.compile(r'(?msi)<td.*?<h6><a href="([^"]*?)"')
        self.regex_date = re.compile(r'(?msi)<td width="80".*?default">(\d{2})\.(\d{2})\.(\d{4})')
        self.regex_name = re.compile(r'(?msi)title="([^"]*?)"')

    def run(self, ):
        now_date = '{dt.year}.{dt.month}.{dt.day}'.format(
            dt=datetime.datetime.now()
        )
        for page in range(self.page_max):
            try:
                url_search = self.url.format(now_date, page + 1, self.page_max,
                                             self.key_word)
                req_worker = RequestWorker(url_search)
                req_worker.start()
                self.list_req_workers.append(req_worker)
            except Exception as e:
                import traceback
                traceback.print_exc()
        self._get_results()

    def _parser(self, html):
        for item in self.regex_item.finditer(html):
            item_html = item.group(0)
            dict_result = {}
            url_exploit = self.regex_url.search(item_html).group(1)
            dict_result['url'] = url_exploit
            match_date = self.regex_date.search(item_html)
            date = "{0}-{1}-{2}".format(match_date.group(3),
                                        match_date.group(2),
                                        match_date.group(1)
                                        )
            dict_result['date'] = date
            dict_result['name'] = self.regex_name.search(item_html).group(1)
            self.list_result.append(dict_result)


class ZeroDay(Scraper):
    def __init__(self, key_word):
        Scraper.__init__(self)
        self.name_site = "ZeroDay"
        self.name_class = ZeroDay.__name__
        self.key_word = key_word
        self.url = "https://j5dtyooqyukedkrl.onion.to/search?search_request={0}"
        self.session_url = "https://j5dtyooqyukedkrl.onion.to"
        self.base_url = "https://j5dtyooqyukedkrl.onion.to"
        self.list_result = []
        self.regex_item = re.compile(r"(?msi)<div class='ExploitTableContent'.*?<div class='tips_value_big'>")
        self.regex_date = re.compile(r"(?msi)href='/date.*?>(\d{2})-(\d{2})-(\d{4})")
        self.regex_url = re.compile(r"(?msi)href='(/exploit.*?)'")
        self.regex_name = re.compile(r"(?msi)href='/exploit.*?'>([^<]*?)<")

    def run(self, ):
        try:
            url_search = self.url.format(self.key_word)
            req_worker = RequestWorker(url=url_search, data={'agree': 'Yes%2C+I+agree'},
                                       session_url=self.session_url)
            req_worker.start()
            self.list_req_workers.append(req_worker)
        except Exception as e:
            import traceback
            traceback.print_exc()
        self._get_results()

    def _parser(self, html):
        for item in self.regex_item.finditer(html):
            item_html = item.group(0)
            dict_result = {}
            dict_result['url'] = self.base_url + self.regex_url.search(item_html).group(1)
            match_date = self.regex_date.search(item_html)
            date = "{0}-{1}-{2}".format(match_date.group(3),
                                        match_date.group(2),
                                        match_date.group(1)
                                        )
            dict_result['date'] = date
            dict_result['name'] = self.regex_name.search(item_html).group(1)
            self.list_result.append(dict_result)


class Vulners(Scraper):
    def __init__(self, key_word):
        Scraper.__init__(self)
        self.name_site = "Vulners"
        self.name_class = Vulners.__name__
        self.key_word = key_word
        self.url_domain = "vulners.com"
        self.path = "/api/v3/search/lucene/"
        self.list_result = []
        self.regex_date = re.compile(r"(\d{4})-(\d{2})-(\d{2})")

    def run(self, ):
        try:
            data = {}
            data['query'] = "{0} last year".format(self.key_word)
            req_worker = RequestWorkerHttpLib(self.url_domain, self.path, data)
            req_worker.start()
            self.list_req_workers.append(req_worker)
        except Exception as e:
            import traceback
            traceback.print_exc()
        self._get_results()

    def _parser(self, html):
        json_data = json.loads(html)
        for data in json_data['data']['search']:
            dict_result = {}
            dict_result['url'] = data["_source"]['href']
            dict_result['name'] = data["_source"]["title"]
            dict_result['date'] = self.regex_date.search(data["_source"]["published"]).group(0)
            self.list_result.append(dict_result)


class NationaVulnerabilityDB(Scraper):
    def __init__(self, key_word):
        Scraper.__init__(self)
        self.name_site = "NationaVulnerabilityDB"
        self.name_class = NationaVulnerabilityDB.__name__
        self.key_word = key_word
        self.url = "https://web.nvd.nist.gov/view/vuln/search-results?query={0}&search_type=all&cves=on&startIndex={1}"
        self.base_url = 'https://web.nvd.nist.gov/view/vuln/'
        self.page_max = 60
        self.list_result = []
        self.regex_item = re.compile(r'(?msi)<dt>.*?a href="detail.*?</dd>')
        self.regex_name = re.compile(r'(?msi)<dt>.*?Summary:.*?>([^<]*?)<')
        self.regex_date = re.compile(r'(?msi)<dt>.*?Summary:.*?>.*?Published:.*?>.*?(\d{1,2})\/(\d{1,2})\/(\d{4})')
        self.regex_url = re.compile(r'(?msi)<dt>.*?href="([^"]*?vulnId.*?)"')

    def run(self, ):
        for page in range(0,self.page_max+1,20):
            try:
                url_search = self.url.format(
                    self.key_word,
                    page
                )
                req_worker = RequestWorker(url_search)
                req_worker.start()
                self.list_req_workers.append(req_worker)
            except Exception as e:
                import traceback
                traceback.print_exc()
        self._get_results()

    def _parser(self, html):
        for item in self.regex_item.finditer(html):
            item_html = item.group(0)
            dict_results = {}
            dict_results['name'] = self.regex_name.search(item_html).group(1)
            match_date = self.regex_date.search(item_html)
            date = "{0}-{1}-{2}".format(match_date.group(3),
                                        match_date.group(1),
                                        match_date.group(2)
                                        )
            dict_results['date'] = date
            dict_results['url'] = self.base_url + self.regex_url.search(item_html).group(1)
            self.list_result.append(dict_results)

class WpvulndbB(Scraper):
    def __init__(self, key_word):
        Scraper.__init__(self)
        self.name_site = "Wpvulndb"
        self.name_class = NationaVulnerabilityDB.__name__
        self.key_word = key_word
        self.url = "https://wpvulndb.com/searches?page={1}&text={0}&utf8=%E2%9C%93&vuln_type="
        self.url_base = "https://wpvulndb.com"
        self.page_max = 2
        self.list_result = []
        self.regex_item = re.compile(r'(?msi)<tr>.*?<td>.*?<a.*?</tr>')
        self.regex_name = re.compile(r'(?msi)<a href="[^"]*?">\d+?<.*?href.*?>([^<]*?)<')
        self.regex_date = re.compile(r'(?msi)created-at">([^<]*?)<')
        self.regex_url = re.compile(r'(?msi)<a href="([^"]*?)">\d+?<')

    def run(self, ):
        for page in range(self.page_max+1):
            try:
                url_search = self.url.format(
                    self.key_word,
                    page
                )
                req_worker = RequestWorker(url_search)
                req_worker.start()
                self.list_req_workers.append(req_worker)
            except Exception as e:
                import traceback
                traceback.print_exc()
        self._get_results()

    def _parser(self, html):
        for item in self.regex_item.finditer(html):
            dict_results = {}
            item_html = item.group(0)
            url = self.url_base + self.regex_url.search(item_html).group(1)
            dict_results['url'] = url
            dict_results['name'] = self.regex_name.search(item_html).group(1)
            dict_results['date'] =  self.regex_date.search(item_html).group(1)
            self.list_result.append(dict_results)