一、form表单相关属性
<form action="./a.php" enctype="multipart/form-data" method="post">
用户名:<input type="text" name="submit-name" required minlength="4" maxlength="8" size="10"><br>
另外的用户名: <input type="text" name="othername" pattern="[a-z]{3,6}"><br>
密码; <input type="password" name="password"><br>
文件:<input type="file" name="files"><br>
<input type="submit" value="上传">
<input type="reset" value="清除">
<textarea name="neirong" id="neirong" cols="30" rows="5"></textarea>
</form>
action属性
给后端提交的一个地址
<form action="https://example.com/api"></form>
method属性
传参的方法,一般用的是post传参
<form method="post"></form>
enctype属性
上传一些文件
<form enctype="multipart/form-data"></form>
required属性
限制输入长度
用户名:<input type="text" name="submit-name" required minlength="4" maxlength="8" size="10"><br>
pattern属性
正则表达式限制
另外的用户名: <input type="text" name="othername" pattern="[a-z]{3,6}"><br>
passwd属性
隐藏密码
密码; <input type="password" name="password" ><br>
textarea属性
<textarea name="neirong" id="neirong" cols="30" rows="5"></textarea>
二、iframe(网页中嵌入其他网页)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="div">aaaaaaa</div>
<iframe src="./b.html" width="10%" height="200" frameborder="1" sandbox="allow-scripts allow-same-origin allow-modals"></iframe>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>hello world</h1>
</body>
<script src="./b.js"></script>
</html>
alert(document.cookie);
<iframe>的一些属性
嵌入的网页默认具有正常权限,比如执行脚本、提交表单、弹出窗口等。如果嵌入的网页是其他网站的页面,你不了解对方会执行什么操作,因此就存在安全风险。
sandbox属性
allow-forms:允许提交表单。
allow-modals:允许提示框,即允许执行window.alert()等会产生弹出提示框的 JavaScript 方法。
allow-popups:允许嵌入的网页使用window.open()方法弹出窗口。
allow-popups-to-escape-sandbox:允许弹出窗口不受沙箱的限制。
allow-orientation-lock:允许嵌入的网页用脚本锁定屏幕的方向,即横屏或竖屏。
allow-pointer-lock:允许嵌入的网页使用 Pointer Lock API,锁定鼠标的移动。
allow-presentation:允许嵌入的网页使用 Presentation API。
allow-same-origin:不打开该项限制,将使得所有加载的网页都视为跨域。
allow-scripts:允许嵌入的网页运行脚本(但不创建弹出窗口)。
allow-storage-access-by-user-activation:sandbox属性同时设置了这个值和allow-same-origin的情况下,允许<iframe>嵌入的第三方网页通过用户发起document.requestStorageAccess()请求,经由 Storage Access API 访问父窗口的 Cookie。
allow-top-navigation:允许嵌入的网页对顶级窗口进行导航。
allow-top-navigation-by-user-activation:允许嵌入的网页对顶级窗口进行导航,但必须由用户激活。
allow-downloads-without-user-activation:允许在没有用户激活的情况下,嵌入的网页启动下载。
三、referer(请求头包含了当前请求页面的来源页面的地址)
referrer-policy:其作用是为了控制请求头中的referrer的内容
no-referrer
整个referee首部会被移除,访问来源信息不随着请求一起发送。
no-referrer-when-downgrade
在没有指定任何策略的情况下用户代理的默认行为。在同等安全级别的情况下,引用页面的地址会被发送(HTTPS->HTTPS),但是在降级的情况下不会被发送 (HTTPS->HTTP).
origin
在任何情况下,仅发送文件的源作为引用地址。例如 https://example.com/page.html 会将 https://example.com/ 作为引用地址。
origin-when-cross-origin
对于同源的请求,会发送完整的URL作为引用地址,但是对于非同源请求仅发送文件的源。
same-origin
对于同源的请求会发送引用地址,但是对于非同源请求则不发送引用地址信息。
6 .strict-origin
在同等安全级别的情况下,发送文件的源作为引用地址(HTTPS->HTTPS),但是在降级的情况下不会
发送 (HTTPS->HTTP)。
strict-origin-when-cross-origin
对于同源的请求,会发送完整的URL作为引用地址;在同等安全级别的情况下,发送文件的源作为引
用地址(HTTPS->HTTPS);在降级的情况下不发送此首部 (HTTPS->HTTP)。
unsafe-url
无论是同源请求还是非同源请求,都发送完整的 URL(移除参数信息之后)作为引用地址。(最不安全了)
四、防盗链
防盗链的工作原理
通过Referer或者签名,网站可以检测目标网页访问的来源网页,如果是资源文件,则可以追踪到显示
它的网页地址 一旦检测到来源不是本站,即进行阻止或者返回指定的页面
如何绕过图片的防盗链(无referer信息)
(1) 方案一(strict-origin-when-cross-origin下的同源降级
(HTTPS->HTTP))
(此实验需要在浏览器较低的版本实现,最新版本浏览器会自动拒绝同源降级)
先利用openssl生成自签名证书
(https://github.com/zxl925768661/Blog/tree/main/HTTP%E7%9B%B8%E5%85%B3/Demos/referer/demo03))
客户端的js
let https = require("https");
let fs = require("fs");
let url = require("url");
let path = require("path");
var options = {
hostname: "localhost",
port: 8000,
path: "/",
method: "GET",
rejectUnauthorized: false,
key: fs.readFileSync("./keys/client.key"),
cert: fs.readFileSync("./keys/client.crt"),
ca: [fs.readFileSync("../ca/ca.crt")],
};
// 创建服务器
https.createServer(options, function (req, res) {
let staticPath = path.join(__dirname, "src");
let pathObj = url.parse(req.url, true);
if (pathObj.pathname === "/") {
pathObj.pathname += "index.html";
}
// 读取静态目录里面的文件,然后发送出去
let filePath = path.join(staticPath, pathObj.pathname);
fs.readFile(filePath, "binary", function (err, content) {
if (err) {
res.writeHead(404, "Not Found");
res.end("<h1>404 Not Found</h1>");
} else {
res.writeHead(200, "OK");
res.write(content, "binary");
res.end();
}
});
}).listen(8080);
客户端的html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>client</title>
</head>
<body>
<h1>client页面</h1>
<div id="container">
<!-- <img src="https://localhost:8000/" referrerpolicy="no-referrer"> -->
<img src="http://192.168.192.128:9090">
</div>
<!-- <script src="js/fetchImg.js"></script> -->
</body>
</html>
服务端的js
et https = require("https");
let fs = require("fs");
let url = require("url");
let path = require("path");
// 白名单
const whiteList = ["192.168.191.128:8080"]; //我们客户端请求的
const options = {
key: fs.readFileSync("./keys/server.key"),
cert: fs.readFileSync("./keys/server.crt"),
};
https
.createServer(options, function (req, res) {
let refer = req.headers["referer"] || req.headers["refer"];
console.log('refer----', refer, req.url);
res.setHeader("Access-Control-Allow-Origin", "*");
if (refer) {
let referHostName = url.parse(refer, true).host;
let currentHostName = url.parse(req.url, true).host;
console.log(referHostName, currentHostName, '--==')
// 当referer不为空, 但host未能命中目标网站且不在白名单内时, 返回错误的图
if (
referHostName != currentHostName &&
whiteList.indexOf(referHostName) == -1
) {
res.setHeader("Content-Type", "image/jpeg");
fs.createReadStream(path.join(__dirname, "./src/img/403.jpg")).pipe(res);
return;
}
}
// 当referer为空时, 返回正确的图
res.setHeader("Content-Type", "image/jpeg");
fs.createReadStream(path.join(__dirname, "./src/img/1.jpg")).pipe(res);
}).listen(9090);
node client.js和node server.js
浏览器访问:https://192.168.191.128:8080
成功为
(2)方案二(设置meta标签)
头部加入<meta name="referrer" content="no-referrer">属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="referrer" content="no-referrer">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsJCQcJCQcJCQkJCwkJCQkJCQsJCwsMCwsLDA0QDBEODQ4MEhkSJRodJR0ZHxwpKRYlNzU2GioyPi0pMBk7IRP/2wBDAQcICAsJCxULCxUsHRkdLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCz/wAARCAEHAQcDASIAAhEBAxEB/8QAGwABAAIDAQEAAAAAAAAAAAAAAAECAwYHBQT/xABREAABAwEEBQUIDAwFBQEAAAABAAIDBAURElEGITFBcRNhgaGzByI1NnJ1kbIVMjRSVWJzdJSxtMEUFyMzQkNUgpLR0tNTk6LC8BZEY2Th8f/EABsBAQACAwEBAAAAAAAAAAAAAAAFBgEDBAIH/8QANxEAAgECBAIGCQMEAwAAAAAAAAEC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PexRg9QWe4DUApRQLk5bvMtEYRj+lZEXBLlKLyegnQiIB0J0IiAdCdCISBeUBjftHMFVCb7yiAIiIAiIgB2niiHaeKIAiIgIWRjtx6FREBmRUa/cfSroAiIgCIiAIiIAoIBBBuIN4N6lEBAF2WQUoiAIiIAiIgCIiAIiE3bUAWN7r9Q2b+dHPv1DZ9aqgCIiAIiIAiIgB2niiHaeKIAiIgCIiAICRsKIgLYzzKcfMqIgL4+ZMfMsalAXx8yY+ZY1KAvj5kx8yoiAvj5kx8yxqUBfHzJj5lREBfHzJj5ljUoC+PmTHzLGpQFsbsgqkk7SiIAiIgCIiAIiIAiIgB2niiHaeKIAiIgCIiAIiIAiIgIUoiAhSiIAiIgIUoiAIiICFKIgIUoiAIiIAiIgCIiAIiIAiIgJLSSmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SIiA//9k=" alt="">
</body>
</html>
(3) 方案三(设置referrerpolicy="no-referrer")
<!DOCTYPE html>
<html lang="en">
<head>
<!-- <meta name="referrer" content="no-referrer"> -->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<img referrerpolicy="no-referrer" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsJCQcJCQcJCQkJCwkJCQkJCQsJCwsMCwsLDA0QDBEODQ4MEhkSJRodJR0ZHxwpKRYlNzU2GioyPi0pMBk7IRP/2wBDAQcICAsJCxULCxUsHRkdLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCz/wAARCAEHAQcDASIAAhEBAxEB/8QAGwABAAIDAQEAAAAAAAAAA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q17tS07694O0FdMWp6QWWYnvr4G/kpDfUtH6t5/WXZHfz8dU9hl61Loaj328ir4zhycenorbdLxNeJAF//wC8Atvsqw6WOnZJXU8ctTL37myjE2Jp2MAOq/Pn4Lz9H7LM8jK+oYRDEb6Zrh+ckH6y47hu59e5bbcs4nevPoaT238jGDYcsvWKy32T8TAyis+P83SU7CPexRg9QWe4DUApRQLk5bvMtEYRj+lZEXBLlKLyegnQiIB0J0IiAdCdCISBeUBjftHMFVCb7yiAIiIAiIgB2niiHaeKIAiIgIWRjtx6FREBmRUa/cfSroAiIgCIiAIiIAoIBBBuIN4N6lEBAF2WQUoiAIiIAiIgCIiAIiE3bUAWN7r9Q2b+dHPv1DZ9aqgCIiAIiIAiIgB2niiHaeKIAiIgCIiAICRsKIgLYzzKcfMqIgL4+ZMfMsalAXx8yY+ZY1KAvj5kx8yoiAvj5kx8yxqUBfHzJj5lREBfHzJj5ljUoC+PmTHzLGpQFsbsgqkk7SiIAiIgCIiAIiIAiIgB2niiHaeKIAiIgCIiAIiIAiIgIUoiAhSiIAiIgIUoiAIiICFKIgIUoiAIiIAiIgCIiAIiIAiIgJLSSmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SYXZIiAYXZJhdkiIBhdkmF2SIgGF2SIiA//9k=" alt="" >
</body>
</html>
(4) 方案四(XMLHttpRequest中setRequestHeader方法)
1.非同源情况下
// 通过ajax下载图片
function loadImage(uri) {
return new Promise(resolve => {
let xhr = new XMLHttpRequest();
xhr.responseType = "blob";
xhr.onload = function() {
resolve(xhr.response);
};
xhr.open("GET", uri, true);
// 通过setRequestHeader设置header不会生效
// 会提示 Refused to set unsafe header "Referer"
xhr.setRequestHeader("Referer", "");
xhr.send();
});
}
// 将下载下来的二进制大对象数据转换成base64,然后展示在页面上
function handleBlob(blob) {
let reader = new FileReader();
reader.onload = function(evt) {
let img = document.createElement('img');
img.src = evt.target.result;
document.getElementById('container').appendChild(img)
};
reader.readAsDataURL(blob);
}
const imgSrc = " https://tiebapic.baidu.com/forum/w%3D580%3B/sign=f88eb0f2cf82b9013dadc33b43b6ab77/562c11dfa9ec8a135455cc35b203918fa1ecc09c.jpg";
loadImage(imgSrc).then(blob => {
handleBlob(blob);
});
首先依旧是把百度贴吧的图片放在我们src中,之后把图片地址传递给loadimage这个函数,之后通过ajex把图片下下来,用到了promise异步下载,当下载成功调用resolve,下载失败调用的是reject,成功调用httprequest去请求url也就是百度图吧的图片,之后通过设置requestheade的referrer为空去限制,之后通过onload函数监听,把监听的结果返回给我们的resolve,resolve函数会把结果返回给.then(blob),其实reslove函数就是一个回调函数,之后把结果传递给handleBlob(blob)这个函数,这个函数建立了一个FileReader()对象,这个对象有一个监听的函数,并且还重建了一个img标签,最终把src从事件中拿了出来,把它放入到了container里面了,最后访问(不成功的原因在于我们的浏览器有些保留字段的设置,恰巧referer就是其中之一,所以就不让了)另外最终的图片是利用base64编码表示的,利用的接口函数就是readAsDataURL(blob)这个函数,在同源下是可以的
2.同源情况下
// 通过ajax下载图片
function loadImage(uri) {
return new Promise(resolve => {
let xhr = new XMLHttpRequest();
xhr.responseType = "blob";
xhr.onload = function() {
resolve(xhr.response);
};
xhr.open("GET", uri, true);
// 通过setRequestHeader设置header不会生效
// 会提示 Refused to set unsafe header "Referer"
xhr.setRequestHeader("Referrer", "");
xhr.send();
});
}
// 将下载下来的二进制大对象数据转换成base64,然后展示在页面上
function handleBlob(blob) {
let reader = new FileReader();
reader.onload = function(evt) {
let img = document.createElement('img');
img.src = evt.target.result;
document.getElementById('tupian').appendChild(img)
};
reader.readAsDataURL(blob);
}
const imgSrc = "http://127.0.0.1/3/1.jpg";
loadImage(imgSrc).then(blob => {
handleBlob(blob);
});
<!DOCTYPE html>
<html lang="en">
<head>
<!-- <meta name="referrer" content="no-referrer"> -->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="tupian">aaaa</div>
</body>
<script src="./test.js"></script>
</html>
五、Burp Suite抓包工具
POST /2/a.php HTTP/1.1
Host: 10.4.136.247
Content-Length: 325
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1 Origin: http://10.4.136.247
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary5DaoJrBa0XD8Zxld
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://10.4.136.247/2/a.html
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
------WebKitFormBoundary5DaoJrBa0XD8Zxld
Content-Disposition: form-data; name="submit-name"
admin
------WebKitFormBoundary5DaoJrBa0XD8Zxld
Content-Disposition: form-data; name="files"; filename="1.php"
Content-Type: application/octet-stream
<?php
var_dump["$username"]
------WebKitFormBoundary5DaoJrBa0XD8Zxld--
POST /2/a.php HTTP/1.1
提交的方法是post,提交的地址是/2/a.php,利用的http协议是1.1
Host: 10.4.136.247
请求的地址
Content-Length: 325
请求的长度为325
Cache-Control: max-age=0
缓存,无缓存
Upgrade-Insecure-Requests: 1 Origin: http://10.4.136.247
来源地址
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary5DaoJrBa0XD8Zxld
文件的类型是form-data
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
浏览器的内核版本
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
支持的文件类型
Referer: http://10.4.136.247/2/a.htmlAc cept-Encoding: gzip, deflate
referer请求访问的文件目录
Accept-Language: zh-CN,zh;q=0.9
语言
Connection: close
------WebKitFormBoundary5DaoJrBa0XD8Zxld
Content-Disposition: form-data; name="submit-name"
前端传输的名字,后端抓取的名字
admin
------WebKitFormBoundary5DaoJrBa0XD8Zxld
抓取的名字是admin
Content-Disposition: form-data; name="files"; filename="1.php"
抓取的是文件files,文件是1.php
Content-Type: application/octet-stream
文件类型
<?php
var_dump["$username"]
抓取的内容<?php var_dump["$username"]
六、cookies和session
存在客户端和服务端,当我们的用户去访问一个浏览器,我们需要注册账号和密码,当我们注册成功后,我们的服务器会将我们用户数据存储到数据库,数据库生成一个session文件,并将其返回给我们的客户端,我们客户端会将这个文件存储在我们的cookie中,当我们再次去登录服务器的时候,我们的服务器会将我们的cookie的值和我们的服务器的session值进行对比,如果相同就可以登陆,所以我们黑客常见的是想办法去盗取我们客户端的cookie。文章来源:https://www.toymoban.com/news/detail-468368.html
七、同源和跨域
同源:协议相同、host相同、端口相同文章来源地址https://www.toymoban.com/news/detail-468368.html
到了这里,关于安全基础第二天:http的header和referrer的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!