Skip to content

Commit

Permalink
Improve upload functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
brightio committed Dec 27, 2021
1 parent a51804e commit 1990d20
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions penelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
import platform
import threading
import subprocess
import urllib.request

from pathlib import Path
from itertools import islice
from datetime import datetime
from collections import deque
from urllib.request import urlopen

class MainMenu(cmd.Cmd):

Expand Down Expand Up @@ -257,7 +257,7 @@ def do_open(self, remote_path):

def do_upload(self, local_globs):
"""\
Upload files and folders to the target. If URL is specified then it is downloaded
Upload files/folders to the target. If HTTP(S)/FTP(S) URL is specified then it is downloaded
locally and then uploaded to the target
"""
if self.sid:
Expand Down Expand Up @@ -1328,8 +1328,16 @@ def upload(self, local_item_path):
data=io.BytesIO()
tar=tarfile.open(mode='w:gz',fileobj=data)

if local_item_path.startswith('http'):
items=[urlopen(local_item_path, timeout=options.SHORT_TIMEOUT).read()]
if re.match('(http|ftp)s?://', local_item_path, re.IGNORECASE):
logger.info(paint(f"... ⇣ Downloading {local_item_path}", 'blue'))
req = urllib.request.Request(local_item_path, headers={'User-Agent':options.useragent})
try:
items=[urllib.request.urlopen(req, timeout=options.SHORT_TIMEOUT).read()]
except Exception as e:
logger.error(f"Cannot download: {e}")
return False
else:
logger.info(paint("... ⇥ Download completed. Pushing it to the target", 'blue'))

elif local_item_path.startswith(os.path.sep):
items=list(Path(os.path.sep).glob(local_item_path.lstrip(os.path.sep)))
Expand Down Expand Up @@ -1583,6 +1591,7 @@ def __setattr__(self, name, value):
options.cmd_histfile=options.BASEDIR/'cmd_history.log'
options.debug_histfile=options.BASEDIR/'cmd_debug.log'
options.histlength=1000
options.useragent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0"

# EXTRAS
options.recon_scripts={
Expand Down

0 comments on commit 1990d20

Please sign in to comment.