check the code and fixed the error import aiohttp import asyncio import string import…
- User
check the code and fixed the error
import aiohttp import asyncio import string import itertools import urllib3 import aiofiles
Suppress InsecureRequestWarning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
base_url = "https://navratnayantra.com/Admin/" output_file = "fuzzing_results.txt" state_file = "fuzzing_state.txt" # Define state_file as a global variable characters = string.ascii_lowercase
async def generate_words(length): """Generate all combinations of lowercase letters of given length""" return [''.join(candidate) for candidate in itertools.product(characters, repeat=length)]
async def fuzz_endpoints(session, word): async with session.get(base_url + word, verify_ssl=False) as response: print(f"Trying: {response.url}") if response.status == 200: print(f"Found endpoint: {response.url}") async with aiofiles.open(output_file, 'a') as f: await f.write(f"Found endpoint: {response.url}\n") return word # Return the processed word
async def main(): global state_file # Define state_file as a global variable # Load the state from the state file try: with open(state_file, 'r') as sf: processed_words = set(sf.read().splitlines()) except FileNotFoundError: processed_words = set()
codeasync with aiohttp.ClientSession() as session: for length in range(1, 6): words = await generate_words(length) tasks = [fuzz_endpoints(session, word) for word in words if word not in processed_words] new_words = await asyncio.gather(*tasks) processed_words.update(new_words) # Update processed_words with newly processed words # Update the state file after processing all requests with open(state_file, 'w') as sf: sf.write('\n'.join(processed_words))if name == "main": asyncio.run(main())
- Assistant