Skip to content

Commit 0aacf16

Browse files
committed
fixed wappalyzer db
1 parent 268e8b0 commit 0aacf16

2 files changed

Lines changed: 47 additions & 31 deletions

File tree

webtech/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# DON'T EDIT THIS FILE
2-
__version__ = "1.2.12"
2+
__version__ = "1.3"

webtech/database.py

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import os.path
4+
from os import unlink
45
import time
56
from .__burp__ import BURP
67
from .utils import user_data_dir
8+
from string import ascii_lowercase
9+
import json
710

811
if not BURP:
912
try:
@@ -21,7 +24,7 @@
2124
os.mkdir(DATA_DIR)
2225
DATABASE_FILE = os.path.join(DATA_DIR, "webtech.json")
2326
WAPPALYZER_DATABASE_FILE = os.path.join(DATA_DIR, "apps.json")
24-
WAPPALYZER_DATABASE_URL = "https://raw.githubusercontent.com/AliasIO/wappalyzer/master/src/technologies.json"
27+
WAPPALYZER_DATABASE_URL_BASE = "https://raw.githubusercontent.com/AliasIO/wappalyzer/master/src/technologies/"
2528
WEBTECH_DATABASE_URL = "https://raw.githubusercontent.com/ShielderSec/webtech/master/webtech/webtech.json"
2629
DAYS = 60 * 60 * 24
2730

@@ -30,54 +33,67 @@ def download_database_file(url, target_file):
3033
"""
3134
Download the database file from the WAPPPALIZER repository
3235
"""
33-
print("Updating database...")
36+
print("Downloading database: {}".format(url))
3437
response = urlopen(url)
3538
with open(target_file, 'wb') as out_file:
3639
out_file.write(response.read())
37-
print("Database updated successfully!")
3840

3941

40-
def download(webfile, dbfile, name, force=False):
42+
def download():
4143
"""
4244
Check if outdated and download file
4345
"""
46+
try:
47+
download_database_file(WEBTECH_DATABASE_URL, DATABASE_FILE)
48+
except:
49+
pass
50+
with open(WAPPALYZER_DATABASE_FILE, 'w') as f:
51+
json.dump({"apps":{}}, f)
52+
53+
for c in ascii_lowercase + "_":
54+
try:
55+
download_database_file("{}{}.json".format(WAPPALYZER_DATABASE_URL_BASE,c), os.path.join(DATA_DIR,"temp.json"))
56+
merge_partial_wappalyzer_database()
57+
unlink(os.path.join(DATA_DIR,"temp.json"))
58+
except URLError as e:
59+
print("The Wappalyzer database seems offline. Report this issue to: https://github.com/ShielderSec/webtech/")
60+
pass
61+
62+
63+
def update_database(args=None, force=False):
64+
"""
65+
Update the database if it's not present or too old
66+
"""
4467
now = int(time.time())
45-
if not os.path.isfile(dbfile):
46-
print("{} Database file not present.".format(name))
47-
download_database_file(webfile, dbfile)
48-
# set timestamp in filename
68+
if not os.path.isfile(WAPPALYZER_DATABASE_FILE):
69+
print("Database file not present.")
70+
download()
4971
else:
50-
last_update = int(os.path.getmtime(dbfile))
72+
last_update = int(os.path.getmtime(WAPPALYZER_DATABASE_FILE))
5173
if last_update < now - 30 * DAYS or force:
5274
if force:
53-
print("Force update of {} Database file".format(name))
75+
print("Force update of Database file")
5476
else:
55-
print("{} Database file is older than 30 days.".format(name))
56-
os.remove(dbfile)
57-
download_database_file(webfile, dbfile)
77+
print("Database file is older than 30 days.")
78+
unlink(WAPPALYZER_DATABASE_FILE)
79+
download()
80+
5881

59-
60-
def update_database(args=None, force=False):
82+
def merge_partial_wappalyzer_database():
6183
"""
62-
Update the database if it's not present or too old
84+
This helper function merges a partial wappalyzer db with the other ones.
6385
"""
64-
try:
65-
download(WAPPALYZER_DATABASE_URL, WAPPALYZER_DATABASE_FILE, "Wappalyzer", force=force)
66-
except URLError as e:
67-
print("The Wappalyzer database seems offline. Report this issue to: https://github.com/ShielderSec/webtech/")
68-
pass
69-
70-
try:
71-
download(WEBTECH_DATABASE_URL, DATABASE_FILE, "WebTech", force=force)
72-
return True
73-
except URLError as e:
74-
print("Unable to update database, check your internet connection and Github.com availability.")
75-
return False
76-
86+
87+
with open(WAPPALYZER_DATABASE_FILE, 'r+') as f1:
88+
with open(os.path.join(DATA_DIR,"temp.json")) as f2:
89+
current = json.load(f1)
90+
temp = {"apps": json.load(f2)}
91+
f1.seek(0)
92+
json.dump(merge_databases(current, temp),f1)
7793

7894
def merge_databases(db1, db2):
7995
"""
80-
This helper function merge elements from two databases without overrding its elements
96+
This helper function merges elements from two databases without overrding its elements
8197
This function is not generic and *follow the Wappalyzer db scheme*
8298
"""
8399
# Wappalyzer DB format must have an apps/technologies object

0 commit comments

Comments
 (0)