예제 #1
0
파일: scan.py 프로젝트: Cel1ca/Monkey
def main():
    args = parse_args()
    log = get_logger()
    if args.status_bar:
        configure_logger(filename=join(conf.DIRECTORY, 'scan.log'))
        log.info('-' * 37)
        log.info('Starting up!')
    else:
        configure_logger(filename=None)
    log.setLevel(args.log_level)

    AccountManager.register('captcha_queue', callable=get_captchas)
    AccountManager.register('extra_queue', callable=get_extras)
    AccountManager.register('lv30_captcha_queue', callable=get_lv30_captchas)
    AccountManager.register('lv30_account_queue', callable=get_lv30_accounts)
    if conf.MAP_WORKERS:
        AccountManager.register('worker_dict',
                                callable=get_workers,
                                proxytype=DictProxy)
        AccountManager.register('lv30_worker_dict',
                                callable=get_lv30_workers,
                                proxytype=DictProxy)
    address = get_address()
    manager = AccountManager(address=address, authkey=conf.AUTHKEY)
    try:
        manager.start(mgr_init)
    except (OSError, EOFError) as e:
        if platform == 'win32' or not isinstance(address, str):
            raise OSError(
                'Another instance is running with the same manager address. Stop that process or change your MANAGER_ADDRESS.'
            ) from e
        else:
            raise OSError(
                'Another instance is running with the same socket. Stop that process or: rm {}'
                .format(address)) from e

    LOOP.set_exception_handler(exception_handler)

    overseer = Overseer(manager)
    overseer.start(args.status_bar)
    launcher = LOOP.create_task(overseer.launch(args.bootstrap, args.pickle))

    if conf.GO_HASH:
        hashkey = conf.GO_HASH_KEY
    else:
        hashkey = conf.HASH_KEY
    activate_hash_server(hashkey,
                         go_hash=conf.GO_HASH,
                         hash_endpoint=conf.HASH_ENDPOINT,
                         gohash_endpoint=conf.GOHASH_ENDPOINT)
    if platform != 'win32':
        LOOP.add_signal_handler(SIGINT, launcher.cancel)
        LOOP.add_signal_handler(SIGTERM, launcher.cancel)

    try:
        LOOP.run_until_complete(launcher)
    except (KeyboardInterrupt, SystemExit):
        launcher.cancel()
    finally:
        cleanup(overseer, manager)
 def manager_connect():
     global worker_dict
     global manager
     try:
         manager = AccountManager(address=utils.get_address(),
                                  authkey=config.AUTHKEY)
         manager.connect()
         worker_dict = manager.worker_dict()
     except (FileNotFoundError, AttributeError, RemoteError,
             ConnectionRefusedError):
         print('Unable to connect to manager for worker data.')
         worker_dict = {}
예제 #3
0
파일: scan.py 프로젝트: Kiltres/Monocle
def main():
    args = parse_args()
    log = get_logger()
    if args.status_bar:
        configure_logger(filename=join(conf.DIRECTORY, 'scan.log'))
        log.info('-' * 37)
        log.info('Starting up!')
    else:
        configure_logger(filename=None)
    log.setLevel(args.log_level)

    AccountManager.register('captcha_queue', callable=get_captchas)
    AccountManager.register('extra_queue', callable=get_extras)
    if conf.MAP_WORKERS:
        AccountManager.register('worker_dict', callable=get_workers,
                                proxytype=DictProxy)
    address = get_address()
    manager = AccountManager(address=address, authkey=conf.AUTHKEY)
    try:
        manager.start(mgr_init)
    except (OSError, EOFError) as e:
        if platform == 'win32' or not isinstance(address, str):
            raise OSError('Another instance is running with the same manager address. Stop that process or change your MANAGER_ADDRESS.') from e
        else:
            raise OSError('Another instance is running with the same socket. Stop that process or: rm {}'.format(address)) from e

    LOOP.set_exception_handler(exception_handler)

    overseer = Overseer(manager)
    overseer.start(args.status_bar)
    launcher = LOOP.create_task(overseer.launch(args.bootstrap, args.pickle))
    activate_hash_server(conf.HASH_KEY)
    if platform != 'win32':
        LOOP.add_signal_handler(SIGINT, launcher.cancel)
        LOOP.add_signal_handler(SIGTERM, launcher.cancel)
    try:
        LOOP.run_until_complete(launcher)
    except (KeyboardInterrupt, SystemExit):
        launcher.cancel()
    finally:
        cleanup(overseer, manager)
