megamaster - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of megamaster.php

  1. <?php
  2. include "vendor/autoload.php";
  3.  
  4. use \GuzzleHttp\Client;
  5. use \GuzzleHttp\Psr7\Request;
  6. use \GuzzleHttp\Cookie\CookieJar as CookieHandler;
  7. use \GuzzleHttp\Command\Guzzle\GuzzleClient;
  8. use DOMDocument;
  9.  
  10. ini_set('display_errors', 0);
  11.  
  12.  
  13. class AdapterIQQ {
  14.  
  15.     private $client;
  16.     private $url_base = '';
  17.     private $login_info = [
  18.                     'username' => '',
  19.                     'passwd' => ''
  20.                 ];
  21.  
  22.  
  23.     private $urls_path = [
  24.         'filter' => '/path/to/action',
  25.         'get' => '/path/to/action',
  26.         'filter_group' => '/path/to/action',
  27.     ];
  28.  
  29.     private $data = [];
  30.  
  31.     private $SALMResponse;
  32.     private $uaid;
  33.  
  34. //    private $client_id = 'e37ffdec11c0245cb2e0';
  35.  
  36.  
  37.     public function __construct()
  38.     {
  39.         $this->client = new Client(['cookies' => true]);
  40.        # $this->client->setDefaultOptions('verify', false);
  41.         $this->get_landing_context_azure();
  42.         $this->send_username_info();
  43.         $this->do_auth_in_azure();
  44.     }
  45.  
  46.     public function get_landing_context_azure()
  47.     {
  48.         $client = $this->client;
  49.         $headers_init = [
  50.             'Connection' => 'keep-alive',
  51.             'Host'=> 'iqq.abbott.com',
  52.             'User-Agent'=> 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36'
  53.          ];
  54.      
  55.         $landing = $client->request('GET','https://iiq.abbott.com/', [/*'headers' => $headers_init,*/ 
  56.                                                                         'debug'=> false,
  57.                                                                         'verify' => false,
  58.                                                                         'allow_redirects' => ['track_redirects' => true]]);
  59.             $raw_html = $landing->getBody()->getContents();
  60.             $cookie_jar = $client->getConfig('cookies');
  61.             $cookie = $cookie_jar->toArray();
  62.             $headers = $landing->getHeaders();
  63.             $historyUri = $landing->getHeader(\GuzzleHttp\RedirectMiddleware::HISTORY_HEADER);
  64.             
  65.             $data = [
  66.                 'flowToken' => $this->search_in_serverData('sFT', $raw_html),
  67.                 'ctx' => $this->search_in_serverData('sCtx', $raw_html),
  68.                 'requestId' => $this->search_in_serverData('requestId', $raw_html),
  69.                 'apiCanary' => $this->search_in_serverData('apiCanary', $raw_html),
  70.                 'canary' => $this->search_in_serverData('canary', $raw_html),
  71.                 'correlationId' => $this->search_in_serverData('correlationId', $raw_html),
  72.                 'x-ms-request-id' => $headers['x-ms-request-id'][0],
  73.                 'client-request-id' => $this->search_in_serverData('correlationId', $raw_html),
  74.                 'hpgrequestid' => $this->search_in_serverData('sessionId', $raw_html),
  75.                 'Referer' => $historyUri[1]
  76.             ];
  77.  
  78.             $this->data = $data;
  79.             // var_dump($data);
  80.  
  81.         }
  82.         
  83.         
  84.     private function parse_uri($link_microsoftonline){
  85.         return parse_url($link_microsoftonline);
  86.     }   
  87.     
  88.  
  89.     private function search_in_serverData($name, $data)
  90.     {
  91.  
  92.         $regExp = '/"'.$name.'":"(.*?)"/';
  93.             preg_match($regExp, $data, $mathes);
  94.         return $mathes[1];
  95.  
  96.     }
  97.  
  98.     public function send_username_info()
  99.     {
  100.         $client = $this->client;
  101.  
  102.         $headers_for_login = [
  103.             'Accept' => 'application/json',
  104.             'Referer' => $this->data['Referer'],
  105.             'Origin' => 'https://login.microsoftonline.com',
  106.             'client-request-id' => $this->data['client-request-id'],
  107.             'hpgact' => '1900',
  108.             'hpgid' => '1104',
  109.             'Host' => 'login.microsoftonline.com',
  110.             'hpgrequestid' => $this->data['hpgrequestid'],
  111.             'Content-Type' => 'application/json; charset=UTF-8',
  112.             'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'    
  113.         ];
  114.  
  115.         
  116.         $body_request = [
  117.             'checkPhones' => false,
  118.             'country' => 'DE',
  119.             'federationFlags' => 0,
  120.             'flowToken' => $this->data['flowToken'],
  121.             'forceotclogin' => false,
  122.             'isAccessPassSupported' => true,
  123.             'isCookieBannerShown' => false,
  124.             'isExternalFederationDisallowed' => false,
  125.             'isFidoSupported' => false,
  126.             'isOtherIdpSupported' => true,
  127.             'isRemoteConnectSupported' => false,
  128.             'isRemoteNGCSupported' => true,
  129.             'isSignup' => false,
  130.             'originalRequest' => $this->data['ctx'],
  131.             'username' => $this->login_info['username'],
  132.         ];
  133.  
  134.         $cookie_jar = $client->getConfig('cookies');
  135.  
  136.         $send_login = $client->request('POST', 'https://login.microsoftonline.com/common/GetCredentialType?mkt=en-US',
  137.                                         ['headers' => $headers_for_login,
  138.                                          'json' => $body_request,
  139.                                          'cookies' => $cookie_jar] );
  140.  
  141.     //    $response_login = $send_login->getBody()->getContents();
  142.     //     var_dump($this->flow_token);
  143.     //     var_dump($client->getConfig('cookies'));
  144.     //var_dump($this->get_login_uri($this->data['Referer']));
  145.     //var_dump($response_login);
  146.  
  147.     }
  148.  
  149.     public function do_auth_in_azure()
  150.     {
  151.         $client = $this->client;
  152.  
  153.         $headers_for_login = [
  154.             'Accept' => 'application/json',
  155.             'Referer' => $this->data['Referer'],
  156.             'Origin' => 'https://login.microsoftonline.com',
  157.             'client-request-id' => $this->data['client-request-id'],
  158.             'hpgact' => '1900',
  159.             'hpgid' => '1104',
  160.             'Host' => 'login.microsoftonline.com',
  161.             'hpgrequestid' => $this->data['hpgrequestid'],
  162.             'Content-Type' => 'application/json; charset=UTF-8',
  163.             'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'    
  164.         ];
  165.  
  166.         $json = [
  167.             'i13' => '0',
  168.             'login' => $this->login_info['username'],
  169.             'loginfmt' => $this->login_info['username'],
  170.             'type'=> '11',
  171.             'LoginOptions' => '3',
  172.             'lrt' => '',
  173.             'lrtPartition' =>'',
  174.             'hisRegion' => '',
  175.             'hisScaleUnit' => '',
  176.             'passwd' => $this->login_info['passwd'],
  177.             'ps' => '2',
  178.             'psRNGCDefaultType'=> '',
  179.             'psRNGCEntropy' => '',
  180.             'psRNGCSLK' => '',
  181.             'canary' => $this->data['canary'],
  182.             'ctx' => $this->data['ctx'],
  183.             'hpgrequestid' => $this->data['hpgrequestid'],
  184.             'flowToken' => $this->data['flowToken'],
  185.             'PPSX' => 'P',
  186.             'NewUser' => '1',
  187.             'FoundMSAs' => '',
  188.             'fspost' =>'0',
  189.             'i21' => '0',
  190.             'CookieDisclosure' => '0',
  191.             'IsFidoSupported' => '1',
  192.             'isSignupPost' => '0',
  193.             'i19' => '35114'
  194.         ];
  195.         $prepare_cookie = $client->getConfig('cookies');
  196.         $request_auth = $client->request('POST', $this->get_login_uri($this->data['Referer']), 
  197.             ['headers' => $headers_for_auth,
  198.              'form_params'=> $json , 
  199.              'cookies' => $prepare_cookie, 
  200.              'debug' => true]);
  201.  
  202.         $historyUri = $request_auth->getHeader(\GuzzleHttp\RedirectMiddleware::HISTORY_HEADER);
  203.  
  204.         $response_auth = $request_auth->getBody()->getContents();
  205.         $this->parse_SALMResponse($response_auth);
  206.         #$cookie_jar = $client->getConfig('cookies');
  207.         
  208.  
  209.     }
  210.  
  211.     public function parse_SALMResponse($raw_html)
  212.     {
  213.         $regExpFlowToken = '#name="SAMLResponse" value="("|)([^"]+)"#';
  214.         preg_match($regExpFlowToken, $raw_html, $saml_matches);
  215.         $this->SAMLResponse = $saml_matches[2];
  216.     }
  217.  
  218.     private function get_login_uri($referer)
  219.     {
  220.         $parse_uri_referer = parse_url($referer);
  221.         $parse = explode('/', $parse_uri_referer['path']);
  222.         return 'https://login.microsoftonline.com/'.$parse[1].'/login';
  223.     }
  224.  
  225.     // public function do_request_to_iqq_service($path, $data)
  226.     // {
  227.       
  228.     // }
  229.  
  230. }
  231.  
  232. $adapter = new AdapterIQQ();
  233.  
  234.  
  235. ?>
File Description
  • megamaster
  • PHP Code
  • 05 May-2022
  • 8.36 Kb
You can Share it: