testtest - 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 testtest.php

  1. <?php
  2.     private $urls_path = [
  3.         'auth' => 'identityiq/home.jsf',// document - get
  4.         'setTimeZone' => 'identityiq/ui/setTimeZone.jsf',// document - get
  5.         'access' => '/identityiq/accessRequest/accessRequest.jsf', // document - get CSRF & XSRF parse
  6.         'filter' => '/path/to/action', //
  7.         'get' => '/path/to/action',
  8.         'filter_group' => '/path/to/action',
  9.     ];
  10.  
  11.     private $data = [];
  12.  
  13.     private $SAMLResponse;
  14.     
  15.     private $CSRF;
  16.     private $XSRF;
  17.  
  18.     public function __construct()
  19.     {
  20.         $this->client = new Client(['cookies' => true]);
  21.        # $this->client->setDefaultOptions('verify', false);
  22.         $this->init_process_login();
  23.     }
  24.  
  25.     private function init_process_login()
  26.     {
  27.         $this->get_landing_context_azure();
  28.         $this->send_username_info();
  29.         $this->do_auth_in_azure();
  30.  
  31.         $json = [
  32.             'SAMLResponse' => $this->SAMLResponse,
  33.             'RelayState' => $this->url_base.$this->urls_path['auth']
  34.         ];
  35.  
  36.         $this->get_session_iiq_service('POST', $json );
  37.  
  38.         $this->get_session_iiq_service('GET', false);
  39.     }
  40.  
  41.     public function get_landing_context_azure()
  42.     {
  43.         $client = $this->client;
  44.         $headers_init = [
  45.             'Connection' => 'keep-alive',
  46.             'Host'=> 'iqq.abbott.com',
  47.             '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'
  48.          ];
  49.      
  50.         $landing = $client->request('GET', $this->url_base, [/*'headers' => $headers_init,*/ 
  51.                                                                         'debug'=> false,
  52.                                                                         'verify' => false,
  53.                                                                         'allow_redirects' => ['track_redirects' => true]]);
  54.             $raw_html = $landing->getBody()->getContents();
  55.             $cookie_jar = $client->getConfig('cookies');
  56.             $headers = $landing->getHeaders();
  57.             $historyUri = $landing->getHeader(\GuzzleHttp\RedirectMiddleware::HISTORY_HEADER);
  58.             
  59.             $data = [
  60.                 'flowToken' => $this->search_in_serverData('sFT', $raw_html),
  61.                 'ctx' => $this->search_in_serverData('sCtx', $raw_html),
  62.                 'requestId' =>null /*$this->search_in_serverData('requestId', $raw_html)*/,
  63.                 'apiCanary' => $this->search_in_serverData('apiCanary', $raw_html),
  64.                 'canary' => $this->search_in_serverData('canary', $raw_html),
  65.                 'correlationId' => $this->search_in_serverData('correlationId', $raw_html),
  66.                 'x-ms-request-id' => $headers['x-ms-request-id'][0],
  67.                 'client-request-id' => $this->search_in_serverData('correlationId', $raw_html),
  68.                 'hpgrequestid' => $this->search_in_serverData('sessionId', $raw_html),
  69.                 'Referer' => $historyUri[1]
  70.             ];
  71.  
  72.             $this->data = $data;
  73.             // var_dump($data);
  74.  
  75.         }
  76.         
  77.  
  78.  
  79.     private function search_in_serverData($name, $data)
  80.     {
  81.  
  82.         $regExp = '/"'.$name.'":"(.*?)"/';
  83.             preg_match($regExp, $data, $mathes);
  84.         return $mathes[1];
  85.  
  86.     }
  87.  
  88.     public function send_username_info()
  89.     {
  90.         $client = $this->client;
  91.  
  92.         $headers_for_login = [
  93.             'Accept' => 'application/json',
  94.             'canary' => $this->data['canary'],
  95.             'Referer' => $this->data['Referer'],
  96.             'Origin' => 'https://login.microsoftonline.com',
  97.             'client-request-id' => $this->data['client-request-id'],
  98.             'hpgact' => '1900',
  99.             'hpgid' => '1104',
  100.             'Host' => 'login.microsoftonline.com',
  101.             'hpgrequestid' => $this->data['hpgrequestid'],
  102.             'Content-Type' => 'application/json; charset=UTF-8',
  103.             'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'    
  104.         ];
  105.  
  106.         
  107.         $body_request = [
  108.             'checkPhones' => false,
  109.             'country' => 'DE',
  110.             'federationFlags' => 0,
  111.             'flowToken' => $this->data['flowToken'],
  112.             'forceotclogin' => false,
  113.             'isAccessPassSupported' => true,
  114.             'isCookieBannerShown' => false,
  115.             'isExternalFederationDisallowed' => false,
  116.             'isFidoSupported' => false,
  117.             'isOtherIdpSupported' => true,
  118.             'isRemoteConnectSupported' => false,
  119.             'isRemoteNGCSupported' => true,
  120.             'isSignup' => false,
  121.             'originalRequest' => $this->data['ctx'],
  122.             'username' => $this->login_info['username'],
  123.         ];
  124.  
  125.         $cookie_jar = $client->getConfig('cookies');
  126.  
  127.         $send_login = $client->request('POST', 'https://login.microsoftonline.com/common/GetCredentialType?mkt=en-US',
  128.                                         ['headers' => $headers_for_login,
  129.                                          'json' => $body_request,
  130.                                          'cookies' => $cookie_jar] );
  131.  
  132.         
  133.     }
  134.  
  135.     public function do_auth_in_azure()
  136.     {
  137.         $client = $this->client;
  138.  
  139.  
  140.         $headers_for_auth = [
  141.             'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  142.             'Referer' => $this->data['Referer'],
  143.             'Origin' => 'https://login.microsoftonline.com',
  144.             'client-request-id' => $this->data['client-request-id'],
  145.             'hpgact' => '1900',
  146.             'hpgid' => '1104',
  147.             'Host' => 'login.microsoftonline.com',
  148.             'hpgrequestid' => $this->data['hpgrequestid'],
  149.             'Content-Type' => 'application/x-www-form-urlencoded',
  150.             'Content-Length' => '1531',
  151.             'sec-ch-ua' => '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
  152.             'sec-ch-ua-platform' => '"Windows"',
  153.             'sec-ch-ua-mobile' => '?0',
  154.             'Sec-Fetch-Dest' => 'document',
  155.             'Sec-Fetch-Mode' => 'navigate',
  156.             'Sec-Fetch-Site' => 'same-origin',
  157.             'Sec-Fetch-User' => '?1',
  158.             'Upgrade-Insecure-Requests' => '1',
  159.             'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'    
  160.         ];
  161.  
  162.         $json = [
  163.             'i13' => '0',
  164.             'login' => $this->login_info['username'],
  165.             'loginfmt' => $this->login_info['username'],
  166.             'type'=> '11',
  167.             'LoginOptions' => '3',
  168.             'lrt' => '',
  169.             'lrtPartition' =>'',
  170.             'hisRegion' => '',
  171.             'hisScaleUnit' => '',
  172.             'passwd' => $this->login_info['passwd'],
  173.             'ps' => '2',
  174.             'psRNGCDefaultType'=> '',
  175.             'psRNGCEntropy' => '',
  176.             'psRNGCSLK' => '',
  177.             'canary' => $this->data['canary'],
  178.             'ctx' => $this->data['ctx'],
  179.             'hpgrequestid' => $this->data['hpgrequestid'],
  180.             'flowToken' => $this->data['flowToken'],
  181.             'PPSX' => 'P',
  182.             'NewUser' => '1',
  183.             'FoundMSAs' => '',
  184.             'fspost' =>'0',
  185.             'i21' => '0',
  186.             'CookieDisclosure' => '0',
  187.             'IsFidoSupported' => '1',
  188.             'isSignupPost' => '0',
  189.           //  'i19' => '35114'
  190.         ];
  191.  
  192.  
  193.         $prepare_cookie = $client->getConfig('cookies');
  194.  
  195.         $request_auth = $client->request('POST', $this->get_login_uri($this->data['Referer']), 
  196.             [/* 'headers' => $headers_for_auth, */
  197.              'form_params'=> $json , 
  198.              'cookies' => $prepare_cookie, 
  199.              'debug' => false]);
  200.  
  201.         $historyUri = $request_auth->getHeader(\GuzzleHttp\RedirectMiddleware::HISTORY_HEADER);
  202.  
  203.         $response_auth = $request_auth->getBody()->getContents();
  204.         $this->parse_SALMResponse($response_auth);
  205.         #$cookie_jar = $client->getConfig('cookies');
  206.         
  207.  
  208.     }
  209.  
  210.     private function parse_SALMResponse($raw_html)
  211.     {
  212.         $regExpFlowToken = '#name="SAMLResponse" value="("|)([^"]+)"#';
  213.         preg_match($regExpFlowToken, $raw_html, $saml_matches);
  214.         $this->SAMLResponse = $saml_matches[2];
  215.     }
  216.  
  217.     private function get_login_uri($referer)
  218.     {
  219.         $parse_uri_referer = parse_url($referer);
  220.         $parse = explode('/', $parse_uri_referer['path']);
  221.         return 'https://login.microsoftonline.com/'.$parse[1].'/login';
  222.     }
  223.  
  224.  
  225.     private function get_session_iiq_service($method, $json)
  226.     {
  227.         $client = $this->client;
  228.         //TODO поправить заголовки по феншую. 
  229.         $headers_for_session_iiq = [
  230.             'Accept' => 'application/json',
  231.             'Referer' => $this->data['Referer'],
  232.             'Origin' => 'https://login.microsoftonline.com',
  233.             'client-request-id' => $this->data['client-request-id'],
  234.             'hpgact' => '1900',
  235.             'hpgid' => '1104',
  236.             'Host' => 'login.microsoftonline.com',
  237.             'hpgrequestid' => $this->data['hpgrequestid'],
  238.             'Content-Type' => 'application/json; charset=UTF-8',
  239.             'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'    
  240.         ];
  241.         $cookie_jar = $client->getConfig('cookies');
  242.         // $json = [
  243.         //     'SAMLResponse' => $this->SAMLResponse,
  244.         //     'RelayState' => $this->url_base.$this->urls_path['auth']
  245.         // ];
  246.         $params =  [
  247.             /*'headers' => $headers_for_session_iiq,*/ 
  248.             'debug'=> false,
  249.             'verify' => false,
  250.             'cookie' => $cookie_jar,
  251.         /*'allow_redirects' => false*/
  252.         ];
  253.  
  254.         if($json){
  255.             $params = array_merge($params, ['form_params' => $json]);
  256.         }
  257.  
  258.         $init_session = $client->request($method, $this->url_base.$this->urls_path['auth'],$params);
  259.         
  260.        // $historyUri = $init_session->getHeader(\GuzzleHttp\RedirectMiddleware::HISTORY_HEADER);
  261.         
  262.         if(!$json){
  263.             var_dump($init_session->getBody()->getContents());
  264.           //  var_dump($client->getConfig('cookies'));
  265.         }
  266.         
  267.  
  268.     }
  269.  
  270.     private function get_csrf_token($raw_html)
  271.     {
  272.  
  273.     }
  274.  
  275.     public function get_user($user_id)
  276.     {
  277.         $client = $this->client;
  278.         //TODO поправить заголовки по феншую. 
  279.         $headers_for_session_iiq = [
  280.             'Accept' => 'application/json',
  281.             'Referer' => $this->data['Referer'],
  282.             'Origin' => 'https://login.microsoftonline.com',
  283.             'client-request-id' => $this->data['client-request-id'],
  284.             'hpgact' => '1900',
  285.             'hpgid' => '1104',
  286.             'Host' => 'login.microsoftonline.com',
  287.             'hpgrequestid' => $this->data['hpgrequestid'],
  288.             'Content-Type' => 'application/json; charset=UTF-8',
  289.             'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'    
  290.         ];
  291.  
  292.         $cookie_jar = $client->getConfig('cookies');
  293.  
  294.         $json = [
  295.             'SAMLResponse' => $this->SAMLResponse,
  296.             '' => $this->url_base.$this->urls_path['auth']
  297.         ];
  298.  
  299.  
  300.         $request = $client->request('POST', $this->url_base, ['headers' => $headers_for_session_iiq, 
  301.                                                                     'debug'=> false,
  302.                                                                     'verify' => false,
  303.                                                                     'cookie' => $cookie_jar,
  304.                                                                     'allow_redirects' => ['track_redirects' => true]]);
  305.         
  306.         
  307.         $result = $request->getBody()->getContents();
  308.  
  309.         return $result;
  310.     }
  311.  
  312.  
  313.  
  314.  
  315. }
  316.  
  317. $adapter = new AdapterIQQ();
  318.  
File Description
  • testtest
  • PHP Code
  • 20 May-2022
  • 11.69 Kb
You can Share it: