2014-02-15 101 views
2

我想为asp密码保护的网页开发自动报废。我有这个页面的登录名/密码。报废密码保护asp页面

首先,通过firefox在授权期间查看Firebug日志。我发现的:

  1. 当我打开登录页面时,我用“__RequestVerificationToken”得到cookie。即http://mysite
  2. 当我按下登陆按钮FF使POST查询http://mysite/Account/Login带参数的用户名,密码和__RequestVerificationToken,也它使用的cookie保存在步骤1中
  3. 在成功授权的情况下,我得到另一个饼干.ASPXAUTH并进入http://mysite/Account/Index (页,我想放弃)

我的代码

//1. Get __RequestVerificationToken cookie 

    $urlLogin = "http://mysite"; 
    $cookieFile = "cookie.txt"; 
    $regs=array(); 

    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, $urlLogin); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
    curl_setopt($ch, CURLOPT_VERBOSE, TRUE); 
    curl_setopt($ch, CURLOPT_STDERR,$f = fopen("answer.txt", "w+")); 
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0'); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); 

    $data=curl_exec($ch); 

//2. Parse token value for the post request 

$hash=file_get_contents("answer.txt"); 
preg_match_all('/=(.*); p/i',$hash, $regs); 

//3. Make a post request 

    $postData = '__RequestVerificationToken='.$regs[1][0].'&UserName=someLogin'.'&Password=somePassword'; 
    $urlSecuredPage = "http://mysite/Account/Login"; 
    curl_setopt($ch, CURLOPT_URL, $urlSecuredPage); 
    curl_setopt($ch, CURLOPT_POST, TRUE); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); 

    $data = curl_exec($ch); 
    curl_close($ch); 

在步骤3我的cookie保存在步骤1中与__Requ的新值改写estVerificationToken。我不明白为什么会发生。因此,我无法授权由于__RequestVerificationToken错误而导致HTTP 500错误。

我在哪里错了?

+0

你'__RequestVerificationToken'是会话相关的,据我得到,只要用户得到验证,'的价值__RequestVerificationToken'正确的代码被修改,只对该用户保持有效,一旦用户注销,值将再次改变。所以基于此来转变你的逻辑。我认为。 – saveATcode

+0

saveATcode - 对 - __RequestVerificationToken是会话依赖的,但它在步骤1到步骤3的FF中仍然相同。只有关闭浏览器并再次访问站点时,它才会更改。 –

+0

在步骤3中,我的cookie在步骤1中保存,并以__RequestVerificationToken的新值重写。你在你的问题中写了这个,这意味着错误在其他地方.. – saveATcode

回答

2

__RequestVerificationToken应该有两件事情。其中一个隐藏的输入值,第二个在cookie中。隐藏输入值的值在每个请求中发送。对于每个请求它都有一个新的价值。这取决于cookie值。

所以你需要保存输入值和cookie,并将它们一起发回。如果您不会从隐藏输入发送值,则Asp.Net MVC认为这是一次攻击,并生成新的cookie。只有在验证失败或cookie本身不存在的情况下才会生成新的cookie。如果你得到这个cookie,并且你总是通过POST请求发送__RequestVerificationToken输入值,那么它不应该生成新的cookie。

如果它仍然生成,那么您将从隐藏的输入值发送不正确的__RequestVerificationToken。尝试从Fiddler \ Charles那里做同样的事情,并且检查将是否返回成功结果。

它们被用来防止CSRF攻击。

+0

我想起它,但页面上没有隐藏的输入值,或者我错过了它。 Page -http://www.ins-union-life.ru/ –

+1

它拥有它 - “

' –

+0

的防伪验证基于两个输入值和cookie值作品。所以,如果他们中的一个失踪了,那么它将无法工作。 –

0

大感谢Sergey Litvinovhindmost

下面

$urlLogin = "http://mysite"; 
$cookieFile = "/Volumes/Media/WebServer/aszh/cookie.txt"; 
$regs=array(); 

$ch = curl_init(); 

//Make GET request and get __RequestVerificationToken cookie 
curl_setopt($ch, CURLOPT_URL, $urlLogin); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
curl_setopt($ch, CURLOPT_VERBOSE, TRUE); 
curl_setopt($ch, CURLOPT_STDERR,$f = fopen("/Volumes/Media/WebServer/aszh/answer.txt", "w+")); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0'); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); 

$data=curl_exec($ch); 

//Parse answer and get __RequestVerificationToken hidden input value 
preg_match_all('/type="hidden" value="(.*)" /i', $data, $regs); 
$token = $regs[1][0]; 

$postData = array('__RequestVerificationToken'=>$token, 
    'UserName'=>'userName', 
    'Password'=>'password'); 


//Make POST request and get .ASPXAUTH cookie 
$urlSecuredPage = "http://mysite/Account/Login"; 
curl_setopt($ch, CURLOPT_URL, $urlSecuredPage); 
curl_setopt($ch, CURLOPT_POST, TRUE); 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); 

$data = curl_exec($ch); 
curl_close($ch);