def encrypt_exploit(exploit_dir, target_team, config, signer=None): # Remove trailing slash, for user convenience exploit_dir = remove_trailing_slash(exploit_dir) out_file = exploit_dir + ".zip.pgp" # Retrieve information from config teams = config["teams"] instructor_pubkey = teams["instructor"]["pub_key_id"] target_pubkey = teams[target_team]['pub_key_id'] # Zip the directory tmp_path = "/tmp/gitctf_%s" % random_string(6) shutil.make_archive(tmp_path, "zip", exploit_dir) zip_file = tmp_path + ".zip" # make_archive() automatically appends suffix. # Encrypt the zipped file encrypt_cmd = "gpg -o %s " % out_file if signer is not None: signer_pubkey = config["individual"][signer]['pub_key_id'] encrypt_cmd += "--default-key %s --sign " % signer_pubkey encrypt_cmd += "-e -r %s -r %s " % (instructor_pubkey, target_pubkey) encrypt_cmd += "--armor %s" % zip_file _, err, ret = run_command(encrypt_cmd, None) rmfile(zip_file) # Clean up zip file. if ret != 0: print "[*] Failed to sign/encrypt %s" % zip_file print err return None return out_file
def post(write_key, host=None, timeout=15, **kwargs): """Post the `kwargs` to the API""" body = kwargs body["sentAt"] = datetime.utcnow().replace(tzinfo=tzutc()).isoformat() url = remove_trailing_slash( host or 'https://hosted.rudderlabs.com') + '/v1/batch' auth = HTTPBasicAuth(write_key, '') data = json.dumps(body, cls=DatetimeSerializer) headers = { 'Content-Type': 'application/json', 'User-Agent': 'rudderstack-python/' + VERSION } res = _session.post(url, data=data, auth=auth, headers=headers, timeout=timeout) if res.status_code == 200: return res try: payload = res.json() raise APIError(res.status_code, payload['code'], payload['message']) except ValueError: raise APIError(res.status_code, 'unknown', res.text)
def __init__(self, folders=[]): # Remove the leading forward slash if present self.root_path = utils.remove_trailing_slash(settings.OPENKM['configuration']['UploadRoot']) self.repository = RepositoryManager() self.folder = FolderManager() if folders: dependencies = self.generate_path_dependencies(folders) self.build_path(dependencies)
def __init__(self, folders=[]): # Remove the leading forward slash if present self.root_path = utils.remove_trailing_slash( settings.OPENKM['configuration']['UploadRoot']) self.repository = RepositoryManager() self.folder = FolderManager() if folders: dependencies = self.generate_path_dependencies(folders) self.build_path(dependencies)
def create(self, folder_obj): folder_obj.path = utils.remove_trailing_slash(folder_obj.path) super(FolderManager, self).create(folder_obj)