-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
gen_glpi_wordlists.py
executable file
·128 lines (106 loc) · 5.61 KB
/
gen_glpi_wordlists.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File name : gen_glpi_wordlists.py
# Author : Podalirius (@podalirius_)
# Date created : 20 Dec 2021
import json
import os
import sys
import requests
import argparse
from bs4 import BeautifulSoup
def parseArgs():
parser = argparse.ArgumentParser(description="Description message")
parser.add_argument("-v", "--verbose", default=None, action="store_true", help='Verbose mode (default: False)')
parser.add_argument("-f", "--force", default=None, action="store_true", help='Force updating existing wordlists. (default: False)')
parser.add_argument("-n", "--no-commit", default=False, action="store_true", help='Disable automatic commit (default: False)')
return parser.parse_args()
def get_releases_from_github(username, repo, per_page=100):
# https://docs.github.com/en/rest/reference/repos#releases
print("[+] Loading %s/%s versions ... " % (username, repo))
versions, page_number, running = {}, 1, True
while running:
r = requests.get(
"https://api.github.com/repos/%s/%s/releases?per_page=%d&page=%d" % (username, repo, per_page, page_number),
headers={"Accept": "application/vnd.github.v3+json"}
)
if type(r.json()) == dict:
if "message" in r.json().keys():
print(r.json()['message'])
running = False
else:
for release in r.json():
if release['tag_name'].startswith('v'):
release['tag_name'] = release['tag_name'][1:]
versions[release['tag_name']] = release['zipball_url']
if len(r.json()) < per_page:
running = False
page_number += 1
print('[>] Loaded %d %s/%s versions.' % (len(versions.keys()), username, repo))
return versions
def save_wordlist(result, version, filename):
list_of_files = [l.strip() for l in result.split()]
f = open('./versions/%s/%s' % (version, filename), "w")
for remotefile in list_of_files:
if remotefile not in ['.', './', '..', '../']:
if remotefile.startswith('./'):
remotefile = remotefile[1:]
f.write(remotefile + "\n")
f.close()
if __name__ == '__main__':
options = parseArgs()
os.chdir(os.path.dirname(__file__))
versions = get_releases_from_github("glpi-project", "glpi")
for version in versions.keys():
str_version = version
generate = False
if not os.path.exists('./versions/%s/' % str_version):
os.makedirs('./versions/%s/' % str_version, exist_ok=True)
generate = True
elif options.force:
generate = True
elif options.verbose:
print('[>] Ignoring glpi version %s (local wordlists exists)' % str_version)
if generate:
print('[>] Extracting wordlists for glpi version %s' % str_version)
dl_url = versions[version]
if options.verbose:
print(" [>] Create dir ...")
os.system('rm -rf /tmp/paths_glpi_extract/; mkdir -p /tmp/paths_glpi_extract/')
else:
os.popen('rm -rf /tmp/paths_glpi_extract/; mkdir -p /tmp/paths_glpi_extract/').read()
if options.verbose:
print(" [>] Getting file ...")
print('wget -q --show-progress "%s" -O /tmp/paths_glpi_extract/glpi.zip' % dl_url)
os.system('wget -q --show-progress "%s" -O /tmp/paths_glpi_extract/glpi.zip' % dl_url)
else:
os.popen('wget -q "%s" -O /tmp/paths_glpi_extract/glpi.zip' % dl_url).read()
if options.verbose:
print(" [>] Unzipping archive ...")
os.system('cd /tmp/paths_glpi_extract/; unzip glpi.zip 1>/dev/null')
else:
os.popen('cd /tmp/paths_glpi_extract/; unzip glpi.zip 1>/dev/null').read()
if options.verbose:
print(" [>] Getting wordlist ...")
save_wordlist(os.popen('cd /tmp/paths_glpi_extract/glpi*/; find .').read(), version, filename="glpi.txt")
save_wordlist(os.popen('cd /tmp/paths_glpi_extract/glpi*/; find . -type f').read(), version, filename="glpi_files.txt")
save_wordlist(os.popen('cd /tmp/paths_glpi_extract/glpi*/; find . -type d').read(), version, filename="glpi_dirs.txt")
if not options.no_commit:
if os.path.exists("./versions/"):
if options.verbose:
print(" [>] Committing results ...")
os.system('git add ./versions/%s/*; git commit -m "Added wordlists for glpi version %s";' % (version, version))
else:
os.popen('git add ./versions/%s/*; git commit -m "Added wordlists for glpi version %s";' % (version, version)).read()
if os.path.exists("./versions/"):
if options.verbose:
print(" [>] Creating common wordlists ...")
os.system('find ./versions/ -type f -name "glpi.txt" -exec cat {} \\; | sort -u > glpi.txt')
os.system('find ./versions/ -type f -name "glpi_files.txt" -exec cat {} \\; | sort -u > glpi_files.txt')
os.system('find ./versions/ -type f -name "glpi_dirs.txt" -exec cat {} \\; | sort -u > glpi_dirs.txt')
if not options.no_commit:
if options.verbose:
print(" [>] Committing results ...")
os.system('git add *.txt; git commit -m "Added general wordlists for glpi";')
else:
os.popen('git add *.txt; git commit -m "Added general wordlists for glpi";').read()