Skip to content

Instantly share code, notes, and snippets.

@viniciuspereiras
Created December 12, 2024 17:46
Show Gist options
  • Save viniciuspereiras/0c2614d1adfb50c1b5a2dddb1b0d9dd0 to your computer and use it in GitHub Desktop.
Save viniciuspereiras/0c2614d1adfb50c1b5a2dddb1b0d9dd0 to your computer and use it in GitHub Desktop.
import requests
import xml.etree.ElementTree as ET
import argparse
import os
parser = argparse.ArgumentParser(description='Get jar files of an jnlp')
parser.add_argument('--jnlp', type=str, help='jnlp file')
parser.add_argument('--url', type=str, help='url of jnlp file',)
parser.add_argument('--output', type=str, help='output dir')
args = parser.parse_args()
if args.jnlp:
jnlp = args.jnlp
with open(jnlp) as f:
jnlp = f.read()
elif args.url:
jnlp = requests.get(args.url).text
if not jnlp:
print("[!] Error getting jnlp")
exit(1)
else:
print("[!] Please provide jnlp file or url")
exit(1)
output = args.output
if not os.path.exists(output):
print(f"[+] Creating output dir {output}")
os.makedirs(output)
jnlp = jnlp.replace("<jfx:javafx-runtime version=\"2.0+\" />", "") # if keep showing error just delete manually the line that isnt xml valid
xmltree = ET.ElementTree(ET.fromstring(jnlp))
root = xmltree.getroot()
codebase = root.attrib['codebase']
print('[+] Parsing jnlp')
print(f"[+] Codebase: {codebase}")
for jar in root.iter('jar'):
jarname = jar.get('href')
jarversion = jar.get('version')
url_final = f"{codebase}{jarname}?version-id={jarversion}"
print(f"Downloading {url_final}")
r = requests.get(url_final)
with open(f"{output}/{jarname}", "wb") as f:
f.write(r.content)
print("[+] Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment