PHP khử từ hóa CTF

Deserialization là một lớp dễ bị tổn thương thường bị bỏ qua. Thật tuyệt khi CCCamp CTF năm nay bao gồm một thử thách dựa trên web thú vị dựa trên lớp dễ bị tổn thương này

Thử thách bao gồm liên kết đến dịch vụ web cho phép chuyển đổi hình ảnh do người dùng cung cấp thành tệp PDF. Người dùng có thể tải lên các tệp hình ảnh, thêm một số nội dung HTML bổ sung vào hộp văn bản và hiển thị toàn bộ thành tệp PDF

Tệp ZIP chứa mã nguồn của ứng dụng web cũng có sẵn

Những điều sau đây là đáng chú ý

  • Ứng dụng web dựa trên PHP sử dụng thư viện TCPDF trong phiên bản
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    1 cho quá trình chuyển đổi
  • Trong webroot, có một tệp tên là
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    2 sẽ chứa cờ trên máy chủ thử thách. Tệp trong ZIP được cung cấp chỉ bao gồm cờ giả. Sự hiện diện của tệp này có thể được coi là một gợi ý rằng nội dung của tệp này phải được đọc bằng RCE hoặc một cách khai thác khác
  • Không thể chỉ tải lên trình bao web PHP vì các tệp đã tải lên được kiểm tra về loại tệp và thông tin exif. Tôi không thể bỏ qua kiểm tra này và tôi nghĩ rằng không thể làm điều này ngay từ đầu
  • Các tệp đã tải lên được lưu trữ trong thư mục
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    3

Tôi quyết định kiểm tra thư viện TCPDF để biết các lỗ hổng công khai. Tôi đã tìm thấy một lỗ hổng RCE cho các phiên bản tmpfile]] { $info = pathinfo[$this->tmpfile]; if [$info['extension'] == "pdf"] { unlink[$this->tmpfile]; } else { echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile]; } } } 0 dựa trên quá trình giải tuần tự hóa

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 không an toàn. Khai thác cũng tham chiếu các slide của một cuộc nói chuyện tại BlackHat 2018 giải thích các khai thác dựa trên
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 và cũng chứa một nghiên cứu điển hình về thư viện TCPDF

Bởi vì tôi không thể giải thích rõ hơn về cách khai thác khử lưu huỳnh của

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1, hãy trích dẫn Daniel Timofte

Tương tự như các cuộc tấn công ROP [lập trình hướng trở lại] vào các tệp nhị phân đã biên dịch, kiểu khai thác này được thực hiện thông qua PHP object injection [POI], một dạng lập trình hướng thuộc tính [POP] trong bối cảnh mã PHP hướng đối tượng

Mát lạnh. Gì?

Tệp

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 cho phép hợp nhất toàn bộ ứng dụng PHP thành một tệp nén duy nhất. Do đó, điều này cũng có thể chứa các đối tượng PHP được tuần tự hóa. Trình bao bọc luồng
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
5 của PHP có thể được sử dụng để làm việc với các tệp này và khiến tệp
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 được đọc và các đối tượng được lưu trữ được khởi tạo. Nhiều hàm PHP ma thuật khác nhau được gọi ngầm trong khi toàn bộ điều này diễn ra, chẳng hạn như hàm hủy đối tượng có tên là
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
7

Để sử dụng cái này để khai thác, bạn cần những thứ này

  • Một cách để tải tệp
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    1 được tạo thủ công lên máy chủ. Giả sử chúng ta đã có cái này, vì ứng dụng web cho phép tải lên các tệp hình ảnh
  • Một lớp dễ bị tổn thương, còn được gọi là một tiện ích trong ngữ cảnh này, thực hiện những điều nguy hiểm đối với các đối tượng trong các chức năng ma thuật như
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    7
  • Một số cách để kích hoạt quá trình khử lưu huỳnh bằng cách sử dụng trình bao bọc luồng
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    5

Một ví dụ về điều nguy hiểm như vậy có thể là thực thi

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
11 trên một giá trị thuộc tính đối tượng. Do đó, kẻ tấn công có thể tải lên tệp
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 độc hại có chứa lệnh shell độc hại dưới dạng giá trị của một trong các thuộc tính chuỗi. Sau khi làm cho
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 được deserialized, hàm hủy được gọi để thực thi
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
11 với lệnh do kẻ tấn công cung cấp làm đối số

Bản chất của lỗ hổng TCPDF là các thẻ

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
15 do người dùng cung cấp được xử lý theo cách cho phép kẻ tấn công thực hiện lệnh gọi tới
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
16 trong thư viện dễ bị tấn công. Có nhiều chức năng hệ thống tệp khác nhau khiến các
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 bị deserialized, và tất nhiên chức năng này nằm trong số đó. Điều này có thể bị khai thác bằng cách sử dụng tham số do kẻ tấn công kiểm soát tham chiếu đường dẫn tệp với trình xử lý
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
5. Xem xét ví dụ sau trong ngữ cảnh của TCPDF

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
9

Khi nhập dòng này vào hộp văn bản đầu vào HTML của ứng dụng web, những điều sau đây sẽ xảy ra

  • Ứng dụng web phân tích cú pháp thẻ
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    15 thành
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    10. Hàm này thực hiện lệnh gọi bên trong tới
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    11 với tham số đầu tiên là đường dẫn tệp hình ảnh do người dùng cung cấp, bao gồm trình bao bọc
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    5
  • Sau đó, hàm
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    11 sẽ cố kiểm tra xem đường dẫn tệp đã cho có thực sự tồn tại hay không bằng cách sử dụng
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    14
  • Vì đường dẫn tệp bắt đầu bằng
    function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    5, nên ứng dụng web sau đó sẽ cố gắng giải tuần tự hóa tệp đã cho
  • function __destruct[]
    {
        if [file_exists[$this->tmpfile]]
        {
        $info = pathinfo[$this->tmpfile];
        if [$info['extension'] == "pdf"]
        {
            unlink[$this->tmpfile];
        }
        else
        {
            echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
        }
        }
    }
    
    7 cuối cùng sẽ được gọi bằng cách sử dụng đối tượng do kẻ tấn công cung cấp có thể dẫn đến việc khai thác thành công

Có vẻ như các chức năng dễ bị tổn thương được đề cập trong cuộc nói chuyện cũng có mặt trong phiên bản TCPDF

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
17 mà thử thách dựa trên. Đây có vẻ là một chiến lược tốt để giải quyết thách thức này

Ok tuyệt nhưng làm thế nào để khai thác điều này?

Điều đầu tiên cần thiết để điều này hoạt động là một tiện ích phù hợp. Có một bộ công cụ rất hay cho việc này được gọi là phpggc. Thật không may, các tiện ích có trong công cụ này không thể được sử dụng để khai thác mục tiêu nhưng nó là một ví dụ điển hình về cách loại bỏ cuộc tấn công này

Tìm một tiện ích

Sau khi thực hiện một số nghiên cứu, rõ ràng là TCPDF không chứa tiện ích phù hợp, vì vậy tôi quyết định kiểm tra chính các ứng dụng web chứ không chỉ thư viện dễ bị tấn công. Sau một số phân tích thực sự kỹ lưỡng [thực sự là 1337

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
18], nội dung tệp
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
19 được phát hiện là đáng ngờ. Nó chứa một lớp gọi là
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
10 cũng có hàm hủy riêng

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}

Chúng tôi có thể sử dụng tiện ích này để đọc các tệp tùy ý trên máy chủ từ xa. Khi hủy một đối tượng có giá trị

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
11 mà không có phần mở rộng
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
12, thì
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
11 sẽ được hiển thị cho người dùng với
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
14. Điều này có thể được sử dụng để lấy nội dung của
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
2. ]

Xin lưu ý rằng các tiện ích thuộc loại này cũng có thể tồn tại trong bất kỳ thư viện bên thứ ba nào mà ứng dụng web đang sử dụng nội bộ

Xây dựng The Phar

Trước tiên, cần phải tạo một tệp

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
16 với nội dung này

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1

Theo mặc định, cài đặt này được đặt thành

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
17 để ngăn việc tạo tệp
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1

Xem xét danh sách PHP này có thể được sử dụng để tạo một

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 có thể được giải tuần tự hóa bởi ứng dụng web mục tiêu

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1

Đây là phiên bản sửa đổi của tác giả

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 có thể tìm thấy trong phần thứ hai của bài đăng trên blog tuyệt vời của Daniel Timofte

PHP lưu các đối tượng trong tệp

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 theo không gian tên và tên lớp của chúng. Điều này có nghĩa là để cho phép giải tuần tự hóa chính xác trên máy chủ mục tiêu, không gian tên ban đầu và tên lớp phải được sử dụng cho đối tượng tuần tự hóa độc hại. Đây là lý do tại sao toàn bộ mã được bao bọc trong không gian tên chính xác, như được xác định bằng cách sử dụng mã nguồn được cung cấp

Một điều thú vị khác là chúng ta chỉ cần cung cấp tên và thuộc tính chính xác để quá trình khử lưu huỳnh hoạt động ở đầu bên kia. Không yêu cầu các thuộc tính hoặc nhập khẩu khác không cần thiết

kêu gọi

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1

mang lại một

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
92 chứa đối tượng được chế tạo. Sau khi nhận xét loại tệp và kiểm tra exif trên một phiên bản cục bộ của ứng dụng web mục tiêu, điều này đã được tìm thấy là hoạt động hoàn hảo

Tạo đa ngôn ngữ Phar-JPEG

Điều duy nhất còn thiếu là

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 được tạo trên thực tế không phải là một tệp ảnh hợp lệ. Do đó, tệp này sẽ bị máy chủ đích từ chối và không thể tải lên theo cách này

Bài nói chuyện được đề cập trước đây cũng chứa thông tin về các tệp đa ngôn ngữ Phar-JPEG. Đây là những tệp có vẻ là hình ảnh nhưng thực tế chúng nhúng tệp

function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
1 hợp lệ bên trong. Điều này có thể được xây dựng thủ công hoặc sử dụng công cụ tuyệt vời này. Tôi đã sử dụng cái sau với một số sửa đổi nhỏ để làm cho nó hoạt động với tiện ích tùy chỉnh. Tất nhiên,
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
95 đã được đặt thành
function __destruct[]
{
    if [file_exists[$this->tmpfile]]
    {
    $info = pathinfo[$this->tmpfile];
    if [$info['extension'] == "pdf"]
    {
        unlink[$this->tmpfile];
    }
    else
    {
        echo "Could not delete created PDF: Not a pdf. Check the file: " . file_get_contents[$this->tmpfile];
    }
    }
}
96 để lấy cờ

Chủ Đề