Javi

AWS: Empty and delete S3 bucket

Feb 21st, 2026
79
0
Never
8
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # delete_s3_buckets.sh
  3. # Empties and deletes all S3 buckets matching a given name prefix.
  4. #
  5. # Usage:
  6. # ./delete_s3_buckets.sh <bucket-name-prefix> [--dry-run]
  7. #
  8. # Examples:
  9. # ./delete_s3_buckets.sh my-temp-bucket
  10. # ./delete_s3_buckets.sh dev- --dry-run
  11. #
  12. # Requirements: aws-cli v2, jq
  13.  
  14. set -euo pipefail
  15.  
  16. # ── Colours ──────────────────────────────────────────────────────────────────
  17. RED='\033[0;31m'; YELLOW='\033[1;33m'; GREEN='\033[0;32m'; NC='\033[0m'
  18.  
  19. # ── Args ─────────────────────────────────────────────────────────────────────
  20. if [[ $# -lt 1 ]]; then
  21. echo "Usage: $0 <bucket-name-prefix> [--dry-run]"
  22. exit 1
  23. fi
  24.  
  25. PREFIX="$1"
  26. DRY_RUN=false
  27. [[ "${2:-}" == "--dry-run" ]] && DRY_RUN=true
  28.  
  29. $DRY_RUN && echo -e "${YELLOW}[DRY-RUN] No changes will be made.${NC}"
  30.  
  31. # ── Helpers ───────────────────────────────────────────────────────────────────
  32. log_info() { echo -e "${GREEN}[INFO]${NC} $*"; }
  33. log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
  34. log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
  35.  
  36. # Delete a list of {Key, VersionId} objects in chunks of 1000 (AWS API limit).
  37. # Payload is written to a temp file to avoid ARG_MAX shell limits.
  38. delete_objects_chunked() {
  39. local bucket="$1"
  40. local all_objects_json="$2" # JSON array: [{Key:..., VersionId:...}, ...]
  41.  
  42. local total
  43. total=$(echo "$all_objects_json" | jq 'length')
  44. [[ "$total" -eq 0 ]] && return 0
  45.  
  46. local tmp_file
  47. tmp_file=$(mktemp /tmp/s3_delete_XXXXXX.json)
  48. # shellcheck disable=SC2064
  49. trap "rm -f $tmp_file" RETURN
  50.  
  51. local offset=0
  52. local chunk_size=1000
  53. local deleted_total=0
  54.  
  55. while [[ "$offset" -lt "$total" ]]; do
  56. local chunk
  57. chunk=$(echo "$all_objects_json" | jq --argjson o "$offset" --argjson s "$chunk_size" \
  58. '{ Objects: .[$o:$o+$s], Quiet: true }')
  59.  
  60. local count
  61. count=$(echo "$chunk" | jq '.Objects | length')
  62.  
  63. if $DRY_RUN; then
  64. log_info " [DRY-RUN] Would delete $count object versions (offset $offset)."
  65. else
  66. echo "$chunk" > "$tmp_file"
  67. aws s3api delete-objects \
  68. --bucket "$bucket" \
  69. --delete "file://$tmp_file" \
  70. --output json > /dev/null
  71. (( deleted_total += count )) || true
  72. log_info " Deleted $count object versions (offset $offset, running total: $deleted_total)."
  73. fi
  74.  
  75. (( offset += chunk_size )) || true
  76. done
  77. }
  78.  
  79. # Empty a bucket: removes all object versions and delete markers (works for
  80. # versioned, suspended, and non-versioned buckets).
  81. empty_bucket() {
  82. local bucket="$1"
  83.  
  84. log_info "Emptying bucket: $bucket"
  85.  
  86. # Remove all object versions (including delete markers)
  87. local has_more="true"
  88. local key_marker="" version_marker=""
  89.  
  90. while [[ "$has_more" == "true" ]]; do
  91. local list_args=(--bucket "$bucket" --output json)
  92. [[ -n "$key_marker" ]] && list_args+=(--key-marker "$key_marker")
  93. [[ -n "$version_marker" ]] && list_args+=(--version-id-marker "$version_marker")
  94.  
  95. local result
  96. result=$(aws s3api list-object-versions "${list_args[@]}" 2>/dev/null || echo '{}')
  97.  
  98. # Combine Versions + DeleteMarkers into one array
  99. local objects
  100. objects=$(echo "$result" | jq '
  101. [
  102. ((.Versions // []) | .[] | { Key: .Key, VersionId: .VersionId }),
  103. ((.DeleteMarkers // []) | .[] | { Key: .Key, VersionId: .VersionId })
  104. ]
  105. ')
  106.  
  107. delete_objects_chunked "$bucket" "$objects"
  108.  
  109. # Pagination
  110. local truncated
  111. truncated=$(echo "$result" | jq -r '.IsTruncated // false')
  112. if [[ "$truncated" == "true" ]]; then
  113. key_marker=$(echo "$result" | jq -r '.NextKeyMarker // ""')
  114. version_marker=$(echo "$result" | jq -r '.NextVersionIdMarker // ""')
  115. else
  116. has_more="false"
  117. fi
  118. done
  119.  
  120. # Also remove any remaining non-versioned objects (just in case)
  121. if ! $DRY_RUN; then
  122. aws s3 rm "s3://$bucket" --recursive --quiet 2>/dev/null || true
  123. fi
  124.  
  125. log_info "Bucket $bucket is now empty."
  126. }
  127.  
  128. delete_bucket() {
  129. local bucket="$1"
  130. if $DRY_RUN; then
  131. log_info "[DRY-RUN] Would delete bucket: $bucket"
  132. else
  133. aws s3api delete-bucket --bucket "$bucket"
  134. log_info "Deleted bucket: $bucket"
  135. fi
  136. }
  137.  
  138. # ── Main ──────────────────────────────────────────────────────────────────────
  139. log_info "Looking for buckets with prefix: \"$PREFIX\""
  140.  
  141. # List all buckets and filter by prefix
  142. BUCKETS=$(aws s3api list-buckets \
  143. --query "Buckets[?starts_with(Name, \`$PREFIX\`)].Name" \
  144. --output text)
  145.  
  146. if [[ -z "$BUCKETS" ]]; then
  147. log_warn "No buckets found matching prefix \"$PREFIX\"."
  148. exit 0
  149. fi
  150.  
  151. # Convert tab/space-separated output to array
  152. read -ra BUCKET_ARRAY <<< "$BUCKETS"
  153.  
  154. echo ""
  155. echo -e "${YELLOW}The following buckets will be emptied and deleted:${NC}"
  156. for b in "${BUCKET_ARRAY[@]}"; do echo " - $b"; done
  157. echo ""
  158.  
  159. if ! $DRY_RUN; then
  160. read -rp "Are you sure? This is IRREVERSIBLE. Type 'yes' to continue: " confirm
  161. [[ "$confirm" != "yes" ]] && { log_warn "Aborted."; exit 0; }
  162. fi
  163.  
  164. ERRORS=0
  165. for BUCKET in "${BUCKET_ARRAY[@]}"; do
  166. echo "──────────────────────────────────────────"
  167. if empty_bucket "$BUCKET" && delete_bucket "$BUCKET"; then
  168. log_info "✓ $BUCKET processed successfully."
  169. else
  170. log_error "✗ Failed to process bucket: $BUCKET"
  171. (( ERRORS++ )) || true
  172. fi
  173. done
  174.  
  175. echo "══════════════════════════════════════════"
  176. if [[ "$ERRORS" -eq 0 ]]; then
  177. log_info "All done. ${#BUCKET_ARRAY[@]} bucket(s) processed."
  178. else
  179. log_error "$ERRORS bucket(s) failed. Check the output above."
  180. exit 1
  181. fi
Advertisement
Comments
  • Lenbozon
    116 days
    # CSS 0.85 KB | 0 0
    1. ✅ Leaked Exploit Documentation:
    2.  
    3. https://docs.google.com/document/d/1dOCZEHS5JtM51RITOJzbS4o3hZ-__wTTRXQkV1MexNQ/edit?usp=sharing
    4.  
    5. This made me $13,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 38% — they will simply correct the exchange rate.
    8. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    9.  
    10. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from Swapzone — instant swap).
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment