Esempio n. 1
0
 def run(self, hour_range=HOUR_RANGE):
     date_range = kuzuha.build_date_filter_by_range({'hours': hour_range})
     posts = kuzuha.search('http', _filter=date_range, sort=[])
     tweet = ''
     for (url, count) in self._count_url(posts).most_common():
         if url.startswith('https://twitter.com/'):
             tweet_id = self.extract_tweet_id(url)
             if tweet_id:
                 logger.info('RT: id=%s (%s)' % (tweet_id, url))
                 if not self.debug:
                     try:
                         self.twitter.api.statuses.retweet(id=tweet_id)
                     except TwitterHTTPError as e:
                         logger.warn('%s %s' % (type(e), str(e)))
                 continue
         title = self._get_title(url)
         new_url_info = TWEET_FORMAT % (title, url, count)
         expected_length = self.calc_tweet_length(tweet, title, count)
         if expected_length < (MAX_TWEET_LENGTH - len(HASH_TAG)):
             tweet += new_url_info
         else:
             tweet = tweet[:-len(DELIMITER)] + HASH_TAG
             if tweet != HASH_TAG:
                 tweet = tweet.replace('\n', '').replace('\r', '')
                 yield tweet
             tweet = new_url_info
     if tweet:
         if tweet.endswith(DELIMITER):
             tweet = tweet[:-len(DELIMITER)]
         tweet = tweet.replace('\n', '').replace('\r', '')
         yield tweet + HASH_TAG
Esempio n. 2
0
 def run(self, hour_range=HOUR_RANGE):
     date_range = kuzuha.build_date_filter_by_range({'hours': hour_range})
     posts = kuzuha.search('http', _filter=date_range, sort=[])
     tweet = ''
     for (url, count) in self._count_url(posts).most_common():
         if url.startswith('https://twitter.com/'):
             tweet_id = self.extract_tweet_id(url)
             if tweet_id:
                 logger.info('RT: id=%s (%s)' % (tweet_id, url))
                 if not self.debug:
                     try:
                         self.twitter.api.statuses.retweet(id=tweet_id)
                     except TwitterHTTPError as e:
                         logger.warn('%s %s' % (type(e), str(e)))
                 continue
         title = self._get_title(url)
         new_url_info = TWEET_FORMAT % (title, url, count)
         expected_length = self.calc_tweet_length(tweet, title, count)
         if expected_length < (MAX_TWEET_LENGTH - len(HASH_TAG)):
             tweet += new_url_info
         else:
             tweet = tweet[:-len(DELIMITER)] + HASH_TAG
             if tweet != HASH_TAG:
                 tweet = tweet.replace('\n', '').replace('\r', '')
                 yield tweet
             tweet = new_url_info
     if tweet:
         if tweet.endswith(DELIMITER):
             tweet = tweet[:-len(DELIMITER)]
         tweet = tweet.replace('\n', '').replace('\r', '')
         yield tweet + HASH_TAG
Esempio n. 3
0
    def send_msg(self, client, obj, msg):
        message = json.loads(msg.payload.decode("utf-8"))
        logger.info(message)

        rtv = self.slack_helper.search_and_open_group(message.get('src_name'))
        if not rtv:
            logger.warn('search_and_open_group failed ' + str(rtv))
            rtv = self.slack_helper.create_private_group(
                message.get('src_name'))
            if not rtv:
                logger.error('cant create group ' +
                             str(message.get('src_name')))
                # return False
                gid = None
            else:
                gid = rtv
        else:
            gid = rtv

        self.set_sessions(
            dict(gid=gid,
                 src_id=message.get('src_id'),
                 type=message.get('type')))
        rtv = self.slack_helper.send_msg_to_private_group(
            gid, message.get('content'), None, message.get('src_id'), '')
        if not rtv:
            logger.warn(rtv)
Esempio n. 4
0
    def check_event(self, app, id, msg=None, is_regex=False, msg_args=None):
        """Checks for an EVS event message in the telemetry packet history,
        assuming a particular structure for CFE_EVS_LongEventTlm_t.
        This can be generified in the future to determine the structure from the MID map.
        """
        log.info("Checking event on {}".format(self.config.name))
        if msg_args is not None and len(msg_args) > 0:
            try:
                msg = msg % literal_eval(msg_args)
            except Exception as e:
                log.error(
                    "Failed to check Event ID {} in App {} with message: '{}' with msg_args = {}"
                    .format(id, app, msg, msg_args))
                log.debug(traceback.format_exc())
                return False

        if not str(id).isnumeric():
            id = self.resolve_macros(id)

        # TODO - Should use the mid_map and EVS event name to determine these...
        # These are the values that will be used to look through the telemetry packets
        # for the expected packet
        args = [{
            "compare": "streq",
            "variable": "Payload.PacketID.AppName",
            "value": app
        }, {
            "compare": "==",
            "variable": "Payload.PacketID.EventID",
            "value": id
        }]

        result = self.cfs.check_tlm_value(self.cfs.evs_short_event_msg_mid,
                                          args,
                                          discard_old_packets=False)
        if result:
            log.info(
                "Received EVS_ShortEventTlm_t. Ignoring 'Message' field...")
        else:
            if msg:
                compare = "regex" if is_regex else "streq"
                args.append({
                    "compare": compare,
                    "variable": "Payload.Message",
                    "value": msg
                })
                result = self.cfs.check_tlm_value(
                    self.cfs.evs_long_event_msg_mid,
                    args,
                    discard_old_packets=False)
            else:
                log.warn(
                    "No msg provided; any message for App {} and Event ID {} will be matched."
                    .format(app, id))
                result = self.cfs.check_tlm_value(
                    self.cfs.evs_long_event_msg_mid,
                    args,
                    discard_old_packets=False)

        return result
Esempio n. 5
0
    def exploit(self):
        ip = []
        is_cdn = False
        logger.warn('DNS resolve starting of target {}'.format(
            self.target_netloc))
        match_result = re.compile('flightHandler\((.*?)\)')
        url = 'http://ping.aizhan.com/?r=site/PingResult&callback=flightHandler&type=ping&id={}'
        data = requests.get(url.format(self.target_netloc)).content
        result = match_result.findall(data)
        if not result:
            logger.critical('Failed to get ping result of target {}'.format(
                self.target_netloc))
            return
        result = json.loads(result[0])
        if 'status' in result and result['status'] == 500:
            logger.critical('Failed to get ping result of target {}'.format(
                self.target_netloc))
            return

        for i in result:
            logger.info(u'IP address of {} ({}): {}'.format(
                self.target_netloc, result[i]['monitor_name'],
                result[i]['ip']))
            ip.append(result[i]['ip'])

        if len(set(ip)) > 2:
            logger.warn(
                'It seems target use CDN according to the result'.format(
                    self.target_netloc))
            is_cdn = True

        return {'result': {'is_cdn': is_cdn, 'ip': ip}, 'status': True}
Esempio n. 6
0
    def up_metres(self, altitude, relative=True):
        if altitude <= 0:
            logger.warn('Altitude({}) is invalid'.format(altitude))
            return
        try:
            CAlt = self.get_altitude(False)

            if relative:
                TAlt = CAlt + altitude
            else:
                init_alt = self.ORB.get_init_alt()
                TAlt = init_alt + altitude
            if TAlt < CAlt:
                logger.warn('TAlt({}) is less than CAlt ({}).'.format(
                    TAlt, CAlt))
                return
            self.GradualTHR(0, 60)
            watcher = CancelWatcher()
            while not watcher.IsCancel():
                CAlt = self.get_altitude(False)
                if CAlt >= TAlt:
                    break
                time.sleep(.1)
            self.brake()
        except AssertionError, e:
            logger.error(e)
Esempio n. 7
0
    def run(self):
        logger.info('Start Receiver Thread')
        concurrent_command = [mc._SetGear]
        buffer_size = 4096
        while True:
            # use this to receive command
            message = self.sock.recv(buffer_size).strip()

            if not message or message is '':
                continue
            try:
                cmd_object = deserialize(message)
                logger.debug('Receive Command:\n{}'.format(cmd_object))
            except Exception as e:
                logger.error(e)
                continue
            time_stamp = cmd_object.timestamp
            timeout = time.time() - time_stamp
            if timeout > self.timeout:
                logger.warn(
                    'Command is out-of-date,timeout:{}'.format(timeout))
                continue
            code = cmd_object.code
            if code in concurrent_command:
                self.work_queue.put(cmd_object)
            else:
                CancelWatcher.Cancel = True
                time.sleep(.1)
                try:
                    self.parser(cmd_object)
                except Exception as e:
                    logger.error(e)
