MCPcopy
hub / github.com/brightio/penelope / upload

Method upload

penelope.py:3642–3961  ·  view source on GitHub ↗
(self, local_items, remote_path=None, randomize_fname=False, url_to_bytes_fn=None)

Source from the content-addressed store, hash-verified

3640 return downloaded
3641
3642 def upload(self, local_items, remote_path=None, randomize_fname=False, url_to_bytes_fn=None):
3643
3644 url_to_bytes_fn = url_to_bytes_fn or url_to_bytes
3645 destination = remote_path or self.cwd
3646
3647 if not self.write_access(destination):
3648 return []
3649
3650 # Initialization
3651 try:
3652 local_items = [item if re.match(r'(http|ftp)s?://', item, re.IGNORECASE)\
3653 else normalize_path(item) for item in shlex.split(local_items)]
3654
3655 except ValueError as e:
3656 logger.error(e)
3657 return []
3658
3659 # Check for necessary binaries
3660 if self.OS == 'Unix' and not self.agent:
3661 dependencies = ['echo', 'base64', 'tar', 'rm']
3662 for binary in dependencies:
3663 if not self.bin[binary]:
3664 logger.error(f"'{binary}' binary is not available at the target. Cannot upload...")
3665 return []
3666
3667 # Resolve items
3668 resolved_items = []
3669 for item in local_items:
3670 # Download URL
3671 if re.match(r'(http|ftp)s?://', item, re.IGNORECASE):
3672 try:
3673 filename, item = url_to_bytes_fn(item)
3674 if not item:
3675 continue
3676 resolved_items.append((filename, item))
3677 except Exception as e:
3678 logger.error(e)
3679 else:
3680 if os.path.isabs(item):
3681 items = list(Path('/').glob(item.lstrip('/')))
3682 else:
3683 items = list(Path().glob(item))
3684 if items:
3685 resolved_items.extend(items)
3686 else:
3687 logger.error(f"No such file or directory: {item}")
3688
3689 if not resolved_items:
3690 return []
3691
3692 if self.OS == 'Unix':
3693 # Get remote available space
3694 remote_space = remote_block_size = None
3695 if self.agent:
3696 response = self.exec(f"""
3697 stats = os.statvfs(normalize_path('{destination}'))
3698 stdout_stream << (str(stats.f_bavail) + ';' + str(stats.f_frsize)).encode()
3699 """, python=True, value=True)

Callers 15

need_binaryMethod · 0.95
do_uploadMethod · 0.80
do_upgradeMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
upload_mimikatzMethod · 0.80
runMethod · 0.80
upload_sharphoundMethod · 0.80
upload_ghostpackMethod · 0.80
runMethod · 0.80
runMethod · 0.80

Calls 15

write_accessMethod · 0.95
execMethod · 0.95
addMethod · 0.95
updateMethod · 0.95
terminateMethod · 0.95
startMethod · 0.95
stopMethod · 0.95
get_glob_sizeFunction · 0.85
paintClass · 0.85
PBarClass · 0.85
FileServerClass · 0.85
traceMethod · 0.80

Tested by

no test coverage detected