def get_deviceId(device): device = AdbClient(device.serialno) d_out = device.shell("dumpsys iphonesubinfo") lines = d_out.strip() devline = lines.split("\n")[2] dev_id = devline.split("=")[1].strip() return dev_id
def __init__(self): #adb = obtainAdbPath() # 手机唯一标识 self.deviceTag = 'M3LDU15518000041' try: self.adbClient = AdbClient(self.deviceTag, settransport=False) except RuntimeError, ex: if re.search('Connection refused', str(ex)): raise RuntimeError("adb is not running") raise (ex)
def __init__(self, deviceid, settings): self._settings = settings config = configparser.ConfigParser() config.read("config.ini") self._mongodb_client = pymongo.MongoClient( config.get("global", "mongodbip"), 27017) try: self.adbClient = AdbClient(deviceid, hostname=config.get( "global", "adbserver"), settransport=False) except RuntimeError, ex: if re.search('Connection refused', str(ex)): raise RuntimeError("adb is not running") raise (ex)
def main(): devices = adb.get_attached_devices() print """ !!! Test AntiVirus !!! !!! Attenzione: !!! !!! Prima dell'installazione dell'agente, al dispositivo va impedito il libero accesso ad internet. !!! """ print """ prerequisiti: 1) Telefono connesso in USB, 2) USB Debugging enabled (settings/developer options/usb debugging) 3) connesso wifi TP-LINK_9EF638 <======== NB!!!!!!!!!!!!!!!!!!!!!!! 4) NESSUNA SIM INSTALLATA <======== NB!!!!!!!!!!!!!!!!!!!!!!! 5) screen time 2m (settings/display/sleep) """ print "devices connessi:" for device in devices: print device if not devices: print "non ci sono device connessi" else: if len(devices) > 1: dev = raw_input("su quale device si vuole eseguire il test? ") print "Eseguo il test su %s" % dev if len(sys.argv) >= 2: serialno = sys.argv[1] else: serialno = '.*' device = AdbClient(serialno=serialno) pre_test(device) for av in avs_to_test: do_test(device, av) post_test(device) print "Fine."
def __init__(self): assert len(sys.argv) == 4 self.size = map(int, sys.argv[1].split("x")) orig = map(int, sys.argv[2].split("x")) self.orig = orig[1], orig[0] self.path = sys.argv[3] self.scalel = True self.scalep = False self.cap = CapClient(self) self.cap.start() self.touch = TouchClient(self) self.touch.start() self.rot = RotationClient() self.rot.start() self.adb = AdbClient() self.adb.start() self.mouse_down = False self.mouse_time = 0 self.mouse_inmenu = False self.show_menu = False self.show_menu_time = 0 self.show_nav = False #image scale orig to disp self.scale = self.orig[0] / float(self.size[0]) self.ratio = self.orig[0] / float(self.orig[1]) #size of raw image in landscape mode self.sizel = self.size[0], int(self.orig[1] / self.scale) #size of raw image in portrait mode self.sizep = int(self.orig[1] / self.scale), self.size[0] self.rotation = 0 self.calc_scale() pygame.init() pygame.font.init() self.screen = pygame.display.set_mode( self.size, pygame.FULLSCREEN | pygame.HWSURFACE) pygame.display.set_caption("adbmirror") self.color = (200, 200, 200) font = pygame.font.Font("res/fontawesome.ttf", 70) self.img_close = font.render(u'\uf00d', True, self.color) self.img_portrait = font.render(u'\uf10b', True, self.color) self.img_landscape = pygame.transform.rotate(self.img_portrait, 90) self.img_bars = font.render(u'\uf0c9', True, self.color) font = pygame.font.Font("res/fontawesome.ttf", 30) img_back = font.render(u'\uf053', True, self.color) img_home = font.render(u'\uf015', True, self.color) img_box = font.render(u'\uf009', True, self.color) self.menu_w = int(self.size[0] * MENU_WIDTH / 100.0) self.menu_h = int(self.size[1] / 3) self.update_menu() self.nav_w = int(self.size[0] * NAV_WIDTH / 100.0) self.img_nav = pygame.Surface((self.nav_w, self.size[1])) self.blit_center(self.img_nav, img_box, (0, 0, self.nav_w, self.menu_h)) self.blit_center(self.img_nav, img_home, (0, self.menu_h, self.nav_w, self.menu_h)) self.blit_center(self.img_nav, img_back, (0, self.menu_h * 2, self.nav_w, self.menu_h))
class Main(): def __init__(self): assert len(sys.argv) == 4 self.size = map(int, sys.argv[1].split("x")) orig = map(int, sys.argv[2].split("x")) self.orig = orig[1], orig[0] self.path = sys.argv[3] self.scalel = True self.scalep = False self.cap = CapClient(self) self.cap.start() self.touch = TouchClient(self) self.touch.start() self.rot = RotationClient() self.rot.start() self.adb = AdbClient() self.adb.start() self.mouse_down = False self.mouse_time = 0 self.mouse_inmenu = False self.show_menu = False self.show_menu_time = 0 self.show_nav = False #image scale orig to disp self.scale = self.orig[0] / float(self.size[0]) self.ratio = self.orig[0] / float(self.orig[1]) #size of raw image in landscape mode self.sizel = self.size[0], int(self.orig[1] / self.scale) #size of raw image in portrait mode self.sizep = int(self.orig[1] / self.scale), self.size[0] self.rotation = 0 self.calc_scale() pygame.init() pygame.font.init() self.screen = pygame.display.set_mode( self.size, pygame.FULLSCREEN | pygame.HWSURFACE) pygame.display.set_caption("adbmirror") self.color = (200, 200, 200) font = pygame.font.Font("res/fontawesome.ttf", 70) self.img_close = font.render(u'\uf00d', True, self.color) self.img_portrait = font.render(u'\uf10b', True, self.color) self.img_landscape = pygame.transform.rotate(self.img_portrait, 90) self.img_bars = font.render(u'\uf0c9', True, self.color) font = pygame.font.Font("res/fontawesome.ttf", 30) img_back = font.render(u'\uf053', True, self.color) img_home = font.render(u'\uf015', True, self.color) img_box = font.render(u'\uf009', True, self.color) self.menu_w = int(self.size[0] * MENU_WIDTH / 100.0) self.menu_h = int(self.size[1] / 3) self.update_menu() self.nav_w = int(self.size[0] * NAV_WIDTH / 100.0) self.img_nav = pygame.Surface((self.nav_w, self.size[1])) self.blit_center(self.img_nav, img_box, (0, 0, self.nav_w, self.menu_h)) self.blit_center(self.img_nav, img_home, (0, self.menu_h, self.nav_w, self.menu_h)) self.blit_center(self.img_nav, img_back, (0, self.menu_h * 2, self.nav_w, self.menu_h)) def update_menu(self): self.img_menu = pygame.Surface((self.menu_w, self.size[1])) self.blit_center(self.img_menu, self.img_close, (0, 0, self.menu_w, self.menu_h)) if self.landscape: self.blit_center(self.img_menu, self.img_portrait, (0, self.menu_h, self.menu_w, self.menu_h)) else: self.blit_center(self.img_menu, self.img_landscape, (0, self.menu_h, self.menu_w, self.menu_h)) self.blit_center(self.img_menu, self.img_bars, (0, self.menu_h * 2, self.menu_w, self.menu_h)) def calc_scale(self): self.landscape = self.rotation in [90, 270] if self.show_nav: max_w = self.size[0] - self.nav_w else: max_w = self.size[0] if self.landscape: x = 0 w = max_w if self.scalel: h = self.size[1] y = 0 else: h = w / self.ratio y = (self.size[1] - h) / 2 else: y = 0 h = self.size[1] if self.scalep: x = 0 w = max_w else: w = h / self.ratio x = (self.size[0] - w) / 2 self.proj = map(int, [x, y, w, h]) self.frame_update = True def blit_center(self, dst, src, rect): x = rect[0] - int((src.get_width() / 2) - (rect[2] / 2)) y = rect[1] - int((src.get_height() / 2) - (rect[3] / 2)) dst.blit(src, (x, y)) def exit(self): self.running = False self.cap.write(["end"]) self.touch.write(["end"]) self.rot.write(["end"]) self.adb.write(["end"]) def events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: self.exit() if hasattr(event, "pos"): ix, iy = event.pos self.mouse_inmenu = ix <= self.size[1] * MENU_BORDER / 100.0 fx = min(max(0, (ix - self.proj[0]) / float(self.proj[2])), 1) fy = min(max(0, (iy - self.proj[1]) / float(self.proj[3])), 1) if self.rotation == 0: x = fx y = fy if self.rotation == 90: x = 1.0 - fy y = fx if self.rotation == 180: x = 1.0 - fx y = 1.0 - fy if self.rotation == 270: x = fy y = 1.0 - fx if hasattr(event, "button"): if event.button is not 1: continue if event.type == pygame.MOUSEBUTTONDOWN: if ix < self.menu_w and self.show_menu: self.menu_action(iy / (self.size[1] / 3)) elif ix > self.size[0] - self.nav_w and self.show_nav: self.nav_action(iy / (self.size[1] / 3)) else: self.touch.write(["down", x, y]) self.mouse_down = True self.mouse_time = time() if event.type == pygame.MOUSEBUTTONUP: self.touch.write(["up"]) self.mouse_down = False if event.type == pygame.MOUSEMOTION: if self.mouse_down: self.touch.write(["move", x, y]) def nav_action(self, but): if but == 0: self.adb.write(["apps"]) if but == 1: self.adb.write(["home"]) if but == 2: self.adb.write(["back"]) def menu_action(self, but): if but == 0: self.exit() if but == 1: if self.landscape: self.adb.write(["portrait"]) else: self.adb.write(["landscape"]) if but == 2: self.show_nav = not self.show_nav self.calc_scale() self.show_menu = False def menu_loop(self): if self.mouse_down and time( ) - self.mouse_time > MENU_TAP and self.mouse_inmenu: self.show_menu = True self.screen_update = True self.show_menu_time = time() if self.show_menu and time() - self.show_menu_time > MENU_TIMEOUT: self.show_menu = False self.screen_update = True def run(self): self.running = True self.adb.write(["landscape"]) self.screen_update = True self.frame_update = False frame_cache = pygame.Surface(self.size) last_frame = None while self.running: self.events() for msg in self.rot.read(): cmd = msg[0] if cmd == "rot": self.rotation = msg[1] self.calc_scale() self.update_menu() #we will process only one frame at the time msgs = self.cap.read() msgl = len(msgs) if msgl: msg = msgs[msgl - 1] cmd = msg[0] if cmd == "data": data = cStringIO.StringIO(msg[1]) last_frame = pygame.image.load(data) self.frame_update = True for msg in self.adb.read(): cmd = msg[0] if cmd == "end": self.exit() self.menu_loop() if self.frame_update: self.frame_update = False if last_frame is not None: if self.landscape: a = last_frame.subsurface( pygame.Rect((0, 0), self.sizel)) else: a = last_frame.subsurface( pygame.Rect((0, 0), self.sizep)) aw, ah = a.get_size() if aw != self.proj[2] or ah != self.proj[3]: frame_cache = pygame.transform.smoothscale( a, (self.proj[2], self.proj[3])) else: frame_cache = a.copy() self.screen_update = True if self.screen_update: self.screen.fill((0, 0, 0)) self.screen_update = False self.screen.blit(frame_cache, (self.proj[0], self.proj[1])) if self.show_menu: self.screen.blit(self.img_menu, (0, 0)) if self.show_nav: self.screen.blit(self.img_nav, (self.size[0] - self.nav_w, 0)) pygame.display.update()
def main(argv): devices = adb.get_attached_devices() print """ !!! Test AntiVirus !!! !!! Attenzione: !!! !!! Prima dell'installazione dell'agente, al dispositivo va impedito il libero accesso ad internet. !!! """ print """ prerequisiti: 1) Telefono connesso in USB, 2) USB Debugging enabled (settings/developer options/usb debugging) 3) NESSUNA SIM INSTALLATA <======== NB!!!!!!!!!!!!!!!!!!!!!!! 4) screen time 2m (settings/display/sleep) """ print "devices connessi:" for device in devices: print device if not devices: print "non ci sono device connessi" else: if len(devices) > 1: dev = raw_input("su quale device si vuole eseguire il test? ") print "Eseguo il test su %s" % dev if len(sys.argv) >= 2: serialno = sys.argv[1] else: serialno = '.*' device = AdbClient(serialno=serialno) # print 'Args=', (str(sys.argv)) # operation = sys.argv[1] init = raw_input('Init everything? (y/n)') if init == "y": print "Init!" commands.init_device(device.serialno) dev = device.serialno operation = -1 while operation != "99": print '' print '################# OPERATIONS #################' print 'What operation do you want to perform?' print '1 - get new configuration from installed av' print '2 - use net RSSM' print '3 - use net TPLINK' print '4 - disable net' print '5 - get wifi network name' print '6 - ping google' print '7 - test all avs' print '8 - test a single av' print '9 - is infected?' print '10 - got r00t?' print '11 - pull file' print '12 - push file' print '' print '################# INTERNAL TESTS #################' print '20 - test get_server' print '21 - test set_server' print '22 - test get_client' print '23 - test set_client' print '24 - test install' print '25 - test install_agent' print '26 - test uninstall' print '27 - test uninstall_agent' print '28 - test execute' print '29 - test execute_agent' print '' print '################# EXIT #################' print '99 - Clean & exit!' operation = raw_input() if operation == '1': print 'Which av you want to retrieve?' print str(apk_dataLoader.get_av_list()) av = raw_input() commands.update(av, dev) elif operation == '2': commands.wifi('open', dev) elif operation == '3': commands.wifi('av', dev) elif operation == '4': commands.wifi('disable', dev) elif operation == '5': print commands.info_wifi_network(dev) elif operation == '6': if commands.can_ping_google(dev): print "I can ping google" else: print "I canNOT ping google" elif operation == '7': # TODO: andrebbe spostato il do_test for av in apk_dataLoader.get_av_list(): do_test(device, av) elif operation == '8': # TODO: andrebbe spostato il do_test print 'Which av you want to test?' print str(apk_dataLoader.get_av_list()) av = raw_input() do_test(device, av) elif operation == '9': if commands.check_infection(dev): print "Infected" else: print "Clean" elif operation == '10': if commands.check_su_permissions(dev): print "Root!" else: print "Not root :(" elif operation == '11': print '12 - pull file' commands.pull(['file.png'], '/sdcard/', 'tmp', dev) if os.path.exists('tmp/file.png'): print 'Pull OK!' #debug: time.sleep(20) os.remove('tmp/file.png') else: print 'Pull failed!' elif operation == '12': print '13 - push file' commands.push(['file.png'], 'assets', '/sdcard/', dev) elif operation == '20': print "testvarsrv= " + commands.get_server('testvarsrv') elif operation == '21': commands.set_server({'testvarsrv': 'testvaluesrv'}) elif operation == '22': print "testvarcli= " + commands.get_client('testvarcli') elif operation == '23': commands.set_client({'testvarcli': 'testvaluecli'}) elif operation == '24': commands.install('wifi_enabler', dev) elif operation == '25': commands.install_agent(dev) elif operation == '26': commands.uninstall('wifi_enabler', dev) elif operation == '27': commands.uninstall_agent(dev) elif operation == '28': commands.execute('wifi_enabler', dev) elif operation == '29': commands.execute_agent(dev) print "Operazioni terminate, cleaning time" commands.reset_device(dev) print "The end"
sys.exit(0) #Remove the local files so we can make sure it's copying new ones if os.path.exists(messageLocalFile): os.remove(messageLocalFile) if os.path.exists(challengeLocalFile): os.remove(challengeLocalFile) #Create challenge file print "Creating Challenge" challengeBytes = os.urandom(16) open(challengeLocalFile,"wb").write(challengeBytes) if plat == AL: adb = AdbClient() devices = adb.GetDevices() print devices if len(devices._device_map) == 0: print "No device connected, exiting..." sys.exit(0) else: device = devices[1] print "Connecting to Device %s " % device #Copy challenge to device print "Copying challenge" device.Push(challengeLocalFile,challengeOnDeviceFile) print "Running client"