用vbscript來添加ip策略 自動封IP

字號:


    看過有網(wǎng)友介紹的方法,不過是手工一條一條地封,而攻擊IP一般都是數(shù)千個不同的IP。用手工封IP的辦法太麻煩。下面我們用程序來實現(xiàn)自動封這些IP!
    程序主要是讀取這個網(wǎng)站的iis日志,分析出其中的IP地址,用安全策略自動封閉。VBS代碼如下:
    代碼如下:
    '代碼開始
    Set fileobj=CreateObject("Scripting.filesystemobject")
    logfilepath="E:w3logW3SVC237ex070512old.log" '注意指定受攻擊網(wǎng)站的日志路徑。
    '如果是虛擬主機(jī),要查是哪個網(wǎng)站受攻擊,可以查看:C:WINDOWSsystem32LogFilesHTTPERR ,
    根據(jù)錯誤日志很容易分析出來。
    writelog "netsh ipsec static add policy name=XBLUE"
    writelog "netsh ipsec static add filterlist name=denyip"
    overip=""
    f_name=logfilepath
    '指定日志文件
    '程序功能:把logfiles中的IP提取成ipsec需要的過濾格式,導(dǎo)入ipsec中過濾。適合某個網(wǎng)站受大量CC攻擊的情況。
    set fileobj88=CreateObject("Scripting.FileSystemObject")
    Set MYFILE=fileobj88.OpenTextFile(f_name,1,false)
    contentover=MYFILE.ReadAll()
    contentip=lcase(contentover)
    MYFILE.close
    set fileobj88=nothing
    on error resume next
    myline=split(contentip,chr(13))
    for i=0 to ubound(myline)-1
    myline2=split(myline(i)," ")
    newip=myline2(6)
    '指定分離的標(biāo)識字符串!
    if instr(overip,newip)=0 then '去除重復(fù)的IP。
    overip=overip&newip
    dsafasf=split(newip,".")
    if ubound(dsafasf)=3 then
    writelog "netsh ipsec static add filter filterlist=denyip srcaddr="&newip&" dstaddr=Me
    dstport=80 protocol=TCP"
    end if
    else
    wscript.echo newip &" is exits!"
    end if
    next
    writelog "netsh ipsec static add filteraction name=denyact action=block"
    writelog "netsh ipsec static add rule name=kill3389 policy=XBLUE filterlist=denyip
    filteraction=denyact"
    writelog "netsh ipsec static set policy name=XBLUE assign=y"
    Sub writelog(errmes) '導(dǎo)出IPsec的策略文件為一個bat文件。
    ipfilename="denyerrorip.bat"
    Set logfile=fileobj.opentextfile(ipfilename,8,true)
    logfile.writeline errmes
    logfile.close
    Set logfile=nothing
    End Sub
    '代碼結(jié)束
    把上述代碼存為一個.vbs文件,設(shè)置好其中日志的路徑。雙擊運行即可,運行完畢后生成一個denyerrorip.bat文件,這個是ipsec所需要的策略文件,直接雙擊運行即可。