ferret-scan 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/LICENSE +21 -0
  3. package/README.md +416 -0
  4. package/bin/ferret.js +822 -0
  5. package/dist/__tests__/basic.test.d.ts +6 -0
  6. package/dist/__tests__/basic.test.js +80 -0
  7. package/dist/analyzers/AstAnalyzer.d.ts +30 -0
  8. package/dist/analyzers/AstAnalyzer.js +332 -0
  9. package/dist/analyzers/CorrelationAnalyzer.d.ts +21 -0
  10. package/dist/analyzers/CorrelationAnalyzer.js +288 -0
  11. package/dist/index.d.ts +17 -0
  12. package/dist/index.js +22 -0
  13. package/dist/intelligence/IndicatorMatcher.d.ts +50 -0
  14. package/dist/intelligence/IndicatorMatcher.js +285 -0
  15. package/dist/intelligence/ThreatFeed.d.ts +99 -0
  16. package/dist/intelligence/ThreatFeed.js +296 -0
  17. package/dist/remediation/Fixer.d.ts +71 -0
  18. package/dist/remediation/Fixer.js +391 -0
  19. package/dist/remediation/Quarantine.d.ts +102 -0
  20. package/dist/remediation/Quarantine.js +329 -0
  21. package/dist/reporters/ConsoleReporter.d.ts +13 -0
  22. package/dist/reporters/ConsoleReporter.js +185 -0
  23. package/dist/reporters/HtmlReporter.d.ts +25 -0
  24. package/dist/reporters/HtmlReporter.js +604 -0
  25. package/dist/reporters/SarifReporter.d.ts +86 -0
  26. package/dist/reporters/SarifReporter.js +117 -0
  27. package/dist/rules/ai-specific.d.ts +8 -0
  28. package/dist/rules/ai-specific.js +221 -0
  29. package/dist/rules/backdoors.d.ts +8 -0
  30. package/dist/rules/backdoors.js +134 -0
  31. package/dist/rules/correlationRules.d.ts +8 -0
  32. package/dist/rules/correlationRules.js +227 -0
  33. package/dist/rules/credentials.d.ts +8 -0
  34. package/dist/rules/credentials.js +194 -0
  35. package/dist/rules/exfiltration.d.ts +8 -0
  36. package/dist/rules/exfiltration.js +139 -0
  37. package/dist/rules/index.d.ts +51 -0
  38. package/dist/rules/index.js +97 -0
  39. package/dist/rules/injection.d.ts +8 -0
  40. package/dist/rules/injection.js +136 -0
  41. package/dist/rules/obfuscation.d.ts +8 -0
  42. package/dist/rules/obfuscation.js +159 -0
  43. package/dist/rules/permissions.d.ts +8 -0
  44. package/dist/rules/permissions.js +129 -0
  45. package/dist/rules/persistence.d.ts +8 -0
  46. package/dist/rules/persistence.js +117 -0
  47. package/dist/rules/semanticRules.d.ts +10 -0
  48. package/dist/rules/semanticRules.js +212 -0
  49. package/dist/rules/supply-chain.d.ts +8 -0
  50. package/dist/rules/supply-chain.js +148 -0
  51. package/dist/scanner/FileDiscovery.d.ts +24 -0
  52. package/dist/scanner/FileDiscovery.js +282 -0
  53. package/dist/scanner/PatternMatcher.d.ts +25 -0
  54. package/dist/scanner/PatternMatcher.js +206 -0
  55. package/dist/scanner/Scanner.d.ts +14 -0
  56. package/dist/scanner/Scanner.js +266 -0
  57. package/dist/scanner/WatchMode.d.ts +29 -0
  58. package/dist/scanner/WatchMode.js +195 -0
  59. package/dist/types.d.ts +332 -0
  60. package/dist/types.js +53 -0
  61. package/dist/utils/baseline.d.ts +80 -0
  62. package/dist/utils/baseline.js +276 -0
  63. package/dist/utils/config.d.ts +21 -0
  64. package/dist/utils/config.js +247 -0
  65. package/dist/utils/ignore.d.ts +18 -0
  66. package/dist/utils/ignore.js +82 -0
  67. package/dist/utils/logger.d.ts +32 -0
  68. package/dist/utils/logger.js +75 -0
  69. package/package.json +119 -0
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Rule Registry - Manages all security detection rules
3
+ */
4
+ import { exfiltrationRules } from './exfiltration.js';
5
+ import { credentialRules } from './credentials.js';
6
+ import { injectionRules } from './injection.js';
7
+ import { backdoorRules } from './backdoors.js';
8
+ import { obfuscationRules } from './obfuscation.js';
9
+ import { permissionRules } from './permissions.js';
10
+ import { persistenceRules } from './persistence.js';
11
+ import { supplyChainRules } from './supply-chain.js';
12
+ import { aiSpecificRules } from './ai-specific.js';
13
+ import { semanticRules } from './semanticRules.js';
14
+ import { correlationRules } from './correlationRules.js';
15
+ import logger from '../utils/logger.js';
16
+ /**
17
+ * All built-in rules
18
+ */
19
+ const ALL_RULES = [
20
+ ...exfiltrationRules,
21
+ ...credentialRules,
22
+ ...injectionRules,
23
+ ...backdoorRules,
24
+ ...obfuscationRules,
25
+ ...permissionRules,
26
+ ...persistenceRules,
27
+ ...supplyChainRules,
28
+ ...aiSpecificRules,
29
+ ...semanticRules,
30
+ ...correlationRules,
31
+ ];
32
+ /**
33
+ * Get all rules
34
+ */
35
+ export function getAllRules() {
36
+ return ALL_RULES;
37
+ }
38
+ /**
39
+ * Get rules filtered by categories
40
+ */
41
+ export function getRulesByCategories(categories) {
42
+ return ALL_RULES.filter(rule => categories.includes(rule.category));
43
+ }
44
+ /**
45
+ * Get rules filtered by severity
46
+ */
47
+ export function getRulesBySeverity(severities) {
48
+ return ALL_RULES.filter(rule => severities.includes(rule.severity));
49
+ }
50
+ /**
51
+ * Get a specific rule by ID
52
+ */
53
+ export function getRuleById(id) {
54
+ return ALL_RULES.find(rule => rule.id === id);
55
+ }
56
+ /**
57
+ * Get enabled rules only
58
+ */
59
+ export function getEnabledRules() {
60
+ return ALL_RULES.filter(rule => rule.enabled);
61
+ }
62
+ /**
63
+ * Get rules for scanning with filters applied
64
+ */
65
+ export function getRulesForScan(categories, severities) {
66
+ const rules = ALL_RULES.filter(rule => {
67
+ if (!rule.enabled)
68
+ return false;
69
+ if (!categories.includes(rule.category))
70
+ return false;
71
+ if (!severities.includes(rule.severity))
72
+ return false;
73
+ return true;
74
+ });
75
+ logger.debug(`Loaded ${rules.length} rules for scan`);
76
+ return rules;
77
+ }
78
+ /**
79
+ * Get rule statistics
80
+ */
81
+ export function getRuleStats() {
82
+ const byCategory = {};
83
+ const bySeverity = {};
84
+ for (const rule of ALL_RULES) {
85
+ byCategory[rule.category] = (byCategory[rule.category] ?? 0) + 1;
86
+ bySeverity[rule.severity] = (bySeverity[rule.severity] ?? 0) + 1;
87
+ }
88
+ return {
89
+ total: ALL_RULES.length,
90
+ enabled: ALL_RULES.filter(r => r.enabled).length,
91
+ byCategory: byCategory,
92
+ bySeverity: bySeverity,
93
+ };
94
+ }
95
+ export { exfiltrationRules, credentialRules, injectionRules, backdoorRules, obfuscationRules, permissionRules, persistenceRules, supplyChainRules, aiSpecificRules, semanticRules, correlationRules, };
96
+ export default getAllRules;
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Prompt Injection Detection Rules
3
+ * Detects malicious instructions to manipulate AI behavior
4
+ */
5
+ import type { Rule } from '../types.js';
6
+ export declare const injectionRules: Rule[];
7
+ export default injectionRules;
8
+ //# sourceMappingURL=injection.d.ts.map
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Prompt Injection Detection Rules
3
+ * Detects malicious instructions to manipulate AI behavior
4
+ */
5
+ export const injectionRules = [
6
+ {
7
+ id: 'INJ-001',
8
+ name: 'Ignore Instructions Pattern',
9
+ category: 'injection',
10
+ severity: 'HIGH',
11
+ description: 'Detects attempts to make Claude ignore previous instructions',
12
+ patterns: [
13
+ /ignore\s+(previous|all|above|prior|system)\s+instructions/gi,
14
+ /disregard\s+(previous|all|above|prior|your)\s+(rules|guidelines|instructions)/gi,
15
+ /forget\s+(previous|all|above|prior)\s+instructions/gi,
16
+ /override\s+(previous|all|system)\s+instructions/gi,
17
+ ],
18
+ fileTypes: ['md', 'json'],
19
+ components: ['skill', 'agent', 'ai-config-md', 'settings', 'plugin'],
20
+ remediation: 'Remove override instructions. These patterns are commonly used in prompt injection attacks.',
21
+ references: [
22
+ 'https://owasp.org/www-project-top-10-for-large-language-model-applications/',
23
+ ],
24
+ enabled: true,
25
+ },
26
+ {
27
+ id: 'INJ-002',
28
+ name: 'Mode Switching Attack',
29
+ category: 'injection',
30
+ severity: 'HIGH',
31
+ description: 'Detects attempts to switch Claude into different operational modes',
32
+ patterns: [
33
+ /you\s+are\s+now\s+in\s+.*(mode|state)/gi,
34
+ /enter\s+(developer|admin|debug|unrestricted|jailbreak)\s+mode/gi,
35
+ /switch\s+to\s+(developer|admin|debug|unrestricted)\s+mode/gi,
36
+ /activate\s+(developer|admin|debug|god)\s+mode/gi,
37
+ ],
38
+ fileTypes: ['md', 'json'],
39
+ components: ['skill', 'agent', 'ai-config-md', 'settings'],
40
+ remediation: 'Remove mode switching instructions. These are prompt injection techniques.',
41
+ references: [],
42
+ enabled: true,
43
+ },
44
+ {
45
+ id: 'INJ-003',
46
+ name: 'DAN Jailbreak Pattern',
47
+ category: 'injection',
48
+ severity: 'CRITICAL',
49
+ description: 'Detects "Do Anything Now" and similar jailbreak attempts',
50
+ patterns: [
51
+ /\bDAN\b/g,
52
+ /Do\s+Anything\s+Now/gi,
53
+ /jailbreak/gi,
54
+ /jailbroken/gi,
55
+ /bypass\s+(filter|safety|restriction|guardrail)/gi,
56
+ ],
57
+ fileTypes: ['md', 'json'],
58
+ components: ['skill', 'agent', 'ai-config-md', 'settings'],
59
+ remediation: 'Remove jailbreak attempts. These patterns attempt to bypass safety measures.',
60
+ references: [],
61
+ enabled: true,
62
+ },
63
+ {
64
+ id: 'INJ-004',
65
+ name: 'Safety Override Pattern',
66
+ category: 'injection',
67
+ severity: 'HIGH',
68
+ description: 'Detects attempts to override safety guidelines',
69
+ patterns: [
70
+ /disregard\s+(your|safety|ethical)\s+(guidelines|rules|constraints)/gi,
71
+ /you\s+(don't|do\s+not)\s+have\s+(any\s+)?(restrictions|limits|constraints)/gi,
72
+ /pretend\s+.*not\s+bound\s+by/gi,
73
+ /act\s+as\s+if\s+you\s+have\s+no\s+(restrictions|limits)/gi,
74
+ ],
75
+ fileTypes: ['md', 'json'],
76
+ components: ['skill', 'agent', 'ai-config-md'],
77
+ remediation: 'Remove safety override instructions.',
78
+ references: [],
79
+ enabled: true,
80
+ },
81
+ {
82
+ id: 'INJ-005',
83
+ name: 'Role Manipulation',
84
+ category: 'injection',
85
+ severity: 'MEDIUM',
86
+ description: 'Detects suspicious role-play instructions that may be injection attempts',
87
+ patterns: [
88
+ /roleplay\s+as\s+.*(evil|malicious|hacker|attacker)/gi,
89
+ /pretend\s+(to\s+be|you\s+are)\s+.*(evil|malicious|hacker)/gi,
90
+ /act\s+as\s+.*(evil|malicious|hacker|attacker)/gi,
91
+ /you\s+are\s+(an?\s+)?(evil|malicious|rogue|compromised)/gi,
92
+ ],
93
+ fileTypes: ['md', 'json'],
94
+ components: ['skill', 'agent', 'ai-config-md'],
95
+ remediation: 'Remove role manipulation instructions that encourage malicious behavior.',
96
+ references: [],
97
+ enabled: true,
98
+ },
99
+ {
100
+ id: 'INJ-006',
101
+ name: 'Hidden Instruction Pattern',
102
+ category: 'injection',
103
+ severity: 'HIGH',
104
+ description: 'Detects hidden instructions using HTML comments or special formatting',
105
+ patterns: [
106
+ /<!--.*?(ignore|override|disregard|bypass).*?-->/gis,
107
+ /\[hidden\].*?(ignore|override|disregard)/gi,
108
+ /\[SYSTEM\].*?instruction/gi,
109
+ ],
110
+ fileTypes: ['md'],
111
+ components: ['skill', 'agent', 'ai-config-md'],
112
+ remediation: 'Remove hidden instructions from HTML comments or special tags.',
113
+ references: [],
114
+ enabled: true,
115
+ },
116
+ {
117
+ id: 'INJ-007',
118
+ name: 'Instruction Hierarchy Manipulation',
119
+ category: 'injection',
120
+ severity: 'HIGH',
121
+ description: 'Detects attempts to manipulate instruction priority',
122
+ patterns: [
123
+ /this\s+instruction\s+(takes|has)\s+(priority|precedence)/gi,
124
+ /highest\s+priority\s+instruction/gi,
125
+ /override\s+all\s+other\s+instructions/gi,
126
+ /this\s+supersedes\s+all/gi,
127
+ ],
128
+ fileTypes: ['md', 'json'],
129
+ components: ['skill', 'agent', 'ai-config-md'],
130
+ remediation: 'Remove instruction priority manipulation attempts.',
131
+ references: [],
132
+ enabled: true,
133
+ },
134
+ ];
135
+ export default injectionRules;
136
+ //# sourceMappingURL=injection.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Obfuscation Detection Rules
3
+ * Detects hidden or encoded malicious content
4
+ */
5
+ import type { Rule } from '../types.js';
6
+ export declare const obfuscationRules: Rule[];
7
+ export default obfuscationRules;
8
+ //# sourceMappingURL=obfuscation.d.ts.map
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Obfuscation Detection Rules
3
+ * Detects hidden or encoded malicious content
4
+ */
5
+ export const obfuscationRules = [
6
+ {
7
+ id: 'OBF-001',
8
+ name: 'Base64 Encoded Commands',
9
+ category: 'obfuscation',
10
+ severity: 'HIGH',
11
+ description: 'Detects base64 encoding combined with execution, often used to hide malicious commands',
12
+ patterns: [
13
+ /echo\s+['"][A-Za-z0-9+/=]{20,}['"]\s*\|\s*base64\s+-d/gi,
14
+ /base64\s+-d\s+<<</gi,
15
+ /atob\s*\(/gi,
16
+ /Buffer\.from\s*\([^)]+,\s*['"]base64['"]\)/gi,
17
+ ],
18
+ fileTypes: ['sh', 'bash', 'zsh', 'md', 'json'],
19
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin', 'mcp'],
20
+ remediation: 'Decode and review base64 content. Remove if malicious.',
21
+ references: [],
22
+ enabled: true,
23
+ },
24
+ {
25
+ id: 'OBF-002',
26
+ name: 'JavaScript String Obfuscation',
27
+ category: 'obfuscation',
28
+ severity: 'HIGH',
29
+ description: 'Detects JavaScript string obfuscation techniques',
30
+ patterns: [
31
+ /String\.fromCharCode\s*\(/gi,
32
+ /\[['"]\\x[0-9a-f]{2}['"]\]/gi,
33
+ /\\u[0-9a-f]{4}/gi,
34
+ /unescape\s*\(/gi,
35
+ ],
36
+ fileTypes: ['md', 'json'],
37
+ components: ['skill', 'agent', 'ai-config-md', 'mcp', 'plugin'],
38
+ remediation: 'Review obfuscated JavaScript code. Remove if suspicious.',
39
+ references: [],
40
+ enabled: true,
41
+ },
42
+ {
43
+ id: 'OBF-003',
44
+ name: 'Zero-Width Characters',
45
+ category: 'obfuscation',
46
+ severity: 'HIGH',
47
+ description: 'Detects invisible zero-width characters that may hide content',
48
+ patterns: [
49
+ /[\u200B-\u200D\uFEFF]/g,
50
+ /[\u2060-\u2064]/g,
51
+ /[\u180E]/g,
52
+ ],
53
+ fileTypes: ['md', 'json', 'yaml', 'yml'],
54
+ components: ['skill', 'agent', 'ai-config-md', 'settings', 'mcp'],
55
+ remediation: 'Remove zero-width characters. These can be used to hide malicious content.',
56
+ references: [],
57
+ enabled: true,
58
+ // Filter out emoji ZWJ sequences (used in compound emojis like 👨‍💻)
59
+ excludePatterns: [
60
+ /[\u{1F300}-\u{1F9FF}]\u200D/gu, // Emoji followed by ZWJ
61
+ /\u200D[\u{1F300}-\u{1F9FF}]/gu, // ZWJ followed by emoji
62
+ /[\u{1F468}-\u{1F469}]\u200D/gu, // Person emoji + ZWJ (family/profession emojis)
63
+ ],
64
+ excludeContext: [
65
+ /emoji|gitmoji/gi,
66
+ /commit\s+(message|type|convention)/gi,
67
+ ],
68
+ },
69
+ {
70
+ id: 'OBF-004',
71
+ name: 'Extended ASCII Blocks',
72
+ category: 'obfuscation',
73
+ severity: 'MEDIUM',
74
+ description: 'Detects long sequences of extended ASCII characters that may hide content',
75
+ patterns: [
76
+ /[\u0080-\u00FF]{20,}/g,
77
+ ],
78
+ fileTypes: ['md', 'json'],
79
+ components: ['skill', 'agent', 'ai-config-md'],
80
+ remediation: 'Review extended ASCII sequences for hidden content.',
81
+ references: [],
82
+ enabled: true,
83
+ },
84
+ {
85
+ id: 'OBF-005',
86
+ name: 'HTML Comment Hiding',
87
+ category: 'obfuscation',
88
+ severity: 'MEDIUM',
89
+ description: 'Detects potentially malicious content hidden in HTML comments',
90
+ patterns: [
91
+ /<!--[\s\S]{100,}?-->/g,
92
+ /<!--.*?(script|eval|function).*?-->/gis,
93
+ ],
94
+ fileTypes: ['md'],
95
+ components: ['skill', 'agent', 'ai-config-md'],
96
+ remediation: 'Review HTML comments for hidden malicious content.',
97
+ references: [],
98
+ enabled: true,
99
+ },
100
+ {
101
+ id: 'OBF-006',
102
+ name: 'Long Whitespace Sequences',
103
+ category: 'obfuscation',
104
+ severity: 'LOW',
105
+ description: 'Detects unusually long whitespace that may hide steganographic content',
106
+ patterns: [
107
+ /\s{50,}/g,
108
+ /\t{20,}/g,
109
+ ],
110
+ fileTypes: ['md', 'sh', 'bash'],
111
+ components: ['skill', 'agent', 'ai-config-md', 'hook'],
112
+ remediation: 'Review long whitespace sequences. These could hide steganographic content.',
113
+ references: [],
114
+ enabled: true,
115
+ // Filter out ASCII art and diagrams
116
+ excludeContext: [
117
+ /[┌┐└┘├┤┬┴┼─│]/g, // Box drawing characters (ASCII art)
118
+ /[╔╗╚╝╠╣╦╩╬═║]/g, // Double-line box drawing
119
+ /[+\-|]{3,}/g, // Simple ASCII art borders
120
+ /diagram|flowchart|architecture/gi,
121
+ /```(ascii|text|diagram)/gi,
122
+ ],
123
+ },
124
+ {
125
+ id: 'OBF-007',
126
+ name: 'Hex Encoded Content',
127
+ category: 'obfuscation',
128
+ severity: 'HIGH',
129
+ description: 'Detects hex-encoded strings that may hide commands',
130
+ patterns: [
131
+ /\\x[0-9a-fA-F]{2}(?:\\x[0-9a-fA-F]{2}){10,}/g,
132
+ /0x[0-9a-fA-F]{2}(?:,\s*0x[0-9a-fA-F]{2}){10,}/g,
133
+ ],
134
+ fileTypes: ['md', 'json', 'sh', 'bash'],
135
+ components: ['skill', 'agent', 'ai-config-md', 'hook', 'mcp'],
136
+ remediation: 'Decode and review hex-encoded content.',
137
+ references: [],
138
+ enabled: true,
139
+ },
140
+ {
141
+ id: 'OBF-008',
142
+ name: 'ANSI Escape Sequences',
143
+ category: 'obfuscation',
144
+ severity: 'MEDIUM',
145
+ description: 'Detects ANSI escape sequences that may hide terminal output',
146
+ patterns: [
147
+ /\x1b\[[0-9;]*m/g,
148
+ /\\e\[[0-9;]*m/g,
149
+ /\\033\[[0-9;]*m/g,
150
+ ],
151
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
152
+ components: ['hook', 'skill', 'agent', 'ai-config-md'],
153
+ remediation: 'Review ANSI sequences. They can be used to hide terminal output.',
154
+ references: [],
155
+ enabled: true,
156
+ },
157
+ ];
158
+ export default obfuscationRules;
159
+ //# sourceMappingURL=obfuscation.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Permission Escalation Detection Rules
3
+ * Detects attempts to gain elevated privileges
4
+ */
5
+ import type { Rule } from '../types.js';
6
+ export declare const permissionRules: Rule[];
7
+ export default permissionRules;
8
+ //# sourceMappingURL=permissions.d.ts.map
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Permission Escalation Detection Rules
3
+ * Detects attempts to gain elevated privileges
4
+ */
5
+ export const permissionRules = [
6
+ {
7
+ id: 'PERM-001',
8
+ name: 'Wildcard Permission Grant',
9
+ category: 'permissions',
10
+ severity: 'CRITICAL',
11
+ description: 'Detects wildcard permissions that allow unrestricted tool access',
12
+ patterns: [
13
+ /"allow".*Bash\s*\(\s*\*\s*\)/gi,
14
+ /"permissions".*"\*"/gi,
15
+ /defaultMode.*dontAsk/gi,
16
+ /allowAll.*true/gi,
17
+ ],
18
+ fileTypes: ['json'],
19
+ components: ['settings', 'mcp', 'plugin'],
20
+ remediation: 'Never use wildcard permissions. Specify exact allowed commands.',
21
+ references: [],
22
+ enabled: true,
23
+ },
24
+ {
25
+ id: 'PERM-002',
26
+ name: 'Sudo Usage',
27
+ category: 'permissions',
28
+ severity: 'HIGH',
29
+ description: 'Detects sudo commands which execute with elevated privileges',
30
+ patterns: [
31
+ /sudo\s+/gi,
32
+ /sudo\s+-i/gi,
33
+ /sudo\s+su/gi,
34
+ /doas\s+/gi,
35
+ ],
36
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
37
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
38
+ remediation: 'Avoid sudo in hooks and skills. Operations should run with user privileges.',
39
+ references: [],
40
+ enabled: true,
41
+ // Filter out installation instructions in documentation
42
+ // Note: Don't use 'g' flag for excludePatterns (causes regex state issues with .test())
43
+ excludePatterns: [
44
+ /sudo\s+apt(-get)?\s+install/i, // Package installation docs
45
+ /sudo\s+yum\s+install/i,
46
+ /sudo\s+dnf\s+install/i,
47
+ /sudo\s+pacman\s+-S/i,
48
+ /sudo\s+brew\s+install/i,
49
+ ],
50
+ excludeContext: [
51
+ /readme/i,
52
+ /installation|install\s+(instructions|guide|steps)/i,
53
+ /getting\s+started/i,
54
+ /prerequisites/i,
55
+ /requirements/i,
56
+ ],
57
+ },
58
+ {
59
+ id: 'PERM-003',
60
+ name: 'Insecure File Permissions',
61
+ category: 'permissions',
62
+ severity: 'HIGH',
63
+ description: 'Detects overly permissive file permission settings',
64
+ patterns: [
65
+ /chmod\s+777/gi,
66
+ /chmod\s+666/gi,
67
+ /chmod\s+-R\s+777/gi,
68
+ /chmod\s+a\+rwx/gi,
69
+ ],
70
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
71
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
72
+ remediation: 'Avoid overly permissive chmod settings. Use minimal required permissions.',
73
+ references: [],
74
+ enabled: true,
75
+ },
76
+ {
77
+ id: 'PERM-004',
78
+ name: 'Ownership Change',
79
+ category: 'permissions',
80
+ severity: 'MEDIUM',
81
+ description: 'Detects file ownership changes which may indicate privilege escalation',
82
+ patterns: [
83
+ /chown\s+root/gi,
84
+ /chown\s+-R\s+root/gi,
85
+ /chgrp\s+root/gi,
86
+ ],
87
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
88
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
89
+ remediation: 'Review ownership changes. Changing to root ownership may indicate issues.',
90
+ references: [],
91
+ enabled: true,
92
+ },
93
+ {
94
+ id: 'PERM-005',
95
+ name: 'SUID/SGID Manipulation',
96
+ category: 'permissions',
97
+ severity: 'CRITICAL',
98
+ description: 'Detects SUID/SGID bit manipulation which can enable privilege escalation',
99
+ patterns: [
100
+ /chmod\s+[0-7]*[4-7][0-7]{2}/gi, // SUID/SGID bits
101
+ /chmod\s+u\+s/gi,
102
+ /chmod\s+g\+s/gi,
103
+ ],
104
+ fileTypes: ['sh', 'bash', 'zsh'],
105
+ components: ['hook', 'plugin'],
106
+ remediation: 'Never set SUID/SGID bits in hooks or scripts.',
107
+ references: [],
108
+ enabled: true,
109
+ },
110
+ {
111
+ id: 'PERM-006',
112
+ name: 'Dangerous Tool Permissions',
113
+ category: 'permissions',
114
+ severity: 'HIGH',
115
+ description: 'Detects permissions for dangerous tools in Claude settings',
116
+ patterns: [
117
+ /"allowedTools".*"Bash"/gi,
118
+ /"trustedTools".*".*"/gi,
119
+ /allowBash.*true/gi,
120
+ ],
121
+ fileTypes: ['json'],
122
+ components: ['settings', 'mcp'],
123
+ remediation: 'Review tool permissions carefully. Limit Bash access to specific commands.',
124
+ references: [],
125
+ enabled: true,
126
+ },
127
+ ];
128
+ export default permissionRules;
129
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Persistence Detection Rules
3
+ * Detects attempts to maintain access across sessions
4
+ */
5
+ import type { Rule } from '../types.js';
6
+ export declare const persistenceRules: Rule[];
7
+ export default persistenceRules;
8
+ //# sourceMappingURL=persistence.d.ts.map
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Persistence Detection Rules
3
+ * Detects attempts to maintain access across sessions
4
+ */
5
+ export const persistenceRules = [
6
+ {
7
+ id: 'PERS-001',
8
+ name: 'Crontab Modification',
9
+ category: 'persistence',
10
+ severity: 'HIGH',
11
+ description: 'Detects crontab modifications which can establish persistent access',
12
+ patterns: [
13
+ /crontab\s+-e/gi,
14
+ /crontab\s+-l/gi,
15
+ /crontab\s+</gi,
16
+ /\/etc\/cron/gi,
17
+ /\/var\/spool\/cron/gi,
18
+ ],
19
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
20
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
21
+ remediation: 'Remove crontab modifications. Persistent scheduled tasks should be reviewed.',
22
+ references: [],
23
+ enabled: true,
24
+ },
25
+ {
26
+ id: 'PERS-002',
27
+ name: 'Shell RC File Modification',
28
+ category: 'persistence',
29
+ severity: 'HIGH',
30
+ description: 'Detects modifications to shell configuration files',
31
+ patterns: [
32
+ /~\/\.bashrc/gi,
33
+ /~\/\.zshrc/gi,
34
+ /~\/\.profile/gi,
35
+ /~\/\.bash_profile/gi,
36
+ />>\s*~\/\.(bash|zsh|profile)/gi,
37
+ ],
38
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
39
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
40
+ remediation: 'Avoid modifying shell RC files. These persist across sessions.',
41
+ references: [],
42
+ enabled: true,
43
+ },
44
+ {
45
+ id: 'PERS-003',
46
+ name: 'Git Hook Modification',
47
+ category: 'persistence',
48
+ severity: 'MEDIUM',
49
+ description: 'Detects modifications to git hooks which execute on git operations',
50
+ patterns: [
51
+ /\.git\/hooks\/(pre|post)-/gi,
52
+ /git\/hooks\/commit/gi,
53
+ /git\/hooks\/push/gi,
54
+ ],
55
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
56
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
57
+ remediation: 'Review git hook modifications. These execute automatically on git operations.',
58
+ references: [],
59
+ enabled: true,
60
+ },
61
+ {
62
+ id: 'PERS-004',
63
+ name: 'Systemd Service Creation',
64
+ category: 'persistence',
65
+ severity: 'CRITICAL',
66
+ description: 'Detects creation of systemd services for persistent execution',
67
+ patterns: [
68
+ /systemctl\s+enable/gi,
69
+ /\/etc\/systemd\/system/gi,
70
+ /\.service\s*$/gm,
71
+ /systemctl\s+start/gi,
72
+ ],
73
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
74
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
75
+ remediation: 'Never create systemd services from hooks or skills.',
76
+ references: [],
77
+ enabled: true,
78
+ },
79
+ {
80
+ id: 'PERS-005',
81
+ name: 'LaunchAgent/LaunchDaemon (macOS)',
82
+ category: 'persistence',
83
+ severity: 'CRITICAL',
84
+ description: 'Detects creation of macOS launch agents or daemons',
85
+ patterns: [
86
+ /LaunchAgents/gi,
87
+ /LaunchDaemons/gi,
88
+ /launchctl\s+load/gi,
89
+ /\.plist\s*$/gm,
90
+ ],
91
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
92
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
93
+ remediation: 'Never create Launch Agents or Daemons from configuration files.',
94
+ references: [],
95
+ enabled: true,
96
+ },
97
+ {
98
+ id: 'PERS-006',
99
+ name: 'Startup Script Modification',
100
+ category: 'persistence',
101
+ severity: 'HIGH',
102
+ description: 'Detects modifications to system startup scripts',
103
+ patterns: [
104
+ /\/etc\/rc\.local/gi,
105
+ /\/etc\/init\.d/gi,
106
+ /\/etc\/profile\.d/gi,
107
+ /autostart/gi,
108
+ ],
109
+ fileTypes: ['sh', 'bash', 'zsh', 'md'],
110
+ components: ['hook', 'skill', 'agent', 'ai-config-md', 'plugin'],
111
+ remediation: 'Avoid modifying startup scripts for persistence.',
112
+ references: [],
113
+ enabled: true,
114
+ },
115
+ ];
116
+ export default persistenceRules;
117
+ //# sourceMappingURL=persistence.js.map