Code Monkey home page Code Monkey logo

voterobot's Introduction

现阶段,在微信朋友圈举办的投票活动层出不穷,相信已经有不少同学对此不胜其烦,因为总会时不时地冒出个人(亲戚、朋友、or whatever)来请你帮TA投票。

本文倒没有打算从道德或者情感层面来探讨这个问题,我所感兴趣的是,当前大多数投票活动其实都是存在明显漏洞的,通过简单的技术手段就可以实现“刷票”。

案例描述

这里就有一个案例。

某美发网上商城(以下简称S商城)在微信平台上举办了一场在线投票活动,微信用户可通过活动链接访问到投票页面,对喜欢的发型师作品进行投票;每个微信帐号每天只能给单个作品投1张选票。

投票活动页面如下图所示:

漏洞分析

表面上看,S商城已经对投票活动进行了反作弊处理,因为限制了每个微信用户每天只能投一张票。如果用户都是正常地通过微信访问这个投票服务进行投票的话,的确是能起到预期效果的。

然而,如果查看投票页面的原始地址,即按住页面向下拖动,会发现屏幕顶端显示为"本网页由XXX提供",需要注意的是,这里的"XXX"并不是"mp.weixin.qq.com",而是S商城的域名。也就是说,这个投票活动的程序是运行在S商城的服务器上面的。

基于以上分析,可以推断出用户投票操作的网络拓扑结构示意图应该是这样的:

微信用户访问投票页面时,微信服务器只是进行了请求转发,具体的投票计数与校验都是在S商城的服务器上的。

那么,S商城是怎么来区分投票用户的呢?

这里就涉及到微信公众平台OpenID的概念了。官方对OpenID的解释是:加密后的微信号,每个用户对每个公众号的OpenID是唯一的。

要验证这一点也很容易,只需要通过采用多个微信账号进行投票,并对投票过程进行网络抓包,查看POST中的参数就可以证实。

基于这一点,微信公众平台在转发投票请求时,会在POST参数中包含用户的OpenID;S商城在接收到投票的POST请求后,通过查询当前OpenID是否在当天已经投过票,就可以阻止单一用户重复投票的行为了。

然而,这里面却存在一个很大的漏洞!

S商城只能判断OpenID是否出现了重复,但是却无法校验OpenID的有效性,因为它是无法调用微信服务器来对这个OpenID进行校验的。

VoteRobot实现

明确了这个漏洞后,要实现刷票就很简单了。

  • 采用微信用户正常地进行一次投票操作,对设备进行网络抓包,获取到投票过程中HTTP层面的请求参数和响应内容;
  • 使用Fiddler(或Python脚本)构造投票的HTTP POST请求,保持各参数与真实投票时抓取到的参数内容一致;
  • 随机生成不同的OpenID参数,重复进行POST请求。

如果要实现批量刷票,或者刷票自动化操作,那么就可以将刷票请求通过Python脚本来实现;甚至,采用LoadRunner也是可以的。

运行VoteRobot.py,输出日志如下:

======== Start to vote zpid(38), Total votes: 3
1 tickets has been voted, the next ticket will be voted after 35 seconds.
2 tickets has been voted, the next ticket will be voted after 31 seconds.
3 tickets has been voted, the next ticket will be voted after 10 seconds.
======== Voting Ended!

需要注意的是,通常自动化刷票时最好有个随机的时间间隔,并且,最好能动态模拟不同的设备,即修改User-Agent,否则,服务端可以较为容易地识别作弊行为。

作弊与反作弊?

看到这里,也许有的同学心中窃喜,以后投票都可以采用这种方式“刷票”了么?

很遗憾,当然不是。

其实本文中案例的漏洞是很低级的,只是,当前的确还存在不少比例的投票活动是采用这种模式。

要判断一个投票活动是否可以采用这种方式来作弊也很简单。采用本文中的方法,若查看到活动的网址是非微信官方的,而且整个投票过程也没有额外的校验,那么实现作弊的可能性就很大了;再通过抓包看下通讯交互过程,并用网络请求工具修改参数后重新请求下,即可验证是否真的可以作弊了。

另外,也许有人想问了,网络中的投票活动就没法杜绝“刷票”行为了么?

答案是,完全杜绝的确很难。听说过12306的黄牛党没?听说过Apple Store专业给应用刷榜单的没?听说过“网络水军”、“五毛党”没?

不过,活动举办方可以通过一些手段,大大提高作弊的门槛。例如,当前有不少活动就采用了如下方式:

  • 要求投票用户先关注活动举办方的公众号,然后调用微信官方的投票功能;
  • 要求投票用户在投票活动举办方的网站上进行注册(手机号验证、实名验证)

不管采用这两种方式中的哪一种,本文中的“刷票”方法就完全失效了。

voterobot's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

voterobot's Issues

磐石投票好像没办法绕过

昨天晚上搞到现在。
磐石投票,微信用户一人一票,弹出授权登陆界面,感觉流程是这样的:
(三个端,手机端标记为A,第三方网站标记为B,微信服务器标记为C)
(1) A访问投票网址url_1,B判断是否是微信浏览器(修改User-Agent简单绕过),不是微信浏览器则提示用微信浏览器登陆,否则进入(2)。
(2) B让A访问微信服务器C用于授权(如https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=httpxxx),此时C将用户的code通过Get参数传递给B的回调地址redirect_uri。B通过获取的code进一步处理。
(3) 我尝试了下绕过微信服务器,直接随机生成参数code调用redirect_uri,发现B获取code后,会进一步向C去验证。随机生成的code当然就出错了= = ,返回微信错误码40029:invalid code

所以就炸了。

换 OpenID刷票问题

现在服务端那帮人也不傻,不会直接把 openid 给暴露出来了通过 client 端提交的数据来判断的,因为这样 client 端可以作弊,一般都是直接把 openid 话在 session 中,这样client 端没办法绕开微信的单点认证,这样只有一个微信帐号的话,就没有办法通过 openid 刷票了

验证一下openId有效性

在商家后台上调用微信的获取用户信息的接口,直接就可以鉴别出真假openId,一行代码就可以杜绝这种低级漏洞。并且可以记录投票者的用户名。一般在做微信二次开发的时候,都应该注意。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.