Tuesday, March 22, 2011

Discover Machine info connected to N/W using Nmap Linux tool

#! /bin/bash

ETHERNET=eth0

HostList=(`arp -vni $ETHERNET |cut -d " " -f 1 |grep -r 192 |xargs`)

for (( i = 0 ; i <= ${#HostList[*]} ; i++ ))
    do
    #nmap ${HostList[i]}
    #nmap -O --system-dns ${HostList[i]}
    #nmap -O --osscan-guess --system-dns ${HostList[i]}
    nmap  -F -O -o2 --osscan-limit -oX ${HostList[i]}_$i.xml  ${HostList[i]}
done

Linux add User passwd without prompting for password

Much simpler : 

echo "passwd " | /usr/bin/passwd --stdin "username"


Squid Proxy Blacklist Auto Update Shell Script

Do necessary changes for path rest is self explanatory : 

cat Update_Blacklists

#! /bin/bash
if [ -d "/usr/local/squid/share/squidGuard"  ] ;then

    cd /usr/local/squid/share/squidGuard/
    rm -f -f bl.tar.gz
        mv /usr/local/squid/share/squidGuard/db/blacklists /usr/local/squid/share/squidGuard/db/blacklists.old
    wget -O bl.tar.gz http://ftp.tdcnorge.no/pub/www/proxy/squidGuard/contrib/blacklists.tar.gz

    tar --ungzip --extract --exclude=*.diff --directory=/usr/local/squid/share/squidGuard/db --verbose -f bl.tar.gz

    rm -f -f bl.tar.gz

    wget -O bl.tar.gz ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib/blacklists.tar.gz

    tar --ungzip --extract --exclude=*.diff --directory=/usr/local/squid/share/squidGuard/db --verbose -f bl.tar.gz

    rm -f -f bl.tar.gz

    chown -R squid:squid /usr/local/squid/share/squidGuard/db

    find /usr/local/squid/share/squidGuard/db   |xargs chmod 755
        rm -rf /usr/local/squid/share/squidGuard/db/blacklists/global_usage
    rm -rf /usr/local/squid/share/squidGuard/db/blacklists/README   

else
   echo "Error squid  may not be Installed "
       
fi

list_of_f=(`ls /usr/local/squid/share/squidGuard/db/blacklists`)
for ((  i = 0 ;  i < ${#list_of_f[*]};  i++  ))
    do
        serch=`ls /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]} |grep -w urls`
 if [ "$serch" == ""  ]; then

  echo " /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]} : urls not present "
  echo " So adding it : `touch /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]}/urls && echo "warex.com" >touch /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]}/urls`"
 else
  echo "hi $serch"
 fi

 serch1=`ls /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]} |grep -w domains`
        if [ "$serch1" == ""  ]; then

                echo " /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]} : domains not present "
  echo " So adding it : `touch /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]}/domains && echo " So adding it : `touch /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]}/domains`"`"
        else
                echo "hi $serch1"
        fi


done
chown -R squid:squid /usr/local/squid/share/squidGuard/db/*

        find /usr/local/squid/share/squidGuard/db/blacklists   |xargs chmod 755
        rm -rf /usr/local/squid/share/squidGuard/db/blacklists/global_usage
        rm -rf /usr/local/squid/share/squidGuard/db/blacklists/README

chmod 755 /usr/local/squid/share/squidGuard/squidGuard.conf

chmod -R 777 /usr/local/squid/share/squidGuard/db/blacklists

chmod -R 777 /usr/local/squid/share/squidGuard/log

#ind  /usr/local/squid/share/squidGuard/db/blacklists -type d -exec chmod 755 \{\} \; -print

chmod 777 /usr/local/squid/share/squidGuard/log


Best Regards

ChetanM

Block Commonly Used Torrent on Linux Getway

#! /bin/bash


  iptables -I FORWARD -i eth0 -p tcp --syn --dport 1: -m connlimit --connlimit-above 25 -j REJECT
   iptables -I FORWARD -i eth0 -p tcp --syn --dport 1024: -m connlimit --connlimit-above 5 -j REJECT
   iptables -I FORWARD -i eth0 -p udp --dport 1: -m connlimit --connlimit-above 25 -j REJECT
   iptables -I FORWARD -i eth0 -p udp --dport 1024: -m connlimit --connlimit-above 5 -j REJECT

# filter out bad/corrupted p2p traffic

    iptables -I PREROUTING -t mangle -m conntrack --ctstate INVALID -j DROP

# block Blobster and Piolet from downloading the initial peer list

    iptables -I FORWARD -i eth0 -p tcp --dport 80 -d 128.121.0.0/16 -j REJECT

# and then to block the specific apps :

    # block eDonkey

    iptables -I FORWARD -i eth0 -p tcp --dport 4662 -j REJECT
    iptables -I FORWARD -i eth0 -p tcp --sport 4662 -j REJECT

    # block Limewire, Morpheus, Bearshare

    iptables -I FORWARD -i eth0 -p tcp --dport 6346:6347 -j REJECT
    iptables -I FORWARD -i eth0 -p tcp --sport 6346:6347 -j REJECT
    iptables -I FORWARD -i eth0 -p udp --dport 6346:6347 -j REJECT
    iptables -I FORWARD -i eth0 -p udp --sport 6346:6347 -j REJECT

    # block eMule

    iptables -I FORWARD -i eth0 -p udp --dport 4672 -j REJECT
    iptables -I FORWARD -i eth0 -p udp --sport 4672 -j REJECT

    # block BitTorrent

    iptables -I FORWARD -i eth0 -p tcp --dport 6881:6889 -j REJECT
    iptables -I FORWARD -i eth0 -p tcp --sport 6881:6889 -j REJECT
    iptables -I FORWARD -i eth0 -p udp --dport 6881:6889 -j REJECT
    iptables -I FORWARD -i eth0 -p udp --sport 6881:6889 -j REJECT

    # block WinMx

    iptables -I FORWARD -i eth0 -p tcp --dport 6699 -j REJECT
    iptables -I FORWARD -i eth0 -p tcp --sport 6699 -j REJECT
    iptables -I FORWARD -i eth0 -p udp --dport 6699 -j REJECT
    iptables -I FORWARD -i eth0 -p udp --sport 6699 -j REJECT

Command Line File Based Network Devices Settings

Step 1. : get N/W config data.

#! /bin/bash

 system-config-network-cmd -d >net_device_data.txt

Step 2. : Edit the file with required changes

cat net_device_data.txt

DeviceList.Ethernet.eth0.AutoDNS=true
DeviceList.Ethernet.eth0.HardwareAddress=00:08:a1:ee:63:18
DeviceList.Ethernet.eth0.Type=Ethernet
DeviceList.Ethernet.eth0.IPv6Init=false
DeviceList.Ethernet.eth0.Netmask=255.255.255.0
DeviceList.Ethernet.eth0.BootProto=none
DeviceList.Ethernet.eth0.Device=eth0
DeviceList.Ethernet.eth0.OnBoot=true
DeviceList.Ethernet.eth0.IP=192.168.1.63
DeviceList.Ethernet.eth0.DeviceId=eth0
DeviceList.Ethernet.eth0.AllowUser=false
DeviceList.Ethernet.eth0.Gateway=192.168.3.63
DeviceList.Ethernet.eth1.HardwareAddress=00:e0:4c:D9:0a:c6
DeviceList.Ethernet.eth1.Type=Ethernet
DeviceList.Ethernet.eth1.IPv6Init=false
DeviceList.Ethernet.eth1.Netmask=255.255.255.240
DeviceList.Ethernet.eth1.BootProto=none
DeviceList.Ethernet.eth1.Device=eth1
DeviceList.Ethernet.eth1.OnBoot=true
DeviceList.Ethernet.eth1.IP=15.1.5.179
DeviceList.Ethernet.eth1.DeviceId=eth1
DeviceList.Ethernet.eth1.AllowUser=false
DeviceList.Ethernet.eth1.Gateway=15.1.5.177

Update N/W details .


Step3 .: update the new changes


#! /bin/bash

system-config-network-cmd -i -f net_device_data_save.txt


Result : helpfull for N/W setting with any web user interface  .



Play Active Directory Ntlm Auth With Users and Group Web Integration.

#! /bin/bash

check_group_ads()
{
echo "">/tmp/glist$$$
arr=(`echo $*`)
IFS=$'\n'
arr=(`wbinfo -g`)
for (( i = 0 ; i < ${#arr[*]}; i++ ))
do
check="`wbinfo -n "${arr[i]}"| grep -w 'Group'`"
if [ "$check" == "" ] ;then
   echo "NA" >>/tmp/glist$$$
else
 wbinfo -n  ${arr[i]} |xargs |cut -d " " -f 1 >>/tmp/glist$$$
fi
done
cat /tmp/glist$$$ |xargs >/home/ads/ads_group_check
}


gid_cheking()
{
IFS=$' '
echo "">/home/ads/group_gid
garr=(`cat /home/ads/ads_group_check|xargs `)
for (( i = 0 ; i < ${#garr[*]}; i++ ))
do
check="`wbinfo -n "${garr[i]}"| grep -w 'Group'`"
if [ "${garr[i]}" == "NA" ] ;then
   echo "" &>/dev/null
else
echo "${arr[i]} =>" >>/home/ads/group_gid
 wbinfo -Y "${garr[i]}" >>/home/ads/group_gid
echo ";" >>/home/ads/group_gid
fi
done
cat /home/ads/group_gid |xargs > /home/ads/group_gid_details
}

user_gid_checking()
{
echo "">/home/ads/user_gid
ugc=(`wbinfo -u|xargs`)
for (( i = 0 ; i < ${#ugc[*]}; i++ ))
do
echo "${ugc[i]} =>" >>/home/ads/user_gid
#wbinfo -r "${ugc[i]}" |xargs >>/home/ads/user_gid
wbinfo -r "${ugc[i]}" |xargs |cut -d " " -f 2-100  >>/home/ads/user_gid
echo ";" >>/home/ads/user_gid


done
cat /home/ads/user_gid |xargs >/home/ads/user_gid_details
}


check_group_ads $* &>/dev/null
check_group_ads
gid_cheking
user_gid_checking

============================

The Result Is Simple files contaning #array type entrys with user / group id for furter process with databased backed application .