chiwormjava 2.0.5 → 2.0.6

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 (3) hide show
  1. package/java.json +35 -27
  2. package/package.json +1 -1
  3. package/readme.md +655 -837
package/readme.md CHANGED
@@ -42,595 +42,493 @@ javacodewatch
42
42
 
43
43
  ---
44
44
 
45
- ---
46
- Step 1: Place devices
47
- Add in Packet Tracer:
48
- 2 Routers (2621XM)
49
- 2 Switches (2960)
50
- 4 PCs
51
-
52
- Arrange as:
53
- PC1 PC2 PC3 PC4
54
- | | | |
55
- Switch1 Switch2
56
- | |
57
- Router1 ---- WAN ---- Router2
58
-
59
- Step 2: Add Serial Ports
60
- Click Router -> Physical tab
61
- Turn Power OFF
62
- Insert WIC-2T module
63
- Turn Power ON
64
- Now Serial0/0/0 and Serial0/0/1 will be available
65
-
66
- Step 3: Connect cables
67
- LAN:
68
- PC to Switch using Copper Straight-Through
69
- Switch to Router using Copper Straight-Through
70
-
71
- WAN:
72
- Use Serial DCE cable
73
- Router1 Serial0/0/0 to Router2 Serial0/0/0
74
-
75
- Step 4: Configure Router1
76
- enable
77
- configure terminal
78
-
79
- interface gigabitEthernet 0/0
80
- ip address 192.168.1.1 255.255.255.0
81
- no shutdown
82
- exit
83
-
84
- interface serial 0/0/0
85
- ip address 172.16.1.1 255.255.255.252
86
- clock rate 64000
87
- no shutdown
88
- exit
89
-
90
- Step 5: Configure Router2
91
- enable
92
- configure terminal
93
-
94
- interface gigabitEthernet 0/0
95
- ip address 10.0.0.1 255.255.255.248
96
- no shutdown
97
- exit
98
-
99
- interface serial 0/0/0
100
- ip address 172.16.1.2 255.255.255.252
101
- no shutdown
102
- exit
103
-
104
- Step 6: Configure PCs
105
- Left network:
106
- PC1 IP 192.168.1.2 Mask 255.255.255.0 Gateway 192.168.1.1
107
- PC2 IP 192.168.1.3 Gateway 192.168.1.1
108
-
109
- Right network:
110
- PC3 IP 10.0.0.2 Mask 255.255.255.248 Gateway 10.0.0.1
111
- PC4 IP 10.0.0.3 Gateway 10.0.0.1
112
-
113
- Step 7: Configure Routing
114
- Router1:
115
- ip route 10.0.0.0 255.255.255.248 172.16.1.2
116
-
117
- Router2:
118
- ip route 192.168.1.0 255.255.255.0 172.16.1.1
119
-
120
- Step 8: Verify interfaces
121
- Run:
122
- show ip interface brief
123
-
124
- Status should be up up
125
- If not, use no shutdown
126
-
127
- Step 9: Test connectivity
128
- From PC1:
129
- ping 10.0.0.2
130
-
131
- Expected reply from destination
132
-
133
- Step 10: Simulation Mode
134
- Click Simulation
135
- Reset Simulation
136
- Edit Filters and select ARP and ICMP
137
-
138
- Send packet using Add Simple PDU from PC1 to PC3
139
- Click Play or Capture/Forward
140
-
141
- Expected packet flow:
142
- PC1 -> Switch1 -> Router1 -> Router2 -> Switch2 -> PC3
143
-
144
- First ARP then ICMP communication successful
145
-
146
-
147
-
148
- Step 1: Setting Up the Topology
149
- Add devices:
150
- 1 Router (2911 or similar)
151
- 1 Switch (2960)
152
- 3 PCs (PC0, PC1, PC2)
153
- 1 Cloud or Server
154
-
155
- Step 2: Assign IP Addresses
156
- Private Network:
157
- PC0 IP 192.168.1.2 Mask 255.255.255.0 Gateway 192.168.1.1
158
- PC1 IP 192.168.1.3 Mask 255.255.255.0 Gateway 192.168.1.1
159
- PC2 IP 192.168.1.4 Mask 255.255.255.0 Gateway 192.168.1.1
160
-
161
- Step 3: Configure Router Interfaces
162
- Router> enable
163
- Router# configure terminal
164
-
165
- Interface gig0/0
166
- Router(config)# interface gig0/0
167
- Router(config-if)# ip address 192.168.1.1 255.255.255.0
168
- Router(config-if)# no shutdown
169
-
170
- Interface gig0/1
171
- Router(config)# interface gig0/1
172
- Router(config-if)# ip address 203.0.113.1 255.255.255.0
173
- Router(config-if)# no shutdown
174
-
175
- Assign IP to Cloud/Server
176
- IP 203.0.113.2
177
- Mask 255.255.255.0
178
-
179
- Step 4: Configure NAT
180
- Define inside and outside interfaces
181
- Router(config)# interface gig0/0
182
- Router(config-if)# ip nat inside
183
- Router(config-if)# exit
184
-
185
- Router(config)# interface gig0/1
186
- Router(config-if)# ip nat outside
187
- Router(config-if)# exit
188
-
189
- Configure PAT
190
- Router(config)# access-list 1 permit 192.168.1.0 0.0.0.255
191
- Router(config)# ip nat inside source list 1 interface gig0/1 overload
192
-
193
- Step 5: Configure Routing
194
- Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.2
195
-
196
- Step 6: Test Configuration
197
- From PC command prompt:
198
- ping 203.0.113.2
199
-
200
- If reply is received, NAT is working
201
-
202
- Verify NAT translations
203
- Router# show ip nat translations
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
- AIM:
226
- To analyze packet fragmentation by changing packet size and observing its effect using Wireshark.
227
-
228
- Step 1: Open Wireshark
229
- Launch Wireshark
230
- Select active interface (WiFi or Ethernet)
231
- Click Start Capture
232
-
233
- Step 2: Check MTU size
234
- Open Command Prompt and run:
235
- netsh interface ipv4 show subinterfaces
236
- Note MTU value (usually 1500 bytes)
237
-
238
- Step 3: Test without fragmentation
239
- ping 8.8.8.8 -f -l 1472
240
- 1472 + 28 header = 1500, fits MTU
241
- Output: Reply received, no fragmentation
242
-
243
- Step 4: Force fragmentation error
244
- ping 8.8.8.8 -f -l 2000
245
- Output: Packet needs to be fragmented but DF set
246
- Meaning: Packet too large and fragmentation not allowed
247
-
248
- Step 5: Allow fragmentation
249
- ping 8.8.8.8 -l 2000
250
- Packet is divided into fragments
251
- May observe delay or packet loss
252
45
 
