Skip to content

Instantly share code, notes, and snippets.

@hakasenyang
Created April 19, 2021 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakasenyang/bd56e78e9d648585c0024dfd18c8cb77 to your computer and use it in GitHub Desktop.
Save hakasenyang/bd56e78e9d648585c0024dfd18c8cb77 to your computer and use it in GitHub Desktop.
KT carrier reset (PHP)
<?php
class WEBParser
{
private $httph = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36';
public function splits($data, $first, $end, $num = 1)
{
$temp = @explode($first, $data);
$temp = @explode($end, $temp[$num]);
$temp = $temp[0];
return $temp;
}
public function WEBParsing($url, $cookie = NULL, $headershow = TRUE, $postparam = NULL, $otherheader = NULL)
{
$ch = curl_init();
$opts = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_HEADER => $headershow,
CURLOPT_USERAGENT => $this->httph,
);
curl_setopt_array($ch, $opts);
if ($otherheader) curl_setopt($ch, CURLOPT_HTTPHEADER, $otherheader);
if ($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
if ($postparam)
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postparam);
}
$data = curl_exec($ch);
if (curl_errno($ch))
return curl_errno($ch);
curl_close($ch);
return ($data) ? $data : false;
}
}
/** Initialize Parser */
$parse = new WEBParser();
/** Check after accessing the access.olleh.com page. */
$tmp = $parse->WEBParsing('http://access.olleh.com/');
/** URL Check */
preg_match_all('/(?:Location: https?:\/\/)([-\w\.]+)+(:\d+)?(([\w\/\_\.]*(\?\S+)?)?)?/', $tmp, $tmp_url);
$https = stripos($tmp, 'https://') ? true : false;
/** Check Variable (URL) */
if (is_null($tmp_url[1][0])) die('Cannot find URL...' . PHP_EOL);
/** Get URL */
$url = trim($tmp_url[1][0]);
if (!stripos($url, 'olleh.com') && !stripos($url, 'kt.com')) die('It is not a KT URL address.' . PHP_EOL);
/** Port, Original URL, ... */
$port = ($tmp_url[2][0]) ? trim($tmp_url[2][0]) : NULL;
$origurl = (($https) ? 'https://' : 'http://') . $url . $port . $tmp_url[3][0];
$main = (($https) ? 'https://' : 'http://') . $url . $port;
/** POST args */
preg_match_all('/[\?&](?:[\w]+)=([\w\.]+)/', $tmp_url[5][0], $tmp_arg);
if (is_null($tmp_arg[1][0]) || is_null($tmp_arg[1][1])) die('Variable find error' . PHP_EOL);
$n1 = trim($tmp_arg[1][0]);
$n2 = trim($tmp_arg[1][1]);
/** Get Cookies (PHPSESSID) - Needed */
$start = $parse->WEBParsing($origurl);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $start, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}
// var_dump($cookies);
/** Cookie error */
if (is_null($cookies['PHPSESSID'])) die('Cookie error' . PHP_EOL);
/** Must connect this page */
$second = $parse->WEBParsing($main . '/enterAdminId.html?sso=' . $n1 . '&no=' . $n2, 'PHPSESSID=' . $cookies['PHPSESSID'], true);
if (!stripos($second, '<h1><a href="http://access.olleh.com" title="')) die('Problems accessing the 2nd page.' . PHP_EOL);
/** RESET!!! */
$end = $parse->WEBParsing($main . '/reauth_said.html', 'PHPSESSID=' . $cookies['PHPSESSID'], true, 'userID=reset&userPW=reset1&sso=' . $n1 . '&no=' . $n2,
array('Referer: ' . $main . '/enterAdminId.html?sso=' . $n1 . '&no=' . $n2)
);
/** Success? */
if (stripos($end, 'Location: error.html?sso=')) die('KT reset was successful!!!' . PHP_EOL);
die('The problem occurred at the end...' . PHP_EOL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment