Authorization in the personal Cabinet MTS using CURL?

Hi all. You must use PHP to log in the personal Cabinet MTS.
I'm doing a query on the website https://lk.ssl.mts.ru/ and the answer I came this
5b50a43506f7a964605248.png
I'm trying to get out of shape parameters and send post request. In the result I come up with this answer
5b50a7b26d11e172475306.png
Who can tell what it is?
Here is the piece of code curl
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$phone = '915111111';
$pass = '11111';
$aHeaders = array(
 'Connection: keep-alive',
 'Upgrade-Insecure-Requests: 1',

 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
 'Accept-Encoding: gzip, deflate, sdch, br',
 'Accept-Language: ru-ru,ru;q=0.9,en-US;q=0.8,en;q=0.7'
);
$ch = curl_init();
curl_setopt($ch, THIS, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/' . $phone . '-cookie.txt'); // save cookies to a file
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/' . $phone . '-cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36');


function CURL($url, $aPost=array(), $aHeaders=array()){
 global $ch;
 curl_setopt($ch, CURLOPT_URL, $url);
 if(is_array($aPost) && count($aPost)){
 curl_setopt($ch, CURLOPT_POST, 1); // use the data in post
 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aPost));
}
if(count($aHeaders)){
 curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeaders);
}
 $html = curl_exec($ch);
 if(curl_exec($ch) === false) {
 $error = 'curl Error :' . curl_error($ch);
 print_r( $error);
 return false;
}
 else {
 return $html;
}
}


function ParseForm($htmlForm)
{
 $valueRegExp = '/value\\s*=\\s*("[^"]*"|\'[^\']*\'|[\\w\\-\\/\\\\]+)/i';
 $inputRegExp = '/<input[^-->]+name\\s*=\\s*("[^"]*"|\'[^\']*\'|[\\w\\-\\/\\\\]+)[^>]*>|<select[^>]+name\\s*=\\s*("[^"]*"|\'[^\']*\'|[\\w\\-\\/\\\\]+)[^>]*>[\\s\\S]*?<\\/select>/i';
 $returnValue = preg_match_all($inputRegExp, $htmlForm, $matches);
 if (!count($matches)) {
 return false;
}

 $aResult = array();
 foreach ($matches[0] as $key => $sStr) {
 $value = null;
 $name = ";
 $nameInput = $matches[1][$key];
 $selInput = $matches[2][$key];
 if ($nameInput) {
 if (preg_match('/type\s*=\s*[\'"]?button[\'"]?/i', $sStr, $matchesButton)) {
 $value = 'undefined';
 } else if (preg_match('/type\s*=\s*[\'"]?checkbox[\'"]?/i', $sStr, $matchesCheckbox)) {
 if (preg_match('/[^\w\-]checked[^\w\-]/i', $sStr, $matchesCheckbox)) {
 preg_match($valueRegExp, $sStr, $matchesValue);
 $value = isset($matchesValue[1]) ? $matchesValue[1] : 'on';
}
 } else {
 preg_match($valueRegExp, $sStr, $matchesValue);
 $value = isset($matchesValue[1]) ? $matchesValue[1] : ";
}
 $name = preg_replace('/^"([^"]*)"$|^\'([^\']*)\'$/', '$1$2', $nameInput) ;
 } //value = /[^\w\-]checked[^\w\-]/i.test(str) ? getParam(str, nullVal, nullVal, valueRegExp, valueReplace) || 'on' : undefined;

 else if ($selInput) {
 $name = preg_replace('/^"([^"]*)"$|^\'([^\']*)\'$/', '$1$2', $selInput) ;

}
 if ($value != 'undefined') {
 $aResult[$name] = $value;
}
}
 if (preg_match('/type=\"submit\" value=\"(.*?)\"/i', $htmlForm, $matchesSubmit)) {
 // print_r($matchesSubmit);
}

 return $aResult;
}
function endsWith($str, $suffix) {
 if(strrpos($str, $suffix, -1) === false){
 return false;
}
 return true;
}


function joinUrl($url, $path) {
 if (!$path) //Empty path
 return $url;
 if (preg_match('/^\//', $path)){
 //Absolute path
 return preg_replace('/^(\\w+:\\/\\/[\\w.\\-]+).*$/', '$1'.$path, $url );
}

 if (preg_match('/^\w+:\/\//', $path)) {
 return $path;
}
 //relative path
 $url = preg_replace('/\\?.*$/', ", $url);

 if (preg_match('/:\\/\\/.*\\//', $url)){
 $url = $url = preg_replace('/\\/[^\\/]*$/', '/', $url);
}
 if (!endsWith($url, '/'))
 $url .= '/';
 return $url + $path;
}

redirectIfNeeded function($html, $url){
 //Needed redirect form...
 if(preg_match('/<body[^>]+onload[^>]+submit/i', $html, $matches)){
 $aPost = ParseForm($html);
 $action = ";
 if(preg_match('/<form[^>]+action=[\'"]([^\'"]*)/', $html, $matchesAction)){
 $action = $matchesAction[1];
}
 $url = joinUrl($url, $action);
 $aHeadersNew = array_merge($GLOBALS['aHeaders'], array('Refefer: '.$url));

 $html = CURL($url, $aPost, $aHeadersNew);
 $html = mb_convert_encoding($html, 'UTF-8');

print_r($html);

}

 //return $html;
}

/*********************/



$url = "https://lk.ssl.mts.ru/";
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);


$html = redirectIfNeeded($html, $url);
//├ąprint_r($html);

return;</form[^></body[^></select[^>
June 3rd 19 at 19:40
2 answers
June 3rd 19 at 19:42
Although the answer says 500 error and suggests to try later.
Maybe someone knows whether it is possible to get on https://login.mts.ru/amserver/UI/Login?service=lk&...
June 3rd 19 at 19:44
first remove the Accept-Encoding: gzip, deflate, sdch, br to not get crinkled text
Without this header, I always get error 500

5b50bd3de3457335394127.png - conor.Ko commented on June 3rd 19 at 19:47
Further analyze all traffic during authorization in order to pretend to be a "real" user, pay attention to the different tokens and headers. - Dominic_Ja commented on June 3rd 19 at 19:50
Advise what better to do on a Mac? - conor.Ko commented on June 3rd 19 at 19:53
any browser that supports DevTools, I personally use chrome - Dominic_Ja commented on June 3rd 19 at 19:56

Find more questions by tags MTSPHP