Chinaunix首页 | 论坛 | 博客
  • 博客访问: 201058
  • 博文数量: 48
  • 博客积分: 1935
  • 博客等级: 上尉
  • 技术积分: 491
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-29 00:59
文章分类

全部博文(48)

文章存档

2011年(1)

2010年(47)

我的朋友

分类:

2010-11-18 23:31:04

1.ntlm是什么 

早期smb协议在网络上传输明文口令。后来出现 lan manager challenge/response 验证机制,简称lm,它是如此简单以至很轻易就被破解。微软提出了windowsnt挑战/响应验证机制,称之为ntlm。现在已经有了更新的ntlmv2以及kerberos验证体系。ntlmwindows早期安全协议,因向后兼容性而保留下来。ntlmnt lan manager的缩写,即nt lan管理器。ntlm 是为没有加入到域中的计算机(如独立服务器和工作组)提供的身份验证协议。

具体说明可以参考下面资源:

 

 

2.ntlm验证答应windows用户使用当前登录系统的身份进行认证,当前用户应该是登陆在一个域(domain)上,他的身份是可以自动通过浏览器传递给服务器的。它是一种单点登录的策略,系统可以通过ntlm重用登录到windows系统中的用户凭证,不用再次要求用户输入密码进行认证。 

下面是.net的实现方式,如下: 

static void main(string[] args)

        {

            try

            {

                credentialcache mycredentialcache = new credentialcache();

                mycredentialcache.add(new uri("****.com /default.aspx"), "ntlm"new networkcredential("carysun""****""******"));

                httpwebrequest req;

                req = (httpwebrequest)httpwebrequest.create("****.com /default.aspx ");

                req.method = "get";

                req.keepalive = true;

                req.credentials = mycredentialcache;

                //保存cookie

                cookiecontainer cc = new cookiecontainer();

                req.cookiecontainer = cc;

                httpwebresponse res;

                res = (httpwebresponse)req.getresponse();

                console.writeline(res.statuscode);

                if (res.statuscode == httpstatuscode.ok)

                {

                    //验证成功

                    console.writeline(res.statuscode);                

 

                }

            }

            catch (exception ex)

            {

                //验证失败

 

            }

            console.readline();

        }

python-ntlm(官网地址:)是一个用来访问ntlm认证网址的module。下面是借助该module的实现代码。

import urllib2

from urlparse import urlparse, urlunparse

from ntlm import httpntlmauthhandler

from urllib2 import request, urlopen, urlerror, httperror

 

user = '*****\\carysun'

password = "********"

url = "*****.com/default.aspx"

 

passman = urllib2.httppasswordmgrwithdefaultrealm()

passman.add_password(none, url, user, password)

# create the ntlm authentication handler

auth_ntlm = httpntlmauthhandler.httpntlmauthhandler(passman)

 

# create and install the opener

opener = urllib2.build_opener(auth_ntlm)

urllib2.install_opener(opener) 

 

req = urllib2.request(url)

try:

    response = urllib2.urlopen(req)

except httperror,e:

    print 'error code:',e.code

except urlerror,e:

    print 'reason:',e.reason

else:

    print (response.read())


阅读(2284) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-19 15:16:10

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com