253
- Step 6: Analyze in Wireshark
254
- Apply filter:
255
- ip.flags.mf == 1 or ip.frag_offset > 0
256
-
257
- Observation:
258
- Multiple packets for single ping
259
- Fragmented packets visible
260
-
261
- Observations:
262
- Fragmented packets have same Identification ID
263
- Different Fragment Offset values
264
- MF flag indicates more fragments
265
- Last packet has MF = 0
266
-
267
- Performance Impact:
268
- More packets generated
269
- Increased delay
270
- Possible packet loss
271
-
272
- Final Observation:
273
- Small packet: No fragmentation
274
- Large packet with DF: Error
275
- Large packet without DF: Fragmentation occurs
276
-
277
- Conclusion:
278
- If packet size exceeds MTU, it is divided into smaller fragments, affecting performance
279
-
280
- Output:
281
- Ping command results showing success or error
282
- Wireshark showing fragmented packets using filter
283
-
284
- Result:
285
- Fragmentation observed and analyzed successfully
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
- AIM:
306
- To identify vulnerabilities and secure the network using Access Control List (ACL) and Port Security.
307
-
308
- Step 1: Topology Setup
309
- Add devices:
310
- 1 Router (2911)
311
- 1 Switch (2960)
312
- 2 PCs
313
-
314
- Step 2: Connections
315
- PC1 FastEthernet0 to Switch Fa0/1 using Copper Straight-Through
316
- PC2 FastEthernet0 to Switch Fa0/2 using Copper Straight-Through
317
- Switch Fa0/24 to Router GigabitEthernet0/0
318
-
319
- Step 3: Configure PCs
320
- PC1 IP 192.168.1.10 Mask 255.255.255.0 Gateway 192.168.1.1
321
- PC2 IP 192.168.1.20 Mask 255.255.255.0 Gateway 192.168.1.1
322
-
323
- Step 4: Configure Router
324
- enable
325
- configure terminal
326
- interface g0/0
327
- ip address 192.168.1.1 255.255.255.0
328
- no shutdown
329
- exit
330
-
331
- Step 5: Test Before Security
332
- From PC2:
333
- ping 192.168.1.10
334
- Communication should be successful
335
-
336
- Step 6: Apply ACL
337
- access-list 1 deny 192.168.1.20
338
- access-list 1 permit any
339
-
340
- Apply ACL:
341
- interface g0/0
342
- ip access-group 1 in
343
- exit
344
-
345
- Step 7: Test After Security
346
- From PC2:
347
- ping 192.168.1.10
348
- Should fail
46
+ ---
47
+ const http = require('http')
48
+ const fs = require('fs')
349
49
 
350
- From PC1:
351
- ping 192.168.1.20
352
- Should work
50
+ const server = http.createServer();
353
51
 
354
- Step 8: Configure Port Security on Switch
355
- enable
356
- configure terminal
357
- interface fa0/1
358
- switchport mode access
359
- switchport port-security
360
- switchport port-security maximum 1
361
- exit
52
+ server.on('request', (req, res) => {
53
+ const rstream = fs.createReadStream('./product.json',"utf-8");
54
+ rstream.pipe(res);
55
+ })
362
56
 
363
- Vulnerabilities Identified:
364
- No access control
365
- No device restriction
366
- No traffic filtering
57
+ server.on("request", (req, res) => {
367
58
 
368
- Security Measures Applied:
369
- ACL controls communication between devices
370
- Port Security restricts number of devices per port
59
+ const rstream = fs.createReadStream("./product.json", "utf-8");
371
60
 
372
- Additional Concepts:
373
- IDS detects suspicious activities such as unusual traffic
374
- IPsec encrypts data for secure transmission
61
+ rstream.on("data", (chunkData) => {
62
+ res.write(chunkData);
63
+ });
375
64
 
376
- Simulation (Optional):
377
- Use Simulation mode
378
- Filter ICMP
379
- Observe packet drop due to ACL
65
+ rstream.on("end", () => {
66
+ res.end(); // correct: just end response
67
+ });
380
68
 
381
- Final Result:
382
- PC2 is blocked
383
- PC1 is allowed
384
- Switch ports are secured
385
- Network is protected successfully
69
+ rstream.on("error", (err) => {
70
+ console.log(err);
71
+ res.writeHead(500, { "Content-Type": "text/plain" });
72
+ res.end("File not found");
73
+ });
386
74
 
75
+ });
387
76
 
77
+ server.listen(3000, "127.0.0.1", () => {
78
+ console.log("Server is running at http://127.0.0.1:3000");
79
+ });
388
80
 
389
81
 
390
82
 
83
+ ---
391
84
 
85
+ import readline from "readline";
86
+
87
+ const r1 = readline.createInterface({
88
+ input: process.stdin,
89
+ output: process.stdout
90
+ })
91
+
92
+
93
+ // Armstrong
94
+ let n;
95
+ r1.question('Enter a num : ', (num) => {
96
+ n = parseInt(num)
97
+ let arm = 0;
98
+ let og = n;
99
+
100
+ let len = num.length;
101
+
102
+ while(n > 0){
103
+ let dig = n % 10;
104
+ arm += Math.pow(dig,len);
105
+ n = Math.floor(n / 10);
106
+ }
107
+ if(og == arm)
108
+ console.log('Is Armstrong!!');
109
+ else
110
+ console.log('Is Not a Armstrong!!');
111
+ })
112
+
113
+
114
+ // calculator
115
+ let n1, n2;
116
+ r1.question('Enter the num : ', (num1) => {
117
+ n1 = parseInt(num1);
118
+ r1.question('Enter the num : ', (num2) => {
119
+ n2 = parseInt(num2);
120
+
121
+ let sum = n1 + n2;
122
+ let sub = n1 - n2;
123
+ let mul = n1 * n2;
124
+ let div = n1 / n2;
125
+
126
+ console.log('Addition : ', sum);
127
+ console.log('Subtraction : ', sub);
128
+ console.log('Multiplication : ', mul);
129
+ console.log('Division : ', div);
130
+ })
131
+ })
132
+
133
+ // Even or ODD
134
+ r1.question('Enter a num : ', (num) => {
135
+ let n = num;
136
+ if(n % 2 == 0)
137
+ console.log('Even');
138
+ else
139
+ console.log('Odd');
140
+ })
141
+
142
+
143
+ // palindrom
144
+ r1.question('Enter a num : ', (num) => {
145
+ let s = num.toString();
146
+ let revNum = s.split('').reverse().join('');
147
+ if(revNum == s)
148
+ console.log('Is palindrome')
149
+ else
150
+ console.log('Not a palindrome')
151
+ })
152
+
153
+
154
+ //Factorial of a Number
155
+ r1.question('Enter a number: ', (num) => {
156
+ let n = parseInt(num);
157
+ let fact = 1;
392
158
 
159
+ for(let i = 1; i <= n; i++){
160
+ fact *= i;
161
+ }
393
162
 
163
+ console.log('Factorial:', fact);
164
+ });
394
165
 
395
166
 
167
+ //Fibonacci Series
168
+ r1.question('Enter number of terms: ', (num) => {
169
+ let n = parseInt(num);
170
+ let a = 0, b = 1;
396
171
 
172
+ console.log(a);
173
+ console.log(b);
397
174
 
175
+ for(let i = 2; i < n; i++){
176
+ let next = a + b;
177
+ console.log(next);
178
+ a = b;
179
+ b = next;
180
+ }
181
+ });
398
182
 
