Advertisement
Kenningar

Bungie Xbox Authentication test

Nov 1st, 2016
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.53 KB | None | 0 0
  1. <?php
  2. function do_webauth($method, $username, $password) {
  3.         $cookie_file = './cookie/'; // a valid file path to where the cookies will be stored (ie cookie.txt)
  4.         $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
  5.  
  6.         $methods = array(
  7.                 'psn' => 'Psnid',
  8.                 'xbox' => 'Xuid'//'Wlid'
  9.         );
  10.         $dest = 'Wlid'; if (isset($methods[$method])) $dest = $methods[$method];
  11.         $url = 'https://www.bungie.net/fr/User/SignIn/'.$dest;
  12.  
  13.         $default_options = array(
  14.                 CURLOPT_USERAGENT => $user_agent,
  15.                 CURLOPT_COOKIEJAR => $cookie_file,
  16.                 CURLOPT_COOKIEFILE => $cookie_file,
  17.                 CURLOPT_RETURNTRANSFER => true,
  18.                 CURLOPT_SSL_VERIFYHOST => 2,
  19.         );
  20.  
  21.         // Get Third Party Authorization URL
  22.         $ch = curl_init();
  23.         curl_setopt_array($ch, $default_options);
  24.         curl_setopt_array($ch, array(
  25.                 CURLOPT_URL => $url,
  26.         ));
  27.         curl_exec($ch);
  28.         $redirect_url = curl_getinfo($ch)['redirect_url'];
  29.         curl_close($ch);
  30.  
  31.         // Bungie Cookies are still valid
  32.         if (!$redirect_url) return true;
  33.  
  34.         // Try to authenticate with Third Party
  35.         $ch = curl_init();
  36.         curl_setopt_array($ch, $default_options);
  37.         curl_setopt_array($ch, array(
  38.                 CURLOPT_URL => $redirect_url,
  39.         ));
  40.         $auth_result = curl_exec($ch);
  41.         $auth_info = curl_getinfo($ch);
  42.         $auth_url = $auth_info['redirect_url'];
  43.  
  44.         // Normally authentication will produce a 302 Redirect, but Xbox is special...
  45.         if ($auth_info['http_code'] == 200) $auth_url = $auth_info['url'];
  46.  
  47.         curl_close($ch);
  48.  
  49.         // No valid cookies
  50.         if (strpos($auth_url, $url.'?code') !== 0) {
  51.                 $result = false;
  52.                 switch($method) {
  53.                         case 'psn':
  54.                                 $login_url = 'https://auth.api.sonyentertainmentnetwork.com/login.do';
  55.  
  56.                                 // Login to PSN
  57.                                 $ch = curl_init();
  58.                                 curl_setopt_array($ch, $default_options);
  59.                                 curl_setopt_array($ch, array(
  60.                                         CURLOPT_URL => $login_url,
  61.                                         CURLOPT_POST => 3,
  62.                                         CURLOPT_POSTFIELDS => http_build_query(array(
  63.                                                 'j_username' => $username,
  64.                                                 'j_password' => $password,
  65.                                                 'rememberSignIn' => 1 // Remember signin
  66.                                         )),
  67.                                 ));
  68.                                 curl_exec($ch);
  69.                                 $redirect_url = curl_getinfo($ch)['redirect_url'];
  70.                                 curl_close($ch);
  71.  
  72.                                 if (strpos($redirect_url, 'authentication_error') !== false) return false;
  73.  
  74.                                 // Authenticate with Bungie
  75.                                 $ch = curl_init();
  76.                                 curl_setopt_array($ch, $default_options);
  77.                                 curl_setopt_array($ch, array(
  78.                                         CURLOPT_URL => $redirect_url,
  79.                                         CURLOPT_FOLLOWLOCATION => true
  80.                                 ));
  81.                                 curl_exec($ch);
  82.                                 $result = curl_getinfo($ch);
  83.                                 curl_close($ch);
  84.                                 break;
  85.                         case 'xbox':
  86.                                 $login_url = 'https://login.live.com/ppsecure/post.srf?'.substr($redirect_url, strpos($redirect_url, '?')+1);
  87.                                 preg_match('/id\="i0327" value\="(.*?)"\//', $auth_result, $ppft);
  88.  
  89.                                 if (count($ppft) == 2) {
  90.                                         $ch = curl_init();
  91.                                         curl_setopt_array($ch, $default_options);
  92.                                         curl_setopt_array($ch, array(
  93.                                                 CURLOPT_URL => $login_url,
  94.                                                 CURLOPT_POST => 3,
  95.                                                 CURLOPT_POSTFIELDS => http_build_query(array(
  96.                                                         'login' => $username,
  97.                                                         'passwd' => $password,
  98.                                                         'KMSI' => 1, // Stay signed in
  99.                                                         'PPFT' => $ppft[1]
  100.                                                 )),
  101.                                                 CURLOPT_FOLLOWLOCATION => true
  102.                                         ));
  103.                                         $auth_result = curl_exec($ch);
  104.                                         $auth_url = curl_getinfo($ch)['url'];
  105.                                         curl_close($ch);
  106.  
  107.                                         if (strpos($auth_url, $url.'?code') === 0) {
  108.                                                 return true;
  109.                                         }
  110.                                 }
  111.                                 return false;
  112.                                 break;
  113.                 }
  114.                 $result_url = $result['url'];
  115.                 if ($result['http_code'] == 302) $result_url = $result['redirect_url'];
  116.  
  117.                 // Account has not been registered with Bungie
  118.                 if (strpos($result_url, '/Register') !== false) return false;
  119.  
  120.                 // Login successful, "bungleatk" should be set
  121.                 // Facebook/PSN should return with ?code=
  122.                 // Xbox should have ?wa=wsignin1.0
  123.                 return strpos($result_url, $url) === 0;
  124.         }
  125.         // Valid Third Party Cookies, re-authenticating Bungie Login
  126.         $ch = curl_init();
  127.         curl_setopt_array($ch, $default_options);
  128.         curl_setopt_array($ch, array(
  129.                 CURLOPT_URL => $auth_url,
  130.         ));
  131.         curl_exec($ch);
  132.         curl_close($ch);
  133.         return true;
  134. }
  135.  
  136. $method = 'xbox';
  137. $username = '[my username]';
  138. $password = '[my password]';
  139.  
  140.  
  141. $resultat = do_webauth($method,$username,$password);
  142.  
  143. var_dump($resultat);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement