NOT TESTED!!!!!
Final refactor New download system
This commit is contained in:
@@ -7,7 +7,7 @@ def dl(urls, save_to):
|
|||||||
for url in urls:
|
for url in urls:
|
||||||
def dl_thread(url_in_thread):
|
def dl_thread(url_in_thread):
|
||||||
with requests.get(url_in_thread, stream=True) as r:
|
with requests.get(url_in_thread, stream=True) as r:
|
||||||
with open(save_to, "wb") as f:
|
with open(save_to + "/" + url.split('/')[-1], "wb") as f:
|
||||||
pbar = tqdm(unit="B", unit_scale=True, total=int(r.headers['Content-Length']),
|
pbar = tqdm(unit="B", unit_scale=True, total=int(r.headers['Content-Length']),
|
||||||
position=urls.index(url_in_thread))
|
position=urls.index(url_in_thread))
|
||||||
for chunk in r.iter_content(chunk_size=1024):
|
for chunk in r.iter_content(chunk_size=1024):
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import threading
|
|||||||
from rich import print
|
from rich import print
|
||||||
import requests
|
import requests
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
from tqdm import tqdm
|
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
from modules.virustotal import get_key, scan_file, get_report
|
from modules.virustotal import scan_to_cli
|
||||||
from modules.http_status import handle
|
from modules.http_status import handle
|
||||||
|
from modules.download import dl
|
||||||
|
|
||||||
|
|
||||||
def install(package):
|
def install(package):
|
||||||
@@ -17,7 +17,7 @@ def install(package):
|
|||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
|
|
||||||
if r_code[1] not in [403, 401]:
|
if r_code[1] not in [403, 401]:
|
||||||
print(r_code[0])
|
return r_code[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(f"[green]App {r['name']} found, information loaded[/]")
|
print(f"[green]App {r['name']} found, information loaded[/]")
|
||||||
@@ -26,33 +26,14 @@ def install(package):
|
|||||||
os.makedirs('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
os.makedirs('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
||||||
|
|
||||||
print(f"Downloading {r['url'].split('/')[-1]}")
|
print(f"Downloading {r['url'].split('/')[-1]}")
|
||||||
|
to_download = [r['url']]
|
||||||
|
if r['download']:
|
||||||
|
print(f"Found dependency")
|
||||||
|
print(f"Downloading {r['download'].split('/')[-1]}")
|
||||||
|
to_download.append(r['download'])
|
||||||
|
|
||||||
chunk_size = 1024
|
dl(to_download, '{0}apps/{1}'.format(horsy_vars.horsypath, r['name']))
|
||||||
file_r = requests.get(r['url'], stream=True)
|
scan_to_cli('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
|
||||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath), "wb") as f:
|
|
||||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
|
||||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
|
||||||
if chunk:
|
|
||||||
pbar.update(len(chunk))
|
|
||||||
f.write(chunk)
|
|
||||||
pbar.close()
|
|
||||||
|
|
||||||
print(f"Starting virustotal scan")
|
|
||||||
if not get_key():
|
|
||||||
print(f"[red]Virustotal api key not found[/]")
|
|
||||||
print(f"You can add it by entering [bold]horsy --vt \[your key][/] in terminal")
|
|
||||||
else:
|
|
||||||
print(f"[green]Virustotal api key found[/]")
|
|
||||||
print(f"[italic white]If you want to disable scan, type [/][bold]horsy --vt disable[/]"
|
|
||||||
f"[italic white] in terminal[/]")
|
|
||||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
|
|
||||||
print(f"[green]Virustotal scan finished[/]")
|
|
||||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1],
|
|
||||||
horsy_vars.horsypath))
|
|
||||||
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
|
|
||||||
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
|
||||||
|
|
||||||
print(f"[green][OK] Done[/]")
|
|
||||||
|
|
||||||
def unzip(file, where):
|
def unzip(file, where):
|
||||||
with zipfile.ZipFile(file, 'r') as zip_ref:
|
with zipfile.ZipFile(file, 'r') as zip_ref:
|
||||||
@@ -65,37 +46,11 @@ def install(package):
|
|||||||
'{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
'{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
||||||
|
|
||||||
if r['download']:
|
if r['download']:
|
||||||
print(f"Found dependency")
|
if scan_to_cli('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1],
|
||||||
# if not is_gui:
|
horsy_vars.horsypath))['detect']['malicious'] > 0:
|
||||||
print(f"Downloading {r['download'].split('/')[-1]}")
|
print(f"[red]Dependency can be malicious. It may run now, if this added to installation "
|
||||||
|
f"config[/]")
|
||||||
chunk_size = 1024
|
input("Press enter if you want continue, or ctrl+c to exit")
|
||||||
file_r = requests.get(r['download'], stream=True)
|
|
||||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath),
|
|
||||||
"wb") as f:
|
|
||||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
|
||||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
|
||||||
if chunk:
|
|
||||||
pbar.update(len(chunk))
|
|
||||||
f.write(chunk)
|
|
||||||
pbar.close()
|
|
||||||
|
|
||||||
print(f"Starting virustotal scan")
|
|
||||||
if not get_key():
|
|
||||||
print(f"[red]Virustotal api key not found[/]")
|
|
||||||
print(f"You can add it by entering [italic white]horsy --vt \[your key][/] in terminal")
|
|
||||||
else:
|
|
||||||
print(f"[green]Virustotal api key found[/]")
|
|
||||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath))
|
|
||||||
print(f"[green]Virustotal scan finished[/]")
|
|
||||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1],
|
|
||||||
horsy_vars.horsypath))
|
|
||||||
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
|
|
||||||
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
|
||||||
if analysis['detect']['malicious'] > 0:
|
|
||||||
print(f"[red]Dependency can be malicious. It may run now, if this added to installation "
|
|
||||||
f"config[/]")
|
|
||||||
input("Press enter if you want continue, or ctrl+c to exit")
|
|
||||||
|
|
||||||
if r['install']:
|
if r['install']:
|
||||||
print(f"Found install option")
|
print(f"Found install option")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import requests
|
|||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
|
from rich import print
|
||||||
|
|
||||||
|
|
||||||
def add_to_cfg(key):
|
def add_to_cfg(key):
|
||||||
@@ -59,3 +60,22 @@ def get_report(filename):
|
|||||||
analysis['link'] = 'No data'
|
analysis['link'] = 'No data'
|
||||||
|
|
||||||
return analysis
|
return analysis
|
||||||
|
|
||||||
|
|
||||||
|
def scan_to_cli(filename):
|
||||||
|
print(f"Starting virustotal scan")
|
||||||
|
if not get_key():
|
||||||
|
print(f"[red]Virustotal api key not found[/]")
|
||||||
|
print(f"You can add it by entering [bold]horsy --vt \[your key][/] in terminal")
|
||||||
|
else:
|
||||||
|
print(f"[green]Virustotal api key found[/]")
|
||||||
|
print(f"[italic white]If you want to disable scan, type [/][bold]horsy --vt disable[/]"
|
||||||
|
f"[italic white] in terminal[/]")
|
||||||
|
scan_file(filename)
|
||||||
|
print(f"[green]Virustotal scan finished[/]")
|
||||||
|
analysis = get_report(filename)
|
||||||
|
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
|
||||||
|
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
||||||
|
|
||||||
|
print(f"[green][OK] Done[/]")
|
||||||
|
return analysis
|
||||||
|
|||||||
Reference in New Issue
Block a user