183
+ //Prime Number Check
184
+ r1.question('Enter a number: ', (num) => {
185
+ let n = parseInt(num);
186
+ let isPrime = true;
399
187
 
188
+ if(n <= 1) isPrime = false;
400
189
 
190
+ for(let i = 2; i <= Math.sqrt(n); i++){
191
+ if(n % i === 0){
192
+ isPrime = false;
193
+ break;
194
+ }
195
+ }
401
196
 
197
+ console.log(isPrime ? 'Prime' : 'Not Prime');
198
+ });
402
199
 
403
200
 
201
+ //Sum of Digits
202
+ r1.question('Enter a number: ', (num) => {
203
+ let n = parseInt(num);
204
+ let sum = 0;
404
205
 
206
+ while(n > 0){
207
+ sum += n % 10;
208
+ n = Math.floor(n / 10);
209
+ }
405
210
 
211
+ console.log('Sum of digits:', sum);
212
+ });
406
213
 
407
214
 
215
+ //Reverse a Number
216
+ r1.question('Enter a number: ', (num) => {
217
+ let n = parseInt(num);
218
+ let rev = 0;
408
219
 
220
+ while(n > 0){
221
+ let digit = n % 10;
222
+ rev = rev * 10 + digit;
223
+ n = Math.floor(n / 10);
224
+ }
409
225
 
410
- AIM:
411
- To demonstrate IP Spoofing attack and implement security measures to prevent unauthorized access.
226
+ console.log('Reversed number:', rev);
227
+ });
412
228
 
413
- Step 1: Topology Setup
414
- Devices required:
415
- 1 Router (2911)
416
- 1 Switch (2960)
417
- PC1 (Trusted user)
418
- PC2 (Attacker)
419
- 1 Server
420
229
 
421
- Connections:
422
- PC1 to Switch Fa0/1
423
- PC2 to Switch Fa0/2
424
- Switch Fa0/24 to Router G0/0
425
- Server to Router G0/1
230
+ //Largest of Three Numbers
231
+ r1.question('Enter first number: ', (a) => {
232
+ r1.question('Enter second number: ', (b) => {
233
+ r1.question('Enter third number: ', (c) => {
426
234
 
427
- Step 2: IP Configuration
428
- PC1 IP 192.168.1.10 Gateway 192.168.1.1
429
- PC2 IP 192.168.1.20 Gateway 192.168.1.1
430
- Server IP 10.0.0.2 Gateway 10.0.0.1
235
+ let n1 = parseInt(a);
236
+ let n2 = parseInt(b);
237
+ let n3 = parseInt(c);
431
238
 
432
- Step 3: Configure Router
433
- enable
434
- configure terminal
239
+ let max = Math.max(n1, n2, n3);
435
240
 
436
- interface g0/0
437
- ip address 192.168.1.1 255.255.255.0
438
- no shutdown
439
- exit
241
+ console.log('Largest:', max);
242
+ });
243
+ });
244
+ });
440
245
 
441
- interface g0/1
442
- ip address 10.0.0.1 255.255.255.0
443
- no shutdown
444
- exit
445
246
 
446
- Step 4: Configure Routing
447
- ip route 10.0.0.0 255.255.255.0 10.0.0.1
247
+ //Largest of Three Numbers
248
+ r1.question('Enter a number: ', (num) => {
249
+ let n = parseInt(num);
448
250
 
449
- Step 5: Apply Trust-Based ACL
450
- access-list 10 permit 192.168.1.10
451
- access-list 10 deny any
251
+ for(let i = 1; i <= 10; i++){
252
+ console.log(`${n} x ${i} = ${n * i}`);
253
+ }
254
+ });
452
255
 
453
- interface g0/0
454
- ip access-group 10 in
455
256
 
456
- Step 6: Test Before Attack
457
- From PC1:
458
- ping 10.0.0.2 (should work)
257
+ //Count Digits
258
+ r1.question('Enter a number: ', (num) => {
259
+ let count = num.length;
260
+ console.log('Total digits:', count);
261
+ });
459
262
 
460
- From PC2:
461
- ping 10.0.0.2 (should fail)
462
263
 
463
- Step 7: Simulate IP Spoofing
464
- Change PC2 IP to 192.168.1.10
465
264
 
466
- Test again:
467
- ping 10.0.0.2 (should work)
265
+ ---
468
266
 
469
- Step 8: Impact
470
- Unauthorized access
471
- Security bypass
472
- Fake identity
473
267
 
474
- Step 9: Countermeasure 1 Anti-Spoofing ACL
475
- ip access-list extended ANTI-SPOOF
476
- deny ip 192.168.1.0 0.0.0.255 any
477
- permit ip any any
268
+ <!DOCTYPE html>
269
+ <html lang="en">
270
+ <head>
271
+ <meta charset="UTF-8">
272
+ <title>My App</title>
273
+
274
+ <style>
275
+ * {
276
+ margin: 0;
277
+ padding: 0;
278
+ box-sizing: border-box;
279
+ font-family: Arial, sans-serif;
280
+ }
281
+
282
+ body {
283
+ background: #f5f7fa;
284
+ }
285
+
286
+ .navbar {
287
+ display: flex;
288
+ justify-content: space-between;
289
+ padding: 15px 40px;
290
+ background: #333;
291
+ color: white;
292
+ }
293
+
294
+ .navbar a {
295
+ color: white;
296
+ margin-left: 20px;
297
+ text-decoration: none;
298
+ }
299
+
300
+ .hero {
301
+ text-align: center;
302
+ padding: 60px 20px;
303
+ }
304
+
305
+ .hero h1 {
306
+ font-size: 36px;
307
+ }
308
+
309
+ .hero p {
310
+ margin: 10px 0;
311
+ }
312
+
313
+ .features {
314
+ display: flex;
315
+ justify-content: center;
316
+ gap: 20px;
317
+ padding: 40px;
318
+ }
319
+
320
+ .card {
321
+ background: white;
322
+ padding: 20px;
323
+ width: 200px;
324
+ text-align: center;
325
+ border-radius: 8px;
326
+ }
327
+
328
+ .dynamic {
329
+ text-align: center;
330
+ margin: 20px;
331
+ font-size: 20px;
332
+ color: #333;
333
+ }
334
+
335
+ footer {
336
+ text-align: center;
337
+ padding: 15px;
338
+ background: #333;
339
+ color: white;
340
+ }
341
+ </style>
342
+ </head>
343
+
344
+ <body>
345
+
346
+ <!-- Navbar -->
347
+ <nav class="navbar">
348
+ <h2>MyApp</h2>
349
+ <div>
350
+ <a href="/home">Home</a>
351
+ <a href="/about">About</a>
352
+ <a href="/contact">Contact</a>
353
+ <a href="/support">Support</a>
354
+ </div>
355
+ </nav>
356
+
357
+ <!-- Dynamic Content from Server -->
358
+ <div class="dynamic">
359
+ {{CONTENT}}
360
+ </div>
361
+
362
+ <!-- Hero Section -->
363
+ <section class="hero">
364
+ <h1>Simple Node Application</h1>
365
+ <p>This page is served using a basic Node.js server.</p>
366
+ </section>
367
+
368
+ <!-- Features -->
369
+ <section class="features">
370
+ <div class="card">
371
+ <h3>Fast</h3>
372
+ <p>Handles requests efficiently</p>
373
+ </div>
374
+ <div class="card">
375
+ <h3>Simple</h3>
376
+ <p>Easy routing and structure</p>
377
+ </div>
378
+ <div class="card">
379
+ <h3>Flexible</h3>
380
+ <p>Can be extended easily</p>
381
+ </div>
382
+ </section>
383
+
384
+ <!-- Footer -->
385
+ <footer>
386
+ <p>Basic Node Server Example</p>
387
+ </footer>
388
+
389
+ </body>
390
+ </html>
478
391
 
