Полный исходный код ниже.У нас есть клиент, у которого есть сервер, который был изолирован от публичной сети.Рассматриваемый сервер был взломан, поэтому он был отключен, за исключением одной машины с доступом по ssh.Это "сломано", а также.Компромисс заключался в перезаписи sshd версией, несовместимой с современными версиями sftp и scp (задыхается, потому что он не считает PermitLocalCommand
недопустимым вариантом).Он также содержит rsync
, поэтому я не могу rsync файлы к нему.ftp
не разрешено из-за проблем с соответствием.
У меня есть потрясающий обходной путь гетто, когда я просто кодирую / декодирую файлы base64, чтобы передать их на сервер.Работает хорошо, за исключением того, что это глупо.
Я не могу вставить более 4096 байт в строку ввода.Иногда.
Для воспроизведения: возьмите 4096 символов данных, кодированных b64 (не стесняйтесь сгенерировать их с помощью этого скрипта для начала).Затем декодируйте его с помощью той же программы: `program.py -d --stdin -o outfile.png
Он вставит 4096 байт, а затем просто издаст звуковой сигнал.Я не знаю, это проблема программирования, проблема Python 3 или проблема PuTTY.Я использую PuTTY 0.70, 64-битная Windows
Бит "FUN" - это когда я открываю python3 вручную, набираю _test = input('prompt: ')
и затем продолжаю вставлять как МНОГО БАЙТОВ за один раз, как я хочу.
Мысли?
#!/usr/bin/env python3
import base64
import argparse
import os
class GhettoSend():
@staticmethod
def get_output(filename, stdout):
if (not filename and not stdout) and (filename and stdout):
raise ValueError('Exactly one must have a value. Come on, dude...')
@staticmethod
def encode(filename):
# use b85send
return
def main():
parser = argparse.ArgumentParser(
description='Ghetto Send for customers without connectivity'
)
input_group = parser.add_mutually_exclusive_group(required=True)
input_group.add_argument(
'-i',
'--input',
help='Filename to encode/decode'
)
input_group.add_argument(
'--stdin',
help='Take input from stdin. Only usable with --decode',
action='store_true'
)
output_group = parser.add_mutually_exclusive_group(required=True)
output_group.add_argument(
'-o',
'--output',
help='Filename to output to.'
)
output_group.add_argument(
'--stdout',
help='Send output to stdout. Only usable with --encode',
action='store_true'
)
function = parser.add_mutually_exclusive_group(required=True)
function.add_argument(
'-e',
'--encode',
help='Encode a file. Packs it to ascii85 for copy/paste.',
action='store_true'
)
function.add_argument(
'-d',
'--decode',
help='Decode a file. Unpacks it from ascii85 from a copy/paste',
action='store_true'
)
encoding = parser.add_mutually_exclusive_group()
encoding.add_argument(
'--base64',
help='Encode/Decode to/from base64 (default is ASCII85)',
action="store_true"
)
encoding.add_argument(
'--base85',
help='Encode/Decode to/from ASCII85 (this is the default if not specified.)',
action='store_true'
)
args = parser.parse_args()
_base64 = args.base64
_ascii85 = args.base64 == False
if not _base64 and not _ascii85:
raise ValueError('base64 or ascii85 needs to be specified.')
_input = args.input
_output = args.output
_stdin = args.stdin
_stdout = args.stdout
_encode = args.encode
_decode = args.decode
bytes_in = None
bytes_out = None
if _encode:
if not _input:
raise ValueError('You need a filename.')
bytes_in = open(_input, 'br').read()
if _base64:
bytes_out = base64.b64encode(bytes_in)
elif _ascii85:
bytes_out = base64.b85encode(bytes_in)
else:
raise ValueError("You shouldn't be able to get this.")
if _stdout:
print('***************** Base64 start *****************')
print(bytes_out.decode())
print('****************** Base64 end ******************')
else:
open(_output, 'bw').write(bytes_out)
elif _decode:
if _stdin:
print('Paste your encoded text here:')
bytes_in = input()
if not bytes_in:
raise ValueError("You can't decode nothing.")
else:
bytes_in = open(_input, 'br').read()
bytes_out = None
if _base64:
bytes_out = base64.b64decode(bytes_in)
elif _ascii85:
bytes_out = base64.b85decode(bytes_in)
else:
raise ValueError("You shouldn't be able to get this.")
open(_output, 'bw').write(bytes_out)
else:
raise ValueError("You shouldn't be able to get this.")
print('base64: {}'.format(_base64))
print('ascii85: {}'.format(_ascii85))
print('input: {}'.format(_input))
print('output: {}'.format(_output))
# GhettoSend.send()
if __name__ == '__main__':
main()