impact中的dce/rpc以及NBNS扫描以及python多线程

NBNS扫描

def getHostNics(host):
    # create NetBIOS object
    n = nmb.NetBIOS()

    # get Netbios NAME
    resp = []
    try:
        resp = n.getnodestatus('*', host, timeout = 0.5)
    except Exception as e:
        logging.critical(str(e))
        return False, False
    netbios_name = ''
    for r in resp:
        if r['TYPE'] == 32:
            netbios_name = r['NAME'].decode()

    mac = n.getmacaddress()
    # get Nics
    res = {}
    try:
        n.set_nameserver(host)
        res = n.gethostbyname(netbios_name, nmb.TYPE_SERVER, timeout = 0.5)
    except Exception as e:
        logging.critical(str(e))
        return False, False
    return ((res.entries)), mac

#开始扫描
nics, mac = getHostNics(host)
nic_r = {}
nic_r['nics'] = []
for nic in nics:
	nic_r['nics'].append(nic)

  DCE/RPC

参考RPCDump

  python 互斥锁与多线程

# 初始化互斥锁
queueLock = threading.Lock()

#使用锁
queueLock.acquire()
#do something....
queueLock.release()

#线程对象
class workerThread (threading.Thread):
    def __init__(self, threadID, name, q):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.q = q
    def run(self):
        while not exitFlag:
            queueLock.acquire()
            if not workQueue.empty():
                task = self.q.get()
                queueLock.release()
                #开始工作
            else:
                # 任务队列为空, 线程退出
                queueLock.release()
                break
#创建多线程
threads = []
for threadID in range(max_thread):
	thread = workerThread(threadID, "workThread" + str(threadID), workQueue)
	thread.start()
	threads.append(thread)

#工作队列:
# 初始化工作队列
workQueue = Queue.Queue(task_number)
#workQueue.put(task)

 python协程与异步

import asyncio
import time


now = lambda: time.time()

async def do_some_work(x):
    print("waiting:",x)
    await asyncio.sleep(x)
    return "Done after {}s".format(x)

async def main():
    coroutine1 = do_some_work(1)
    coroutine2 = do_some_work(2)
    coroutine3 = do_some_work(4)
    tasks = [
        asyncio.ensure_future(coroutine1),
        asyncio.ensure_future(coroutine2),
        asyncio.ensure_future(coroutine3)
    ]
    for task in asyncio.as_completed(tasks):
        result = await task
        print("Task ret: {}".format(result))

start = now()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
print("Time:", now()-start)

https://www.cnblogs.com/zhaof/p/8490045.html

posted @ 2022-01-07 09:46  Ray.floyd  阅读(208)  评论(0编辑  收藏  举报