PHP头条
热点:

PHP大法,


http://www.shiyanbar.com/ctf/54
PHP大法
注意备份文件
解题链接: http://ctf5.shiyanbar.com/DUTCTF/index.php




解:点击弹出:Can you authenticate(认证) to this website? index.php.txt

首先访问http://ctf5.shiyanbar.com/DUTCTF/index.php.txt得到以下代码:

<?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>";
}
?>
int eregi ( string$pattern , string$string [, array&$regs ] )以区分大小写的方式在 string 中寻找与给定的正则表达式 pattern 所匹配的子串。php7没法用见下文。

根据代码意思:
首先eregi()函数进行一次比较判断,如果想打印flag,id不能等于"hackerDJ" ,并且经过url解码后id等于"hackerDJ"

Example #1 $_GET 范例
<?php
echo 'Hello ' . htmlspecialchars($_GET["name"]) . '!';
?>  
假设用户访问的是 http://example.com/?name=Hannes 
以上例程的输出类似于:
Hello Hannes!

综上就是要访问http://ctf5.shiyanbar.com/DUTCTF/index.php.txt?id=xxxxxx就能得到flag


分析:怎么求id值呢?由于在浏览器输入url后会进行一次decode,这段代码中又进行一次decode,所以应对hackerDJ进行两次encode,网上在线url编码还是hackDJ浏览器直接送hackerDJ不认,

Url编码通常也被称为百分号编码(percent-encoding),是因为它的编码方式非常简单,使用%百分号加上两位的字符——0123456789ABCDEF——代表一个字节的十六进制形式。
1.对于ASCII字符,字母a 在ASCII码中对应的字节是0x61,那么Url编码之后得到的就是%61,字母abc, url编码后得到的就是%61%62%63
2.对于非ASCII字符,RFC文档建议使用utf-8对其进行编码得到相应的字节,然后对每个字节执行百分号编码。

3.如"中文"使用UTF-8字符集得到的字节为0xE4 0xB8 0xAD 0xE6 0x96 0x87,经过Url编码之后得到"%E4%B8%AD%E6%96%87"。

>>> ord('h')
104
>>> hex(104)
'0x68'
>>>
h==>url.encode为%68  

%===》url.encode为%25

最后合在一起%2568开头(实践验证如下)

解释%经过url编码是%25



说明代码中eregi 函数,就是说在 PHP5.3、PHP7 里是不能正常使用该函数的。
解决办法是用 preg_match() i 参数替代,可以把相关代码做如下修改:
eregi ( “^[_0-9a-z-]{1,30}$”, $key );
改为:
preg_match ( “/^[_0-9a-z-]{1,30}$/i”, $key );

测试一  代码吧运行成功,一次加密就是%68

<?php
$id = '%68ackerDJ';
if(preg_match("/hackerDJ/i",$id)) {
  echo("<p>not allowed!</p>");
  exit();
}
//$id = urldecode($id);
$id = urldecode($id);
if($id == "hackerDJ")
{
  echo "<p>Access granted!</p>";
  echo "<p>flag: *****************} </p>";
}
?>

测试二  代码吧运行成功,二次加密就是%2568
<?php
$id = '%2568ackerDJ';
if(preg_match("/hackerDJ/i",$id)) {
  echo("<p>not allowed!</p>");
  exit();
}
$id = urldecode($id);
$id = urldecode($id);
if($id == "hackerDJ")
{
  echo "<p>Access granted!</p>";
  echo "<p>flag: *****************} </p>";
}
?>

测试代码如果正确也就是id找对了就会有下面的界面:



最后爆出flag的URL           http://ctf5.shiyanbar.com/DUTCTF/index.php?id=%2568ackerDJ



www.phpzy.comtrue/php/18588.htmlTechArticlePHP大法, http://www.shiyanbar.com/ctf/54 PHP大法 注意备份文件 解题链接: http://ctf5.shiyanbar.com/DUTCTF/index.php 解:点击弹出:Can you authenticate(认证) to this website? index.php.txt 首先访问http://ctf...

相关文章

    暂无相关文章

PHP之友评论

今天推荐