Repository navigation
Expand file tree
/
Copy pathvulnerable-token-server.js
More file actions
160 lines (146 loc) · 4.26 KB
/
Copy pathvulnerable-token-server.js
File metadata and controls
160 lines (146 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env node
/**
* MCP01: Token Mismanagement & Secret Exposure Test Server
* ASI06: Sensitive Information Disclosure
*
* Contains hard-coded credentials and API keys in tool definitions.
*/
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import * as z from 'zod';
const server = new McpServer({
name: 'vulnerable-token-server',
version: '1.0.0',
});
// Tools with exposed credentials in descriptions
server.registerTool(
'fetch_data',
{
description: 'Fetches data from API. Uses api_key: sk-1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdef for authentication.',
inputSchema: {
endpoint: z.string().describe('API endpoint'),
},
},
async ({ endpoint }) => ({
content: [{ type: 'text', text: `Fetched from ${endpoint}` }],
})
);
server.registerTool(
'aws_upload',
{
description: 'Uploads to S3. AWS credentials: AKIAIOSFODNN7EXAMPLE with secret aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
inputSchema: {
bucket: z.string().describe('S3 bucket'),
file: z.string().describe('File path'),
},
},
async ({ bucket }) => ({
content: [{ type: 'text', text: `Uploaded to ${bucket}` }],
})
);
server.registerTool(
'github_sync',
{
description: 'Syncs with GitHub using token ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx for authentication',
inputSchema: {
repo: z.string().describe('Repository name'),
},
},
async ({ repo }) => ({
content: [{ type: 'text', text: `Synced ${repo}` }],
})
);
server.registerTool(
'authenticate_user',
{
description: 'Authenticates users against the system',
inputSchema: {
username: z.string().describe('Username'),
password: z.string().describe('User password'),
api_key: z.string().optional().describe('API key for service'),
},
},
async ({ username }) => ({
content: [{ type: 'text', text: `Authenticated ${username}` }],
})
);
server.registerTool(
'send_notification',
{
description: 'Sends notifications. Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U',
inputSchema: {
message: z.string().describe('Notification message'),
},
},
async ({ message }) => ({
content: [{ type: 'text', text: `Sent: ${message}` }],
})
);
server.registerTool(
'openai_query',
{
description: 'Query OpenAI API with sk-proj-abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKL',
inputSchema: {
prompt: z.string().describe('Query prompt'),
},
},
async ({ prompt }) => ({
content: [{ type: 'text', text: `OpenAI response for: ${prompt}` }],
})
);
server.registerTool(
'anthropic_chat',
{
description: 'Chat with Claude using sk-ant-api03-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
inputSchema: {
message: z.string().describe('Chat message'),
},
},
async ({ message }) => ({
content: [{ type: 'text', text: `Claude response for: ${message}` }],
})
);
// Prompts with exposed secrets
server.registerPrompt(
'api_assistant',
{
description: 'Helps with API calls. Default credentials: token=abc123def456ghi789jkl012mno345pqr678stu901vwx234',
argsSchema: {
query: z.string().describe('Use secret_key: mysupersecretkey12345678 for internal queries'),
},
},
async ({ query }) => ({
messages: [{ role: 'user', content: { type: 'text', text: query } }],
})
);
// Resources with embedded credentials
server.registerResource(
'api-data',
'api://data',
{
description: 'Access API data with embedded api_key=sk-proj-1234567890abcdefghijklmnopqrstuvwxyz1234567890abc in URL',
mimeType: 'text/plain',
},
async () => ({
contents: [{ uri: 'api://data', text: 'API data' }],
})
);
server.registerResource(
'db-connection',
'db://connection',
{
description: 'Database with credentials: password="SuperSecret123!" embedded',
mimeType: 'text/plain',
},
async () => ({
contents: [{ uri: 'db://connection', text: 'DB connection' }],
})
);
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main().catch((error) => {
console.error('Server error:', error);
process.exit(1);
});