479
- interface g0/1
480
- ip access-group ANTI-SPOOF in
481
392
 
482
- Step 10: Countermeasure 2 uRPF
483
- interface g0/0
484
- ip verify unicast source reachable-via rx
485
393
 
486
- Step 11: Switch Port Security
487
- enable
488
- configure terminal
489
394
 
490
- interface fa0/1
491
- switchport mode access
492
- switchport port-security
493
- switchport port-security maximum 1
494
- switchport port-security mac-address sticky
495
- switchport port-security violation shutdown
395
+ ---
496
396
 
497
- Final Understanding:
498
- Before ACL everyone allowed
499
- ACL allows only trusted IP
500
- Spoofing bypasses security
501
- uRPF blocks spoofed packets
502
397
 
503
- Conclusion:
504
- IP-based trust is not secure and must be verified using mechanisms like uRPF and port security
505
398
 
506
- Result:
507
- Attack simulated successfully
508
- Vulnerability identified
509
- Security measures implemented
399
+ const http = require("http");
400
+ const fs = require("fs");
401
+ const path = require("path");
510
402
 
403
+ let counter = 0;
511
404
 
405
+ // Read HTML template
406
+ const content = fs.readFileSync("./indexFinal.html", "utf-8");
512
407
 
408
+ const server = http.createServer((req, res) => {
513
409
 
410
+ counter++;
411
+ console.log(`Server hit ${counter} times`);
514
412
 
413
+ let url = req.url.toLowerCase();
515
414
 
415
+ // Serve CSS
416
+ if (url === "/style.css") {
417
+ const cssPath = path.join(__dirname, "style.css");
418
+ const style = fs.readFileSync(cssPath, "utf-8");
516
419
 
420
+ res.writeHead(200, { "Content-Type": "text/css" });
421
+ return res.end(style);
422
+ }
517
423
 
424
+ // Routing pages
425
+ let pageContent = "";
518
426
 
427
+ if (url === "/" || url === "/home") {
428
+ pageContent = "🏠 Welcome to Home Page";
429
+ }
430
+ else if (url === "/about") {
431
+ pageContent = "📖 About Us Page";
432
+ }
433
+ else if (url === "/contact") {
434
+ pageContent = "📞 Contact Page";
435
+ }
436
+ else if (url === "/support") {
437
+ pageContent = "🛠 Support Page";
438
+ }
439
+ else {
440
+ res.writeHead(404, { "Content-Type": "text/html" });
441
+ return res.end(content.replace("{{CONTENT}}", " 404 Page Not Found"));
442
+ }
519
443
 
444
+ // Common response
445
+ res.writeHead(200, { "Content-Type": "text/html" });
446
+ res.end(content.replace("{{CONTENT}}", pageContent));
520
447
 
448
+ });
521
449
 
450
+ server.listen(3000, "127.0.0.1", () => {
451
+ console.log("Server running at http://127.0.0.1:3000");
452
+ });
522
453
 
523
454
 
524
455
 
525
456
 
526
457
 
527
458
 
459
+ ---
528
460
 
529
461
 
462
+ const http = require("http");
463
+ const fs = require("fs");
530
464
 
465
+ let counter = 0;
531
466
 
467
+ const content = fs.readFileSync("./Template/index.html", "utf-8");
532
468
 
533
- AIM:
534
- To allow normal UDP communication and block unwanted UDP traffic using ACL.
469
+ const server = http.createServer((request, response) => {
535
470
 
536
- Step 1: Build the Network
537
- Devices required:
538
- 1 Router (2911)
539
- 1 Switch (2960)
540
- PC1 (Client)
541
- PC2 (Attacker)
542
- 1 Server
471
+ counter++;
472
+ console.log(`Server started ${counter} times`);
543
473
 
544
- Connections:
545
- PC1 FastEthernet0 to Switch Fa0/1
546
- PC2 FastEthernet0 to Switch Fa0/2
547
- Server FastEthernet0 to Switch Fa0/3
548
- Switch Fa0/24 to Router GigabitEthernet0/0
474
+ let path = request.url.toLowerCase();
549
475
 
550
- Step 2: IP Configuration
551
- PC1 IP 192.168.1.10 Gateway 192.168.1.1
552
- PC2 IP 192.168.1.30 Gateway 192.168.1.1
553
- Server IP 192.168.1.20
554
- Subnet Mask 255.255.255.0
476
+
477
+ if (path === "/" || path === "/home") {
478
+ response.writeHead(200, { "Content-Type": "text/html" });
479
+ response.end(content.replace("{{CONTENT}}", "You are in home page"));
480
+ }
555
481
 
556
- Step 3: Configure Router
557
- enable
558
- configure terminal
559
- interface g0/0
560
- ip address 192.168.1.1 255.255.255.0
561
- no shutdown
562
- exit
482
+
483
+ else if (path === "/about") {
484
+ response.writeHead(200, { "Content-Type": "text/html" });
485
+ response.end(content.replace("{{CONTENT}}", "You are in about us page"));
486
+ }
563
487
 
564
- Step 4: Enable UDP Service on Server
565
- Open Server -> Services -> DNS
566
- Turn DNS ON
567
- Add entry:
568
- Name example.com
569
- Address 192.168.1.20
488
+
489
+ else if (path === "/contact") {
490
+ response.writeHead(200, { "Content-Type": "text/html" });
491
+ response.end(content.replace("{{CONTENT}}", "You are in contact page"));
492
+ }
570
493
 
571
- Step 5: Test UDP Communication
572
- From PC1:
573
- nslookup example.com 192.168.1.20
574
- UDP communication should work
494
+
495
+ else if (path === "/support") {
496
+ response.writeHead(200, { "Content-Type": "text/html" });
497
+ response.end(content.replace("{{CONTENT}}", "Support me aagya bhai"));
498
+ }
575
499
 
576
- Step 6: Apply ACL to Block Attacker
577
- Router(config)# access-list 100 deny udp host 192.168.1.30 any
578
- Router(config)# access-list 100 permit ip any any
500
+
501
+ else if (path === "/product") {
579
502
 
580
- Apply ACL:
581
- interface g0/0
582
- ip access-group 100 in
583
- exit
503
+ fs.readFile("./data/products.json", "utf-8", (error, jsonData) => {
584
504
 
585
- Step 7: Test After ACL
586
- From PC2:
587
- nslookup example.com 192.168.1.20 (should fail)
505
+ if (error) {
506
+ response.writeHead(500, { "Content-Type": "text/plain" });
507
+ return response.end("Error reading JSON file");
508
+ }
588
509
 
589
- From PC1:
590
- nslookup example.com 192.168.1.20 (should work)
510
+ response.writeHead(200, { "Content-Type": "application/json" });
511
+ response.end(jsonData);
512
+ });
513
+ }
591
514
 
592
- Step 8: Block DNS Service (Port-Based ACL)
593
- Router(config)# access-list 101 deny udp any any eq 53
594
- Router(config)# access-list 101 permit ip any any
515
+ // 404
516
+ else {
517
+ response.writeHead(404, { "Content-Type": "text/html" });
518
+ response.end(content.replace("{{CONTENT}}", "Error : 404 NOT FOUND"));
519
+ }
595
520
 
596
- Apply:
597
- interface g0/0
598
- ip access-group 101 in
599
- exit
521
+ });
600
522
 
