首先配置好环境,在控制台上进行设置:(1)设置保护区范围;(2)设置入网范围的ip,使其访问保护区时需要做相关认证;(3)设置例外管理,例外之内的机器无须做认证,直接到相关登录界面即可;(4)旁路开关打开,并打开网络接口和相应的端口(8080)

同时也需要对网络适配器上的网络端口进行对应的配置


需要相关技术:

伪装ip地址;

多线程运行;

打印debug日志

#!/usr/bin/python
#coding:utf-8


import os, sys
import re
import httplib
import time, threading
import urllib2, random 

fail_num = 0
fail_num_1 = 0
thread_num = 0
#filepath = 'C:\Users\zgc\Desktop\result.txt'

import logging

def initLogConf():
    LOG_FILE = "debug.log"
    logging.basicConfig(filename=LOG_FILE,level=logging.DEBUG)


def test_authentication():
    '''
    伪造ip地址,测试是否出现认证界面
    '''
    global fail_num
    a = random.randint(1,255)
    b = random.randint(0,255)
    c = random.randint(0,255)
    d = random.randint(0,255)
    ipAddress = "%d.%d.%d.%d" % (a,b,c,d)
    #ipAddress = "76.27.131.228"
    #a = 172
    #print ipAddress
    headers={"X-Forwarded-For":ipAddress,"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0"}
    conn = httplib.HTTPConnection("172.27.131.216:8080")
    conn.request("HEAD","/","",headers)
    time.sleep(5)
    res = conn.getresponse()
    #print res.getheaders()
    #print res.status,res.reason
    '''
    if a < 172:
        print res.getheaders()
        result = res.getheaders()
        req = urllib2.Request("http://172.27.131.216:8080%s" %(result[5][1]))
        print result[5][1]
        response = urllib2.urlopen(req)
        html = response.read().decode('utf-8')
        xre = r'(<title>)(.+)(</title>)'
        auth = re.search(xre, html).group(2)
        print auth
        auth_word = u"360新天擎"
        if auth != auth_word:
            fail_num_1 += 1
        else:
            continue
        response.close()
    else:
    '''
    conn.close()
    result = res.getheaders()
    #print result
    if result[2][1] != "http://172.27.131.156:8080/nac/register/login?url=172.27.131.216:8080":
        fail_num += 1
    else:
        print result[2][1]
        req = urllib2.Request(result[2][1])
        response = urllib2.urlopen(req)
        html = response.read().decode('utf-8')
        xre = r'(<title>)(.+)(</title>)'
        auth = re.search(xre, html).group(2)
        #print auth
        auth_word = u"企业安全准入控制系统"
        #重定向不是预期效果
        if auth != auth_word:
            fail_num += 1
        response.close()

def multi_threading(thread_num):

    thread_list = list();
    #thread_num = 100
    thread_num = random.randint(1,100)
    for i in range(0, thread_num):
        j = random.randint(1,10000)
        thread_name = "thread_%s" %j
        thread_list.append(threading.Thread(target = test_authentication, name = thread_name))

    for thread in thread_list:
        thread.start()
    
    for thread in thread_list:
        thread.join()


def run(interval):

    while True:
        try:
            time_remaining = interval-time.time()%interval
            time.sleep(time_remaining)
 
            multi_threading(thread_num)

            logging.info("[%s] fail_num: %d\n"%((time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())), fail_num))
        except Exception, e:
            print e

if __name__=="__main__":
    initLogConf()
    #间隔时间
    interval = 30
    #test_authentication()
    run(interval)
    #multi_threading(thread_num)
    #打印出总的失败次数
    #print fail_num


Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