Mostrando entradas con la etiqueta Apache. Mostrar todas las entradas
Mostrando entradas con la etiqueta Apache. Mostrar todas las entradas

apache_access_stats.sh

d
Nombre: apache_access_stats.sh
Autor: @linuxitux
Tomado de Linuxito
#!/bin/bash

# apache_access_stats.sh
#
#     Muestra un gráfico de accesos por hora a un servidor Apache a partir de un archivo
#     de log de accesos
#

mensaje="Muestra un gráfico de accesos por hora a un servidor Apache a partir de un archivo de log de
accesos."

# Variables
ancho=50

if [ $# -lt 1 ]
then
        printf "Uso: $0 ARCHIVO\n$mensaje\n"
        exit 1
fi

# Defino un arreglo de horas desde 0 a 23
hs=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)

# Contabilizo la cantidad de accesos por cada hora
for h in $(cat $* | cut -d '[' -f2 | cut -d "]" -f1 | cut -d ' ' -f1 | cut -d ':' -f2 | sed 's/^0//')
do
        (( hs[$h]++ ))
done

# Calculo la máxima cantidad de accesos
max=0
for h2 in ${hs[@]}
do
        if [ "$h2" -gt "$max" ]
        then
                max=$h2
        fi
done

# Calculo la longitud de caracteres del máximo
longitud=${#max}

# Imprimo el gráfico
echo "HORA (ACCESOS)"
hora="0"
for h3 in ${hs[@]}
do
        # Para cada hora
        # Calculo la cantidad de numerales a imprimir
        c=$(( h3 * ancho / max ))

        # Imprimo la hora con formato "HH:MM"
        if [ $hora == "0" ]
        then
                printf " 0"
        else
                printf "%2.i" "$hora"
        fi
        printf ":00"

        # Imprimo la cantidad de accesos
        printf " (%$longitud.i) " "$h3"

        # Imprimo los numerales
        for (( i=0; i<$c; i++ ))
        do
                printf "#"
        done
        echo

        # Siguiente hora
        (( hora++ ))
done
Leer más...

apache2-vhosts.sh

d
Nombre: apache2-vhosts.sh
Autor: @Tonejito
Descripción: List Apache httpd VirtualHost entries
#!/bin/bash
 
for bin in which apache2ctl grep awk sort
do
  if [ ! -x "`which $bin`" ]
  then
    exit 1
  fi
done
 
apache2ctl -S 2>/dev/null | grep vhost | awk '{print $4}' | sort -u
Leer más...

Servicios: Estado, inicio y reinicio

d
Autor: @D4nnR
Descripción: Este script es para verificar el estado de los servicios del servidor, si algún servicio está caído automaticamente se inicia y si está en ejecución automaticamente se reinicia. La utilidad le das tu :].
Visto en: Por un servidor seguro :)
#!/bin/bash



#Este script revisa los servicios httpd, mysqld y postfix si estan parados los inicia y si estan en ejecucion los reinicia.



# Lista de servicios



echo "##########################################################"



echo "##########################################################"



SERVICIOS=(mysqld)



# Funcion para inicializar/reiniciar servicios



function servicioInit (){



if ! service $1 status &>/dev/null; then



echo -n -e "\t  El servicio esta parado, !! INICIAR $1 !!..."



service $1 start



echo '---Inicio OK---'



service  mysqld status



else



echo -n -e "\t El servicio $1 esta en ejecucion, sin embargo se  va a !! REINICIAR !!"



service $1 restart



echo '---Reinicio-OK---'



service  mysqld status



fi



}






