# dirbuster Asyncio example | |
# © 0xSha.io | |
# 11/2019 | |
import asyncio | |
from aiohttp import ClientSession | |
import time | |
# global | |
lst = [] | |
async def fetch(url, session, queue): | |
while True: | |
# Get a "work item" out of the queue. | |
x = await queue.get() | |
print(x.strip()) | |
# Notify the queue that the "work item" has been processed. | |
queue.task_done() | |
async with session.get(url+x.strip()) as response: | |
if response.status == 200: | |
print(url+x.strip() + "----" + str(response.status)) | |
x = await response.read() | |
lst.append(x) | |
with open("fuzz.txt", "r") as file: | |
#https://github.com/Bo0oM/fuzz.txt/blob/master/fuzz.txt | |
x = file.readlines() | |
url = "http://url.com/" | |
async def run(r): | |
tasks = [] | |
start = time.time() | |
queue = asyncio.Queue() | |
for _ in range(len(x)): | |
# await queue.put(x[_]) | |
queue.put_nowait(x[_]) | |
async with ClientSession() as session: | |
# how many tasks? | |
for i in range(r): | |
task = asyncio.create_task(fetch(url, session, queue)) | |
tasks.append(task) | |
#join them | |
await queue.join() | |
#cancel remaining | |
[task.cancel() for task in tasks] | |
await asyncio.gather(*tasks, return_exceptions=True) | |
# await asyncio.gather(*asyncio.all_tasks(), ).cancel() | |
# https://bugs.python.org/issue29432 | |
# you now have all response bodies in this variable | |
# print(result) | |
end = time.time() | |
print(end - start) | |
if __name__ == '__main__': | |
asyncio.run(run(500)) #change the number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment