完整的源代码如下。我们有一个客户,该客户的服务器已与公共网络隔离。该服务器已受到攻击,因此已被防火墙屏蔽,只有一台具有ssh访问权限的计算机除外。它也是“坏的”。折衷方案涉及用与现代sftp和scp版本不兼容的版本覆盖sshd(选择它是因为它认为PermitLocalCommand
不是无效的选项)。它也位于rsync
上,因此我无法将文件同步到它。由于合规性问题,不允许ftp
。
我有一个绝妙的解决方法,我只需要对文件进行base64编码/解码就可以将它们转移到服务器上。效果很好,只是它很笨。
我不能在输入行中粘贴超过4,096个字节。有时。
要重现:取4,096个字符的b64编码数据(可以从此脚本开始随意生成)。然后,使用相同的程序对其进行解码:`program.py -d --stdin -o outfile.png
它将粘贴4,096字节,然后对您发出哔哔声。我不知道这是编程问题,Python 3问题还是PuTTY问题。我正在使用PuTTY 0.70,64位Windows
“ FUN”位是当我手动打开python3时,键入_test = input('prompt: ')
,然后根据需要一次以MANY BYTES的形式粘贴。
有想法吗?
#!/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()