forked from n1nj4sec/LaZagne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add account extractor for 'Git For Windows' application
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
from config.write_output import print_output, print_debug | ||
from config.constant import * | ||
from config.header import Header | ||
from config.moduleInfo import ModuleInfo | ||
from urlparse import urlparse | ||
|
||
class GitForWindows(ModuleInfo): | ||
|
||
def __init__(self): | ||
options = {'command': '-t', 'action': 'store_true', 'dest': 'gitforwindows', 'help': 'Git for Windows'} | ||
ModuleInfo.__init__(self, 'gitforwindows', 'git', options) | ||
|
||
def extract_credentials(self, location): | ||
""" | ||
Extract the credentials from a Git store file. | ||
See "https://git-scm.com/docs/git-credential-store" for file format. | ||
:param location: Full path to the Git store file | ||
:return: List of credentials founds | ||
""" | ||
pwd_found = [] | ||
values = {} | ||
if os.path.isfile(location): | ||
with open(location) as f: | ||
creds = f.readlines() | ||
# One line have the following format: https://user:[email protected] | ||
for cred in creds: | ||
if len(cred) > 0: | ||
parts = urlparse(cred) | ||
values["Username"] = parts.username | ||
values["Password"] = parts.password | ||
values["URL"] = parts.geturl().replace(parts.username + ":" + parts.password + "@", "").strip() | ||
pwd_found.append(values) | ||
|
||
return pwd_found | ||
|
||
def run(self): | ||
""" | ||
Main function | ||
""" | ||
# Print title | ||
title = "GitForWindows" | ||
Header().title_info(title) | ||
|
||
# According to the "git-credential-store" documentation: | ||
# Build a list of locations in which git credentials can be stored | ||
locations = [] | ||
locations.append(os.environ.get("USERPROFILE") + "\\.git-credentials") | ||
locations.append(os.environ.get("USERPROFILE") + "\\.config\\git\\credentials") | ||
if "XDG_CONFIG_HOME" in os.environ: | ||
locations.append(os.environ.get("XDG_CONFIG_HOME") + "\\git\\credentials") | ||
|
||
# Apply the password extraction on the defined locations | ||
pwd_found = [] | ||
for location in locations: | ||
pwd_found += self.extract_credentials(location) | ||
|
||
# Filter duplicates | ||
final_pwd_found = [] | ||
duplicates_track = [] | ||
for pwd in pwd_found: | ||
pwd_id = pwd["URL"] + pwd["Username"] + pwd["Password"] | ||
if pwd_id not in duplicates_track: | ||
final_pwd_found.append(pwd) | ||
duplicates_track.append(pwd_id) | ||
|
||
# Print the results | ||
if len(final_pwd_found) > 0: | ||
print_output(title, final_pwd_found) |