예제 #4
0
async def main():
    try:
        class AccountManager(BaseManager): pass
        AccountManager.register('captcha_queue')
        AccountManager.register('extra_queue')
        AccountManager.register('lv30_captcha_queue')
        AccountManager.register('lv30_account_queue')
        manager = AccountManager(address=get_address(), authkey=conf.AUTHKEY)
        manager.connect()
        captcha_queue = manager.captcha_queue()
        extra_queue = manager.extra_queue()
        lv30_captcha_queue = manager.lv30_captcha_queue()
        lv30_account_queue = manager.lv30_account_queue()

        def put_account_queue(account):
            if account.get('level', 0) < 30:
                extra_queue.put(account)
            else:
                lv30_account_queue.put(account)

        def put_captcha_queue(account):
            if account.get('leve', 0) < 30:
                captcha_queue.put(account)
            else:
                lv30_captcha_queue.put(account)

        if conf.GO_HASH:
            hashkey = conf.GO_HASH_KEY
        else:
            hashkey = conf.HASH_KEY
        activate_hash_server(hashkey,
            go_hash=conf.GO_HASH,
            hash_endpoint=conf.HASH_ENDPOINT,
            gohash_endpoint=conf.GOHASH_ENDPOINT)

        driver = webdriver.Chrome()
        driver.set_window_size(803, 807)

        while not captcha_queue.empty() or not lv30_captcha_queue.empty():
            try:
                account = captcha_queue.get()
            except Empty:
                try:
                    account = lv30_captcha_queue.get()
                except Empty:
                    break
            username = account.get('username')
            location = account.get('location')
            if location and location != (0,0,0):
                lat = location[0]
                lon = location[1]
            else:
                lat, lon = randomize_point(center, 0.0001)

            try:
                alt = altitudes.get((lat, lon))
            except KeyError:
                alt = await altitudes.fetch((lat, lon))

            try:
                device_info = get_device_info(account)
                api = PGoApi(device_info=device_info)
                api.set_position(lat, lon, alt)

                authenticated = False
                try:
                    if account['provider'] == 'ptc':
                        api.auth_provider = AuthPtc()
                        api.auth_provider._access_token = account['auth']
                        api.auth_provider._access_token_expiry = account['expiry']
                        if api.auth_provider.check_access_token():
                            api.auth_provider.authenticated = True
                            authenticated = True
                except KeyError:
                    pass

                if not authenticated:
                    await api.set_authentication(username=username,
                                                 password=account['password'],
                                                 provider=account.get('provider', 'ptc'))

                request = api.create_request()
                await request.call()

                await sleep(.6)

                request.download_remote_config_version(platform=1, app_version=9100)
                request.check_challenge()
                request.get_hatched_eggs()
                request.get_inventory(last_timestamp_ms=account.get('inventory_timestamp', 0))
                request.check_awarded_badges()
                request.download_settings()
                responses = await request.call()
                account['time'] = time()

                challenge_url = responses['CHECK_CHALLENGE'].challenge_url
                timestamp = responses['GET_INVENTORY'].inventory_delta.new_timestamp_ms
                account['location'] = lat, lon
                account['inventory_timestamp'] = timestamp
                if challenge_url == ' ':
                    account['captcha'] = False
                    print('No CAPTCHA was pending on {}.'.format(username))
                    put_account_queue(account)
                else:
                    print('Trying to solve {}.'.format(username))
                    if await solve_captcha(challenge_url, api, driver, timestamp):
                        account['time'] = time()
                        account['captcha'] = False
                        print('Solved CAPTCHA for {}, putting back in rotation.'.format(username))
                        put_account_queue(account)
                    else:
                        account['time'] = time()
                        print('Failed to solve for {}'.format(username))
                        put_captcha_queue(account)
            except KeyboardInterrupt:
                put_captcha_queue(account)
                break
            except KeyError:
                print('Unexpected or empty response for {}, putting back on queue.'.format(username))
                put_captcha_queue(account)
                try:
                    print(response)
                except Exception:
                    pass
                await sleep(3)
            except (ex.AuthException, ex.AuthTokenExpiredException) as e:
                print('Authentication error on {}: {}'.format(username, e))
                put_captcha_queue(account)
                await sleep(3)
            except ex.AiopogoError as e:
                print('aiopogo error on {}: {}'.format(username, e))
                put_captcha_queue(account)
                await sleep(3)
            except Exception:
                put_captcha_queue(account)
                raise
    finally:
        try:
            driver.close()
            close_sessions()
        except Exception:
            pass
def main():
    args = parse_args()
    logger = getLogger()
    if args.status_bar:
        configure_logger(filename=join(config.DIRECTORY, 'scan.log'))
        logger.info('-' * 30)
        logger.info('Starting up!')
    else:
        configure_logger(filename=None)
    logger.setLevel(args.log_level)

    AccountManager.register('captcha_queue', callable=get_captchas)
    AccountManager.register('extra_queue', callable=get_extras)
    if config.MAP_WORKERS:
        AccountManager.register('worker_dict', callable=get_workers,
                                proxytype=DictProxy)
    address = get_address()
    manager = AccountManager(address=address, authkey=config.AUTHKEY)
    try:
        manager.start(mgr_init)
    except (OSError, EOFError) as e:
        if platform == 'win32' or not isinstance(address, str):
            raise OSError('Another instance is running with the same manager address. Stop that process or change your MANAGER_ADDRESS.') from e
        else:
            raise OSError('Another instance is running with the same socket. Stop that process or: rm {}'.format(address)) from e

    loop = asyncio.get_event_loop()
    loop.set_exception_handler(exception_handler)

    overseer = Overseer(status_bar=args.status_bar, manager=manager)
    overseer.start()
    overseer_thread = Thread(target=overseer.check, name='overseer', daemon=True)
    overseer_thread.start()

    launcher_thread = Thread(target=overseer.launch, name='launcher', daemon=True, args=(args.bootstrap, args.pickle))
    launcher_thread.start()

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print('Exiting, please wait until all tasks finish')
        overseer.kill()

        dump_pickle('accounts', Worker.accounts)
        if config.CACHE_CELLS:
            dump_pickle('cells', Worker.cell_ids)

        pending = asyncio.Task.all_tasks(loop=loop)
        try:
            loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
        except Exception:
            logger.exception('A wild exception appeared during exit!')

        Worker.db_processor.stop()

        try:
            Worker.spawns.update()
        except (DBAPIError):
            pass
        Worker.spawns.session.close()
        manager.shutdown()
        Session.close()

        try:
            loop.close()
        except RuntimeError:
            pass
예제 #6
0
 def __init__(self):
     self._data = {}
     self._manager = AccountManager(address=get_address(), authkey=conf.AUTHKEY)
