Created
December 7, 2017 10:00
-
-
Save russdill/21cc5973ad927e399b1158f81a2d4d33 to your computer and use it in GitHub Desktop.
BF1942 remote console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import socket | |
import struct | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--username', '-u', action='store', required=True) | |
parser.add_argument('--password', '-p', action='store', required=True) | |
parser.add_argument('host') | |
parser.add_argument('cmd', nargs=argparse.REMAINDER) | |
args = parser.parse_args() | |
host, _, port = args.host.partition(':') | |
if not port: | |
port = 4711 | |
remote = (host, port) | |
def crypt(s): | |
b = bytearray(s) | |
for i in range(0, len(s)): | |
b[i] ^= rand[i%10] | |
return b | |
def send(sock, l): | |
sock.send(struct.pack('<I', len(l))) | |
for s in l: | |
sock.send(struct.pack('<I', len(s) + 1) + bytearray(s) + '\0') | |
def recv(sock): | |
n = struct.unpack('<I', sock.recv(4))[0] | |
ret = [] | |
for i in range(0, n): | |
ret.append(sock.recv(struct.unpack('<I', sock.recv(4))[0]).rstrip('\0')) | |
return ret | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect(remote) | |
rand = bytearray(sock.recv(10)) | |
sock.send(struct.pack('<I', len(args.username) + 1) + crypt(args.username) + '\0') | |
sock.send(struct.pack('<I', len(args.password) + 1) + crypt(args.password) + '\0') | |
resp = sock.recv(1) | |
if resp != '\1': | |
raise Exception('Server denied connection: %d' % ord(resp)) | |
send(sock, ['ConsoleMessage 0', ' '.join(args.cmd)]) | |
for s in recv(sock): | |
print s, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment