roaris / ctf-log

0 stars 0 forks source link

HackTheBox: baby WAFfles order (Web) #27

Open roaris opened 4 months ago

roaris commented 4 months ago

https://app.hackthebox.com/challenges/baby%2520WAFfles%2520order

roaris commented 4 months ago

build_docker.shが動かない

$ ./build_docker.sh
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon    256kB
Step 1/12 : FROM alpine:edge
edge: Pulling from library/alpine
4edfc05e3af2: Pull complete
Digest: sha256:e31c3b1cd47718260e1b6163af0a05b3c428dc01fa410baf72ca8b8076e22e72
Status: Downloaded newer image for alpine:edge
 ---> 49b3cb3043cd
Step 2/12 : RUN adduser -D -u 1000 -g 1000 -s /bin/sh www
 ---> Running in 6a60b16778a7
Removing intermediate container 6a60b16778a7
 ---> a76cd380fc87
Step 3/12 : RUN apk add --no-cache --update supervisor nginx php7-fpm
 ---> Running in 6dbc7808dae4
fetch https://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  php7-fpm (no such package):
    required by: world[php7-fpm]
The command '/bin/sh -c apk add --no-cache --update supervisor nginx php7-fpm' returned a non-zero code: 1
Unable to find image 'web_baby_waffles_order:latest' locally
docker: Error response from daemon: pull access denied for web_baby_waffles_order, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

DockerfileのFROM alpine:edgeとなっているところをFROM alpine:3.15にする(edgeは最新の開発中バージョンを表すらしい https://qiita.com/Mister_K/items/1c03b5f794d051d1d82d)

今度はファイルのコピーでエラーになる

Step 8/12 : COPY challenge /www
COPY failed: file not found in build context or excluded by .dockerignore: stat challenge: file does not exist

確かにchallengeというファイルは存在しない この部分をコメントアウトするとビルドは通るが、アクセスすると404が返ってくる 仕方ないので、ローカルで動かすのは諦める

roaris commented 4 months ago

謎のアプリケーション WAFflesというのはワッフル WAFとかけてるのか

POST /api/orderというAPIが存在する 普通にアプリケーションを動かすと、application/jsonのリクエストが送信されるが、application/xmlも受け取れるようになっている file_get_contents('php://input')はリクエストボディを読み込んでいる(参考)

$body = file_get_contents('php://input');
if ($_SERVER['HTTP_CONTENT_TYPE'] === 'application/json')
{
    $order = json_decode($body);
    if (!$order->food)
        return json_encode([
            'status' => 'danger',
            'message' => 'You need to select a food option first'
        ]);
    return json_encode([
        'status' => 'success',
        'message' => "Your {$order->food} order has been submitted successfully."
    ]);
}
else if ($_SERVER['HTTP_CONTENT_TYPE'] === 'application/xml')
{
    $order = simplexml_load_string($body, 'SimpleXMLElement', LIBXML_NOENT);
    if (!$order->food) return 'You need to select a food option first';
    return "Your {$order->food} order has been submitted successfully.";
}
else
{
    return $router->abort(400);
}
roaris commented 4 months ago

simplexml_load_stringはXML文字列をオブジェクトに変換する https://www.php.net/manual/ja/function.simplexml-load-string.php 第三引数のLIBXML_NOENTは https://www.php.net/manual/ja/libxml.constants.php#constant.libxml-noent

警告 エンティティの置換を有効にすると、XML外部エンティティ参照攻撃(XXE) を容易にしてしまうかもしれません。

とある XXEでフラグを読み取る方針で良いだろう

roaris commented 4 months ago

フラグが取れた スクリーンショット 2024-04-26 2 33 06