9月 132010
 

转载: http://blog.csdn.net/hulonglong/archive/2010/08/23/5831619.aspx


本文根据个人经验介绍如何用Wireshark(Ethereal的新名字)去查看捕捉到的SSL(包括HTTPS)里被加密的消息。

大家在使用Tomcat等服务器配置成HTTPS(基于TLS/SSL)后,调 试时往往需要用Wireshark去抓包,并希望查看其中的HTTP消息。但是HTTPS的通讯是加密的,所以默认情况下你只能看到HTTPS在建立连接 之初的交互证书和协商的几个消息而已,真正的业务数据(HTTP消息)是被加密的,你必须借助服务器密钥(私钥)才能查看。即使在HTTPS双向认证(服 务器验证客户端证书)的情况下,你也只需要服务器私钥就可以查看HTTPS消息里的加密内容。
注:如何配置HTTPS服务器可以参考《如何用Tomcat和Openssl构建HTTPS双向认证环境(HTTPS客户端认证)》。
 
1. 配置Wireshark
选 中Wireshark主菜单Edit->Preferences,将打开一个配置窗口;窗口左侧是一棵树(目录),你打开其中的 Protocols,将列出所有Wireshark支持的协议;在其中找到SSL并选中,右边窗口里将列出几个参数,其中“RSA keys list”即用于配置服务器私钥。该配置的格式为:
     <ip>,<port>,<protocol>,<key_file_name>
 
各字段的含义为:
     <ip>    —- 服务器IP地址(对于HTTPS即为WEB服务器)。
     <port>  —- SSL的端口(HTTPS的端口,如443,8443)。
     <protocol> —- 表示SSL里加密的是什么协议,对于HTTPS,这项应该填HTTP。
     <key_file_name> —- 服务器密钥文件,文件里的私钥必须是明文(没有密码保护的格式)。
例如: 192.168.1.1,8443,http,C:/myserverkey/serverkey.pem
 
若你想设置多组这样的配置,可以用分号隔开,如:
   192.168.1.1,8443,http,C:/myserverkey/clearkey.pem;10.10.1.2,443,http,C:/myserverkey/clearkey2.pem
 
2. 导出服务器密钥(私钥)的明文格式(即前面提到的<key_file_name>)
大家当初在配置HTTPS服务器,服务器私钥时,一般都会输入一个保护私钥的密码。那如何导出明文形式的服务器私钥呢,需要视情况而定:
 
(1)若你是像《如何用Tomcat和Openssl构建HTTPS双向认证环境(HTTPS客户端认证)》里所述的那样,用类似于如下命令生成服务器私钥的:
   openssl req -newkey rsa:1024 -keyout serverkey.pem -keyform PEM -out serverreq.pem \
            -outform PEM -subj "/O=ABCom/OU=servers/CN=servername"M
而且你的服务器私钥文件serverkey.pem还在,则可以这样导出服务器私钥明文文件:
   openssl rsa -in serverkey.pem > clearkey.pem
 
执行命令式需要输入私钥的保护密码就可以得到私钥明文文件clearkey.pem了。
 
(2)若你已把serverkey.pem丢了,但还有pkcs12格式的服务器证书库文件,该文件当初用类似于以下命令生成的:
   openssl pkcs12 -export -in servercert.pem -inkey serverkey.pem \
                        -out tomcat.p12 -name tomcat -CAfile "$HOME/testca/cacert.pem" \
                        -caname root -chain
则,你可以用下面命令把服务器私钥从tomcat.p12(pkcs12格式)文件里导出来:
   openssl pkcs12 -in tomcat.p12 -nocerts -nodes -out clearkey.pem
 
执行命令式需要输入pkcs12的保护密码。
然后编辑一下生成的clearkey.pem文件,把“—–BEGIN RSA PRIVATE KEY—–”之前的内容删掉就可以了。
 
(3) 若你的服务器私钥是用java的keytool命令生成的keystore文件,则要弄出来比较麻烦,建议服务器keystore最好用《如何用 Tomcat和Openssl构建HTTPS双向认证环境(HTTPS客户端认证)》里的openssl生成服务器公钥私钥和证书的方法,生成 pkcs12格式的keystore。


 Posted by at 上午 5:31
4月 012010
 

1. https的页面里使用js创建一个iframe时,如果初始化src为“about:blank”, 会有安全提示的,如果初始化src为: javascript: false; 就不会有安全提示了。

