PHP로 웹 셸 만들기
명령을 수행하는 PHP 프로그램을 만들고 싶습니다.
이번 프로그램을 다른 사람이 접근할 수 있는 서버에 두는 것은 매우 위험하다.
실행할 때 주의하세요.
컨디션 
OS: Windows10
XAMPP: 7.2.7
PHP: 7.2.7
Apache: 2.4.33
우선 지령을 수행할 수 있는 것을 만들어라 
GET
 
get_webshell.php<pre><?php system($_GET["cmd"]);?></pre>
system($_GET["cmd"]) GET에서 받은 명령을 실행하고 표시합니다.
URL에 매개 변수를 추가하여 명령을 보냅니다.
데이터 전송 명령
 
 
명령이 실행되었습니다.
POST
 
post_webshell.php<pre><?php system($_POST["cmd"]);?></pre>
<form method="POST"><input autofocus type="text" name="cmd"></form>
POST를 통해 명령을 보내는 텍스트 창을 추가합니다.
실행 시간 명령
 
 
이쪽도 실행됐습니다.
기능 추가 
이러면 이해하기 어려워서 현재 디렉터리와 지령의 역사를 보여 보려고 합니다.
webshell.php<?php
session_start();
$rpath1 = [" ./", " .\\"];
$rpath2 = [" ../", " ..\\"];
if ($_POST["cmd"]) {
    $cmd= $_POST["cmd"];
    //相対パスの置き換え
    $cmd = str_replace ($rpath1, " ".trim($_SESSION["path"])."\\", $cmd);
    $cmd = str_replace ($rpath2, " ".trim($_SESSION["path"])."\\..\\", $cmd);
    $cmd = str_replace (":\\\\", ":\\", $cmd);
    if ($_POST["cmd"] === "session_reset") {
        //session_resetと入力することでリセットする
        $_SESSION = [];
    } elseif (preg_match("/^cd\s/i", $_POST["cmd"])) {
        // cd コマンドでカレントディレクトリを更新
        $_SESSION["history"] .= $_SESSION["path"]."<br>>".$_POST["cmd"]."<br>";
        $_SESSION["path"] = shell_exec($cmd." & @cd");
    } else {
        $_SESSION["history"] .= $_SESSION["path"]."<br>>".$_POST["cmd"]."<br><pre>".htmlspecialchars(mb_convert_encoding(shell_exec($cmd), "UTF-8"), ENT_QUOTES, "UTF-8", true)."</pre>";
    }
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>WebShell</title>
</head>
<body>
    <?php 
        if (empty($_SESSION["history"])) $_SESSION["history"] = "";
        if (empty($_SESSION["path"])) $_SESSION["path"] = shell_exec("@cd");
        echo $_SESSION["history"];    
        echo $_SESSION["path"] 
    ?>
    <form method="POST">
        ><input autofocus type="text" name="cmd">
    </form>
</body>
</html>
세션을 사용하여 실행 중인 명령과 현재 디렉토리를 저장합니다.
명령의 ./ 또는 ../ 상대 경로를 저장된 현재 디렉토리로 대체하여 디렉토리 지정을 재현합니다.(디렉토리를 지정하지 않으면 현재 디렉토리가 프로그램과 같은 레벨이 됩니다.)
 
 
CSS 추가
 
얻기 어려운 기회인 만큼 외관도 바뀐다.<head>에 다음을 추가합니다.<style>
    *{
        color: #00ff00;
        font-size: 15px;
        font-family: Hack, monospace;
    }
    body{
        background-color: #000000;
    }
    input{
        border: 0px;
        background-color: transparent;
    }
</style>
 
 
멋있어졌어.
최후 
글의 첫머리에도 이번 프로그램을 다른 사람이 접근할 수 있는 서버에 두는 것은 위험하므로 실행할 때 주의하시기 바랍니다.
PHP 초보자는 잘 설치하지 못했지만 최소한의 기능을 설치할 수 있는 것은 괜찮다.
Make IT Advent Calendaar 2018 21일째 보도입니다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(PHP로 웹 셸 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/yukiy4n4g1/items/865ad4c35c2d7deb1c63
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
GET
get_webshell.php
<pre><?php system($_GET["cmd"]);?></pre>
system($_GET["cmd"]) GET에서 받은 명령을 실행하고 표시합니다.URL에 매개 변수를 추가하여 명령을 보냅니다.
데이터 전송 명령
 
 명령이 실행되었습니다.
POST
post_webshell.php
<pre><?php system($_POST["cmd"]);?></pre>
<form method="POST"><input autofocus type="text" name="cmd"></form>
실행 시간 명령
 
 이쪽도 실행됐습니다.
기능 추가 
이러면 이해하기 어려워서 현재 디렉터리와 지령의 역사를 보여 보려고 합니다.
webshell.php<?php
session_start();
$rpath1 = [" ./", " .\\"];
$rpath2 = [" ../", " ..\\"];
if ($_POST["cmd"]) {
    $cmd= $_POST["cmd"];
    //相対パスの置き換え
    $cmd = str_replace ($rpath1, " ".trim($_SESSION["path"])."\\", $cmd);
    $cmd = str_replace ($rpath2, " ".trim($_SESSION["path"])."\\..\\", $cmd);
    $cmd = str_replace (":\\\\", ":\\", $cmd);
    if ($_POST["cmd"] === "session_reset") {
        //session_resetと入力することでリセットする
        $_SESSION = [];
    } elseif (preg_match("/^cd\s/i", $_POST["cmd"])) {
        // cd コマンドでカレントディレクトリを更新
        $_SESSION["history"] .= $_SESSION["path"]."<br>>".$_POST["cmd"]."<br>";
        $_SESSION["path"] = shell_exec($cmd." & @cd");
    } else {
        $_SESSION["history"] .= $_SESSION["path"]."<br>>".$_POST["cmd"]."<br><pre>".htmlspecialchars(mb_convert_encoding(shell_exec($cmd), "UTF-8"), ENT_QUOTES, "UTF-8", true)."</pre>";
    }
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>WebShell</title>
</head>
<body>
    <?php 
        if (empty($_SESSION["history"])) $_SESSION["history"] = "";
        if (empty($_SESSION["path"])) $_SESSION["path"] = shell_exec("@cd");
        echo $_SESSION["history"];    
        echo $_SESSION["path"] 
    ?>
    <form method="POST">
        ><input autofocus type="text" name="cmd">
    </form>
</body>
</html>
세션을 사용하여 실행 중인 명령과 현재 디렉토리를 저장합니다.
명령의 ./ 또는 ../ 상대 경로를 저장된 현재 디렉토리로 대체하여 디렉토리 지정을 재현합니다.(디렉토리를 지정하지 않으면 현재 디렉토리가 프로그램과 같은 레벨이 됩니다.)
 
 
CSS 추가
 
얻기 어려운 기회인 만큼 외관도 바뀐다.<head>에 다음을 추가합니다.<style>
    *{
        color: #00ff00;
        font-size: 15px;
        font-family: Hack, monospace;
    }
    body{
        background-color: #000000;
    }
    input{
        border: 0px;
        background-color: transparent;
    }
</style>
 
 
멋있어졌어.
최후 
글의 첫머리에도 이번 프로그램을 다른 사람이 접근할 수 있는 서버에 두는 것은 위험하므로 실행할 때 주의하시기 바랍니다.
PHP 초보자는 잘 설치하지 못했지만 최소한의 기능을 설치할 수 있는 것은 괜찮다.
Make IT Advent Calendaar 2018 21일째 보도입니다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(PHP로 웹 셸 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/yukiy4n4g1/items/865ad4c35c2d7deb1c63
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
<?php
session_start();
$rpath1 = [" ./", " .\\"];
$rpath2 = [" ../", " ..\\"];
if ($_POST["cmd"]) {
    $cmd= $_POST["cmd"];
    //相対パスの置き換え
    $cmd = str_replace ($rpath1, " ".trim($_SESSION["path"])."\\", $cmd);
    $cmd = str_replace ($rpath2, " ".trim($_SESSION["path"])."\\..\\", $cmd);
    $cmd = str_replace (":\\\\", ":\\", $cmd);
    if ($_POST["cmd"] === "session_reset") {
        //session_resetと入力することでリセットする
        $_SESSION = [];
    } elseif (preg_match("/^cd\s/i", $_POST["cmd"])) {
        // cd コマンドでカレントディレクトリを更新
        $_SESSION["history"] .= $_SESSION["path"]."<br>>".$_POST["cmd"]."<br>";
        $_SESSION["path"] = shell_exec($cmd." & @cd");
    } else {
        $_SESSION["history"] .= $_SESSION["path"]."<br>>".$_POST["cmd"]."<br><pre>".htmlspecialchars(mb_convert_encoding(shell_exec($cmd), "UTF-8"), ENT_QUOTES, "UTF-8", true)."</pre>";
    }
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>WebShell</title>
</head>
<body>
    <?php 
        if (empty($_SESSION["history"])) $_SESSION["history"] = "";
        if (empty($_SESSION["path"])) $_SESSION["path"] = shell_exec("@cd");
        echo $_SESSION["history"];    
        echo $_SESSION["path"] 
    ?>
    <form method="POST">
        ><input autofocus type="text" name="cmd">
    </form>
</body>
</html>
<style>
    *{
        color: #00ff00;
        font-size: 15px;
        font-family: Hack, monospace;
    }
    body{
        background-color: #000000;
    }
    input{
        border: 0px;
        background-color: transparent;
    }
</style>
글의 첫머리에도 이번 프로그램을 다른 사람이 접근할 수 있는 서버에 두는 것은 위험하므로 실행할 때 주의하시기 바랍니다.
PHP 초보자는 잘 설치하지 못했지만 최소한의 기능을 설치할 수 있는 것은 괜찮다.
Make IT Advent Calendaar 2018 21일째 보도입니다.
Reference
이 문제에 관하여(PHP로 웹 셸 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/yukiy4n4g1/items/865ad4c35c2d7deb1c63텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)