-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
114 lines (94 loc) · 5.73 KB
/
Copy pathmain.c
File metadata and controls
114 lines (94 loc) · 5.73 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
#include "multics_rings.h"
/**
* Main program demonstrating Multics ring-based access control
*/
int main() {
printf("╔════════════════════════════════════════════════════════════════╗\n");
printf("║ MULTICS RING-BASED ACCESS CONTROL SIMULATION ║\n");
printf("╚════════════════════════════════════════════════════════════════╝\n\n");
// 5.1.2: Create 4 users, each assigned to a different ring level
User kernel_user = {
.name = "root",
.user_id = 1000,
.ring_level = RING_0_KERNEL,
.last_failed_attempt = 0,
.failed_attempt_count = 0
};
User system_daemon = {
.name = "systemd",
.user_id = 2000,
.ring_level = RING_1_SYSTEM,
.last_failed_attempt = 0,
.failed_attempt_count = 0
};
User regular_user = {
.name = "alice",
.user_id = 3000,
.ring_level = RING_2_USER,
.last_failed_attempt = 0,
.failed_attempt_count = 0
};
User guest_user = {
.name = "guest",
.user_id = 4000,
.ring_level = RING_3_GUEST,
.last_failed_attempt = 0,
.failed_attempt_count = 0
};
// Display user information
printf("📋 SYSTEM USERS:\n\n");
printf("%-15s | %-10s | %s\n", "Username", "User ID", "Ring Level");
printf("────────────────────────────────────────────────────────────────\n");
printf("%-15s | %-10d | %s\n", kernel_user.name, kernel_user.user_id, get_ring_name(kernel_user.ring_level));
printf("%-15s | %-10d | %s\n", system_daemon.name, system_daemon.user_id, get_ring_name(system_daemon.ring_level));
printf("%-15s | %-10d | %s\n", regular_user.name, regular_user.user_id, get_ring_name(regular_user.ring_level));
printf("%-15s | %-10d | %s\n", guest_user.name, guest_user.user_id, get_ring_name(guest_user.ring_level));
printf("\n\n");
printf("╔════════════════════════════════════════════════════════════════╗\n");
printf("║ TEST CASE SCENARIOS ║\n");
printf("╚════════════════════════════════════════════════════════════════╝\n");
// 5.2.2: Test Case 1 - Ring 3 user trying to access Ring 0 (should fail)
printf("\n\n📝 TEST 1: Guest user attempting to access Kernel functions\n");
printf("Expected: DENIED (Ring 3 cannot access Ring 0)\n");
execute_ring_operation(&guest_user, RING_0_KERNEL, "Modify kernel memory");
// 5.2.2: Test Case 2 - Ring 3 user trying to access Ring 1 (should fail)
printf("\n\n📝 TEST 2: Guest user attempting to access System Services\n");
printf("Expected: DENIED (Ring 3 cannot access Ring 1)\n");
execute_ring_operation(&guest_user, RING_1_SYSTEM, "Start system daemon");
// Test Case 3 - Ring 3 user accessing their own ring (should succeed)
printf("\n\n📝 TEST 3: Guest user accessing their own ring level\n");
printf("Expected: GRANTED (Same ring access)\n");
execute_ring_operation(&guest_user, RING_3_GUEST, "Run sandboxed application");
// Test Case 4 - Ring 2 user accessing Ring 1 via gate (should succeed - adjacent)
printf("\n\n📝 TEST 4: Regular user accessing System Services via gate\n");
printf("Expected: GRANTED (Adjacent ring access)\n");
execute_ring_operation(®ular_user, RING_1_SYSTEM, "Request system service");
// Test Case 5 - Ring 2 user trying to access Ring 0 (should fail - non-adjacent)
printf("\n\n📝 TEST 5: Regular user attempting direct kernel access\n");
printf("Expected: DENIED (Non-adjacent ring)\n");
execute_ring_operation(®ular_user, RING_0_KERNEL, "Execute privileged instruction");
// Test Case 6 - Ring 0 user accessing any ring (should succeed)
printf("\n\n📝 TEST 6: Kernel user accessing lower privilege rings\n");
printf("Expected: GRANTED (Kernel has access to all rings)\n");
execute_ring_operation(&kernel_user, RING_3_GUEST, "Inspect guest process");
// Test Case 7 - Multiple failed attempts to demonstrate rate limiting
printf("\n\n📝 TEST 7: Demonstrating rate limiting and covert channel protection\n");
printf("Attempting multiple unauthorized accesses...\n");
for (int i = 0; i < 7; i++) {
printf("\n--- Attempt %d ---\n", i + 1);
execute_ring_operation(&guest_user, RING_0_KERNEL, "Unauthorized kernel access");
}
// Test Case 8 - System daemon accessing kernel via gate
printf("\n\n📝 TEST 8: System daemon accessing kernel via gate\n");
printf("Expected: GRANTED (Adjacent ring access)\n");
execute_ring_operation(&system_daemon, RING_0_KERNEL, "Request kernel service");
// Test Case 9 - User accessing lower privilege ring
printf("\n\n📝 TEST 9: Regular user accessing guest ring\n");
printf("Expected: GRANTED (Access to lower privilege ring)\n");
execute_ring_operation(®ular_user, RING_3_GUEST, "Monitor guest process");
// Display final statistics
display_statistics();
printf("\n✓ All test cases completed!\n");
printf("📄 Access logs saved to: %s\n\n", "access_log.txt");
return 0;
}