601
- Test:
602
- From PC1:
603
- nslookup example.com 192.168.1.20 (should fail)
523
+ server.listen(3000, "127.0.0.1", () => {
524
+ console.log("Server running at http://127.0.0.1:3000");
525
+ });
604
526
 
605
- Step 9: Important Concept
606
- If all devices are in same network, traffic bypasses router
607
- Communication becomes PC -> Switch -> Server
608
- ACL will not work
609
527
 
610
- Step 10: Fix Topology
611
- Change Server network:
612
- Server IP 10.0.0.2 Gateway 10.0.0.1
613
528
 
614
- Configure Router:
615
- interface g0/1
616
- ip address 10.0.0.1 255.255.255.0
617
- no shutdown
618
529
 
619
- Now traffic flows through router:
620
- PC -> Router -> Server
621
- ACL works correctly
622
530
 
623
- Concepts:
624
- UDP is fast and connectionless protocol
625
- ACL filters traffic based on rules
626
- Port 53 is used for DNS
627
- Router must be in path for ACL to work
628
531
 
629
- Result:
630
- UDP communication tested
631
- Attacker blocked using ACL
632
- DNS service blocked using port-based ACL
633
- Network secured successfully
634
532
 
635
533
 
636
534
 
@@ -648,93 +546,46 @@ Network secured successfully
648
546
 
649
547
 
650
548
 
549
+ ---
651
550
 
551
+ [
552
+ {
553
+ "id": 1,
554
+ "name": "Laptop",
555
+ "price": 60000
556
+ },
557
+ {
558
+ "id": 2,
559
+ "name": "Phone",
560
+ "price": 20000
561
+ },
562
+ {
563
+ "id": 3,
564
+ "name": "Tablet",
565
+ "price": 30000
566
+ }
567
+ ]
652
568
 
653
569
 
654
570
 
655
571
 
656
572
 
657
- AIM:
658
- Create a network, enable DNS (UDP), allow normal user, and block attacker using ACL.
659
573
 
660
- Step 1: Topology
661
- PC1 (Client) and PC2 (Attacker) connected to Switch
662
- Switch connected to Router G0/0
663
- Router G0/1 connected to Server
664
574
 
665
- Step 2: Connections
666
- Use Copper Straight-Through cables
667
- PC1 to Switch Fa0/1
668
- PC2 to Switch Fa0/2
669
- Switch to Router G0/0
670
- Router G0/1 to Server
671
- All links should be active
672
575
 
673
- Step 3: IP Configuration
674
- PC1 IP 192.168.1.10 Mask 255.255.255.0 Gateway 192.168.1.1 DNS 10.0.0.2
675
- PC2 IP 192.168.1.30 Mask 255.255.255.0 Gateway 192.168.1.1 DNS 10.0.0.2
676
- Server IP 10.0.0.2 Mask 255.255.255.0 Gateway 10.0.0.1
677
576
 
678
- Step 4: Router Configuration
679
- enable
680
- configure terminal
681
577
 
682
- interface g0/0
683
- ip address 192.168.1.1 255.255.255.0
684
- no shutdown
685
- exit
686
578
 
687
- interface g0/1
688
- ip address 10.0.0.1 255.255.255.0
689
- no shutdown
690
- exit
691
579
 
692
- Step 5: Enable DNS on Server
693
- Open Server -> Services -> DNS
694
- Turn DNS ON
695
- Add entry:
696
- Name example.com
697
- Address 10.0.0.2
698
580
 
699
- Step 6: Initial Testing
700
- From PC1:
701
- ping 10.0.0.2
702
- This builds ARP
703
581
 
704
- Then:
705
- nslookup example.com
706
- Should work successfully
707
582
 
708
- Step 7: Apply ACL Security
709
- configure terminal
710
583
 
711
- access-list 101 deny udp host 192.168.1.30 any
712
- access-list 101 permit ip any any
713
584
 
714
- interface g0/0
715
- ip access-group 101 in
716
- exit
717
585
 
718
- Step 8: Final Testing
719
- From PC1:
720
- nslookup example.com
721
- Should work
722
586
 
723
- From PC2:
724
- nslookup example.com
725
- Should fail
726
587
 
727
- Concepts:
728
- Router must be in path for ACL to work
729
- DNS uses UDP port 53
730
- First ping builds ARP and avoids timeout
731
- ACL filters traffic based on rules
732
588
 
733
- Final Result:
734
- PC1 allowed
735
- PC2 blocked
736
- DNS working
737
- ACL applied successfully
738
589
 
739
590
 
740
591
 
@@ -742,21 +593,72 @@ ACL applied successfully
742
593
 
743
594
 
744
595
 
596
+ ---
745
597
 
746
598
 
599
+ GET
747
600
 
601
+ ---
602
+ const express = require('express');
603
+ const fs = require('fs');
748
604
 
605
+ const app = express();
749
606
 
607
+ // Helper function to read data
608
+ function getProducts() {
609
+ const data = fs.readFileSync('./product.json', 'utf-8');
610
+ return JSON.parse(data).products;
611
+ }
750
612
 
613
+ // Home route
614
+ app.get('/', (req, res) => {
615
+ res.status(200).send('You are on home page');
616
+ });
751
617
 
618
+ // About route
619
+ app.get('/about', (req, res) => {
620
+ res.status(200).send('You are on about page');
621
+ });
752
622
 
623
+ // Get all products
624
+ app.get('/product', (req, res) => {
625
+ const products = getProducts();
753
626
 
627
+ res.status(200).json({
628
+ status: 'success',
629
+ results: products.length,
630
+ data: products
631
+ });
632
+ });
754
633
 