for ((i=0; i<${#SERVICIOS[*]}; i++)) do #if $estado = "start"; then if [ -z $1 ]; then echo "Verificando servicio: ${SERVICIO[$i]} ->"



servicioInit ${SERVICIOS[$i]}



done



echo "##########################################################"



echo "##########################################################"



SERVICIOS=(httpd)



# Funcion para inicializar/reiniciar servicios



function servicioInit (){



if ! service $1 status &>/dev/null; then



echo -n -e "\t  El servicio esta parado, !! INICIAR $1 !!..."



service $1 start



echo '---Inicio OK---'



service  httpd status



else



echo -n -e "\t El servicio $1 esta en ejecucion, sin embargo se  va a !! REINICIAR !!"



service $1 restart



echo '---Reinicio-OK---'



service  httpd status



fi



}






for ((i=0; i<${#SERVICIOS[*]}; i++)) do #if $estado = "start"; then if [ -z $1 ]; then echo "Verificando servicio: ${SERVICIO[$i]} ->"



servicioInit ${SERVICIOS[$i]}



done



echo "##########################################################"



echo "##########################################################"



SERVICIOS=(postfix)



# Funcion para inicializar/reiniciar servicios



function servicioInit (){



if ! service $1 status &>/dev/null; then



echo -n -e "\t  El servicio esta parado, !! INICIAR $1 !!..."



service $1 start



echo '---Inicio OK---'



service  postfix status



else



echo -n -e "\t El servicio $1 esta en ejecucion, sin embargo se  va a !! REINICIAR !!"



service $1 restart



echo '---Reinicio-OK---'



service  postfix status



fi



}






for ((i=0; i<${#SERVICIOS[*]}; i++)) do #if $estado = "start"; then if [ -z $1 ]; then echo "Verificando servicio: ${SERVICIO[$i]} ->"



servicioInit ${SERVICIOS[$i]}



done



echo "##########################################################"



echo "##########################################################"

Leer más...

Bash Website Backup Script

d
Nombre: backup-sitename.sh
Descripción: Script que permite realizar un backup de un sitio web
Más información del Script en loneshooter
#!/bin/sh
 
# Cron job runs with:
# bash /home/account/backup/backup-sitename.sh
 
SITEDIRNAME="sitename"
DBNAME="account_dbname"
DBUSER="account_name"
DBPASS="password"
BASEBCKPPATH="/home/account/backup"
DATE=$(date -I)
DESTINATIONDIR="$BASEBCKPPATH/$DATE/$SITEDIRNAME" #e.g. /home/account/backup/2012-07-29/sitename
ERRORLOG=$DESTINATIONDIR/error.log
 
# Delete all previous backups
if [ -d "$DESTINATIONDIR" ]; then
  rm -rf $DESTINATIONDIR
fi
 
# Create backup directory if it doesn't exist, e.g. /home/account/backup/2012-07-29/sitename
if [ ! -d "$DESTINATIONDIR" ]; then
  mkdir -p $DESTINATIONDIR
fi
 
# Backup site folder
tar -czf $DESTINATIONDIR/${SITEDIRNAME}_${DATE}.tgz -C /home/account/addon ./$SITEDIRNAME 2> $ERRORLOG
 
# Backup site database
mysqldump -u $DBUSER -p$DBPASS -h localhost $DBNAME| gzip -9 > $DESTINATIONDIR/${DBNAME}_${DATE}.sql.gz 2> $ERRORLOG
Leer más...

Versions.sh

d
Nombre: Versions.sh
Autor: Damon Parker
Descripción: Shell script para encontrar las versiones instaladas de los Demonios Principales de un Servidor.
Visto en Damon Parker
#!/bin/sh

# $Id: versions.sh 30 2007-02-26 19:18:48Z damonp $
#
# Shell script to list versions of common server daemons and utilities
#
# Copyright (c) 2007 Damon Parker < damonp@damonparker.org >
# Licensed under the GNU GPL.  See http://www.gnu.org/licenses/gpl.html

# This script is not supported in any way.  Use at your own risk.
#

uname -a

if [ -f /etc/redhat-release ]; then
        echo
        echo Redhat Version:
        cat /etc/redhat-release
fi

echo
echo Apache:
httpd -v
php -v

echo
echo MySQL:
mysql -V

echo
echo Security:
ssh -V
openssl version

echo
echo Network:
/sbin/ifconfig
Leer más...

Shell Script para analizar Access.log

d
Nombre: webaccess.bash
Autor: Desconocido
Descripción: Script que genera una serie de estadísticas útiles, habida cuenta de un archivo de registro de formato de Apache access_log.
Visto en Linux Party
#!/bin/bash

# webaccess - analyze an Apache-format access_log file, extracting
# useful and interesting statistics

bytes_in_gb=1048576
scriptbc="$HOME/bin/scriptbc"
nicenumber="$HOME/bin/nicenumber"
host="intuitive.com"

if [ $# -eq 0 -o ! -f "$1" ] ; then
echo "Usage: $(basename $0) logfile" >&2
exit 1
fi

firstdate="$(head -1 "$1" | awk '{print $4}' | sed 's/[//')"
lastdate="$(tail -1 "$1" | awk '{print $4}' | sed 's/[//')"

echo "Results of analyzing log file $1"
echo ""
echo " Start date: $(echo $firstdate|sed 's/:/ at /')"
echo " End date: $(echo $lastdate|sed 's/:/ at /')"

hits="$(wc -l < "$1" | sed 's/[^[:digit:]]//g')"

echo " Hits: $($nicenumber $hits) (total accesses)"

pages="$(grep -ivE '(.txt|.gif|.jpg|.png)' "$1" | wc -l | sed 's/[^[:digit:]]//g')"

echo " Pageviews: $($nicenumber $pages) (hits minus graphics)"

totalbytes="$(awk '{sum+=$10} END {print sum}' "$1")"

echo -n " Transferred: $($nicenumber $totalbytes) bytes "

if [ $totalbytes -gt $bytes_in_gb ] ; then
echo "($($scriptbc $totalbytes / $bytes_in_gb) GB)"
elif [ $totalbytes -gt 1024 ] ; then
echo "($($scriptbc $totalbytes / 1024) MB)"
else
echo ""
fi

# now let's scrape the log file for some useful data:

echo ""
echo "The ten most popular pages were:"

awk '{print $7}' "$1" | grep -ivE '(.gif|.jpg|.png)' | 
sed 's//$//g' | sort | 
uniq -c | sort -rn | head -10

echo ""

echo "The ten most common referrer URLs were:"

awk '{print $11}' "$1" | 
grep -vE "(^"-"$|/www.$host|/$host)" | 
sort | uniq -c | sort -rn | head -10

echo ""
exit 0

Permisos: chmod 700 webaccess.bash 
Ejecución: ./webaccess.bash [ log ]
Leer más...

findshell.pl

d
Nombre: findshell.pl
Autor: traps.darkmindz.com
Descripción: Script que permite detectar shells php
Hace uso del módulo File::Find
Visto en: ketan.lithiumfox.com
#!/usr/bin/perl -w
# findshell v1.0 == code taken/modified from traps.darkmindz.com
#usage: ./findshell.pl [ sensitivity 1-50 ] [ directory to scan ]
use strict;
use File::Find;
my $sens = shift  || 10;
my $folder = shift || './';
find(\&backdoor, "$folder");
sub backdoor {
    if ((/\.(php|txt)/)){
       open (my $IN,"<$_") || die "can not open datei $File::Find::name: $!";
       my @file =  <$IN>;
       #maybe evil stuffs
       my $score = grep (/function_exists\(|phpinfo\(|safe_?mode|shell_exec\(|popen\(|passthru\(|system\(|myshellexec\(|exec\(|getpwuid\(|getgrgid  \(|fileperms\(/i,@file);
       #probably evil stuffs
       my $tempscore = grep(/\`\$\_(post|request|get).{0,20}\`|(include|require|eval|system|passthru|shell_exec).{0,10}\$\_(post|request|get)|eval.{0,10}base64_decode|back_connect|backdoor|r57|PHPJackal|PhpSpy|GiX|Fx29SheLL|w4ck1ng|milw0rm|PhpShell|k1r4|FeeLCoMz|FaTaLisTiCz|Ve_cENxShell|UnixOn|C99madShell|Spamfordz|Locus7s|c100|c99|x2300|cgitelnet|webadmin|cybershell|STUNSHELL|Pr!v8|PHPShell|KaMeLeOn|S4T|oRb|tryag|sniper|noexecshell|\/etc\/passwd|revengans/i, @file);
       $score +=  50 *  $tempscore;
       print "$score - Possible backdoor : $File::Find::name\n" if ($score > $sens-1 );
       close $IN;
  }elsif((/\.(jpg|jpeg|gif|png|tar|zip|gz|rar|pdf)/)){
       open (my $IN,"<$_") || (print "can not open datei $File::Find::name: $!" && next);
       print "5000 - Possible backdoor (php in non-php file): $File::Find::name\n" if grep /(\<\?php|include(\ |\())/i, <$IN>;
       close $IN;
  }
}
Permisos: chmod 700 findshell.pl 
Ejecución: ./findhsell.pl [ sensibilidad del escaneo 1-50 ] [ directorio a escanear ]
Leer más...

Script to Install and Secure Apache2 PHP5 MySQL5 in Ubuntu/Debian

d
Autor: @Desconocido
Descripción: Script que permite instalar de manera automática, y configurar Apache2 PHP y Mysql

MYSQL_PASS="YOUR_PASSWORD_HERE";

echo "+Updating apt-get..."
apt-get update

echo "+Installing SSH..."
apt-get install -q -y ssh

echo "+Changing default SSH port..."
sed -i 's/Port 22/Port 28/' /etc/ssh/sshd_config
/etc/init.d/ssh restart

echo "+Installing Apache2..."
apt-get install -q -y apache2
sed -i 's/ServerTokens Full/ServerTokens Prod/' /etc/apache2/conf.d/security
sed -i 's/ServerSignature On/ServerSignature Off/' /etc/apache2/conf.d/security
sed -i 's/TraceEnable On/TraceEnable Off/' /etc/apache2/conf.d/security
/etc/init.d/apache2 reload
a2enmod rewrite
/etc/init.d/apache2 restart

echo "+Installing PHP5..."
apt-get install -q -y php5
echo "+Securing PHP.ini file..."
sed -i 's/disable_functions =/disable_functions = show_source, system, exec/' /etc/php5/apache2/php.ini
sed -i 's/expose_php = On/expose_php = Off/' /etc/php5/apache2/php.ini
sed -i 's/display_errors = On/display_errors = Off/' /etc/php5/apache2/php.ini
sed -i 's/log_errors = Off/log_errors = On/' /etc/php5/apache2/php.ini
sed -i 's/allow_url_fopen = On/allow_url_fopen = Off/' /etc/php5/apache2/php.ini

echo "+Installing MySQL Server..."
DEBIAN_FRONTEND='noninteractive' apt-get install -q -y mysql-server
mysqladmin -u root password $MYSQL_PASS
apt-get install -q -y php5-mysql
mysql_secure_installation

history -c

echo "+Installation Completed!"

Fuente: Unixmen
Leer más...