Skip to content

Instantly share code, notes, and snippets.

View Pelirrojo's full-sized avatar
🤷‍♂️
Somewhere I have to keep my test code

Manuel Eusebio de Paz Carmona Pelirrojo

🤷‍♂️
Somewhere I have to keep my test code
View GitHub Profile
@Pelirrojo
Pelirrojo / S3-report-bucket-detail-and-cost.py
Created November 11, 2024 20:05
Informe detallado de S3 con coste y detalle del contenido para cada bucket.
#!/usr/bin/env python3
import boto3
import datetime
from pathlib import Path
from typing import Dict, List, Tuple
import humanize
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@Pelirrojo
Pelirrojo / clean_dev_temp_files.sh
Created November 11, 2024 18:38
Script para limpiar node_modules y ipynb_checkpoints del directorio actual e hijos
#!/bin/bash
# Nombre del script: cleanup.sh
# Descripción: Elimina recursivamente directorios .ipynb_checkpoints y node_modules
# Colores para mensajes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
@Pelirrojo
Pelirrojo / evereven_AWS_CW_put-metric-alarm.sh
Created October 30, 2024 14:42
Phase 0 | Initial Detection with CloudWatch Alarms
# A vantablack friday: How to be prepared to stop DDoS Attacks after Halloween
# https://blog.evereven.tech
# Create a cloudwatch alarm
aws cloudwatch put-metric-alarm \
--alarm-name High-CPU-Utilization \
--metric-name CPUUtilization \
--namespace AWS/EC2 \
--period 300 \
--evaluation-periods 1 \
@Pelirrojo
Pelirrojo / evereven_AWS_WAF_CREATE_pattern-matching-rules.sh
Created October 30, 2024 14:32
Phase 2: Enhanced Protection | Implement Custom WAF Rules for Pattern Matching
# A vantablack friday: How to be prepared to stop DDoS Attacks after Halloween
# https://blog.evereven.tech
# Create a WebACL Group Rule (replace [SUSPICIOUS_AGENT_IN_BASE64])
aws wafv2 create-rule-group \
--name "pattern-matching-rules" \
--scope REGIONAL \
--capacity 1000 \
--visibility-config \
MetricName=DDOSRuleMetric,SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true \
@Pelirrojo
Pelirrojo / evereven_AWS_CW_put-dashboard.sh
Created October 30, 2024 14:28
Monitoring the Mitigation
# A vantablack friday: How to be prepared to stop DDoS Attacks after Halloween
# https://blog.evereven.tech
# Create a local json file with the configuration
cat > dashboard.json << 'EOL'
{
"widgets": [
{
"type": "metric",
"properties": {
@Pelirrojo
Pelirrojo / evereven_AWS_APIGW_update-stage.sh
Created October 30, 2024 14:28
Phase 3: Fine-Tuning | Implement Request Throttling in API Gateway
# A vantablack friday: How to be prepared to stop DDoS Attacks after Halloween
# https://blog.evereven.tech
# Get API GW IDs and stage names
aws apigateway get-rest-apis --query 'items[*].[id,name]' --output json
> [
> [
> "abc123xyz",
> "my-api"
> ]
@Pelirrojo
Pelirrojo / evereven_AWS_ASG_update-auto-scaling-group.sh
Created October 30, 2024 14:28
Phase 3: Fine-Tuning | Adjust Auto-Scaling Parameters
# A vantablack friday: How to be prepared to stop DDoS Attacks after Halloween
# https://blog.evereven.tech
# Obtain Auto Scaling Group Name
aws autoscaling describe-auto-scaling-groups \
--query 'AutoScalingGroups[*].[AutoScalingGroupName,MinSize,MaxSize,DesiredCapacity]' \
--output json
> [
> [
> "my-asg-cool-name",
@Pelirrojo
Pelirrojo / evereven_AWS_CLOUDFRONT_update-distribution.sh
Created October 30, 2024 14:28
Phase 2: Enhanced Protection | Add Geographic Restrictions in CloudFront
# A vantablack friday: How to be prepared to stop DDoS Attacks after Halloween
# https://blog.evereven.tech
# Obtain distribution ID
aws cloudfront list-distributions --query 'DistributionList.Items[*].Id' --output json
> [
> "E1PI*******PNY"
> ]
# Obtain codes from: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
@Pelirrojo
Pelirrojo / evereven_AWS_WAF_CREATE_emergency-ddos-rules.sh
Created October 30, 2024 14:27
Phase 1: Immediate Response | Deploy Emergency WAF Rules (Rate based rules)
# A vantablack friday: How to be prepared to stop DDoS Attacks after Halloween
# https://blog.evereven.tech
# Create a WebACL Group Rule
aws wafv2 create-rule-group \
--name "emergency-ddos-rules" \
--scope REGIONAL \
--capacity 1000 \
--visibility-config \
MetricName=DDOSRuleMetric,SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true \
@Pelirrojo
Pelirrojo / wp-evereven_populate-SEO.php
Last active October 15, 2024 10:25
PHP Script to generate the SEO tags through AWS Bedrock with Claude Sonnet
<?php
// Ensure this script its used by consola or exit process
if (php_sapi_name() !== 'cli') {
die('This script can only be run from the command line.');
}
// Load SDK de AWS
require 'vendor/autoload.php';
use Aws\Exception\AwsException;