• Upload-labs(Pass3-4)


    练习网站:upload-labs

    注意:

    能运行phpinfo();?>

    就能运行一句话木马

    本文使用主要是为了简便

    知识点

    $_FILES[表单提交过来的name]

    [name]:获取到的文件名

    [type]: 获取到的文件类型(MIMETYPE)

    [tmp_name]:文件临时存放的路径

    [error]: 上传文件报错信息(为空则上传成功)

    [size]:上传文件的大小

    Move_uploaded_file(需要移动的文件,要移动到的位置)

    Strrchr(指定字符串,匹配的字符) --指针指到指定的字符的位置,取之后的值

    Trim() --去除字符串中的前后空格

    Rtrim() --去除右空格

    Ltrim() --去除左空格

    Strtolower() --将字符串转为小写

    Str_ireplace --(被转换的字符串,替换成的字符串,需要查找的字符串)

    在需要查找的字符串中查找需要被替换的字符串,替换为指定的字符串

    Pass-03(本关需要使用自己搭建upload-labs)

    upload-labs资源

    链接:https://pan.baidu.com/s/1uOM7sSAFusLk-973SkZlCw 
    提取码:ctyl 

    代码:

    1. $is_upload = false;
    2. $msg = null;
    3. if (isset($_POST['submit'])) {
    4. if (file_exists(UPLOAD_PATH)) {
    5. $deny_ext = array('.asp','.aspx','.php','.jsp');
    6. $file_name = trim($_FILES['upload_file']['name']);
    7. $file_name = deldot($file_name);//删除文件名末尾的点
    8. $file_ext = strrchr($file_name, '.');
    9. $file_ext = strtolower($file_ext); //转换为小写
    10. $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
    11. $file_ext = trim($file_ext); //收尾去空
    12. if(!in_array($file_ext, $deny_ext)) {
    13. $temp_file = $_FILES['upload_file']['tmp_name'];
    14. $img_path = UPLOAD_PATH.'/'.date("YmdHis").rand(1000,9999).$file_ext;
    15. if (move_uploaded_file($temp_file,$img_path)) {
    16. $is_upload = true;
    17. } else {
    18. $msg = '上传出错!';
    19. }
    20. } else {
    21. $msg = '不允许上传.asp,.aspx,.php,.jsp后缀文件!';
    22. }
    23. } else {
    24. $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
    25. }
    26. }

    提示:

    本pass禁止上传.asp|.aspx|.php|.jsp后缀文件!

    解题思路:

    httpd.conf文件下添加代码

    AddType application/x-httpd-php .php .phtml .php3 .php4

    该句代码的意思是将.php、.php3、.php4当作php文件

    上传phpinfo.php4

    打开图片链接

    就能查看运行的PHP文件

    Pass-04

    代码:

    1. $is_upload = false;
    2. $msg = null;
    3. if (isset($_POST['submit'])) {
    4. if (file_exists(UPLOAD_PATH)) {
    5. $deny_ext = array(".php",".php5",".php4",".php3",".php2",".php1",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2",".pHp1",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf",".ini");
    6. $file_name = trim($_FILES['upload_file']['name']);
    7. $file_name = deldot($file_name);//删除文件名末尾的点
    8. $file_ext = strrchr($file_name, '.');
    9. $file_ext = strtolower($file_ext); //转换为小写
    10. $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
    11. $file_ext = trim($file_ext); //收尾去空
    12. if (!in_array($file_ext, $deny_ext)) {
    13. $temp_file = $_FILES['upload_file']['tmp_name'];
    14. $img_path = UPLOAD_PATH.'/'.$file_name;
    15. if (move_uploaded_file($temp_file, $img_path)) {
    16. $is_upload = true;
    17. } else {
    18. $msg = '上传出错!';
    19. }
    20. } else {
    21. $msg = '此文件不允许上传!';
    22. }
    23. } else {
    24. $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
    25. }
    26. }

    提示:

    本pass禁止上传.php|.php5|.php4|.php3|.php2|php1|.html|.htm|.phtml|.pHp|.pHp5|.pHp4|.pHp3|.pHp2|pHp1|.Html|.Htm|.pHtml|.jsp|.jspa|.jspx|.jsw|.jsv|.jspf|.jtml|.jSp|.jSpx|.jSpa|.jSw|.jSv|.jSpf|.jHtml|.asp|.aspx|.asa|.asax|.ascx|.ashx|.asmx|.cer|.aSp|.aSpx|.aSa|.aSax|.aScx|.aShx|.aSmx|.cEr|.sWf|.swf后缀文件!

    解题思路:

    上传.htaccess文件

    将jpg文件当作php文件执行

    1. <FilesMatch 'phpinfo.jpg'>
    2. SetHandler application/x-httpd-php
    3. </FilesMatch>

    再上传phpinfo.jpg(是由phpinfo.php改后缀成phpinfo.jpg)

    打开链接

  • 相关阅读:
    14. 对有状态组件和无状态组件的理解及使用场景?
    【Java基础】23.接口
    编译openjdk8==centos7.9编译openjdk8
    SpringBoot+若依+图片导出
    Jmeter控制RPS
    不同的方式检查Null
    React中setState方法详细讲解
    模拟电路 第二章(三极管及其放大电路)【下】
    使用 Zokrates 在 BSV 上创建您的第一个 zkSNARK 证明
    28.云原生之服务网格ServiceMesh和istio
  • 原文地址:https://blog.csdn.net/lyshark_lyshark/article/details/126799928