def download_db(): s3 = boto3.client( 's3', aws_access_key_id=config.get_value('aws_access_key_id', ''), aws_secret_access_key=config.get_value('aws_secret_access_key', '')) try: response = s3.download_file('waid-db', 'server.db', str(db_path)) log.info(f'Database Downloaded{response}') return Response(status=200) except ClientError as e: log.debug(e) return Response(status=500)
def main_flow(self, request, path): self.request = request self.path = path if not config.get_value('is_active', False) != 'False': return self._response() payload = parse_payload(self.request) if config.get_value('is_client', True) == 'True': return self._client_flow(payload) else: return self._server_flow(payload)
def upload_db(): s3_client = boto3.client( 's3', aws_access_key_id=config.get_value('aws_access_key_id', ''), aws_secret_access_key=config.get_value('aws_secret_access_key', '')) try: s3_client.upload_file(str(db_path), 'waid-db', 'server.db') log.info(f'Database uploaded') return Response(status=200) except ClientError as e: log.debug(e) return Response(status=500)
def __send_mail(subject, recipients, text): recp = parse_recipients(recipients) msg = Message(subject, sender=str(config.get_value("mail", "*****@*****.**")), recipients=recp) msg.body = text mail.send(msg)
def _server_flow(self, payload): is_analyzer = config.get_value('is_analyzer', 'True') is_classifier = config.get_value('is_classifier', 'True') log.info( f"Server Mode, Classifier is {'ON' if is_classifier else 'OFF'} " f"and Analyzer is {'ON' if is_classifier else 'OFF'}") if is_analyzer: self._use_analyzer(payload) if is_classifier and payload.anomaly_status != AnomalyStatus.ATTACK.value: self._use_classifier(payload) payload_service.create_payload_request(payload) if payload.anomaly_status == AnomalyStatus.ATTACK.value: return Response(status=403) else: return self._response()
def _ping_server(): host = config.get_value("server_ip", "") if host == "": return first = Flows._ping(host) if not first: second = Flows._ping(host) return True if second else False return True
def _response(self): data = self.request.data if self.request.content_type == 'application/json' else self.request.form self.site_name = config.get_value( 'site_address', 'https://redtiger.labs.overthewire.org/') response = send_request( self.request.method, f'{self.site_name}{self.path}?{self.request.query_string.decode("utf8")}', data=data) return Response(response.content, status=response.status_code, content_type=response.headers['content-type'])
def scheduled_db_update(): if config.get_value('is_client', 'True') == 'True': download_db()
def scheduled_db_collection(): if config.get_value('is_client', 'True') == 'True': SERVER_ADDRESS = config.get_value('server_ip', '') + '/rule/collect' response = requests.post(url=SERVER_ADDRESS, json=read_all_rules_json())
def scheduled_upload_db(): if config.get_value('is_client', 'True') == 'False': upload_db() update_rules_mail(get_all_rules_by_time_delta(dt=2))
def __init__(self, classifier): self.classifier = classifier self.site_name = config.get_value( 'site_address', 'https://redtiger.labs.overthewire.org/') self.request = '' self.path = ''