2. https页面里面含有http请求就一定有安全提示吗? ie中基本是这样的;但是Firefox就不一定

 Posted by at 上午 1:31
3月 092010
 

在QQ中,如果想跟某个用户聊天,该也难怪乎不是你的好友的话,大部分情况必须首先加其为好友。这是比较麻烦的。另外一种情况就是使用临时会话:
tencent://Message/?menu=yes&exe=&uin=10001
把uin后面的改成对方的QQ号

 Posted by at 上午 7:30
1月 162010
 

在.net中公钥的格式总是以modules 、exponent的格式存在的,但是openssl做加密、解密总是使用pem格式的,这里实现了前者到后者的格式转换。

.net生成的public key的格式:
<modulus>
jY39vkCL8xCrUK9eepK2SQ447xiU/bZmnJi6G+4ripHzOJ65YTsxJ3sEOrXCyb0P
MBXQchQ2xpE8g7PyHe4zv07/Q7hbRFJ2CJAIyFj7OD5aejOiIptMzPsYNMx5Gkbs
</modulus>
<exponent>
AQAB
</exponent>

<?php
/** 
 * Zeal Extends of ZendFramework 
 * 
 * @category   Zeal 
 * @package    Zeal 
 * @subpackage Security 
 */  
  
/** 
 * RSA公钥格式转化 
 * 
 * @category   Zeal 
 * @package    Zeal 
 * @subpackage Security 
 */  
class Zeal_Security_RSAPublicKey  
{  
    
/** 
     * ASN.1 type INTEGER class 
     */  
    
const ASN_TYPE_INTEGER 0x02;  
  
    
/** 
     * ASN.1 type BIT STRING class 
     */  
    
const ASN_TYPE_BITSTRING 0x03;  
  
    
/** 
     * ASN.1 type SEQUENCE class 
     */  
    
const ASN_TYPE_SEQUENCE 0x30;  
  
    
/** 
     * The Identifier for RSA Keys 
     */  
    
const RSA_KEY_IDENTIFIER '300D06092A864886F70D0101010500';  
  
    
/** 
     * Constructor  (disabled) 
     * 
     * @return void 
     */  
    
private function __construct()  
    {  
    }  
  
    
/** 
     * Transform an RSA Key in x.509 string format into a PEM encoding and 
     * return an PEM encoded string for openssl to handle 
     * 
     * @param string $certificate x.509 format cert string 
     * @return string The PEM encoded version of the key 
     */  
    
static public function getPublicKeyFromX509($certificate)  
    {  
        
$publicKeyString "-----BEGIN CERTIFICATE-----n" .  
                           
wordwrap($certificate64"n"true) .  
                           
"n-----END CERTIFICATE-----";  
  
        return 
$publicKeyString;  
    }  
  
    
/** 
     * Transform an RSA Key in Modulus/Exponent format into a PEM encoding and 
     * return an PEM encoded string for openssl to handle 
     * 
     * @param string $modulus The RSA Modulus in binary format 
     * @param string $exponent The RSA exponent in binary format 
     * @return string The PEM encoded version of the key 
     */  
    
static public function getPublicKeyFromModExp($modulus$exponent)  
    {  
        
$modulusInteger  self::_encodeValue($modulus,   
                                               
self::ASN_TYPE_INTEGER);  
        
$exponentInteger self::_encodeValue($exponent,   
                                               
self::ASN_TYPE_INTEGER);  
        
$modExpSequence  self::_encodeValue($modulusInteger .   
                                              
$exponentInteger,   
                                               
self::ASN_TYPE_SEQUENCE);  
        
$modExpBitString self::_encodeValue($modExpSequence,   
                                               
self::ASN_TYPE_BITSTRING);  
  
        
$binRsaKeyIdentifier pack"H*"self::RSA_KEY_IDENTIFIER );  
  
        
$publicKeySequence self::_encodeValue($binRsaKeyIdentifier .   
                                                
$modExpBitString,   
                                                 
self::ASN_TYPE_SEQUENCE);  
  
        
$publicKeyInfoBase64 base64_encode$publicKeySequence );  
  
        
$publicKeyString "-----BEGIN PUBLIC KEY-----n";  
        
$publicKeyString .= wordwrap($publicKeyInfoBase6464"n"true);  
        
$publicKeyString .= "n-----END PUBLIC KEY-----n";  
  
        return 
$publicKeyString;  
    }  
  
    