예제 #7
0
async def main():
    try:
        if hasattr(config, 'AUTHKEY'):
            authkey = config.AUTHKEY
        else:
            authkey = b'm3wtw0'

        if hasattr(config, 'HASH_KEY'):
            HASH_KEY = config.HASH_KEY
        else:
            HASH_KEY = None

        class AccountManager(BaseManager):
            pass

        AccountManager.register('captcha_queue')
        AccountManager.register('extra_queue')
        manager = AccountManager(address=get_address(), authkey=authkey)
        manager.connect()
        captcha_queue = manager.captcha_queue()
        extra_queue = manager.extra_queue()

        driver = webdriver.Chrome()
        driver.set_window_size(803, 807)

        while not captcha_queue.empty():
            account = captcha_queue.get()
            username = account.get('username')
            location = account.get('location')
            if location and location != (0, 0, 0):
                lat = location[0]
                lon = location[1]
                try:
                    alt = location[2]
                except IndexError:
                    alt = random_altitude()
            else:
                lat = uniform(LAT_MEAN - 0.001, LAT_MEAN + 0.001)
                lon = uniform(LON_MEAN - 0.001, LON_MEAN + 0.001)
                alt = random_altitude()

            try:
                device_info = get_device_info(account)
                api = PGoApi(device_info=device_info)
                if HASH_KEY:
                    api.activate_hash_server(HASH_KEY)
                api.set_position(lat, lon, alt)

                authenticated = False
                if account.get('provider') == 'ptc' and account.get('refresh'):
                    api._auth_provider = AuthPtc()
                    api._auth_provider.set_refresh_token(
                        account.get('refresh'))
                    api._auth_provider._access_token = account.get('auth')
                    api._auth_provider._access_token_expiry = account.get(
                        'expiry')
                    if api._auth_provider.check_access_token():
                        api._auth_provider._login = True
                        authenticated = True

                if not authenticated:
                    await api.set_authentication(username=username,
                                                 password=account['password'],
                                                 provider=account.get(
                                                     'provider', 'ptc'))

                request = api.create_request()
                request.download_remote_config_version(platform=1,
                                                       app_version=5302)
                request.check_challenge()
                request.get_hatched_eggs()
                request.get_inventory()
                request.check_awarded_badges()
                request.download_settings()
                response = await request.call()
                account['time'] = time()

                if response['status_code'] == 3:
                    print('{} appears to be banned.'.format(username))
                    continue

                responses = response['responses']
                challenge_url = responses['CHECK_CHALLENGE']['challenge_url']
                timestamp = responses.get('GET_INVENTORY',
                                          {}).get('inventory_delta',
                                                  {}).get('new_timestamp_ms')
                account['location'] = lat, lon, alt
                account['inventory_timestamp'] = timestamp
                if challenge_url == ' ':
                    account['captcha'] = False
                    print('No CAPTCHA was pending on {}.'.format(username))
                    extra_queue.put(account)
                else:
                    if await solve_captcha(challenge_url, api, driver,
                                           timestamp):
                        account['time'] = time()
                        account['captcha'] = False
                        print(
                            'Solved CAPTCHA for {}, putting back in rotation.'.
                            format(username))
                        extra_queue.put(account)
                    else:
                        account['time'] = time()
                        print('Failed to solve for {}'.format(username))
                        captcha_queue.put(account)
            except KeyboardInterrupt:
                captcha_queue.put(account)
                break
            except KeyError:
                print(
                    'Unexpected or empty response for {}, putting back on queue.'
                    .format(username))
                captcha_queue.put(account)
                try:
                    print(response)
                except Exception:
                    pass
                await sleep(3)
            except (ex.AuthException, ex.AuthTokenExpiredException) as e:
                print('Authentication error on {}: {}'.format(username, e))
                captcha_queue.put(account)
                await sleep(3)
            except ex.PgoapiError as e:
                print('pgoapi error on {}: {}'.format(username, e))
                captcha_queue.put(account)
                await sleep(3)
            except Exception:
                captcha_queue.put(account)
                raise
    finally:
        try:
            driver.close()
            Session.close()
        except Exception:
            pass
예제 #8
0
 def __init__(self):
     self._data = {}
     self._manager = AccountManager(address=get_address(), authkey=conf.AUTHKEY)
예제 #9
0
async def main():
    try:
        class AccountManager(BaseManager): pass
        AccountManager.register('captcha_queue')
        AccountManager.register('extra_queue')
        manager = AccountManager(address=get_address(), authkey=conf.AUTHKEY)
        manager.connect()
        captcha_queue = manager.captcha_queue()
        extra_queue = manager.extra_queue()

        activate_hash_server(conf.HASH_KEY)

        driver = webdriver.Chrome()
        driver.set_window_size(803, 807)

        while not captcha_queue.empty():
            account = captcha_queue.get()
            username = account.get('username')
            location = account.get('location')
            if location and location != (0,0,0):
                lat = location[0]
                lon = location[1]
            else:
                lat, lon = randomize_point(center, 0.0001)

            try:
                alt = altitudes.get(point)
            except KeyError:
                alt = await altitudes.fetch(point)

            try:
                device_info = get_device_info(account)
                api = PGoApi(device_info=device_info)
                api.set_position(lat, lon, alt)

                authenticated = False
                try:
                    if account['provider'] == 'ptc':
                        api.auth_provider = AuthPtc()
                        api.auth_provider._access_token = account['auth']
                        api.auth_provider._access_token_expiry = account['expiry']
                        if api.auth_provider.check_access_token():
                            api.auth_provider.authenticated = True
                            authenticated = True
                except KeyError:
                    pass

                if not authenticated:
                    await api.set_authentication(username=username,
                                                 password=account['password'],
                                                 provider=account.get('provider', 'ptc'))

                request = api.create_request()
                await request.call()

                await sleep(.6)

                request.download_remote_config_version(platform=1, app_version=6100)
                request.check_challenge()
                request.get_hatched_eggs()
                request.get_inventory()
                request.check_awarded_badges()
                request.download_settings()
                response = await request.call()
                account['time'] = time()

                responses = response['responses']
                challenge_url = responses['CHECK_CHALLENGE']['challenge_url']
                timestamp = responses.get('GET_INVENTORY', {}).get('inventory_delta', {}).get('new_timestamp_ms')
                account['location'] = lat, lon, alt
                account['inventory_timestamp'] = timestamp
                if challenge_url == ' ':
                    account['captcha'] = False
                    print('No CAPTCHA was pending on {}.'.format(username))
                    extra_queue.put(account)
                else:
                    if await solve_captcha(challenge_url, api, driver, timestamp):
                        account['time'] = time()
                        account['captcha'] = False
                        print('Solved CAPTCHA for {}, putting back in rotation.'.format(username))
                        extra_queue.put(account)
                    else:
                        account['time'] = time()
                        print('Failed to solve for {}'.format(username))
                        captcha_queue.put(account)
            except KeyboardInterrupt:
                captcha_queue.put(account)
                break
            except KeyError:
                print('Unexpected or empty response for {}, putting back on queue.'.format(username))
                captcha_queue.put(account)
                try:
                    print(response)
                except Exception:
                    pass
                await sleep(3)
            except (ex.AuthException, ex.AuthTokenExpiredException) as e:
                print('Authentication error on {}: {}'.format(username, e))
                captcha_queue.put(account)
                await sleep(3)
            except ex.AiopogoError as e:
                print('aiopogo error on {}: {}'.format(username, e))
                captcha_queue.put(account)
                await sleep(3)
            except Exception:
                captcha_queue.put(account)
                raise
    finally:
        try:
            driver.close()
            close_sessions()
        except Exception:
            pass
예제 #10
0
from multiprocessing.managers import BaseManager

from monocle.utils import get_address
from monocle import sanitized as conf


class AccountManager(BaseManager):
    pass


AccountManager.register('extra_queue')
manager = AccountManager(address=get_address(), authkey=conf.AUTHKEY)
manager.connect()
extra_queue = manager.extra_queue()


def add_to_queue(account):
    account['time'] = 0
    account['captcha'] = False
    account['banned'] = False
    extra_queue.put(account)