PHP Weak type

Source: Internet
Author: User

Title: PHP is the best language in the World 1

Description: PHP is the world's best language URL, (http://way.nuptzj.cn/php/index.php)

1, we open the page, say is Can you authenticate to this website? Index.txt, change index.php to Index.txt, then we can see the PHP code.

2,php Code: <?php if (eregi ("Hackerdj", $_get[id]) {echo ("<p>not allowed!</p>"); exit ();} $_get[id] = UrlDecode ($_get[id]); if ($_get[id] = = "Hackerdj") {echo "<p>access granted!</p>"; echo "<p>flag: *****************} </p& gt; ";}? >, the problem with this topic is UrlDecode (), which we might think passed over $_get[id] is not URL encoded, but actually has been encoded by the URL. Then this problem only needs to be ID=HACKERDJ two times URL encoding.

Title: PHP is the best language in the World 2

Description: PHP is the best language in the world, this problem examines PHP weak type, url (http://45.63.58.62:8088/xedni.php)

1, first we look at the source code, can maliciously see the PHP code:<?php if (isset ($_get["password"]) && MD5 ($_get["password"]) = = "0") Echo file_get_contents ("/opt/flag.txt"); Else Echo file_get_contents ("xedni.php"); ?> , we see two = =, (compare ==   values only in PHP, different types will be converted to the same type comparison.) ===   must have the same value and type as true to compare types)

2, then is MD5 how to get 0 of the problem, we know that this knowledge point below will know how to do, we directly on the Baidu search (s878926199a, 240610708, Qnkcdzo, AABG7XSS, Aabc9rqs These are I find, can use), It's all settled now,

3, we enter on the original page: password=s878926199a, so you can get flag.

And then I'll give you some of these questions.

Title: Skynet Management System

Description: URL (http://ctf5.shiyanbar.com/10/web1/)

1, open the URL, the inside user name and password are admin, click "Login System" also useless. Do the PHP problem of the Web if you know the source code is more effective, right-click to view the source code, get the first view of the source code, found <!--$test =$_get[' username '); $test =md5 ($test); if ($test = = ' 0 ')-->

2, here asks us to enter a string, after MD5 equals 0, this is the test php weak type. Here I offer 4 values that can be passed: 240610708, Qnkcdzo, AABG7XSS, Aabc9rqs

3, as long as the user name entered any of the above 4 values, you will be prompted:/user.php?fame=hjkleffifer4, no doubt, we visit, you can see the code: $unserialize _str = $_post[' Password ']; $data _unserialize = unserialize ($unserialize _str); if ($data _unserialize[' user '] = = '??? ' && $data _unserialize[' pass ']== '??? ') {Print_r ($flag);} #伟大的科学家php方言道: Into also Boolean, defeated also Boolean. Go back, man. This code is not difficult to understand, that is, the post submitted by the password value "deserialization" (do not understand the Baidu bar, search php manual about the unserialize () function knowledge) to get an array, the user and pass in the array is required to print flag, Here because we don't know two??? What is it, we have to separate ways, starting from the weak PHP type,

True of the 5,bool type is equal to the weak type of any string, and when Unserialize () is present in the code, we can construct the bool type to achieve spoofing. Now we want an array, 2 elements, the user and pass, and the value is the bool type of true, so we get a:2:{s:4: "User"; B:1;s:4: "Pass"; b:1;}, this is deserialization, here I explain in detail,

It will not be explained later (A for array,s represents STRING,B on behalf of BOOL, and the number represents the number/length), so here a for the array array,2 represents the two parameters of the user and the pass,s represents the user is a string, 4, the user string length is 4, B is for type bool, and 1 is true. This is in different types with: and; split open. 6, return to the beginning of the page, enter the account password written above, log in to get flag.

When it comes to deserialization, I think of one more question.

Title: PHP deserialization

Introduction: URL (http://115.28.150.176/php1/index.php) (I do not know how this URL is not open now, you know the question is good) 1, this we will first see the code, <?php class just4fun { var $enter; var $secret; } if (isset($_GET[‘pass‘])) { $pass = $_GET[‘pass‘]; if(get_magic_quotes_gpc()){ $pass=stripslashes($pass); } $o = unserialize($pass); if ($o) { $o->secret = "*"; if ($o->secret === $o->enter) echo "Congratulation! Here is my secret: ".$o->secret; else echo "Oh no... You can‘t fool me"; } else echo "are you trolling?"; } ?>

Declares a class that contains, in this class, $enter $secret two members, first deserializing the passed-in $pass parameter, and passes the argument to $o. If $o->secret === $o->enter , so long output so-called secret, namely O->secret.

2, we first get the parameters we passed in, deserialize them, assign values to secret in $o, and compare $o->secret and $o->enter for equality. Note that this is ' = = = '. 3, in PHP ordinary value assignment behavior is an exception is encountered object, in PHP 5 is a reference assignment, unless explicitly using the Clone keyword to copy, PHP support reference assignment, using "$var = & $othervar;" Grammar. A reference assignment means that two variables point to the same data and nothing is copied. 4, knowing what is said above, we can change the above code:<?php class just4fun { var $enter; var $secret; } $o = new just4fun(); $o->enter = &$o->secret; //这里是重点。我们使用引用传参的特点,让$o->secret的值和$o->enter的值,这样两个变量就永远相等了 echo serialize($o); ?>

5, the serialized string is: O:8: "Just4Fun": 2:{s:5: "Enter"; N;s:6: "Secret"; R:2, run your own code locally to get the following figure

6, and then copy these to commit and get flag:nctf{serialize_and_unserialize}.

PS: For details please refer to (http://115.159.210.46/archives/19.html), I also refer to this.

PHP Weak type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.