634
+ // Get single product by ID
635
+ app.get('/product/:id', (req, res) => {
636
+ const products = getProducts();
637
+ const id = parseInt(req.params.id);
755
638
 
639
+ const product = products.find(el => el.id === id);
756
640
 
641
+ if (!product) {
642
+ return res.status(404).json({
643
+ status: 'fail',
644
+ message: 'Product not found'
645
+ });
646
+ }
757
647
 
648
+ res.status(200).json({
649
+ status: 'success',
650
+ data: product
651
+ });
652
+ });
758
653
 
654
+ // Contact route
655
+ app.get('/contact', (req, res) => {
656
+ res.status(200).send('You are on contact page');
657
+ });
759
658
 
659
+ app.listen(3000, () => {
660
+ console.log('Server running on port 3000');
661
+ });
760
662
 
761
663
 
762
664
 
@@ -764,97 +666,20 @@ ACL applied successfully
764
666
 
765
667
 
766
668
 
767
- AIM:
768
- Simulate a DNS-based UDP hijacking scenario, observe its impact on the client, and apply basic protection.
769
669
 
770
- Step 1: Topology Setup
771
- Connect devices using Copper Straight-Through:
772
- PC1 to Switch
773
- PC2 to Switch
774
- Server to Switch
775
- Switch to Router
776
- Ensure all connections are active
777
670
 
778
- Step 2: IP Configuration
779
- PC1 IP 192.168.1.10 Mask 255.255.255.0 Gateway 192.168.1.1 DNS 192.168.1.100
780
- PC2 IP 192.168.1.20 Gateway 192.168.1.1
781
- Server IP 192.168.1.100 Gateway 192.168.1.1
782
671
 
783
- Step 3: Router Configuration
784
- enable
785
- configure terminal
786
- interface g0/0
787
- ip address 192.168.1.1 255.255.255.0
788
- no shutdown
789
- exit
790
672
 
791
- Step 4: Enable DNS on Real Server
792
- Open Server -> Services -> DNS
793
- Turn DNS ON
794
- Add entry:
795
- example.com maps to 192.168.1.100
796
673
 
797
- Step 5: Test Normal Output
798
- From PC1:
799
- nslookup example.com
800
- Expected result:
801
- Name example.com
802
- Address 192.168.1.100
803
674
 
804
- Step 6: Simulate Attack
805
- Turn OFF real server
806
- On PC2 change IP to 192.168.1.100
807
- Enable DNS on PC2
808
- Add entry:
809
- example.com maps to 5.5.5.5
810
675
 
811
- Step 7: Test Attack Output
812
- From PC1:
813
- nslookup example.com
814
- Expected result:
815
- Name example.com
816
- Address 5.5.5.5
817
676
 
818
- Observation:
819
- Before attack DNS resolves to 192.168.1.100
820
- After attack DNS resolves to 5.5.5.5
821
- Client is misled
822
677
 
823
- Step 8: Apply Basic Protection using Port Security
824
- On Switch CLI:
825
- enable
826
- configure terminal
827
- interface fa0/2
828
- switchport mode access
829
- switchport port-security
830
- switchport port-security maximum 1
831
- switchport port-security mac-address sticky
832
- switchport port-security violation shutdown
833
- exit
834
678
 
835
- Step 9: Final Check
836
- Attempt attack again
837
- Port security blocks attacker or shuts down port
838
679
 
839
- Output Observation Methods:
840
- Command Line:
841
- Use nslookup example.com before and after attack
842
680
 
843
- Simulation Mode:
844
- Select Simulation
845
- Filter DNS or UDP
846
- Run nslookup
847
- Observe source IP, destination IP, and UDP port 53
848
681
 
849
- Conclusion:
850
- DNS over UDP can be exploited by spoofing
851
- Client blindly trusts DNS response
852
- Security measures like port security help prevent attacks
853
682
 
854
- Result:
855
- Attack successfully simulated
856
- Impact observed
857
- Basic protection applied
858
683
 
859
684
 
860
685
 
@@ -868,168 +693,159 @@ Basic protection applied
868
693
 
869
694
 
870
695
 
696
+ POST
871
697
 
698
+ ---
872
699
 
700
+ const express = require('express');
701
+ const fs = require('fs');
873
702
 
703
+ const app = express();
874
704
 
705
+ app.use(express.json());
875
706
 
876
707
 
708
+ function getProducts() {
709
+ const data = fs.readFileSync('./product.json', 'utf-8');
710
+ return JSON.parse(data).products;
711
+ }
877
712
 
713
+ function saveProducts(products) {
714
+ fs.writeFileSync('./product.json', JSON.stringify({ products }, null, 2));
715
+ }
878
716
 
717
+ app.post('/product', (req, res) => {
879
718
 
719
+ const products = getProducts();
720
+ const newProduct = req.body;
880
721
 
722
+
723
+ if (!newProduct.name || !newProduct.price) {
724
+ return res.status(400).json({
725
+ status: 'fail',
726
+ message: 'Name and price are required'
727
+ });
728
+ }
881
729
 
730
+
731
+ const newId = products.length > 0
732
+ ? products[products.length - 1].id + 1
733
+ : 1;
882
734
 
735
+ newProduct.id = newId;
883
736
 
737
+ products.push(newProduct);
884
738
 
739
+ saveProducts(products);
885
740
 
741
+ res.status(201).json({
742
+ status: 'success',
743
+ message: 'Product added successfully',
744
+ data: newProduct
745
+ });
746
+ });
886
747
 
748
+ app.listen(3000, () => {
749
+ console.log('Server running on port 3000');
750
+ });
887
751
 
888
752
 
889
753
 
890
754
 
891
- AIM:
892
- Simulate a DoS condition using continuous requests, observe its impact on a server, and apply prevention techniques.
893
755
 
894
- Step 1: Topology
895
- Devices:
896
- PC1, PC2, PC3, Server connected to Switch
897
- Switch connected to Router G0/0
898
- Ensure all connections are active
899
756
 
900
- Step 2: IP Configuration
901
- PC1 IP 192.168.1.10
902
- PC2 IP 192.168.1.20
903
- PC3 IP 192.168.1.30
904
- Server IP 192.168.1.100
905
- Mask 255.255.255.0
906
- Gateway 192.168.1.1
907
757
 
908
- Step 3: Router Configuration
909
- enable
910
- configure terminal
911
- interface g0/0
912
- ip address 192.168.1.1 255.255.255.0
913
- no shutdown
914
- exit
915
758
 
916
- Step 4: Enable Server Service
917
- Open Server -> Services -> HTTP
918
- Turn HTTP ON
919
759
 
920
- Step 5: Normal Test
921
- From PC1:
922
- ping 192.168.1.100
923
- Stable replies indicate normal operation
924
760
 
925
- Step 6: Simulate DoS Attack
926
- From PC2:
927
- ping 192.168.1.100 -t
928
761
 
929
- From PC3:
930
- ping 192.168.1.100 -t
931
762
 
932
- Continuous traffic is generated
933
763
 
934
- Step 7: Observe Impact
935
- From PC1:
936
- ping 192.168.1.100
937
764
 
938
- Expected results:
939
- Request timed out
940
- High delay
941
- Packet loss
942
765
 
943
- Indicates server overload and network congestion
944
766
 
945
- Step 8: Important Concept
946
- If all devices are in same network, traffic flows directly
947
- PC -> Switch -> Server
948
- Router is bypassed
949
- ACL on router will not work
950
767
 
951
- Step 9: Apply Switch Port Security
952
- enable
953
- configure terminal
954
768
 
955
- interface fa0/2
956
- switchport port-security
957
- switchport port-security maximum 1
958
- switchport port-security violation shutdown
959
- exit
960
769
 
961
- interface fa0/3
962
- switchport port-security
963
- switchport port-security maximum 1
964
- switchport port-security violation shutdown
965
- exit
966
770
 
967
- Limits attacker behavior
968
771
 
969
- Step 10: Improved Topology for Router Control
970
- Change Server network:
971
- Server IP 10.0.0.2 Gateway 10.0.0.1
972
772
 
973
- Add router interface:
974
- interface g0/1
975
- ip address 10.0.0.1 255.255.255.0
976
- no shutdown
977
773
 
978
- Traffic now passes through router
979
774
 
980
- Step 11: Apply ACL Protection
981
- ip access-list extended BLOCK_ICMP
982
- permit icmp host 192.168.1.10 host 10.0.0.2
983
- deny icmp any any
984
775
 
985
- interface g0/0
986
- ip access-group BLOCK_ICMP in
987
776
 
988
- Step 12: Final Testing
989
- From PC1:
990
- ping 10.0.0.2 (should work)
991
777
 
992
- From PC2 and PC3:
993
- ping 10.0.0.2 (should fail)
994
778
 
995
- Output Observation:
996
- Command Line:
997
- Compare ping before and during attack
998
779
 
999
- Simulation Mode:
1000
- Filter ICMP
1001
- Observe multiple packets and congestion
1002
780
 
1003
- Conclusion:
1004
- DoS attack floods server with requests causing delay and packet loss
1005
- Switch port security and ACL help control traffic
1006
781
 
1007
- Result:
1008
- Attack simulated
1009
- Impact observed
1010
- Protection applied successfully
1011
782
 
1012
783
 
1013
784
 
1014
785
 
1015
786
 
1016
787
 
788
+ ---
789
+ PATCH
790
+ ---
1017
791
 
1018
792
 
793
+ const express = require('express');
794
+ const fs = require('fs');
1019
795
 
796
+ const app = express();
1020
797
 
798
+ app.use(express.json());
1021
799
 
800
+ // Helper functions
801
+ function getProducts() {
802
+ const data = fs.readFileSync('./product.json', 'utf-8');
803
+ return JSON.parse(data).products;
804
+ }
1022
805
 
806
+ function saveProducts(products) {
807
+ fs.writeFileSync('./product.json', JSON.stringify({ products }, null, 2));
808
+ }
1023
809
 
1024
810
 
811
+ app.patch('/product/:id', (req, res) => {
1025
812
 
813
+ const products = getProducts();
814
+ const id = parseInt(req.params.id);
1026
815
 
816
+ const product = products.find(el => el.id === id);
1027
817
 
818
+
819
+ if (!product) {
820
+ return res.status(404).json({
821
+ status: 'fail',
822
+ message: 'Product not found'
823
+ });
824
+ }
1028
825
 
826
+
827
+ if (req.body.id) {
828
+ return res.status(400).json({
829
+ status: 'fail',
830
+ message: 'Cannot update product id'
831
+ });
832
+ }
1029
833
 
834
+
835
+ Object.assign(product, req.body);
1030
836
 
837
+ saveProducts(products);
1031
838
 
839
+ res.status(200).json({
840
+ status: 'success',
841
+ message: 'Product updated successfully',
842
+ data: product
843
+ });
844
+ });
1032
845
 
846
+ app.listen(3000, () => {
847
+ console.log('Server running on port 3000');
848
+ });
1033
849
 
1034
850
 
1035
851
 
@@ -1039,9 +855,6 @@ Protection applied successfully
1039
855
 
1040
856
 
1041
857
 
1042
- 1. Basic Network (OSI Flow)
1043
- PC
1044
- ping 192.168.1.2 ++
1045
858
 
1046
859
 
1047
860
 
@@ -1058,60 +871,69 @@ ping 192.168.1.2 ++
1058
871
 
1059
872
 
1060
873
 
1061
- 2. IPv4 Addressing + Routing
1062
- Router
1063
- enable ++
1064
- configure terminal ++
1065
874
 
1066
- interface g0/0 ++
1067
- ip address 192.168.1.1 255.255.255.0 ++
1068
- no shutdown ++
1069
- exit ++
1070
875
 
1071
- interface s0/0/0
1072
- ip address 172.16.1.1 255.255.255.252
1073
- no shutdown
1074
- exit
1075
876
 
1076
- ip route 10.0.0.0 255.255.255.248 172.16.1.2
1077
- PC
1078
- ping 10.0.0.2 ++
1079
877
 
1080
878
 
1081
879
 
1082
880
 
881
+ ---
882
+ DELETE
883
+ ---
1083
884
 
885
+ const express = require('express');
886
+ const fs = require('fs');
1084
887
 
888
+ const app = express();
1085
889
 
890
+ app.use(express.json());
1086
891
 
892
+ function getProducts() {
893
+ const data = fs.readFileSync('./product.json', 'utf-8');
894
+ return JSON.parse(data).products;
895
+ }
1087
896
 
897
+ function saveProducts(products) {
898
+ fs.writeFileSync('./product.json', JSON.stringify({ products }, null, 2));
899
+ }
1088
900
 
901
+ app.delete('/product/:id', (req, res) => {
1089
902
 
903
+ const products = getProducts();
904
+ const id = parseInt(req.params.id);
1090
905
 
1091
- 3. NAT (PAT)
1092
- Router
1093
- enable ++
1094
- configure terminal ++
906
+
907
+ const index = products.findIndex(el => el.id === id);
1095
908
 
1096
- interface g0/0 ++
1097
- ip nat inside
1098
- exit ++
909
+
910
+ if (index === -1) {
911
+ return res.status(404).json({
912
+ status: 'fail',
913
+ message: 'Product not found'
914
+ });
915
+ }
1099
916
 
1100
- interface g0/1 ++
1101
- ip nat outside
1102
- exit ++
917
+
918
+ const deletedProduct = products.splice(index, 1);
1103
919
 
1104
- access-list 1 permit 192.168.1.0 0.0.0.255 ++
920
+ saveProducts(products);
1105
921
 
1106
- ip nat inside source list 1 interface g0/1 overload
922
+ res.status(200).json({
923
+ status: 'success',
924
+ message: 'Product deleted successfully',
925
+ data: deletedProduct[0]
926
+ });
927
+ });
1107
928
 
1108
- ip route 0.0.0.0 0.0.0.0 203.0.113.2
1109
- Router (Check)
1110
- show ip nat translations
1111
- PC
1112
- ping 203.0.113.2 ++
929
+ app.listen(3000, () => {
930
+ console.log('Server running on port 3000');
931
+ });
1113
932
 
1114
933
 
934
+ ---
935
+ PUT
936
+ ---
1115
937
 
1116
938
 
1117
939
 
@@ -1119,11 +941,6 @@ ping 203.0.113.2 ++
1119
941
 
1120
942
 
1121
943
 
1122
- 4. IPv4 Packet Analysis
1123
- Wireshark
1124
- ip.version == 4
1125
- PC
1126
- ping 8.8.8.8 ++
1127
944
 
1128
945
 
1129
946
 
@@ -1131,83 +948,84 @@ ping 8.8.8.8 ++
1131
948
 
1132
949
 
1133
950
 
1134
- 5. Packet Fragmentation
1135
- PC
1136
- netsh interface ipv4 show subinterfaces
1137
951
 
1138
- ping 8.8.8.8 -f -l 1472
1139
- ping 8.8.8.8 -f -l 2000
1140
- ping 8.8.8.8 -l 2000
1141
- Wireshark
1142
- ip.flags.mf == 1 or ip.frag_offset > 0
1143
952
 
1144
953
 
1145
954
 
1146
- 6. Network Security (ACL)
1147
- Router
1148
- enable ++
1149
- configure terminal ++
1150
955
 
1151
- access-list 1 deny 192.168.1.20
1152
- access-list 1 permit any
1153
956
 
1154
- interface g0/0 ++
1155
- ip access-group 1 in
1156
- exit ++
1157
- PC
1158
- ping 192.168.1.10 ++
1159
957
 
1160
958
 
1161
959
 
1162
960
 
1163
- 7. IP Spoofing Protection
1164
- Router
1165
- enable ++
1166
- configure terminal ++
1167
961
 
1168
- ip access-list extended ANTI-SPOOF
1169
- deny ip 192.168.1.0 0.0.0.255 any
1170
- permit ip any any
1171
962
 
1172
- interface g0/1
1173
- ip access-group ANTI-SPOOF in
1174
963
 
1175
- interface g0/0 ++
1176
964
 
965
+ const express = require('express');
966
+ const fs = require('fs');
1177
967
 
1178
- ip verify unicast source reachable-via rx
968
+ const app = express();
1179
969
 
970
+ app.use(express.json());
1180
971
 
972
+ // Helper functions
973
+ function getProducts() {
974
+ const data = fs.readFileSync('./product.json', 'utf-8');
975
+ return JSON.parse(data).products;
976
+ }
1181
977
 
978
+ function saveProducts(products) {
979
+ fs.writeFileSync('./product.json', JSON.stringify({ products }, null, 2));
980
+ }
1182
981
 
982
+ // PUT: Replace product completely
983
+ app.put('/product/:id', (req, res) => {
1183
984
 
985
+ const products = getProducts();
986
+ const id = parseInt(req.params.id);
1184
987
 
988
+ const index = products.findIndex(el => el.id === id);
1185
989
 
990
+
991
+ if (index === -1) {
992
+ return res.status(404).json({
993
+ status: 'fail',
994
+ message: 'Product not found'
995
+ });
996
+ }
1186
997
 
998
+ const newData = req.body;
1187
999
 
1000
+
1001
+ if (!newData.name || !newData.price) {
1002
+ return res.status(400).json({
1003
+ status: 'fail',
1004
+ message: 'Name and price are required'
1005
+ });
1006
+ }
1188
1007
 
1008
+
1009
+ newData.id = id;
1189
1010
 
1011
+
1012
+ products[index] = newData;
1190
1013
 
1014
+ saveProducts(products);
1191
1015
 
1192
- 8. TCP Hijacking (Prevention)
1193
- Router
1194
- enable ++
1195
- configure terminal ++
1016
+ res.status(200).json({
1017
+ status: 'success',
1018
+ message: 'Product replaced successfully',
1019
+ data: newData
1020
+ });
1021
+ });
1196
1022
 
1197
- ip access-list extended BLOCK_TCP
1198
- deny tcp any any eq 23
1199
- permit ip any any
1023
+ app.listen(3000, () => {
1024
+ console.log('Server running on port 3000');
1025
+ });
1200
1026
 
1201
- interface g0/0 ++
1202
- ip access-group BLOCK_TCP in
1203
- 9. UDP Hijacking (DNS)
1204
- 📍 PC
1205
- nslookup example.com
1206
- 📍 Server (DNS setup)
1207
1027
 
1208
- (No CLI, but concept command equivalent)
1209
1028
 
1210
- example.com → 192.168.1.100
1211
1029
 
1212
1030
 
1213
1031
 
@@ -1223,31 +1041,31 @@ example.com → 192.168.1.100
1223
1041
 
1224
1042
 
1225
1043
 
1226
- 10. DoS Simulation
1227
- PC (Attack)
1228
- ping 192.168.1.100 ++
1229
- Switch (Protection)
1230
- enable ++
1231
- configure terminal ++
1232
1044
 
1233
- interface fa0/2
1234
- switchport port-security
1235
- switchport port-security maximum 1
1236
- switchport port-security violation shutdown
1237
1045
 
1238
- interface fa0/3
1239
- switchport port-security
1240
- switchport port-security maximum 1
1241
- switchport port-security violation shutdown
1242
- MASTER REPEATED COMMAND LIST
1243
1046
 
1244
- These appear everywhere (VERY IMPORTANT):
1245
1047
 
1246
- enable ++
1247
- configure terminal ++
1248
- interface g0/0 ++
1249
- no shutdown ++
1250
- exit ++
1251
- ping ++
1252
- access-list ++
1253
- ip access-group ++
1048
+ ---
1049
+ chalk
1050
+ ---
1051
+ const chalk = require('chalk');
1052
+
1053
+ console.log(chalk.red.bold('Error!'));
1054
+ console.log(chalk.green.underline('Success!'));
1055
+ console.log(chalk.blue.italic('Info message'));
1056
+ console.log(chalk.white.bgBlue.bold(' Important Message '));
1057
+ console.log(chalk.black.bgYellow(' Warning Block '));
1058
+ console.log(chalk.bgRed.white.bold(' Critical Error '));
1059
+ console.log(chalk.rgb(255, 136, 0)('Custom Orange Text'));
1060
+ console.log(chalk.hex('#00FFAA')('Hex Color Text'));
1061
+ console.log(chalk.bgHex('#FF5733').white('Styled Background'));
1062
+ console.log(
1063
+ chalk.blue('Hello ' + chalk.yellow.bold('World') + '!')
1064
+ );
1065
+ console.log(
1066
+ chalk.red('H') +
1067
+ chalk.yellow('e') +
1068
+ chalk.green('l') +
1069
+ chalk.blue('l') +
1070
+ chalk.magenta('o')
1071
+ );