Esempio n. 1
0
    def list_machines(self):
        instances = aws_service.get_all_instances(self.config)
        response = []
        instances_running = False
        for instance in instances:
            if instance['State']['Name'] == 'running':
                instances_running = True
                response.append([
                    instance['Tags'][0]['Value'], instance['State']['Name'],
                    instance['NetworkInterfaces'][0]['Association']['PublicIp']
                ])
            else:
                response.append(
                    [instance['Tags'][0]['Value'], instance['State']['Name']])
        print()
        print('Status EC2 Machines\n')
        if len(response) > 0:
            if instances_running:
                print(
                    tabulate(response,
                             headers=['Name', 'Status', 'IP Address']))
            else:
                print(tabulate(response, headers=['Name', 'Status']))
        else:
            print(
                "ERROR: Can't find configured EC2 Attack Range Instances in AWS."
            )
        print()

        if self.config['kubernetes'] == '1':
            print()
            print('Status Kubernetes\n')
            kubernetes_service.list_deployed_applications()
            print()
    def list_machines(self):
        instances = aws_service.get_all_instances(self.config)
        response = []
        instances_running = False
        for instance in instances:
            if instance['State']['Name'] == 'running':
                instances_running = True
                response.append([
                    instance['Tags'][0]['Value'], instance['State']['Name'],
                    instance['NetworkInterfaces'][0]['Association']['PublicIp']
                ])
            else:
                response.append(
                    [instance['Tags'][0]['Value'], instance['State']['Name']])
        print()
        print('Status EC2 Machines\n')
        if len(response) > 0:
            if instances_running:
                print(
                    tabulate(response,
                             headers=['Name', 'Status', 'IP Address']))
            else:
                print(tabulate(response, headers=['Name', 'Status']))
        else:
            print(
                "ERROR: Can't find configured EC2 Attack Range Instances in AWS."
            )
        print()

        if self.config['cloud_attack_range'] == '1':
            print()
            print('Status Serverless infrastructure\n')
            api_gateway_endpoint, error = aws_service.get_apigateway_endpoint(
                self.config)
            if not error:
                arr = []
                arr.append([
                    api_gateway_endpoint['name'],
                    str('https://' + api_gateway_endpoint['id'] +
                        '.execute-api.' + self.config['region'] +
                        '.amazonaws.com/prod/'),
                    'see Attack Range wiki for available REST API endpoints'
                ])
                print(tabulate(arr, headers=['Name', 'URL', 'Note']))
                print()
            else:
                print("ERROR: Can't find REST API Gateway.")

        if self.config['kubernetes'] == '1':
            print()
            print('Status Kubernetes\n')
            kubernetes_service.list_deployed_applications()
            print()