Esempio n. 8
0
    def condition_yaw(self, heading):
        """
        0<=heading<360 (anti-clockwise)
        """
        if config.debug:
            logger.warn('condition_yaw() ...')
            return
        watcher = CancelWatcher()
        assert heading >= 0 and heading < 360, 'Param-heading {} is invalid'.format(
            heading)

        CYaw = self.get_heading()
        target_angle = angle_diff(CYaw, heading)
        TurnAngle = angle_diff(CYaw, target_angle)

        if TurnAngle >= 0 and TurnAngle <= 180:
            is_cw = 1
            logger.debug('Turn left {}'.format(TurnAngle))
            self.yaw_left()
        else:
            is_cw = -1
            logger.debug('Turn right {}'.format(360 - TurnAngle))
            self.yaw_right()

        logger.debug("Current Angle:{} Target Angle:{}".format(
            CYaw, target_angle))
        while not watcher.IsCancel():
            CYaw = self.get_heading()
            # logger.debug("Current Angle:{} Target Angle:{}".format(
            #     CYaw, target_angle))
            if self.isStop(CYaw, target_angle, is_cw):
                break
            time.sleep(.01)
        self.brake()
        logger.debug("Fact Angle: %d" % self.get_heading())
Esempio n. 9
0
    def rmdir(self, path):
        self.check_share()

        path = ntpath.join(self.pwd, ntpath.normpath(path))
        self.ls(path, display=False)

        for identified_file, is_directory, _ in self.completion:
            if is_directory <= 0:
                continue

            filepath = ntpath.join(self.pwd, identified_file)
            logger.debug('Removing directory %s..' % filepath)

            try:
                self.smb.deleteDirectory(self.share, filepath)
            except SessionError, e:
                if e.getErrorCode() == nt_errors.STATUS_ACCESS_DENIED:
                    logger.warn('Access denied to %s' % identified_file)
                elif e.getErrorCode() == nt_errors.STATUS_SHARING_VIOLATION:
                    logger.warn(
                        'Access denied to %s due to share access flags' %
                        identified_file)
                else:
                    logger.error('Unable to remove directory: %s' %
                                 (e.getErrorString(), ))
Esempio n. 10
0
    def process_telemetry(self, json_dict):
        tlm_mid_name = None
        tlm_data_type = None

        if "tlm_mid_name" not in json_dict.keys():
            log.error("No tlm_mid_name field in JSON.")
        else:
            tlm_mid_name = json_dict["tlm_mid_name"]

        if "tlm_data_type" not in json_dict.keys():
            log.error("No tlm_data_type field in JSON.")
        else:
            tlm_data_type = json_dict["tlm_data_type"]

        try:
            param_class, param_enums = self._create_parameterized_type(
                json_dict, type_id="tlm_data_type", arg_id="tlm_parameters")
            self.type_dict[json_dict['tlm_data_type']] = param_class
            if tlm_mid_name is not None:
                if tlm_mid_name in self.mids:
                    mid = self.mids[tlm_mid_name]
                    self.add_telem_msg(tlm_mid_name, mid, tlm_data_type,
                                       param_class, param_enums)
                else:
                    log.warn(
                        "Unknown MID name {} in {}. Skipping this message".
                        format(tlm_mid_name, self.current_file_name))
            else:
                log.warn("{} has no MID. Skipping this message".format(
                    self.current_file_name))
        except Exception as e:
            log.error("Failed to create telemetry data type {}: {}".format(
                tlm_data_type, e))
Esempio n. 11
0
    def check_output(self, output_contains=None, output_does_not_contain=None, exit_code=0):
        result = True
        log.info("Remote Verify Command with output containing: \"{cont}\","
                 " not containing: \"{ncont}\""
                 ", and exit code: {code}"
                 .format(cont=output_contains, ncont=output_does_not_contain, code=exit_code))

        if self.last_result is None:
            log.warn("No output received from remote connection...")
            result = False
        else:
            # Check if stdout contains the nominal output
            if output_contains is not None and output_contains not in self.last_result.stdout.strip():
                log.warn("Output does not contain: {}".format(output_contains))
                result = False

            # Check if stdout doesn't contain offnomial output
            if output_does_not_contain is not None and len(output_does_not_contain) > 0 \
                    and output_does_not_contain in self.last_result.stdout.strip():
                log.warn("Output contains: {}...".format(output_does_not_contain))
                result = False

            # Check if command exit code matches expected exit code
            if exit_code != self.last_result.exited:
                log.warn("Exit code {} does not equal expected exit code {}...".format(
                    self.last_result.exited, exit_code
                ))
                result = False

        if result:
            log.info("RemoteCheckOutput Passed with exit code {}".format(exit_code))
        else:
            log.warn("RemoteCheckOutput Failed")
        return result
