

from lib.alerttask import AlertTask
from mozdef_util.query_models import SearchQuery, TermMatch, ExistsMatch


class AlertCloudtrailPublicBucket(AlertTask):
    def main(self):
        search_query = SearchQuery(minutes=20)

        search_query.add_must([
            TermMatch('source', 'cloudtrail'),
            TermMatch('details.eventname', 'CreateBucket'),
            TermMatch('details.requestparameters.x-amz-acl', 'public-read-write'),
        ])

        self.filtersManual(search_query)
        self.searchEventsSimple()
        self.walkEvents()

    # Set alert properties
    def onEvent(self, event):
        request_parameters = event['_source']['details']['requestparameters']
        category = 'access'
        tags = ['cloudtrail']
        severity = 'INFO'

        bucket_name = 'Unknown'
        if 'bucketname' in request_parameters:
            bucket_name = request_parameters['bucketname']

        summary = "The s3 bucket {0} is listed as public".format(bucket_name)
        return self.createAlertDict(summary, category, tags, [event], severity)



from lib.alerttask import AlertTask
from mozdef_util.query_models import SearchQuery, TermMatch


class AlertCloudtrailPublicBucket(AlertTask):
    def main(self):
        search_query = SearchQuery(minutes=20)

        search_query.add_must([
            TermMatch('source', 'cloudtrail'),
            TermMatch('details.eventname', 'CreateBucket'),
            TermMatch('details.requestparameters.x-amz-acl', 'public-read-write'),
        ])

        self.filtersManual(search_query)
        self.searchEventsSimple()
        self.walkEvents()

    # Set alert properties
    def onEvent(self, event):
        request_parameters = event['_source']['details']['requestparameters']
        category = 'access'
        tags = ['cloudtrail']
        severity = 'INFO'

        bucket_name = 'Unknown'
        if 'bucketname' in request_parameters:
            bucket_name = request_parameters['bucketname']

        summary = "The s3 bucket {0} is listed as public".format(bucket_name)
        return self.createAlertDict(summary, category, tags, [event], severity)

Remove unused import from cloudtrail public bucket alert
Remove unused import from cloudtrail public bucket alert

  
  
  from lib.alerttask import AlertTask
- from mozdef_util.query_models import SearchQuery, TermMatch, ExistsMatch
+ from mozdef_util.query_models import SearchQuery, TermMatch
  
  
  class AlertCloudtrailPublicBucket(AlertTask):
      def main(self):
          search_query = SearchQuery(minutes=20)
  
          search_query.add_must([
              TermMatch('source', 'cloudtrail'),
              TermMatch('details.eventname', 'CreateBucket'),
              TermMatch('details.requestparameters.x-amz-acl', 'public-read-write'),
          ])
  
          self.filtersManual(search_query)
          self.searchEventsSimple()
          self.walkEvents()
  
      # Set alert properties
      def onEvent(self, event):
          request_parameters = event['_source']['details']['requestparameters']
          category = 'access'
          tags = ['cloudtrail']
          severity = 'INFO'
  
          bucket_name = 'Unknown'
          if 'bucketname' in request_parameters:
              bucket_name = request_parameters['bucketname']
  
          summary = "The s3 bucket {0} is listed as public".format(bucket_name)
          return self.createAlertDict(summary, category, tags, [event], severity)
  
Remove unused import from cloudtrail public bucket alert
## Code Before:


from lib.alerttask import AlertTask
from mozdef_util.query_models import SearchQuery, TermMatch, ExistsMatch


class AlertCloudtrailPublicBucket(AlertTask):
    def main(self):
        search_query = SearchQuery(minutes=20)

        search_query.add_must([
            TermMatch('source', 'cloudtrail'),
            TermMatch('details.eventname', 'CreateBucket'),
            TermMatch('details.requestparameters.x-amz-acl', 'public-read-write'),
        ])

        self.filtersManual(search_query)
        self.searchEventsSimple()
        self.walkEvents()

    # Set alert properties
    def onEvent(self, event):
        request_parameters = event['_source']['details']['requestparameters']
        category = 'access'
        tags = ['cloudtrail']
        severity = 'INFO'

        bucket_name = 'Unknown'
        if 'bucketname' in request_parameters:
            bucket_name = request_parameters['bucketname']

        summary = "The s3 bucket {0} is listed as public".format(bucket_name)
        return self.createAlertDict(summary, category, tags, [event], severity)

## Instruction:
Remove unused import from cloudtrail public bucket alert
## Code After:


from lib.alerttask import AlertTask
from mozdef_util.query_models import SearchQuery, TermMatch


class AlertCloudtrailPublicBucket(AlertTask):
    def main(self):
        search_query = SearchQuery(minutes=20)

        search_query.add_must([
            TermMatch('source', 'cloudtrail'),
            TermMatch('details.eventname', 'CreateBucket'),
            TermMatch('details.requestparameters.x-amz-acl', 'public-read-write'),
        ])

        self.filtersManual(search_query)
        self.searchEventsSimple()
        self.walkEvents()

    # Set alert properties
    def onEvent(self, event):
        request_parameters = event['_source']['details']['requestparameters']
        category = 'access'
        tags = ['cloudtrail']
        severity = 'INFO'

        bucket_name = 'Unknown'
        if 'bucketname' in request_parameters:
            bucket_name = request_parameters['bucketname']

        summary = "The s3 bucket {0} is listed as public".format(bucket_name)
        return self.createAlertDict(summary, category, tags, [event], severity)
