网页具体代码
首先看下页面中的人脸检测的代码
function screenshot() {
if ((overTime >= allTime && allTime > 1) ||tScreenShot==0) {
return;
}
//const img = document.querySelector('#screenshot img');
const video = document.querySelector('#screenshot video');
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
if (canvas.width == 0) {
setTimeout("screenshot()", 1000);
return;
}
canvas.getContext('2d').drawImage(video, 0, 0);
var sendSrc = canvas.toDataURL('image/jpeg');
function SaveScreenShot(base64,state) {
var path = BOSUpload.getScreenShortPath("224287",12870);
canvasDataURL(base64, { width: 300, height: 0 }, function (nbase64,width,height) {
BOSUpload.uploadBase64(nbase64,true, {
ak: "",
sk: "",
sessionToken: "",
bucketname: "ixueto",
path: path
}, function (path) {
$.ajax({
type: "POST",
dataType: "json",
cache: false,
url: "/web/NewAshx/Personal.ashx",
data: { action: 'SaveScreenShotInfo', userId: "",username:"", path: path, cid:, jgpid:, state: state,width: width, height: height, size: nbase64.length },
success: function (result) {
}
//,
//error: function () {
// alert("学习截图保存失败");
//}
});
});
})
}
$.ajax({
type: "POST",
dataType: "json",
cache: false,
url: "/web/NewAshx/Personal.ashx",
data: {action: 'ComparePhotoInfo', userId: "224287", src: sendSrc, cid:12870, jgpid:300152},
success: function (result) {
if (result != null && result.flag) {
//if (nErrorTimes > 0) {
// sendNum = 0;
//}
//sendNum += 100;
$("#s_message2").html("识别成功,计时中");
if (isFirst == 0) {
isFirst++;
t1 = 1;
t2 = 1;
}
setTimeout("screenshot()", 900000);
nErrorTimes = 0;
SaveScreenShot(sendSrc,1);
}
else {
if (sendNum >= 60) {
// sendNum = 0;
}
sendNum++;
if (nErrorTimes == 0) {
updatetimes();
}
nErrorTimes++;
if (isFirst > 0)//
{
isFirst = 0;
t1 = 0;
t2 = 0;
}
if (result != null && result.showMess != null && result.showMess != "") {
$("#s_message2").html("识别失败" + nErrorTimes + "次," + result.showMess + ",保存学时失败");
alert("连续" + nErrorTimes + "次识别失败," + result.showMess);
}
else {
$("#s_message2").html("识别失败" + nErrorTimes + "次,保存学时失败");
alert("连续" + nErrorTimes + "次识别失败");
}
if (nErrorTimes > 10) {
setTimeout("screenshot()", 5000);
}
else {
setTimeout("screenshot()", 3000);
}
if (sendSrc != null && sendSrc.length > 30 && sendNum == 10) {
SaveScreenShot(sendSrc,0);
}
//startTime = new Date();
//$("#s_message2").html("识别失败" + nErrorTimes + "次,不能保存学时,请确认是您本人,且光线清楚");
}
},
error: function () {
if (sendNum >= 60) {
// sendNum = 0;
}
sendNum++;
if (nErrorTimes == 0) {
updatetimes();
}
nErrorTimes++;
if (isFirst > 0)//
{
isFirst = 0;
t1 = 0;
t2 = 0;
}
$("#s_message2").html("识别失败" + nErrorTimes + "次,不能保存学时" + ss) ;
// if (nErrorTimes % 2 == 0) {
alert("连续" + nErrorTimes + "次识别失败");
// }
if (nErrorTimes > 10) {
setTimeout("screenshot()", 5000);
}
else {
setTimeout("screenshot()", 3000);
}
if (sendSrc != null && sendSrc.length > 30 && sendNum == 10) {
SaveScreenShot(sendSrc, 0);
}
//startTime = new Date();
}
});
}
从代码里面可以看到人脸识别的逻辑
获取使用canvas将截取video的画面,将canvas转换为base64编码发送到后台,后台判断是否是你的人脸,识别失败会再识别,识别成功开始计时,再每隔900000毫秒之后再次调用screenshot()。
所以想要伪造很简单,只要截取它ajax请求,将图片的base编码换成自己的图片就ok。
伪造流程
这里使用的是BurpSuitev。其他的能修改数据包抓包软件也行,但是注意知行学徒网是https,抓包软件要配置抓取https。
进入页面之后。允许使用摄像头,就会触发识别的请求,
这就是他的报文,我们只需要将其中的src换成我们的base64的照片就行
图片转base64的网址
上传图片给你一段base64图片(注意,图片要是jpeg格式的)
转换之后的是非url编码的,src的内容需要是url编码的,下面的网站可以进行编码
url编码网站
将src替换成自己的编码内容,然后放包
ok 识别成功