php用于黑名单利用相关函数

首先对DVWA代码执行高级进行一下简单代码审计查看一下它所使用的函数

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
    // Get input
    $target = trim($_REQUEST[ 'ip' ]);

    // Set blacklist
    $substitutions = array(
        '&'  => '',
        ';'  => '',
        '| ' => '',
        '-'  => '',
        '$'  => '',
        '('  => '',
        ')'  => '',
        '`'  => '',
        '||' => '',
    );

    // Remove any of the charactars in the array (blacklist).
    $target = str_replace( array_keys( $substitutions ), $substitutions, $target );

    // Determine OS and execute the ping command.
    if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
        // Windows
        $cmd = shell_exec( 'ping  ' . $target );
    }
    else {
        // *nix
        $cmd = shell_exec( 'ping  -c 4 ' . $target );
    }

    // Feedback for the end user
    echo "<pre>{$cmd}</pre>";
}

?>

通过源码审计发现,它使用array生成一个数组作为黑名单进行过滤。

主要利用函数:

    trim

主要作用:trim函数用于删除字符串两侧的空白字符或其他预定义字符

举例:

<?php
$email = "   example@example.com    ";
$clean_email = trim($email);
echo $clean_email;

?>

执行结果:

example@example.com


    str_replace

主要作用:str_replace() 它用于在字符串中的某个位置替换文本或字符

基本语法:mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

  • $search:要查找的值。
  • $replace:要用作替代值的新值。
  • $subject:要在其中进行搜索和替换操作的字符串或数组。
  • $count (可选):为进行计数而传入的变量名。

举例:

<?php
$original = "hello, world!";
$find     = "world";
$replace  = "xiaohei";

$new_string = str_replace($find, $replace, $original);

echo $new_string;
?>

执行结果:

hello,xiaohei


    array_keys

主要作用:array_keys() 函数用于从关联数组中返回所有键名

举例:

<?php

$person = array("name"=>"Tom", "age"=>26);

$key = array_keys($person);

print_r($key);
?>

执行结果:

Array
(
    [0] => name
    [1] => age
)


    stristr

主要作用:stristr()它的工作方式与 strstr() 函数类似,但它是不区分大小写的

描述:此函数会在字符串中搜索给定的值,并从该值首次出现的位置开始直到字符串结束为止返回该部分的字符串。如果未找到该值,则返回 false

举例:

<?php

$str = "Hello, World!";
$find = "world";

$result = stristr($str, $find);

echo $result; // 输出 "World!"

?>


    php_uname

主要作用:php_uname()它返回有关服务器的信息,例如主机名、操作系统名称和版本号等

举例:

<?php
echo php_uname();
?>

执行结果:

Linux:
Linux localhost.localdomain 5.4.0-96-generic #120-Ubuntu SMP Wed Mar 9 21:½1:59 UTC 2023 x86_64
windows:
Windows NT �� 10.0 build 22631 (Windows 10) AMD64

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值