MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / SQLBruteforce

Class SQLBruteforce

actions/sql_connector.py:25–70  ·  view source on GitHub ↗

Class to handle the SQL brute force process.

Source from the content-addressed store, hash-verified

23
24
25class SQLBruteforce:
26 """
27 Class to handle the SQL brute force process.
28 """
29 def __init__(self, shared_data):
30 self.shared_data = shared_data
31 self.sql_connector = SQLConnector(shared_data)
32 logger.info("SQLConnector initialized.")
33
34 def bruteforce_sql(self, ip, port):
35 """
36 Run the SQL brute force attack on the given IP and port.
37 """
38 return self.sql_connector.run_bruteforce(ip, port)
39
40 def execute(self, ip, port, row, status_key):
41 """
42 Execute the brute force attack and update status.
43 Optimization: Skip bruteforce if valid credentials already exist for this host.
44 """
45 logger.info(f"Executing SQLBruteforce on {ip}:{port}...")
46
47 # Check if we already have valid credentials for this host
48 existing_creds = CredentialChecker.check_existing_credentials(
49 self.shared_data.sqlfile, ip
50 )
51 if existing_creds:
52 logger.info(f"SQL credentials already exist for {ip} - verifying instead of bruteforcing...")
53 # Verify credentials still work
54 if self._verify_credentials(ip, existing_creds):
55 logger.success(f"Existing SQL credentials verified for {ip}: {len(existing_creds)} account(s)")
56 return 'success'
57 else:
58 logger.warning(f"Existing credentials for {ip} no longer valid, will re-bruteforce")
59
60 success, results = self.bruteforce_sql(ip, port)
61 return 'success' if success else 'failed'
62
63 def _verify_credentials(self, ip, credentials):
64 """Verify that existing credentials still work (quick check)."""
65 for user, password in credentials:
66 result = self.sql_connector.sql_connect(ip, user, password)
67 if result: # If we got database list, credentials are valid
68 logger.debug(f"Verified SQL credential for {ip}: {user}")
69 return True
70 return False
71
72class SQLConnector:
73 """

Callers 1

sql_connector.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected