Welcome!

Welcome to Satlover forums, full of great people, ideas and excitement.

Please register if you would like to take part. link..

Register Now

Alert: Don't Use Hotmail Email Accounts for registration

Collapse

Before Access to all Forums and Trial accounts you must need to activate your account Email address

Auto ban Illegal CCcam Users in Debian

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stufer
    Senior Member
    • Oct 2010
    • 110

    Auto ban Illegal CCcam Users in Debian

    [Script] Auto ban Illegal CCcam Users in Debian




    PHP Code:
    #!/bin/sh
    ###########################
    ## Auto Ban script       ##
    ## Illegal CCcam Users   ##
    ## Written By CC_Share   ##
    ## Thanks to Unlocker-AL ##
    ## For the Basic idea    ##
    ###########################
    workdir="/"                        #This is there the debug info from CCcam is dumped
    firewall="/"          #The saved firewall rules
    logdir="/emu/log"                       #The logfile directory
    EMAIL=""                 #Email adres to mail result to
    SUBJECT="Illegal Userlist CCcam"        #Subject title of the email
    EMAILMESSAGE="/emu/log/illegaluser.txt" #List that contains the Illegal users
    rm $workdir/debug.old
    cp $workdir
    /debug.txt $workdir/debug.old
    cp $logdir
    /iptables-save.new $logdir/iptables-save.old
    cat $workdir
    /debug.old|grep illegal $logdir/illegaluser.log
    grep 
    'illegal' $logdir/illegaluser.log awk -F" " '{print $5,$7}' $logdir/illegaluser.txt
    grep 
    'illegal' $logdir/illegaluser.log awk -F" " '{print $7}' grep -'^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' $logdir/badIP.out
    awk 
    '
    {s[$0]++}
    END {
    for(i in s) {
    if(s[i]>1) {
    print i
    }
    }
    }' 
    $logdir/badIP.out $logdir/badIP.block
    while IFSread -r EachLine
    do
    command="iptables -A INPUT -s "$EachLine" -j DROP"
    echo $command
    $command
    done 
    $logdir/badIP.block
    rm $logdir
    /badIP.block
    if [ -s $logdir/illegaluser.txt ] ; then
    iptables
    -save -$logdir/iptables-save.new
    /
    usr/bin/nail -"$SUBJECT" "$EMAIL$EMAILMESSAGE
    else
    echo 
    "No Illegal Users found right now"
    fi
    sleep 1
    $workdir/debug.txt
    exit 
    This script will scan you're debug file for illegal users, sort out the username and ip and insert the IP in ip-tables.

    If you want, the script can also mail you the result so you know what users are put in ip-tables and gives you the advantage to check if it's not a valid user.

    You can put this script in the crontab to enable automatic checking.
    The following is an example how to install.
    PHP Code:
    ./CCcam.x86 -dv > /home/debug.txt 
    then change the following lines in the script to match the debug file and it's location.
    PHP Code:
    workdir="/" 
    Should be
    PHP Code:
    workdir="/home" 
    and this line

    PHP Code:
    firewall="/" 
    Should be changed to where you want the firewall rules to be saved

    PHP Code:
    firewall="/emu/log/" 
    To insert it in the crontab, edit it and insert this line:
    PHP Code:
    00 */1  * * * root /emu/script/./illegal.sh 

    This will run the script every whole hour.



    For the mail function to work, you have to do the following:


    PHP Code:
     apt-get install nail
        apt
    -get install exim4
        dpkg
    -reconfigure exim4-config 

    Insert here a valid email adress

    PHP Code:
    EMAIL="" 
    and it will mail you every time it runs and finds an illegal user. If no user is found, it will not mail you.
  • uttnls

    #2
    Re: Auto ban Illegal CCcam Users in Debian

    Very nice until you posted the starting of CCcam server line, if you do a -dv then you are going to block a console and also when you exit it the server will stop, i think it will be better to run with -v and specify an apropiate log file in CCcam.cfg

    In rest the script looks quite well, nice job

    Comment

    • anacondama
      Banned
      • Jul 2010
      • 865

      #3
      Re: Auto ban Illegal CCcam Users in Debian

      i have a question:
      according to which criteria this script will ban the users??
      Thank you

      Comment

      • uttnls

        #4
        Re: Auto ban Illegal CCcam Users in Debian

        Originally posted by anacondama
        i have a question:
        according to which criteria this script will ban the users??
        Thank you
        It will not ban the usual users.

        Let say you have a user that knows your CCcam IP and Port and is trying different credentials to connect to your server, than that user will be logged as "Illegal users" in CCcam, meaning a user that is trying to connect but it does not have an valid F line, so the script will autoban him via firewall to avoid unnecesary overload of CCcam Server

        That is the functionality in short

        Comment

        Working...