Zipping

 

Enumeration

Zenmap:

Kiểm tra website:
Tôi tìm thấy một page có thể cho phép tôi upload file lên, tại đây tôi chỉ được phép upload file zip và trong file nén đó phải tồn tại file .pdf.

Gaining access rektsu

Đã có một bản vá cho lỗ hổng này, nên phần này tôi viết với mục đích để tham khảo.
Tìm kiếm: Bypass file extensions checks
Tôi tạo Payload web shell php: Web shell php
Sau đó tôi sử dụng hexedit edit tên file.
Tìm đến ký tự a và edit thành nullbyte.
Upload file zip mà tôi vừa mới tạo lên website:
Truy cập đường link mà tôi mới tạo:
Bây giờ tôi đã có một website, sử dụng revershell và tôi nhận được kết nối:

Gaining access rektsu - update

LFI

Tạo file passwd với symlinks:
Upload file:
Kết quả tôi thu được:
Tôi có thể đọc được file passwd, với kỹ thuật này và tôi biết rằng website được viết bằng php. Kiểm tra website tôi thấy page shop:
Đọc source code của page này. Nhưng tôi không có path cho shop, tôi biết rằng /proc/self/cwd/ sẽ giúp tôi giả quyết vấn đề này. proc
File tôi cần đọc là: shop/index.php
Kết quả tôi thu được source code như sau:
Từ source code tôi biết rằng với đầu vào là page tôi có thể include một file php trong server.
Ngoài ra tôi còn thấy có một page như sau:
Từ source code trước tôi biết rằng có tồn tại file shop/product.php trong server. Đọc nó và tôi thu được source code như sau:
PS D:\thehackbox\Machines\Zipping> curl.exe http://zipping.htb/uploads/547676a09eb9b09f749f5837ae0f0e5a/product.pdf
<?php
// Check to make sure the id parameter is specified in the URL
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    // Filtering user input for letters or special characters
    if(preg_match("/^.*[A-Za-z!#$%^&*()\-_=+{}\[\]\\|;:'\",.<>\/?]|[^0-9]$/", $id, $match)) {
        header('Location: index.php');
    } else {
        // Prepare statement and execute, but does not prevent SQL injection
        $stmt = $pdo->prepare("SELECT * FROM products WHERE id = '$id'");
        $stmt->execute();
        // Fetch the product from the database and return the result as an Array
        $product = $stmt->fetch(PDO::FETCH_ASSOC);
        // Check if the product exists (array is not empty)
        if (!$product) {
            // Simple error to display if the id for the product doesn't exists (array is empty)
            exit('Product does not exist!');
        }
    }
} else {
    // Simple error to display if the id wasn't specified
    exit('No ID provided!');
}
?>

<?=template_header('Zipping | Product')?>

<div class="product content-wrapper">
    <img src="assets/imgs/<?=$product['img']?>" width="500" height="500" alt="<?=$product['name']?>">
    <div>
        <h1 class="name"><?=$product['name']?></h1>
        <span class="price">
            &dollar;<?=$product['price']?>
            <?php if ($product['rrp'] > 0): ?>
            <span class="rrp">&dollar;<?=$product['rrp']?></span>
            <?php endif; ?>
        </span>
        <form action="index.php?page=cart" method="post">
            <input type="number" name="quantity" value="1" min="1" max="<?=$product['quantity']?>" placeholder="Quantity" required>
            <input type="hidden" name="product_id" value="<?=$product['id']?>">
            <input type="submit" value="Add To Cart">
        </form>
        <div class="description">
            <?=$product['desc']?>
        </div>
    </div>
</div>

<?=template_footer()?>
PS D:\thehackbox\Machines\Zipping>

Sqli

Từ source code tôi biết rằng với bộ lọc đầu vào không chuẩn dẫn tới lỗ hổng lfi thông qua id. Tôi có thể bỏ qua nó bằng cách thêm ký tự xuống dòng vào id.
Tôi biết rằng db sử dụng là MariaDB. Pentesting Mysql
Thử ghi một file lên server 
Kiểm tra xem file đã được ghi chưa:
Kết quả hiển thị trên website như sau:
Tôi thực hiện ghi một file php độc hại:
Thực thi mã với file shell mà tôi vừa upload:
Tôi đã có được web shell, thực thi revershell và kết nối tới server.

Privilege escalation

Chạy thử stock tôi thấy nó yêu cầu nhập password. sử dụng strings và tôi có thể nhìn thấy password.
rektsu@zipping:/home/rektsu$ strace /usr/bin/stock
strace /usr/bin/stock
execve("/usr/bin/stock", ["/usr/bin/stock"], 0x7ffe5e13f7b0 /* 16 vars */) = 0
....
newfstatat(0, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x1), ...}, AT_EMPTY_PATH) = 0
write(1, "Enter the password: ", 20Enter the password: )    = 20
read(0, ************
************
"************\n", 1024)         = 13
openat(AT_FDCWD, "/home/rektsu/.config/libcounter.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
Tôi tìm thấy khai thác sau: Exploiting Shared Library Misconfigurations




Dryu8

Dryu8 is just a newbie in pentesting and loves to drink beer. I will be happy if you can donate me with a beer.

Post a Comment

Previous Post Next Post