Skip to content

Instantly share code, notes, and snippets.

@ourai
Last active July 24, 2018 07:32
Show Gist options
  • Select an option

  • Save ourai/6239347 to your computer and use it in GitHub Desktop.

Select an option

Save ourai/6239347 to your computer and use it in GitHub Desktop.
阿里巴巴集团 2014 校园招聘攻略

阿里巴巴集团 2014 校园招聘解题攻略

8月20日,阿里校园招聘前端岗位的在线笔试将统一开始。在这之前,我们先玩一下热身赛吧! http://t.cn/zQRFjtd 截至8月18日11:00之前成功通关并且表现优异的同学,将有机会收到我们的惊喜邮件!

以上是阿里巴巴集团校园招聘的某一条微博的内容。

我虽然看到了美女,但不知道那是不是 true ending。即使如此,我也将我的解题方法公布出来。

其实每题都可以在 console 中用 JavaScript 代码来解决,下面就是除了猜图之外的执行代码。

解密码

location.href = Base64.decode( document.getElementById("page").getAttribute("data-t") );

翻镜子

(function() {

var pharaoh = getNode("pharaoh");
var sacrifice = getNode("sacrifice");
var sacrificeCoord = getDotCoord( sacrifice );

ejaculate();

// 射出
function ejaculate() {
    var mirrors = document.getElementsByClassName( "mirror" );

    [].forEach.call( mirrors, magicMirror );
}

// 镜子魔法
function magicMirror( mirror ) {
    setCssStyle( mirror, mirrorStyles( mirror ) );
}

// 镜子样式
function mirrorStyles( mirror ) {
    var id = mirror.id;
    var position = mirrorPosition( id );

    return {
        "webkitTransformOrigin": "50% 0 0",
        "webkitTransform": "rotate(" + (id === "ma" ? -67.5 : 180) + "deg)",
        "left": position.left,
        "top": position.top
    }
}

// 镜子位置
function mirrorPosition( id ) {
    var position;

    if ( id === "ma" ) {
        position = getMaCoord();
    }
    else {
        position = getMbCoord();
    }

    return position;
}

// 通过 id 获取节点
function getNode( id ) {
    return document.getElementById( id );
}

// 获取样式
function getCssStyle( node, ruleKey ) {
    return getComputedStyle(node, null)[ruleKey];
}

// 设置样式
function setCssStyle( node, rules ) {
    for ( var key in rules ) {
        node.style[ key ] = rules[key];
    }
}

// 获取黑点坐标
function getDotCoord( node ) {
    return {
        x: parseFloat( getCssStyle(node, "left") ) + parseFloat( getCssStyle(node, "width") )/2,
        y: parseFloat( getCssStyle(node, "top") ) + parseFloat( getCssStyle(node, "height") )/2
    };
}

// 计算 ma 镜子的图形中心坐标
function getMaCoord() {
    var mirror = getNode("ma");
    var light = getNode("source");
    var coord_y = parseFloat( getCssStyle(light, "top") ) + parseFloat( getCssStyle(light, "height") )/2;
    var dot2ray = coord_y - sacrificeCoord.y;

    return {
        left: sacrificeCoord.x + dot2ray - parseFloat( getCssStyle(mirror, "width") )/2 + "px",
        top: coord_y + "px"
    };
}

// 计算 mb 镜子的图形中心坐标
function getMbCoord() {
    var pharaohCoord = getDotCoord( pharaoh );
    var mirror = getNode( "mb" );
    var dot2dot = (sacrificeCoord.x - pharaohCoord.x)/2;
    var coor_x = pharaohCoord.x + dot2dot - parseFloat(getCssStyle(mirror, "width"))/2;

    return {
        left: coor_x + "px",
        top: pharaohCoord.y - dot2dot + "px"
    };
}

})();

二维码

(function() {
  var qrdata = getQrData().split(" ");
  var ctx = document.getElementById("qr-canvas").getContext("2d");
  
  qrdata.forEach(function( code ) {
    ctx.fillRect.apply( ctx, code.split( "," ) );
  });

  function getQrData() {
    var data;

    [].forEach.call(document.body.childNodes, function( node ) {
      if ( node.nodeType === document.COMMENT_NODE ) {
        data = node.data.replace(/\r|\n/g, "");
      }
    });

    return data;
  }
})();

闯房间

(function( $ ) {
    
var currentRoom = $("#next-room").text();
var stack = [currentRoom];

trace( currentRoom );

function trace( room ) {
	$.ajax({
		url: location.pathname + location.search.replace(/room\=\d+/, function() {
				return "room=" + room;
			}),
		dataType: "html",
		success: function( res ) {
			var nextRoom = $("#next-room", $(res)).text();

			if ( nextRoom !== "" ) {
				stack.push( $("#message", $(res)).text() );

				console.log( "正在进入第 " + nextRoom + " 号房间..." );

				setTimeout(function() {
					trace( nextRoom );
				}, 3000);
			}
			else {
				var url = quizUrl();

				console.log( "已经取得通往西天的地址 " + url + ",5 秒后前往西天!" );

				setTimeout(function() {
					location.href = url;
				}, 5000);
			}
		}
	});
}

function quizUrl() {
	var str = stack.join("");

	return str.substring( str.indexOf("/quiz") );
}

})(jQuery); 
@shenwa12
Copy link

var c = document.getElementById('qr-canvas').getContext('2d');
var s= "请自行复制源码中一大段注释中的数字字符串";
var a=s.split(' ');
alert(a.length);
for(i=0;i<a.length;i++){
var b=a[i].split(',');
c.fillRect(b[0],b[1],b[2],b[3]);
}

@ourai
Copy link
Author

ourai commented Aug 15, 2013

@shenwa12 不优雅。

@liyao
Copy link

liyao commented Aug 15, 2013

nice job!

@xydiva
Copy link

xydiva commented Aug 16, 2013

学习来了~

@fakefish
Copy link

虽然昨天中午就过关了,但好像过的不优雅=。=

@vvianyy
Copy link

vvianyy commented Aug 16, 2013

原来提交框还可以 xss 。。。我说呢 干嘛用的

@599316527
Copy link

最后一关我提交的是script,结果被Chrome自动拦截了

@mariodu
Copy link

mariodu commented Aug 16, 2013

用base64的界面,都可以用Base64.decode进行解码

@mariodu
Copy link

mariodu commented Aug 16, 2013

另外,要是自动化的话,无尽房间那个的解法,第一次请求的room和t的传参可以通过url分析出来,实现完全自动化。

@mariodu
Copy link

mariodu commented Aug 16, 2013

哦,看错了,以为你那段文字是说那个下面代码的。。。上条可以无视。

@ourai
Copy link
Author

ourai commented Aug 16, 2013

@bokeyy 是的,每次提交后会检测指纹图片是否有被遮挡。

我昨天在写脚本的时候,想用 <script> 注入了,但是抛异常了。


@599316527 没错,真正的跨站攻击被拦截掉了。


@mariodu Base64 是淘宝提供的, atob 是原生的。

@lauigi
Copy link

lauigi commented Sep 13, 2013

@ourai Base64是原生的,大概写反了?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment