Last active
November 26, 2018 16:34
-
-
Save No1zy/d2f350ccd8fa1062de67550637d5f93d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| import csv | |
| import sys | |
| import datetime | |
| import requests | |
| from bs4 import BeautifulSoup | |
| BASE_URL = 'https://jvndb.jvn.jp' | |
| SOFTWARE_NAME = sys.argv[1] | |
| def get(url, params = None): | |
| r = requests.get(url, params=params) | |
| r.encoding = r.apparent_encoding | |
| return r | |
| def get_list(num, is_init = None): | |
| url = 'https://jvndb.jvn.jp/search/index.php' | |
| data = { | |
| 'mode': '_vulnerability_search_IA_VulnSearch', | |
| 'lang': 'ja', | |
| 'keyword': SOFTWARE_NAME, | |
| 'useSynonym': '1', | |
| 'vendor': '', | |
| 'product': '', | |
| 'datePublicFromYear': '', | |
| 'datePublicFromMonth': '', | |
| 'datePublicToYear': '', | |
| 'datePublicToMonth': '', | |
| 'dateLastPublishedFromYear': '', | |
| 'dateLastPublishedFromMonth': '', | |
| 'dateLastPublishedToYear': '', | |
| 'dateLastPublishedToMonth': '', | |
| 'cwe': '', | |
| 'searchProductId': '', | |
| 'pageNo' : str(num) | |
| } | |
| r = requests.get(url, params=data) | |
| r.encoding = r.apparent_encoding | |
| bs = BeautifulSoup(r.text, 'html.parser') | |
| if is_init is True: | |
| number_of_vulns = bs.select('td[class="pager_count_class"]')[0].string | |
| number_of_vulns = int(number_of_vulns.split('件')[0]) | |
| if number_of_vulns % 100 == 0: | |
| return number_of_vulns // 100 | |
| else: | |
| return number_of_vulns // 100 + 1 | |
| vuln_list = [] | |
| for tr in bs.select('table[class="result_class"]')[0].find_all('tr'): | |
| for a in tr.select('a[href^="/ja/contents/"]'): | |
| vuln_list.append([ | |
| a.get('href'), | |
| tr.select('td:nth-of-type(2)')[0].string | |
| ]) | |
| return vuln_list | |
| def get_info(lists): | |
| res = [] | |
| for item in lists: | |
| r = get(BASE_URL + item[0]) | |
| bs = BeautifulSoup(r.text, 'html.parser') | |
| affect_version = '' | |
| for li in bs.select('tr:nth-of-type(9) li'): | |
| affect_version += li.string.replace('\xa0', ' ') + '\x0d\x0a' | |
| cve = '' | |
| for li in bs.select('tr:nth-of-type(20) li'): | |
| cve = li.string | |
| date_string = bs.select('div[class="modifytxt"]')[0].string[-10:] | |
| date = datetime.datetime.strptime(date_string, '%Y/%m/%d') | |
| incomming_date = date.strftime('%Y-%m-%d') | |
| res.append([ | |
| SOFTWARE_NAME, | |
| item[1], | |
| affect_version[:-1], | |
| cve, | |
| BASE_URL + item[0], | |
| incomming_date, | |
| ]) | |
| return res | |
| if __name__ == '__main__': | |
| max_page = get_list(1, True) | |
| with open('vuln_info.csv', 'w', encoding='shift_jis') as f: | |
| writer = csv.writer(f, lineterminator='\n', quoting=csv.QUOTE_NONNUMERIC) | |
| writer.writerow(['ソフトウェア名', '概要', '影響のあるバージョン', 'CVE', '情報元URL', '情報着信日']) | |
| for i in range(1,max_page+1): | |
| vuln_list = get_list(i) | |
| res = get_info(vuln_list) | |
| writer.writerows(res) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment