Exemplo n.º 1
0
def run(key, port=DEFAULT_PORT):
    scon = neonet.NrlOpenPort(port)
    while True:
        data = scon.recv(float('inf'))
        adr = data[0]
        data = data[1]
        try:
            if data == b"REMOTE_CONNECT":
                port = random.randint(8192, 2**30)
                scon.send(adr, b"OK=" + hex(port).encode())
                con = neonet.NrlSecureConnection(adr, port, key, 500)
                #_thread.start_new_thread(handle_client, (con, adr))
                handle_client(con, adr)
            else:
                log("Strange data from " + str(adr) + " : " + data.decode())
        except:
            pass
Exemplo n.º 2
0
def handle_client(con, adr):
    log("Remote Control: Accepted connection from " + str(adr))
    running = True
    while running:
        data = con.recv(60000)
        if data == None:
            con.send(b"HELLO?")
            data = con.recv(5000)
            if data == None:
                break
            if data != b"HELLO!":
                con.queue.append(data)  # put it back on if it's not a response
        elif data[:5] == b'CLOSE':
            txt = "Remote Control: " + str(adr) + " is closing the connection."
            if len(data) > 5:
                txt += "  Message = " + data[5:].decode()
            log(txt)
            break
        elif data[:3] == b"CWD":
            try:
                os.chdir(data[3:].decode())
                con.send(b"OK")
            except Exception as e:
                con.send(b"ERROR: " + str(e).encode())
        elif data[:3] == b"SYS":
            try:
                con.send(b"OK")
                cmd = data[3:].decode()
                log("Executing command: " + cmd)
                p = subprocess.Popen(cmd,
                                     shell=True,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT)
                while p.poll() == None:
                    d = p.stdout.read()
                    if len(d) > 0:
                        con.send(b'stdo=' + d)
                    time.sleep(.1)
                con.send(b"done=" + str(p.poll()).encode())
            except Exception as e:
                con.send(b"ERROR: " + str(e).encode())
    log("Remote Control: Connection to " + str(adr) + " is closed.")
Exemplo n.º 3
0
def handle_client(fs, con, adr):
    log("Filebase: Accepted connection from " + str(adr))
    running = True
    while running:
        data = con.recv(60000)
        if data == None:
            con.send(b"HELLO?")
            data = con.recv(5000)
            if data == None:
                break
            if data != b"HELLO!":
                con.queue.append(data)  # put it back on if it's not a response
        elif data[:5] == b'CLOSE':
            txt = "Filebase: " + str(adr) + " is closing the connection."
            if len(data) > 5:
                txt += "  Message = " + data[5:].decode()
            log(txt)
            break
        elif data[:2] == b"WR":
            try:
                idx = data.find(b';')
                fn = data[2:idx].decode()
                fs.write(fn, data[idx:])
                con.send(b"OK")
            except Exception as e:
                con.send(b"ERROR: " + str(e).encode())
        elif data[:2] == b"RD":
            try:
                fn = data[2:].decode()
                data = fs.read(fn)
                if data == -1:
                    con.send(b"FNF")  # file not found
                else:
                    con.send((len(data) // 8192 + 1).to_bytes(4, "big"))
                    for i in range((len(data) // 8192 + 1)):
                        con.send(data[i * 8192:(i + 1) * 8192])
            except Exception as e:
                con.send(b"ERROR: " + str(e).encode())
    log("Filebase: Connection to " + str(adr) + " is closed.")
Exemplo n.º 4
0
import sys, os
sys.path.append(os.path.abspath('../'))

import neonet
import netlog as logging
import filebase, remote_control
import storage, _thread

if not os.path.isfile("cfg.txt"):
    storage.saveDict(
        "cfg.txt", {
            'adr': 0xC7860010,
            'key': 'default-key',
            'filebase-dir': './filebase/',
            'log_dir': './logs/'
        })
cfg = storage.loadDict("cfg.txt")
neonet.setup(cfg['adr'])

logging.add_log_file(os.path.join(cfg['log_dir'], '{}.txt'))

logging.log("Starting Filebase and Remote Control...")
_thread.start_new_thread(filebase.run, (cfg['key'], cfg['filebase-dir']))
_thread.start_new_thread(remote_control.run, (cfg['key'], ))
Exemplo n.º 5
0
        if data == None:
            return None
        elif data == b"FNF":
            return -1
        size = int.from_bytes(data, 'big')
        for i in range(size):
            buffer += self.con.recv()
        return buffer

    def write(self, fn, data):
        if type(data) == str:
            data = data.encode()
        self.con.send(b'WR' + fn.encode() + b';' + data)
        msg = self.con.recv()
        if msg != b"OK":
            if msg != None:
                msg = msg.decode()
            return msg


if __name__ == "__main__":
    add_log_file("logs/filebase/{}.txt")
    log("Starting NeoNet...")
    neonet.setup(0x880210)
    log("Starting filebase.py [default configuration]...")
    try:
        run("password", "filebase_default/")  # TODO: fix this somehow
    except Exception as e:
        log("ERROR: Server threw an exception: " + str(e))
        nope()
Exemplo n.º 6
0
        self.con.send(b'SYS' + cmd.encode())
        msg = self.con.recv()
        if msg != b"OK":
            if msg != None:
                msg = msg.decode()
            return msg

    def sys_pull(self):
        d = self.con.recv(200)
        if d != None:
            d = d.decode()
            cmd = d[:5]
            if cmd == "stdo=":
                return ['stdo', d[5:]]
            elif cmd == "stde=":
                return ['stde', d[5:]]
            elif cmd == "done=":
                return int(d[5:])


if __name__ == "__main__":
    add_log_file("logs/{}.txt")
    log("Starting NeoNet...")
    neonet.setup(0x880210)
    log("Starting remote_control.py ...")
    try:
        run("password")  # TODO: fix this somehow
    except Exception as e:
        log("ERROR: Server threw an exception: " + str(e))
        nope()