常用函数
stripslashes()
: 去掉反斜杠\
。比如,\'
变成'
,\\
变成\
。
addslashes()
:对单引号、双引号、反斜杠、空字节等需要escape的字符增加反斜杠\
。
get_magic_quotes_gpc()
:
在PHP 5.4.0之前,PHP的magic_quotes_gpc
这个directive默认是on的,并且它会对所有GET, POST and COOKIE数据进行addslashes()
操作,所以不该再对已经addslashes() 对数据再次addslashes(),不然失去了addslashes()的功效。于是,get_magic_quotes_gpc()就是用来判断PHP的magic_quotes_gpc
这个directive是否为on的。
生成随机数
// 'Reset code' generation
$reset_code = random_string();
$reset_code = hash("sha1", $reset_code, false);
CSRF检查
来自dedecms V5.7 SP2
function csrf_check()
{
global $token;
if(!isset($token) || strcasecmp($token, $_SESSION['token']) != 0){
echo '<a href="http://bbs.dedecms.com/907721.html">DedeCMS:CSRF Token Check Failed!</a>';
exit;
}
}
测试
>>> $cqq = array('cqq', 'hello', 'world');
=> [
"cqq",
"hello",
"world",
]
>>> $cqq = implode('|', $cqq);
=> "cqq|hello|world"
>>> $num = array(1,2,3,4);
=> [
1,
2,
3,
4,
]
>>> $num = implode('\\', $num)
=> "1\2\3\4"
看到implode()
的作用就是在一个数组的每个元素之间插入一个字符串,然后得到一个新的字符串啊。对int类型也适用,反正最终要输出一个字符串。
拦截白名单
参考:
https://www.leavesongs.com/PENETRATION/360webscan-bypass.html
/**
* 拦截目录白名单
*/
function webscan_white($webscan_white_name,$webscan_white_url_t=array()) {
$url_path=$_SERVER['PHP_SELF'];
$url_var=$_SERVER['QUERY_STRING'];
if (preg_match("/".$webscan_white_name."/is",$url_path)==1) {
return false;
}
foreach ($webscan_white_url_t as $webscan_white_url) {
foreach ($webscan_white_url as $key => $value) {
if(!empty($url_var)&&!empty($value)){
if (stristr($url_path,$key)&&stristr($url_var,$value)) {
return false;
}
}
elseif (empty($url_var)&&empty($value)) {
if (stristr($url_path,$key)) {
return false;
}
}
}
}
return true;
}
套路
在index.php
中
<?php
require_once('class.php');
if($_SESSION['username']) {
header('Location: profile.php');
}
?>
而在class.php
中
<?php
//...
session_start();
?>
不然在index.php
中$_SESSION
对象的值为空。
在一个php文件中后面写class,前面做测试
<?php
//session_start();
//var_dump($_SESSION)
function filter($string) {
// 这里的array中的两个元素一个是' 另一个是\\。加上\是为了转义
$escape = array('\'', '\\\\');
// print_r()函数比var_dump()更易读
print_r($escape);
// implode用于向一个数组的每个元素之间插入一个字符串,然后得到一个新的字符串
$escape = '/' . implode('|', $escape) . '/';
print_r($escape);
$string = preg_replace($escape, '_', $string);
$safe = array('select', 'insert', 'update', 'delete', 'where');
// implode用于向一个数组的每个元素之间插入一个字符串,然后得到一个新的字符串
$safe = '/' . implode('|', $safe) . '/i';
return preg_replace($safe, 'hacker', $string);
}
// 加入@就可以避免终端输出错误信息
@filter();
function test_serialize(){
$cqq = new User("caiqiqi", "qcc");
echo serialize($cqq);
echo "\n";
echo gettype($cqq);
//var_dump($cqq);
}
function test_class(){
$user = new User("caiqiqi", "qcc");
echo $user->__tostring();
}
//test_class();
class User{
private $name = null;
private $pass = null;
function __construct($pname, $ppasswd){
$this->name = $pname;
$this->pass = $ppasswd;
}
public function __tostring(){
return __class__;
}
}