本帖最后由 xidili 于 2023-4-15 18:25 编辑
超新手啥也不会,刚开始学,求教。
网页登录需验证码,xhr获取user_auth_verify文件的响应有这个验证码,我可以直接读取这个code吗?还是如何解决比较好?
下面这个代码是能看到的js文件部分代码。
`` var code="";
// 绘制文字
for(var i=0;i <50;i++) {
ctx.fillStyle = '#86cffa';
ctx.beginPath();
ctx.arc(randomNum(0, width), randomNum(0, height),1,0,2 Math.PI);
ctx.fill();
}
var pool="abcdefghijkmnpqrstuvwxyz1234567890";
for(var i=0;i<=3;i++) {
if(captcha){
var txt = captcha[i];
}else{
var txt=pool[randomNum(0,pool.length)];
}
code=code+txt;
//随机生成字体颜色
ctx.fillStyle = '#141046';
//随机生成字体大小
ctx.font = '22px SimHei';
var x =18 + i14
var y = 28;
//修改坐标原点和旋转角度
ctx.translate(x, y);
ctx.fillText(txt,0,0);
ctx.translate(-x, -y);
}
/绘制干扰点/
return code;
}
function get_code(type){
$.ajax({
url: '../../user_auth_verify.cgi',
type: 'POST',
data: '&submit=submit',
async: false,
timeout: 30000,
success: function(data) {
if(data.verify == 1){
$('#captchaImg').show();
drawCaptcha(data.code);
if(type && type == 'adv')
$('.login-box').addClass('code_show')
}else{
$('#code_cid').hide();
$('#captchaImg').hide();
$('.code-group').css("display","none")
}
},
error:function(){
drawCaptcha();
}
})
}
window.onload = function(){
$.ajaxSetup({
beforeSend: function (XMLHttpRequest,XMLObject) {
XMLHttpRequest.setRequestHeader("HTTP_X_REQUESTED_WITH", "xmlhttprequest");
var XMLObjData = XMLObject.data,repData = '';
if(XMLObjData && XMLObjData.indexOf('%')) repData = XMLObjData.replace(/\%/g,'%25');
else repData = XMLObjData;
var obj_data = decodeURIComponent(repData);
if(/[<>\^]|\b(sum()|\b(cmd|\')|(\'\s+[\s\S]\s+\')|(\'\s+\')|(confirm()|\b(echo\s+)|(:alert)\b|\b(eval\s()||||\b(\or\s+[\s\S]=[\s\S])|\b(and\s+[\s\S]=[\s\S])|(..\/)|(\$(..\/)|(window[location])|(window[\"location\"])|(window[\'location\'])|(window.location)|(..\/)|(\s<\simg\s)|(\s<\siframe\s)|\b(onerror\s)|\b(sleep\s)|\b(alert(\s)|\b(javascript:\s)|(--)|(\sping\s-n\s)|(\s+or\s+)|\b(exec\s+)|\b(master\s+)|\b(truncate\s+)|\b(declare\s+)|(\s+insert\s+)|\b(select\s+)|\b(delete\s+)|\b(update\s+)|\b(count\s()|(\s+chr\s()|(\s+mid\s()|(\s+chr\s()|(\s+chr\s()/.test(obj_data) ){
alert('输入操作中存在异常注入风险,请重新输入');
return false;
};
if(XMLObject.type=="GET"){
var urlString = XMLObject.url;
var reg = /(&Token.?(?=&|$))|(Token.*?(?=&|$))/;
var UrlArray = XMLObject.url.match(reg);
if(UrlArray && UrlArray[0]){
var repalceString = UrlArray[0];
urlString = urlString.replace(repalceString,"");
}
XMLObject.url = urlString;
}
},
data:{
Token:stringtoaescovert("J112saasdftrU2NUTTI")
}
});
if(document.getElementById("captchaImg")){
document.getElementById("captchaImg").onclick = function(e) {
get_code();
}
}
};``