Esempio n. 12
0
    def ls(self, path, display=True):
        self.check_share()

        if not path:
            pwd = ntpath.join(self.pwd, '*')
        else:
            pwd = ntpath.join(self.pwd, path)

        self.completion = []
        pwd = ntpath.normpath(pwd)

        try:
            files = self.smb.listPath(self.share, pwd)
        except SessionError as e:
            if not display:
                pass
            elif e.getErrorCode() in (nt_errors.STATUS_OBJECT_NAME_NOT_FOUND, nt_errors.STATUS_NO_SUCH_FILE):
                logger.warn('File not found')
            else:
                logger.warn('Unable to list files: %s' % (e.getErrorString(),))

            return

        for f in files:
            if display is True:
                print('%s %8s %10d %s' % (time.ctime(float(f.get_mtime_epoch())),
                                          '<DIR>' if f.is_directory() > 0 else '',
                                          f.get_filesize(), f.get_longname()))

            self.completion.append((f.get_longname(), f.is_directory(), f.get_filesize()))
Esempio n. 13
0
    def download(self, filename, path=None):
        self.check_share()

        basename = os.path.basename(filename)

        if path is None:
            path = '.'
        else:
            path = path.replace('\\', '/')

        self.ls(basename, display=False)

        for identified_file, is_directory, size in self.completion:
            if is_directory > 0:
                self.downloadtree(identified_file)
                self.cd('..')
                continue

            filepath = ntpath.join(self.pwd, identified_file)
            logger.debug('Downloading file %s (%d bytes)..' % (filepath, size))

            try:
                fh = open(os.path.join(path, identified_file), 'wb')
                self.smb.getFile(self.share, filepath, fh.write)
                fh.close()
            except SessionError as e:
                if e.getErrorCode() == nt_errors.STATUS_ACCESS_DENIED:
                    logger.warn('Access denied to %s' % identified_file)
                elif e.getErrorCode() == nt_errors.STATUS_SHARING_VIOLATION:
                    logger.warn('Access denied to %s due to share access flags' % identified_file)
                else:
                    logger.error('Unable to download file: %s' % (e.getErrorString(),))
Esempio n. 14
0
    def run(self):
        logger.info("Initializing sbus_receiver ...")

        while True:
            self._sbus.flushInput()
            try:
                package = self._sbus.read(50).encode('hex')
                # package = self._sbus.readline().encode('hex').strip()
            except serial.SerialException:
                self.publish('Sbus_State', False)
                info = sys.exc_info()
                logger.error("{0}:{1}".format(*info))
                continue
            # print 'package', package

            if package is '':
                continue

            sbusFrame = self.sbus.filter(package)

            # print sbusFrame
            if sbusFrame is None:
                continue

            input = self.sbus.decode(sbusFrame)

            if not self.check(input):
                logger.warn('Receive SBUS is invalid')
                continue
            self.publish('ChannelsInput', input)
            self.publish('Sbus_State', True)
            time.sleep(.01)
Esempio n. 15
0
 def new_slack_msg(self):
     rtm_client = self.slack_helper.create_rtm_client()
     if rtm_client.rtm_connect():
         while True:
             try:
                 rtv = rtm_client.rtm_read()
                 if len(rtv) != 0:
                     logger.debug(rtv[0])
                     if not rtv[0].get('subtype') and rtv[0].get(
                             'type') == 'message':
                         # compose a message
                         gid = rtv[0].get('channel')
                         content = rtv[0].get('text')
                         dest, type = self.get_src_id_and_type_from_sessions(
                             gid)
                         if dest is False:
                             logger.warn('dest is false ' + str(gid))
                         message = Message(type, gid, None, dest, content)
                         self.mq_pub(
                             json.loads(
                                 json.dumps(message,
                                            default=lambda o: o.__dict__)))
                 time.sleep(1)
             except Exception as e:
                 logger.warn(e)
                 rtm_client.rtm_connect()
     else:
         logger.error('rtm_client cant connect')
Esempio n. 16
0
    def build_cfs(self):
        log.info("Building Remote CFS")

        build_out_file = os.path.join(
            "/tmp", "{}_build_cfs_output.txt".format(self.config.name))
        build_command = "{} 2>&1 | tee {}".format(self.config.cfs_build_cmd,
                                                  build_out_file)
        build_success = self.execution_controller.run_command(
            build_command, cwd=self.config.cfs_build_dir)

        log.debug("Build process completed")
        Global.time_manager.wait_seconds(1)

        stdout_final_path = os.path.join(Global.current_script_log_dir,
                                         os.path.basename(build_out_file))
        if not os.path.exists(stdout_final_path):
            if not self.execution_controller.get_file(
                    build_out_file, stdout_final_path, {'delete': True}):
                log.warn(
                    "Cannot move CFS build output file to script log directory."
                )
                if self.execution_controller.last_result:
                    log.debug(
                        self.execution_controller.last_result.stdout.strip())

        if not build_success:
            log.error("Failed to build Remote CFS!")

        return build_success
Esempio n. 17
0
    def exploit(self):
        ip = []
        is_cdn = False
        logger.warn('DNS resolve starting of target {}'.format(self.target_netloc))
        match_result = re.compile('flightHandler\((.*?)\)')
        url = 'http://ping.aizhan.com/?r=site/PingResult&callback=flightHandler&type=ping&id={}'
        data = requests.get(url.format(self.target_netloc)).content
        result = match_result.findall(data)
        if not result:
            logger.critical('Failed to get ping result of target {}'.format(self.target_netloc))
            return
        result = json.loads(result[0])
        if 'status' in result and result['status'] == 500:
            logger.critical('Failed to get ping result of target {}'.format(self.target_netloc))
            return

        for i in result:
            logger.info(u'IP address of {} ({}): {}'.format(self.target_netloc, result[i]['monitor_name'],
                                                            result[i]['ip']))
            ip.append(result[i]['ip'])

        if len(set(ip)) > 2:
            logger.warn('It seems target use CDN according to the result'.format(self.target_netloc))
            is_cdn = True

        return {'result': {'is_cdn': is_cdn, 'ip': ip}, 'status': True}
Esempio n. 18
0
    def rm(self, filename):
        self.check_share()

        filename = ntpath.join(self.pwd, ntpath.normpath(filename))
        self.ls(filename, display=False)

        for identified_file, is_directory, size in self.completion:
            if is_directory > 0:
                continue

            filepath = ntpath.join(self.pwd, identified_file)
            logger.debug('Removing file %s (%d bytes)..' % (filepath, size))

            try:
                self.smb.deleteFile(self.share, filepath)
            except SessionError, e:
                if e.getErrorCode() == nt_errors.STATUS_ACCESS_DENIED:
                    logger.warn('Access denied to %s' % identified_file)
                elif e.getErrorCode() == nt_errors.STATUS_SHARING_VIOLATION:
                    logger.warn(
                        'Access denied to %s due to share access flags' %
                        identified_file)
                else:
                    logger.error('Unable to remove file: %s' %
                                 (e.getErrorString(), ))
Esempio n. 19
0
    def __init__(self,
                 local_ip="",
                 local_port=0,
                 command_interface=None,
                 ccsds_ver=0,
                 mid_map=None,
                 name=None):
        """
        Construct the ToApi class.

        :param local_ip: The IP address we want packets to be forwarded to. Default: 127.0.0.1
        :param local_port: The port we want packets to be forwarded to. Default: 40096
        :param command_interface: An instance of the CommandInterface class (used to send commands to UDP)
        :param ccsds_ver: CCSDS header version (1 or 2)
        """
        OutputManager.__init__(self, local_ip, local_port, command_interface,
                               ccsds_ver)
        for mid, value in mid_map.items():
            if isinstance(value, dict) and TO_ENABLE_OUTPUT in value:
                self.command_args = value[TO_ENABLE_OUTPUT]["ARG_CLASS"]
                self.cc = value[TO_ENABLE_OUTPUT]['CODE']
                self.mid = mid

        if self.command_args is None:
            log.warn(
                "Could not find TO_ENABLE_OUTPUT_CC in MID_Map. Cannot enable output."
            )
            return

        self.command_args.cDestIp = self.local_ip
        self.command_args.usDestPort = self.local_port
        self.name = name
Esempio n. 20
0
    def initialize(self):
        log.debug("Initializing CfsController")
        self.process_ccsds_files()

        ccsds = import_ccsds_header_types()
        if not (ccsds and ccsds.CcsdsPrimaryHeader and ccsds.CcsdsCommand
                and ccsds.CcsdsTelemetry):
            log.error("Unable to import required CCSDS header types")
            return False

        log.info("Starting Local CFS Interface")
        command = CommandInterface(ccsds, self.config.cmd_udp_port,
                                   self.config.cfs_target_ip,
                                   self.config.endianess_of_target)
        telemetry = TlmListener(self.config.ctf_ip, self.config.tlm_udp_port)
        self.cfs = LocalCfsInterface(self.config, telemetry, command,
                                     self.mid_map, ccsds)
        result = self.cfs.init_passed
        if not result:
            log.error("Failed to initialize LocalCfsInterface")
        else:
            if self.config.start_cfs_on_init and not self.cfs_running:
                result = self.start_cfs("")
            else:
                log.warn(
                    "Not starting CFS executable... Expecting \"StartCfs\" in test script..."
                )

        if result:
            log.info("CfsController Initialized")
        return result
Esempio n. 21
0
 def Auto(self):
     if self.vehicle.wp.isNull():
         logger.warn('Waypoint is None.Please set')
         return
     self.vehicle.publish('Mode', 'AI_Auto')
     ID = self.vehicle.wp.ID
     points = self.vehicle.wp.points
     self.navigation(points[ID])
Esempio n. 22
0
    def Guided(self):
        target = self.vehicle.get_target()
        if target is None:
            logger.warn('Target is None.Please set')
            return

        self.publish('Mode', 'AI_GUIDED')
        self.navigation(target)
Esempio n. 23
0
 def disconnect_FTP(self):
     if self.ftpConnect:
         os.chdir(self.curDir)
         self.ftp.cwd(self.remoteBase)
         self.ftp.quit()
         self.ftpConnect = False
     else:
         log.warn("FTP not connected.")
Esempio n. 24
0
    def RTL(self):
        target = self.vehicle.get_home()
        if target is None:
            logger.warn("HomeLocation is None.")
            return

        self.vehicle.publish('Mode', 'AI_RTL')
        self.navigation(target)
Esempio n. 25
0
 def login(self):
     try:
         self.smb.login(self.__user, self.__password, self.__domain,
                        self.__lmhash, self.__nthash)
     except socket.error, e:
         logger.warn('Connection to host %s failed (%s)' %
                     (self.__dstip, e))
         raise RuntimeError
Esempio n. 26
0
    def register_target(self, name=""):
        if name in self.targets:
            if name != "default":
                log.warn("SSH target {} is already registered".format(name))
                log.warn("Overriding Target {} SSH Configuration".format(name))

        self.targets[name] = SshController(SshConfig())
        return True
Esempio n. 27
0
    def bindshell(self, port):
        connected = False
        srvname = ''.join([random.choice(string.ascii_letters) for _ in range(8)])
        local_file = os.path.join(keimpx_path, 'contrib', 'srv_bindshell.exe')
        remote_file = '%s.exe' % ''.join([random.choice(string.ascii_lowercase) for _ in range(8)])

        if not os.path.exists(local_file):
            raise missingFile('srv_bindshell.exe not found in the contrib subfolder')

        logger.info('Launching interactive OS shell')
        logger.debug('Going to use temporary service %s' % srvname)

        if not port:
            port = 4445
        elif not isinstance(port, int):
            port = int(port)

        self.deploy(srvname, local_file, port, remote_file)

        logger.info('Connecting to backdoor on port %d, wait..' % port)

        for counter in range(0, 3):
            try:
                time.sleep(1)

                if str(sys.version.split()[0]) >= '2.6':
                    tn = Telnet(self.__dstip, port, 3)
                else:
                    tn = Telnet(self.__dstip, port)

                connected = True
                tn.interact()
            except (socket.error, socket.herror, socket.gaierror, socket.timeout) as e:
                if connected is False:
                    warn_msg = 'Connection to backdoor on port %d failed (%s)' % (port, e)

                    if counter < 2:
                        warn_msg += ', retrying..'
                        logger.warn(warn_msg)
                    else:
                        logger.error(warn_msg)
            except SessionError as e:
                # traceback.print_exc()
                logger.error('SMB error: %s' % (e.getErrorString(),))
            except KeyboardInterrupt as _:
                print()
                logger.info('User aborted')
            except Exception as e:
                # traceback.print_exc()
                logger.error(str(e))

            if connected is True:
                tn.close()
                sys.stdout.flush()
                break

        time.sleep(1)
        self.undeploy(srvname)
