SQL Query to get list of S3 buckets exposed to internet
- WITH nested_acl_grants as (
- select
- *,
- contains(
- transform(
- CAST(acl_grants AS ARRAY < JSON >),
- a -> json_extract_scalar(a, '$.Grantee.URI') in (
- 'http://acs.amazonaws.com/groups/global/AllUsers',
- 'http://acs.amazonaws.com/groups/global/AuthenticatedUsers'
- )
- ),
- true
- ) as acl_flag
- from
- aws_s3_bucket_current
- ),
- unnested_acl_grants as(
- select
- *,
- CASE WHEN ignore_public_acls = true
- and restrict_public_buckets = true THEN false WHEN (
- restrict_public_buckets = false
- or restrict_public_buckets is null
- )
- and is_bucket_policy_status_public = true THEN true WHEN (
- ignore_public_acls is null
- or ignore_public_acls = false
- )
- and acl_flag = true
- and acl_flag is not null THEN true else false end as public_access
- from
- nested_acl_grants
- ),
- s3 AS (
- select
- a.region_code AS regionCode,
- a.bucket_name AS bucketName,
- a.customer_id AS customerId,
- a.acl_grants AS aclGrants,
- a.acl_owner_display_name AS aclOwnerDisplayName,
- a.acl_owner_id AS aclOwnerId,
- a.block_public_acls AS blockPublicAcls,
- a.block_public_policy AS blockPublicPolicy,
- a.bucket_accelerate_status AS bucketAccelerateStatus,
- a.bucket_cors_enabled AS bucketCorsEnabled,
- a.bucket_creation_date AS bucketCreationDate,
- a.bucket_logging_enabled AS bucketLoggingEnabled,
- a.bucket_logging_target_bucket AS bucketLoggingTargetBucket,
- a.bucket_logging_target_grants AS bucketLoggingTargetGrants,
- a.bucket_logging_target_prefix AS bucketLoggingTargetPrefix,
- a.bucket_policy_serverside_encryption_enabled AS bucketPolicyServersideEncryptionEnabled,
- a.bucket_public_access_block_enabled AS bucketPublicAccessBlockEnabled,
- a.bucket_region AS bucketRegion,
- a.bucket_request_payer AS bucketRequestPayer,
- a.bucket_ssl_access_only AS bucketSslAccessOnly,
- a.bucket_versioning_status_enabled AS bucketVersioningStatusEnabled,
- a.cors_rules AS corsRules,
- a.ignore_public_acls AS ignorePublicAcls,
- a.is_bucket_policy_status_public AS isBucketPolicyStatusPublic,
- a.mfa_delete_status_enabled AS mfaDeleteStatusEnabled,
- a.metrics_configuration_list AS metricsConfigurationList,
- a.notification_config_event_bridge_config AS notificationConfigEventBridgeConfig,
- a.notification_config_lambda_function_configs AS notificationConfigLambdaFunctionConfigs,
- a.notification_config_queue_configs AS notificationConfigQueueConfigs,
- a.notification_config_topic_configs AS notificationConfigTopicConfigs,
- a.object_lock_configuration_rule AS objectLockConfigurationRule,
- a.object_lock_enabled AS objectLockEnabled,
- a.object_ownership_control_rules AS objectOwnershipControlRules,
- a.public_access_block_enabled AS publicAccessBlockEnabled,
- a.restrict_public_buckets AS restrictPublicBuckets,
- a.server_side_encryption_rules AS serverSideEncryptionRules,
- a.serverside_encryption_enabled AS serversideEncryptionEnabled,
- a.tags AS tags,
- a.website_enabled AS websiteEnabled,
- a.account_id AS accountId,
- a.region AS region,
- b.public_access AS isBucketPublic
- FROM
- aws_s3_bucket_current a
- INNER JOIN unnested_acl_grants b ON a.bucket_name = b.bucket_name
- )
- SELECT
- *
- FROM
- s3
- WHERE
-
- isBucketPublic=true
Related Articles
Query to get Installed date of apps on apps table
Following query can be used to get the installed date of apps The installed date of apps on 'apps' table will be available from 5.10.x Uptycs Osquery release. select path, datetime(date_added_time,'unixepoch') as app_installed_time from apps Here ...
SQL query to fetch all the details of assets
SQL query to fetch the instance id, tags ,last activity ,OS, OS version ,Last enrolled ,OSQ version, Gateway IP ,Interface Name ,IP ,asset group select ua.host_name as Hostname, ua.id as InstanceID, ua.tags as TAGS, ua.last_activity_at as ...
Sql query to find the asset-activity within the given time stamps
please find the below query for finding the list of commands executed along with the user and cmd line and key attributes you can add multiple tables based on your needs ,in this query added only 5 tables which are mostly used you can also modify the ...
List the vulnerabilities in the fleet which is having remediation
please find the below query you can modify the query based on the need and conditons required with vulners as (SELECT *, ROW_NUMBER() OVER(PARTITION BY upt_asset_id, cve_list, package_name, package_version, os, os_version ORDER BY IF(upt_type = ...
Query to Retrieve Asset Restart Counts and Reasons for Specific Time Intervals / a specific day
This SQL query is designed to retrieve the number of restarts by assets and their reasons for restarts within a specified time interval. The query allows you to choose the date or time interval by replacing the {required_date} placeholder with your ...