• 审计dvwa高难度命令执行漏洞的代码,编写实例说明如下函数的用法


    审计dvwa高难度命令执行漏洞的代码

    ,编写实例说明如下函数的用法

    代码:

    1. <?php
    2. if( isset( $_POST[ 'Submit' ] ) ) {
    3. // Get input
    4. $target = trim($_REQUEST[ 'ip' ]);
    5. // Set blacklist
    6. $substitutions = array(
    7. '&' => '',
    8. ';' => '',
    9. '| ' => '',
    10. '-' => '',
    11. '$' => '',
    12. '(' => '',
    13. ')' => '',
    14. '`' => '',
    15. '||' => '',
    16. );
    17. // Remove any of the charactars in the array (blacklist).
    18. $target = str_replace( array_keys( $substitutions ), $substitutions, $target );
    19. // Determine OS and execute the ping command.
    20. if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
    21. // Windows
    22. $cmd = shell_exec( 'ping  ' . $target );
    23. }
    24. else {
    25. // *nix
    26. $cmd = shell_exec( 'ping  -c 4 ' . $target );
    27. }
    28. // Feedback for the end user
    29. echo "
      {$cmd}
      "
      ;
    30. }
    31. ?>

    trim

    此函数用于删除字符串两侧的空白字符或其他预定义字符。

    1. $username = $_GET['username'];
    2. $username = trim($username);
    3. echo($username)
    4. ?>

    接受表单传递过来的用户名,并使用trim() 函数删除其两侧任意的空格。

    str_replace

    这个函数用于搜索一个字符串并替换与另一个字符串匹配的部分。

    1. $test = "hello world!";
    2. $test = str_replace("world", "zs", $test);
    3. echo $test; // 输出为:"hello zs!"
    4. ?>

    使用str_replace() 函数讲“world”替换为“zs”

    array_keys

    这个函数返回数组中所有键名的一个新数组。

    1. <?php
    2. $test = array('a' => 'apple', 'b' => 'banana', 'c' => 'cherry');
    3. print_r(array_keys($test)); // 输出  Array ( [0=> a [1=> b [2=> c ) 
    4. ?>

    使用array_keys()函数获取数组中的所有键名。

    stristr 

    这个函数查找字符串在另一字符串中的第一次出现。

    1. $string = "hello world!";
    2. $findme = "world";
    3. $pos = strpos($string,$findme);
    4. if ($pos === false) {
    5. echo "The string '$findme' was not found in the string '$string'";
    6. } else {
    7. echo "The string '$findme' was found in the string '$string'";
    8. }
    9. ?>

    使用strpos()函数查找"World"是否存在于字符串"Hello, World!"中。

    php_uname

    这个函数返回关于服务器的信息,如主机名、操作系统名称和版本号等。

    1. echo php_uname();
    2. // 输出 Windows NT WIN-37QPUN7NO81 6.2 build 9200 (Windows Server 2012 Standard Edition) i586
    3. ?>

    使用php_uname()函数获取服务器信息。

  • 相关阅读:
    一短文读懂编译型与解释型编程语言
    C#上位机系列(4)—示波器一新窗口的建立
    安捷伦N8974A分析仪
    【2023联发科提前批笔试题】~ 题目及参考答案
    简单自定义MVC优化
    神经网络的问题总结
    IPV4跟IPV6的区别
    由ASP.NET Core根据路径下载文件异常引发的探究
    电脑扬声器未插入?4个方法帮你恢复声音!
    设计模式学习(二十四):Spring 中使用到的设计模式
  • 原文地址:https://blog.csdn.net/2301_79118231/article/details/134541012