Esempio n. 28
0
def add_target(line):
    global added_targets
    global targets

    try:
        host, port = parse_target(line)
    except targetError, _:
        logger.warn('Bad line in targets file %s: %s' % (conf.list, line))
        return
Esempio n. 29
0
 def getAtExec(self, command):
     if DataStore.version_major > 6:
         atexec = TSCH_EXEC(self.__destfile if self.__destfile is not None else self.__dstip, username=self.__user,
                            password=self.__password, domain=self.__domain, lmhash=self.__lmhash,
                            nthash=self.__nthash, command=command)
         return atexec
     else:
         logger.warn("This command only works on Windows Vista or newer.")
         return None
Esempio n. 30
0
def add_target(line):
    try:
        host, port = parse_target(line)
    except targetError as _:
        logger.warn('Bad line in targets file %s: %s' % (conf.list, line))
        return
    target = Target(host, port)
    logger.debug('Parsed target: %s' % target.get_identity())
    return target
Esempio n. 31
0
 def wrapper(*args, **kwargs):
     for i in range(num):
         try:
             result = func(*args, **kwargs)
             assert result, ValueError('Null result is not allowed')
             return result
         except Exception as e:
             logger.warn('%s: %s' % (type(e), str(e)))
             time.sleep(interval)
Esempio n. 32
0
 def wrapper(*args, **kwargs):
     for i in range(num):
         try:
             result = func(*args, **kwargs)
             assert result, ValueError('Null result is not allowed')
             return result
         except Exception as e:
             logger.warn('%s: %s' % (type(e), str(e)))
             time.sleep(interval)
Esempio n. 33
0
    def check_share(self, share=None):
        # logger.debug("Into check_share with share: %s, self.share is: %s and self.tid is: %s"
        #              % (share, self.share, self.tid))

        if share:
            self.use(share)
        elif not share and (self.share is None or self.tid is None):
            logger.warn('Share has not been specified, select one')
            self.shares()
Esempio n. 34
0
    def single_mode(self):
        # TODO: 多线程什么鬼的..要改要改
        result = exploit.run('dns_resolve', target=self.target)
        if not result.get('status'):
            logger.error('Something wrong, do you want to continue?[y/N]:')
            if not raw_input().lower() == 'y':
                logger.critical('User abort, quit.')
                return

        if result.get('result').get('is_cdn'):
            logger.warn('Target is using CDN, port scan skipped.')
Esempio n. 35
0
def read_input(msg, counter):
    while True:
        choice = raw_input(msg)

        if choice == "":
            choice = 1
            break
        elif choice.isdigit() and int(choice) >= 1 and int(choice) <= counter:
            choice = int(choice)
            break
        else:
            logger.warn("The choice must be a digit between 1 and %d" % counter)

    return choice
Esempio n. 36
0
    def exploit(self):
        scan_type = self.extra_arg.get('type')
        scan_ext = self.extra_arg.get('ext')
        scan_threads = self.extra_arg.get('threads')
        scan_status_code = self.extra_arg.get('status_code')

        if scan_type == 'general':
            # dir_scan_obj = _tools_DirScan_general
            # TODO: general 模式的 DirScan 还有 bug , 在修复之前我是不会用的..qwq
            dir_scan_obj = _tools_DirScan_fast
        else:
            dir_scan_obj = _tools_DirScan_fast
        scan_threads = scan_threads if scan_threads else 10
        logger.warn('DirScan start with {} thread(s) of target {}'.format(scan_threads, self.target))
        scan = dir_scan_obj(target=self.target,
                            threads_num=scan_threads,
                            ext=scan_ext if scan_ext else 'php',
                            status_code=scan_status_code)
        scan.run()