boa通过cookie验证管理员密码

来源:互联网 发布:ubuntu 关闭网络服务 编辑:程序博客网 时间:2024/05/18 02:27

写一个输入密码的网页 check.html  主要部分就是

 </div><div class="content"><h3><font color ="gray">请输入管理员密码</h3><div><input name="password" type="password" /></div></br><div><input type="button"  value="确定" onclick="loadconfig()"/></div></div>
loadconfig()函数

  function loadconfig(){var code = 1009;netconfigfrm.actioncode.value = code;netconfigfrm.submit();}
此网页的功能就是将密码传给服务器,供cgi程序处理;

CGI部分

CGI处理密码的函数是:

static void set_cookie(){char password[32]={0};cgiFormString("password",password,32);if(strcmp(password,"123456")==0) //比较密码  {htmlHeader("The temp page");htmlBody();fprintf(cgiOut,"<SCRIPT LANGUAGE='JavaScript'>");fprintf(cgiOut, "parent.document.cookie = 'password=123456';");//123456就是密码 cookie的有效时间为直到浏览器关闭fprintf(cgiOut, "parent.window.location.href ='../index.html';");//cookie设置成功后跳转到index.html 这里前面加了一个../ ,是因为此时是在虚拟目录fprintf(cgiOut,"</SCRIPT>");// ./cgi-bin下  如果直接写index.html 那么URL地址就是 http://ip地址/cgi-bin/index.html 那么就会报错,//http://ip地址/index.html 才是希望得到的htmlFooter();}else{htmlHeader("The temp page");htmlBody();fprintf(cgiOut,"<SCRIPT LANGUAGE='JavaScript'>");fprintf(cgiOut, "alert('密码错误')");fprintf(cgiOut,"</SCRIPT>");htmlFooter();}}

在其他网页上的JavaScript加上以下两个函数:

function getCookie(c_name){if (document.cookie.length>0)  {  c_start=document.cookie.indexOf(c_name + "=")  if (c_start!=-1)    {     c_start=c_start + c_name.length+1     c_end=document.cookie.indexOf(";",c_start)    if (c_end==-1) c_end=document.cookie.length    return unescape(document.cookie.substring(c_start,c_end))    }   }return ""}function checkCookie(){username=getCookie('password')if (username!=null && username!="")  return 0;else   window.location.href="check.html"}
在<body>你认为合适的 地方 (一般是最开始的地方)加上以下代码:

<SCRIPT LANGUAGE="JavaScript">checkCookie();</SCRIPT>
检查是否设置了cookie,若没有设置就转到check.html,若设置了(即验证过密码了)就return 0.


当然 这里的密码没有经过加密处理,,有心人可能通过抓包得到密码,可以在脚本处设置加密步骤

希望可以帮助到大家

 PS:在这之前想用boa的验证用户功能 ,对比boa-0.93.16,修改boa-0.94.14rc21里面的源代码,使得boa-0.94.14rc21版能够实现验证用户,但是一直没有成功,每次启动boa服务器的使用,报错 can't recognise keyword “Auth”;  显然还是没有处理配置文件新加的 关键字 Auth 不知道有木有同志成功,望交流。。-^-


0 0
原创粉丝点击