/** 
     * Encode a limited set of data types into ASN.1 encoding format 
     * which is used in X.509 certificates 
     * 
     * @param string $data The data to encode 
     * @param const $type The encoding format constant 
     * @return string The encoded value 
     * @throws Zend_InfoCard_Xml_Security_Exception 
     */  
    
static protected function _encodeValue($data$type)  
    {  
        
// Null pad some data when we get it  
        // (integer values > 128 and bitstrings)  
        
if( (($type == self::ASN_TYPE_INTEGER) && (ord($data) > 0x7f)) ||  
            (
$type == self::ASN_TYPE_BITSTRING)) {  
                
$data "�$data";  
        }  
  
        
$len strlen($data);  
  
        
// encode the value based on length of the string  
        
switch(true) {  
            case (
$len 128):  
                return 
sprintf("%c%c%s"$type$len$data);  
            case (
$len 0x0100):  
                return 
sprintf("%c%c%c%s"$type0x81$len$data);  
            case (
$len 0x010000):  
                return 
sprintf("%c%c%c%c%s"$type0x82,   
                                              
$len 0x0100,   
                                              
$len 0x0100$data);  
            default:  
                throw   
                  new 
Zeal_Security_RSAPublicKey_Exception("Could not encode value",1);  
        }  
  
        throw   
          new 
Zeal_Security_RSAPublicKey_Exception("Invalid code path",2);  
    }  
}  
  
class 
Zeal_Security_RSAPublicKey_Exception extends Exception  
{  
  
}

// example
 
$hCert openssl_pkey_get_public(  
            
Zeal_Security_RSAPublicKey::getPublicKeyFromModExp(  
                
file_get_contents("/home/zeal/certs/public.key"),  
                
"AQAB"  
            
)  
        );  
$dataToCheck "This is Data should be verified!";  
$signBinary ".................................";  
$ok openssl_verify(  
        
$dataToCheck,   
        
$signBinary,   
        
$hCert,  
        
OPENSSL_ALGO_SHA1  
);  
if (
$ok == 1) {  
    echo 
"good";  
}   
elseif (
$ok == 0) {  
    echo 
"bad";  
}   
else {  
    echo 
"error occured";  
}  
?>

 Posted by at 上午 9:37
12月 082009
 

http://bbs2.chinaunix.net/viewthread.php?tid=1623454


[root@login f2r]# nslookup
> server 8.8.8.8
Default server: 8.8.8.8
Address: 8.8.8.8#53
> set type=a
> google.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   google.com
Address: 74.125.67.100
Name:   google.com
Address: 74.125.45.100
Name:   google.com
Address: 74.125.53.100
> sina.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   sina.com
Address: 12.130.152.116
>

8.8.8.8 太强悍的;
还有更强悍的: 4.3.2.1

比较值得思考的是:

这种事情由商业公司干不好吧
都用8.8.8.8,那google要干掉竞争对手,岂非太容易了。


 Posted by at 上午 6:55
11月 122009
 

• 飞速土豆是在本机起的一个服务,浏览器安装该插件后,遇到可以代理的请求时,就由本地服务进程来下载数据了
• 飞速土豆还有缓存的功能,就是如果浏览器里通过飞速土豆下载过某段视频,再用控制台走该代理下载该视频就很快了
• 飞速土豆限制wget下载,是通过限制agent实现的,用-U参数修改agent就可以搞定了

 Posted by at 上午 1:18
11月 012009
 

md5暴力破解的难度分析:

1.  100万次md5("aaaaaa") 的时间
18测试机上: 5.6s
我的pc机上: 1.8s

2.  100万次sha1("aaaaaa") 的时间
18测试机上: 7.2s
我的pc机上: 2.0s

3.  100万次hash(md5,"aaaaaa") 的时间
18测试机上: 1.7s
我的pc机上: 2.3s

4.  100万次hash(sha1,"aaaaaa") 的时间
18测试机上: 2.3s
我的pc机上: 2.6s

5. 对于由字母和数字组成的64位的密钥,可能的情况为:
   36^64 = 4011991914547630480065053387702443812690402487741812225955731622655455723258857248542161222254985216

   这是一个100位的数字,但就这个数字的长度来看,我已经不想猜测需要多少机器,多长时间才能破解了。

疑问: 为什么我的pc机器上作加密比服务器要快那么多? 底层实现不一样,可以看源码。

结论:
1. sha1比md5加密强度是要大一些的, 10:9
2. 按照我的pc机器的破解速度,50万次/s
字符集: a-z A-Z 0-9 . ? – _ 共40个字符,对于最小长度的密码(6位)最慢的情况需要40^6(40亿)次的md5
40亿/50万/3600 =

4000000000/500000/3600 = 2小时

增加md5的次数,对破解难度来讲,是倍数级别的增大的;
增加密码的长度,对破解难度来讲,是指数级别的增大的;

所以试图多几次md5来增加暴力破解的难度是没有太大意义的。但是增加密码长度是很有意义的。

 Posted by at 上午 6:47
10月 272009
 

软件简介:
tcpdump是一款很强大、很有用的网络侦听软件,但是对于ssl加密的数据包就无能为力了;ssldump则是一款可以侦听ssl加密的数据包的软件。

下载地址:
wget "http://www.rtfm.com/ssldump/ssldump-0.9b3.tar.gz
"

安装:

安装时曾遇到这种错误:
./base/pcap-snoop.c:52:21: net/bpf.h: No such file or directory
./base/pcap-snoop.c: In function main':
./base/pcap-snoop.c:207: warning: passing arg 2 of
signal’ from incompatible pointer type
./base/pcap-snoop.c:329: warning: passing arg 3 of `pcap_loop’ from incompatible pointer type
make: *** [pcap-snoop.o] Error 1

因为该软件依赖libpcap包,下载地址:http://www.tcpdump.org/release/libpcap-1.0.0.tar.gz

我的机器上虽然已经按照了libpcap包,但是net/bpf.h 却不存在,但是存在pcap-bpf.h ,于是我就将pcap-bpf.h重命名为bpf.h 放到了net目录下,编译通过。

使用方法:

ssldump -i eth0 -k /etc/ssl/crt/private.key  -nn -d  port 443

其中:
-k : 私钥文件
-d : 打印应用程序数据,对于https来讲就是打印http的数据信息

wireshark也可以这么干的。

 Posted by at 上午 2:41
10月 212009
 

先来一个实际例子吧:
d:>openssl ocsp  -issuer issuer.cer -cert login.sina.com.cn.crt  -url http://ocsp.verisign.com/
Response Verify Failure
2296:error:27069065:OCSP routines:OCSP_basic_verify:certificate verify error:.\crypto\ocsp\ocsp_vfy.c:122:Verify error:unable to get local issuer cert
ificate
login.sina.com.cn.crt: good
        This Update: Oct 20 14:03:40 2009 GMT
        Next Update: Oct 27 14:03:40 2009 GMT

其中,

login.sina.com.cn.crt 是我们要验证的证书
issuer.cer 是颁发login.sina.com.cn.crt的ca的证书

要想看到更加详细的请求和相应的数据的具体内容,可添加 -text 选项,如下:
d:>openssl ocsp  -issuer issuer.cer -cert login.sina.com.cn.crt  -url http://ocsp.verisign.com/ -text
OCSP Request Data:
    Version: 1 (0x0)
    Requestor List:
        Certificate ID:
          Hash Algorithm: sha1
          Issuer Name Hash: C0FE0278FC99188891B3F212E9C7E1B21AB7BFC0
          Issuer Key Hash: 0DFC1DF0A9E0F01CE7F2B213177E6F8D157CD4F6
          Serial Number: 25E692D2645B52CD365386F2424FE9A0
    Request Extensions:
        OCSP Nonce:
            041026AA90D62932AFDE2FFFF5682E3AEDA4
OCSP Response Data:
    OCSP Response Status: successful (0x0)
    Response Type: Basic OCSP Response
    Version: 1 (0x0)
    Responder Id: O = VeriSign Trust Network, OU = "VeriSign, Inc.", OU = VeriSign International Server OCSP Responder – Class 3, OU = Terms of use at
 www.verisign.com/rpa (c)03
    Produced At: Oct 20 14:03:40 2009 GMT
    Responses:
    Certificate ID:
      Hash Algorithm: sha1
      Issuer Name Hash: C0FE0278FC99188891B3F212E9C7E1B21AB7BFC0
      Issuer Key Hash: 0DFC1DF0A9E0F01CE7F2B213177E6F8D157CD4F6
      Serial Number: 25E692D2645B52CD365386F2424FE9A0
    Cert Status: good
    This Update: Oct 20 14:03:40 2009 GMT
    Next Update: Oct 27 14:03:40 2009 GMT

ocsp 的响应是做了ca的签名的,这样保证了响应的数据是可靠的。

相关文章:http://blog.chinaunix.net/u/12066/showart.php?id=491918

 Posted by at 下午 8:22