chiwormjava 2.0.4 → 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 +690 -645
package/readme.md CHANGED
@@ -42,247 +42,488 @@ javacodewatch
42
42
 
43
43
  ---
44
44
 
45
+
45
46
  ---
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
47
+ const http = require('http')
48
+ const fs = require('fs')
49
+
50
+ const server = http.createServer();
51
+
52
+ server.on('request', (req, res) => {
53
+ const rstream = fs.createReadStream('./product.json',"utf-8");
54
+ rstream.pipe(res);
55
+ })
56
+
57
+ server.on("request", (req, res) => {
58
+
59
+ const rstream = fs.createReadStream("./product.json", "utf-8");
60
+
61
+ rstream.on("data", (chunkData) => {
62
+ res.write(chunkData);
63
+ });
64
+
65
+ rstream.on("end", () => {
66
+ res.end(); // ✅ correct: just end response
67
+ });
68
+
69
+ rstream.on("error", (err) => {
70
+ console.log(err);
71
+ res.writeHead(500, { "Content-Type": "text/plain" });
72
+ res.end("File not found");
73
+ });
74
+
75
+ });
76
+
77
+ server.listen(3000, "127.0.0.1", () => {
78
+ console.log("Server is running at http://127.0.0.1:3000");
79
+ });
80
+
81
+
82
+
83
+ ---
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;
158
+
159
+ for(let i = 1; i <= n; i++){
160
+ fact *= i;
161
+ }
162
+
163
+ console.log('Factorial:', fact);
164
+ });
165
+
166
+
167
+ //Fibonacci Series
168
+ r1.question('Enter number of terms: ', (num) => {
169
+ let n = parseInt(num);
170
+ let a = 0, b = 1;
171
+
172
+ console.log(a);
173
+ console.log(b);
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
+ });
182
+
183
+ //Prime Number Check
184
+ r1.question('Enter a number: ', (num) => {
185
+ let n = parseInt(num);
186
+ let isPrime = true;
187
+
188
+ if(n <= 1) isPrime = false;
189
+
190
+ for(let i = 2; i <= Math.sqrt(n); i++){
191
+ if(n % i === 0){
192
+ isPrime = false;
193
+ break;
194
+ }
195
+ }
196
+
197
+ console.log(isPrime ? 'Prime' : 'Not Prime');
198
+ });
123
199
 
124
- Status should be up up
125
- If not, use no shutdown
126
200
 
127
- Step 9: Test connectivity
128
- From PC1:
129
- ping 10.0.0.2
201
+ //Sum of Digits
202
+ r1.question('Enter a number: ', (num) => {
203
+ let n = parseInt(num);
204
+ let sum = 0;
130
205
 
131
- Expected reply from destination
206
+ while(n > 0){
207
+ sum += n % 10;
208
+ n = Math.floor(n / 10);
209
+ }
132
210
 
133
- Step 10: Simulation Mode
134
- Click Simulation
135
- Reset Simulation
136
- Edit Filters and select ARP and ICMP
211
+ console.log('Sum of digits:', sum);
212
+ });
137
213
 
138
- Send packet using Add Simple PDU from PC1 to PC3
139
- Click Play or Capture/Forward
140
214
 
141
- Expected packet flow:
142
- PC1 -> Switch1 -> Router1 -> Router2 -> Switch2 -> PC3
215
+ //Reverse a Number
216
+ r1.question('Enter a number: ', (num) => {
217
+ let n = parseInt(num);
218
+ let rev = 0;
143
219
 
144
- First ARP then ICMP communication successful
220
+ while(n > 0){
221
+ let digit = n % 10;
222
+ rev = rev * 10 + digit;
223
+ n = Math.floor(n / 10);
224
+ }
145
225
 
226
+ console.log('Reversed number:', rev);
227
+ });
146
228
 
147
229
 
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
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) => {
154
234
 
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
235
+ let n1 = parseInt(a);
236
+ let n2 = parseInt(b);
237
+ let n3 = parseInt(c);
160
238
 
161
- Step 3: Configure Router Interfaces
162
- Router> enable
163
- Router# configure terminal
239
+ let max = Math.max(n1, n2, n3);
164
240
 
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
241
+ console.log('Largest:', max);
242
+ });
243
+ });
244
+ });
169
245
 
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
246
 
175
- Assign IP to Cloud/Server
176
- IP 203.0.113.2
177
- Mask 255.255.255.0
247
+ //Largest of Three Numbers
248
+ r1.question('Enter a number: ', (num) => {
249
+ let n = parseInt(num);
178
250
 
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
251
+ for(let i = 1; i <= 10; i++){
252
+ console.log(`${n} x ${i} = ${n * i}`);
253
+ }
254
+ });
184
255
 
185
- Router(config)# interface gig0/1
186
- Router(config-if)# ip nat outside
187
- Router(config-if)# exit
188
256
 
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
257
+ //Count Digits
258
+ r1.question('Enter a number: ', (num) => {
259
+ let count = num.length;
260
+ console.log('Total digits:', count);
261
+ });
192
262
 
193
- Step 5: Configure Routing
194
- Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.2
195
263
 
196
- Step 6: Test Configuration
197
- From PC command prompt:
198
- ping 203.0.113.2
199
264
 
200
- If reply is received, NAT is working
265
+ ---
266
+
267
+
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>
391
+
392
+
393
+
394
+
395
+ ---
396
+
397
+
398
+
399
+ const http = require("http");
400
+ const fs = require("fs");
401
+ const path = require("path");
402
+
403
+ let counter = 0;
404
+
405
+ // Read HTML template
406
+ const content = fs.readFileSync("./indexFinal.html", "utf-8");
201
407
 
202
- Verify NAT translations
203
- Router# show ip nat translations
408
+ const server = http.createServer((req, res) => {
204
409
 
410
+ counter++;
411
+ console.log(`Server hit ${counter} times`);
205
412
 
413
+ let url = req.url.toLowerCase();
206
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");
207
419
 
420
+ res.writeHead(200, { "Content-Type": "text/css" });
421
+ return res.end(style);
422
+ }
208
423
 
424
+ // Routing pages
425
+ let pageContent = "";
209
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
+ }
210
443
 
444
+ // Common response
445
+ res.writeHead(200, { "Content-Type": "text/html" });
446
+ res.end(content.replace("{{CONTENT}}", pageContent));
211
447
 
448
+ });
212
449
 
450
+ server.listen(3000, "127.0.0.1", () => {
451
+ console.log("Server running at http://127.0.0.1:3000");
452
+ });
213
453
 
214
454
 
215
455
 
216
456
 
217
457
 
218
458
 
459
+ ---
219
460
 
220
461
 
462
+ const http = require("http");
463
+ const fs = require("fs");
221
464
 
465
+ let counter = 0;
222
466
 
467
+ const content = fs.readFileSync("./Template/index.html", "utf-8");
223
468
 
469
+ const server = http.createServer((request, response) => {
224
470
 
225
- AIM:
226
- To analyze packet fragmentation by changing packet size and observing its effect using Wireshark.
471
+ counter++;
472
+ console.log(`Server started ${counter} times`);
227
473
 
228
- Step 1: Open Wireshark
229
- Launch Wireshark
230
- Select active interface (WiFi or Ethernet)
231
- Click Start Capture
474
+ let path = request.url.toLowerCase();
232
475
 
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)
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
+ }
237
481
 
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
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
+ }
242
487
 
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
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
+ }
247
493
 
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
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
+ }
252
499
 
253
- Step 6: Analyze in Wireshark
254
- Apply filter:
255
- ip.flags.mf == 1 or ip.frag_offset > 0
500
+
501
+ else if (path === "/product") {
256
502
 
257
- Observation:
258
- Multiple packets for single ping
259
- Fragmented packets visible
503
+ fs.readFile("./data/products.json", "utf-8", (error, jsonData) => {
260
504
 
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
505
+ if (error) {
506
+ response.writeHead(500, { "Content-Type": "text/plain" });
507
+ return response.end("Error reading JSON file");
508
+ }
266
509
 
267
- Performance Impact:
268
- More packets generated
269
- Increased delay
270
- Possible packet loss
510
+ response.writeHead(200, { "Content-Type": "application/json" });
511
+ response.end(jsonData);
512
+ });
513
+ }
271
514
 
272
- Final Observation:
273
- Small packet: No fragmentation
274
- Large packet with DF: Error
275
- Large packet without DF: Fragmentation occurs
515
+ // 404
516
+ else {
517
+ response.writeHead(404, { "Content-Type": "text/html" });
518
+ response.end(content.replace("{{CONTENT}}", "Error : 404 NOT FOUND"));
519
+ }
276
520
 
277
- Conclusion:
278
- If packet size exceeds MTU, it is divided into smaller fragments, affecting performance
521
+ });
279
522
 
280
- Output:
281
- Ping command results showing success or error
282
- Wireshark showing fragmented packets using filter
523
+ server.listen(3000, "127.0.0.1", () => {
524
+ console.log("Server running at http://127.0.0.1:3000");
525
+ });
283
526
 
284
- Result:
285
- Fragmentation observed and analyzed successfully
286
527
 
287
528
 
288
529
 
@@ -302,87 +543,39 @@ Fragmentation observed and analyzed successfully
302
543
 
303
544
 
304
545
 
305
- AIM:
306
- To identify vulnerabilities and secure the network using Access Control List (ACL) and Port Security.
307
546
 
308
- Step 1: Topology Setup
309
- Add devices:
310
- 1 Router (2911)
311
- 1 Switch (2960)
312
- 2 PCs
313
547
 
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
548
 
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
549
+ ---
322
550
 
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
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
+ ]
330
568
 
331
- Step 5: Test Before Security
332
- From PC2:
333
- ping 192.168.1.10
334
- Communication should be successful
335
569
 
336
- Step 6: Apply ACL
337
- access-list 1 deny 192.168.1.20
338
- access-list 1 permit any
339
570
 
340
- Apply ACL:
341
- interface g0/0
342
- ip access-group 1 in
343
- exit
344
571
 
345
- Step 7: Test After Security
346
- From PC2:
347
- ping 192.168.1.10
348
- Should fail
349
572
 
350
- From PC1:
351
- ping 192.168.1.20
352
- Should work
353
573
 
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
362
574
 
363
- Vulnerabilities Identified:
364
- No access control
365
- No device restriction
366
- No traffic filtering
367
575
 
368
- Security Measures Applied:
369
- ACL controls communication between devices
370
- Port Security restricts number of devices per port
371
576
 
372
- Additional Concepts:
373
- IDS detects suspicious activities such as unusual traffic
374
- IPsec encrypts data for secure transmission
375
577
 
376
- Simulation (Optional):
377
- Use Simulation mode
378
- Filter ICMP
379
- Observe packet drop due to ACL
380
578
 
381
- Final Result:
382
- PC2 is blocked
383
- PC1 is allowed
384
- Switch ports are secured
385
- Network is protected successfully
386
579
 
387
580
 
388
581
 
@@ -400,113 +593,86 @@ Network is protected successfully
400
593
 
401
594
 
402
595
 
596
+ ---
403
597
 
404
598
 
599
+ GET
405
600
 
601
+ ---
602
+ const express = require('express');
603
+ const fs = require('fs');
406
604
 
605
+ const app = express();
407
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
+ }
408
612
 
613
+ // Home route
614
+ app.get('/', (req, res) => {
615
+ res.status(200).send('You are on home page');
616
+ });
409
617
 
410
- AIM:
411
- To demonstrate IP Spoofing attack and implement security measures to prevent unauthorized access.
618
+ // About route
619
+ app.get('/about', (req, res) => {
620
+ res.status(200).send('You are on about page');
621
+ });
412
622
 
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
623
+ // Get all products
624
+ app.get('/product', (req, res) => {
625
+ const products = getProducts();
420
626
 
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
627
+ res.status(200).json({
628
+ status: 'success',
629
+ results: products.length,
630
+ data: products
631
+ });
632
+ });
426
633
 
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
634
+ // Get single product by ID
635
+ app.get('/product/:id', (req, res) => {
636
+ const products = getProducts();
637
+ const id = parseInt(req.params.id);
431
638
 
432
- Step 3: Configure Router
433
- enable
434
- configure terminal
639
+ const product = products.find(el => el.id === id);
435
640
 
436
- interface g0/0
437
- ip address 192.168.1.1 255.255.255.0
438
- no shutdown
439
- exit
641
+ if (!product) {
642
+ return res.status(404).json({
643
+ status: 'fail',
644
+ message: 'Product not found'
645
+ });
646
+ }
440
647
 
441
- interface g0/1
442
- ip address 10.0.0.1 255.255.255.0
443
- no shutdown
444
- exit
648
+ res.status(200).json({
649
+ status: 'success',
650
+ data: product
651
+ });
652
+ });
445
653
 
446
- Step 4: Configure Routing
447
- ip route 10.0.0.0 255.255.255.0 10.0.0.1
654
+ // Contact route
655
+ app.get('/contact', (req, res) => {
656
+ res.status(200).send('You are on contact page');
657
+ });
448
658
 
449
- Step 5: Apply Trust-Based ACL
450
- access-list 10 permit 192.168.1.10
451
- access-list 10 deny any
659
+ app.listen(3000, () => {
660
+ console.log('Server running on port 3000');
661
+ });
452
662
 
453
- interface g0/0
454
- ip access-group 10 in
455
663
 
456
- Step 6: Test Before Attack
457
- From PC1:
458
- ping 10.0.0.2 (should work)
459
664
 
460
- From PC2:
461
- ping 10.0.0.2 (should fail)
462
665
 
463
- Step 7: Simulate IP Spoofing
464
- Change PC2 IP to 192.168.1.10
465
666
 
466
- Test again:
467
- ping 10.0.0.2 (should work)
468
667
 
469
- Step 8: Impact
470
- Unauthorized access
471
- Security bypass
472
- Fake identity
473
668
 
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
478
669
 
479
- interface g0/1
480
- ip access-group ANTI-SPOOF in
481
670
 
482
- Step 10: Countermeasure 2 uRPF
483
- interface g0/0
484
- ip verify unicast source reachable-via rx
485
671
 
486
- Step 11: Switch Port Security
487
- enable
488
- configure terminal
489
672
 
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
496
673
 
497
- Final Understanding:
498
- Before ACL everyone allowed
499
- ACL allows only trusted IP
500
- Spoofing bypasses security
501
- uRPF blocks spoofed packets
502
674
 
503
- Conclusion:
504
- IP-based trust is not secure and must be verified using mechanisms like uRPF and port security
505
675
 
506
- Result:
507
- Attack simulated successfully
508
- Vulnerability identified
509
- Security measures implemented
510
676
 
511
677
 
512
678
 
@@ -527,110 +693,67 @@ Security measures implemented
527
693
 
528
694
 
529
695
 
696
+ POST
530
697
 
698
+ ---
531
699
 
700
+ const express = require('express');
701
+ const fs = require('fs');
532
702
 
533
- AIM:
534
- To allow normal UDP communication and block unwanted UDP traffic using ACL.
703
+ const app = express();
535
704
 
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
705
+ app.use(express.json());
543
706
 
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
549
707
 
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
708
+ function getProducts() {
709
+ const data = fs.readFileSync('./product.json', 'utf-8');
710
+ return JSON.parse(data).products;
711
+ }
555
712
 
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
713
+ function saveProducts(products) {
714
+ fs.writeFileSync('./product.json', JSON.stringify({ products }, null, 2));
715
+ }
563
716
 
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
717
+ app.post('/product', (req, res) => {
570
718
 
571
- Step 5: Test UDP Communication
572
- From PC1:
573
- nslookup example.com 192.168.1.20
574
- UDP communication should work
719
+ const products = getProducts();
720
+ const newProduct = req.body;
575
721
 
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
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
+ }
579
729
 
580
- Apply ACL:
581
- interface g0/0
582
- ip access-group 100 in
583
- exit
730
+
731
+ const newId = products.length > 0
732
+ ? products[products.length - 1].id + 1
733
+ : 1;
584
734
 
585
- Step 7: Test After ACL
586
- From PC2:
587
- nslookup example.com 192.168.1.20 (should fail)
735
+ newProduct.id = newId;
588
736
 
589
- From PC1:
590
- nslookup example.com 192.168.1.20 (should work)
737
+ products.push(newProduct);
591
738
 
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
739
+ saveProducts(products);
595
740
 
596
- Apply:
597
- interface g0/0
598
- ip access-group 101 in
599
- exit
741
+ res.status(201).json({
742
+ status: 'success',
743
+ message: 'Product added successfully',
744
+ data: newProduct
745
+ });
746
+ });
600
747
 
601
- Test:
602
- From PC1:
603
- nslookup example.com 192.168.1.20 (should fail)
748
+ app.listen(3000, () => {
749
+ console.log('Server running on port 3000');
750
+ });
604
751
 
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
752
 
610
- Step 10: Fix Topology
611
- Change Server network:
612
- Server IP 10.0.0.2 Gateway 10.0.0.1
613
753
 
614
- Configure Router:
615
- interface g0/1
616
- ip address 10.0.0.1 255.255.255.0
617
- no shutdown
618
754
 
619
- Now traffic flows through router:
620
- PC -> Router -> Server
621
- ACL works correctly
622
755
 
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
756
 
629
- Result:
630
- UDP communication tested
631
- Attacker blocked using ACL
632
- DNS service blocked using port-based ACL
633
- Network secured successfully
634
757
 
635
758
 
636
759
 
@@ -654,95 +777,75 @@ Network secured successfully
654
777
 
655
778
 
656
779
 
657
- AIM:
658
- Create a network, enable DNS (UDP), allow normal user, and block attacker using ACL.
659
780
 
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
781
 
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
782
 
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
783
 
678
- Step 4: Router Configuration
679
- enable
680
- configure terminal
681
784
 
682
- interface g0/0
683
- ip address 192.168.1.1 255.255.255.0
684
- no shutdown
685
- exit
686
785
 
687
- interface g0/1
688
- ip address 10.0.0.1 255.255.255.0
689
- no shutdown
690
- exit
691
786
 
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
787
 
699
- Step 6: Initial Testing
700
- From PC1:
701
- ping 10.0.0.2
702
- This builds ARP
788
+ ---
789
+ PATCH
790
+ ---
703
791
 
704
- Then:
705
- nslookup example.com
706
- Should work successfully
707
792
 
708
- Step 7: Apply ACL Security
709
- configure terminal
793
+ const express = require('express');
794
+ const fs = require('fs');
710
795
 
711
- access-list 101 deny udp host 192.168.1.30 any
712
- access-list 101 permit ip any any
796
+ const app = express();
713
797
 
714
- interface g0/0
715
- ip access-group 101 in
716
- exit
798
+ app.use(express.json());
717
799
 
718
- Step 8: Final Testing
719
- From PC1:
720
- nslookup example.com
721
- Should work
800
+ // Helper functions
801
+ function getProducts() {
802
+ const data = fs.readFileSync('./product.json', 'utf-8');
803
+ return JSON.parse(data).products;
804
+ }
722
805
 
723
- From PC2:
724
- nslookup example.com
725
- Should fail
806
+ function saveProducts(products) {
807
+ fs.writeFileSync('./product.json', JSON.stringify({ products }, null, 2));
808
+ }
726
809
 
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
810
 
733
- Final Result:
734
- PC1 allowed
735
- PC2 blocked
736
- DNS working
737
- ACL applied successfully
811
+ app.patch('/product/:id', (req, res) => {
738
812
 
813
+ const products = getProducts();
814
+ const id = parseInt(req.params.id);
739
815
 
816
+ const product = products.find(el => el.id === id);
740
817
 
818
+
819
+ if (!product) {
820
+ return res.status(404).json({
821
+ status: 'fail',
822
+ message: 'Product not found'
823
+ });
824
+ }
741
825
 
826
+
827
+ if (req.body.id) {
828
+ return res.status(400).json({
829
+ status: 'fail',
830
+ message: 'Cannot update product id'
831
+ });
832
+ }
742
833
 
834
+
835
+ Object.assign(product, req.body);
743
836
 
837
+ saveProducts(products);
744
838
 
839
+ res.status(200).json({
840
+ status: 'success',
841
+ message: 'Product updated successfully',
842
+ data: product
843
+ });
844
+ });
745
845
 
846
+ app.listen(3000, () => {
847
+ console.log('Server running on port 3000');
848
+ });
746
849
 
747
850
 
748
851
 
@@ -764,108 +867,73 @@ ACL applied successfully
764
867
 
765
868
 
766
869
 
767
- AIM:
768
- Simulate a DNS-based UDP hijacking scenario, observe its impact on the client, and apply basic protection.
769
870
 
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
871
 
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
872
 
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
873
 
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
874
 
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
875
 
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
876
 
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
877
 
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
878
 
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
879
 
835
- Step 9: Final Check
836
- Attempt attack again
837
- Port security blocks attacker or shuts down port
838
880
 
839
- Output Observation Methods:
840
- Command Line:
841
- Use nslookup example.com before and after attack
881
+ ---
882
+ DELETE
883
+ ---
884
+
885
+ const express = require('express');
886
+ const fs = require('fs');
842
887
 
843
- Simulation Mode:
844
- Select Simulation
845
- Filter DNS or UDP
846
- Run nslookup
847
- Observe source IP, destination IP, and UDP port 53
888
+ const app = express();
848
889
 
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
890
+ app.use(express.json());
853
891
 
854
- Result:
855
- Attack successfully simulated
856
- Impact observed
857
- Basic protection applied
892
+ function getProducts() {
893
+ const data = fs.readFileSync('./product.json', 'utf-8');
894
+ return JSON.parse(data).products;
895
+ }
858
896
 
897
+ function saveProducts(products) {
898
+ fs.writeFileSync('./product.json', JSON.stringify({ products }, null, 2));
899
+ }
859
900
 
901
+ app.delete('/product/:id', (req, res) => {
860
902
 
903
+ const products = getProducts();
904
+ const id = parseInt(req.params.id);
861
905
 
906
+
907
+ const index = products.findIndex(el => el.id === id);
862
908
 
909
+
910
+ if (index === -1) {
911
+ return res.status(404).json({
912
+ status: 'fail',
913
+ message: 'Product not found'
914
+ });
915
+ }
863
916
 
917
+
918
+ const deletedProduct = products.splice(index, 1);
864
919
 
920
+ saveProducts(products);
865
921
 
922
+ res.status(200).json({
923
+ status: 'success',
924
+ message: 'Product deleted successfully',
925
+ data: deletedProduct[0]
926
+ });
927
+ });
866
928
 
929
+ app.listen(3000, () => {
930
+ console.log('Server running on port 3000');
931
+ });
867
932
 
868
933
 
934
+ ---
935
+ PUT
936
+ ---
869
937
 
870
938
 
871
939
 
@@ -888,126 +956,79 @@ Basic protection applied
888
956
 
889
957
 
890
958
 
891
- AIM:
892
- Simulate a DoS condition using continuous requests, observe its impact on a server, and apply prevention techniques.
893
959
 
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
960
 
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
961
 
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
962
 
916
- Step 4: Enable Server Service
917
- Open Server -> Services -> HTTP
918
- Turn HTTP ON
919
963
 
920
- Step 5: Normal Test
921
- From PC1:
922
- ping 192.168.1.100
923
- Stable replies indicate normal operation
924
964
 
925
- Step 6: Simulate DoS Attack
926
- From PC2:
927
- ping 192.168.1.100 -t
965
+ const express = require('express');
966
+ const fs = require('fs');
928
967
 
929
- From PC3:
930
- ping 192.168.1.100 -t
968
+ const app = express();
931
969
 
932
- Continuous traffic is generated
970
+ app.use(express.json());
933
971
 
934
- Step 7: Observe Impact
935
- From PC1:
936
- ping 192.168.1.100
972
+ // Helper functions
973
+ function getProducts() {
974
+ const data = fs.readFileSync('./product.json', 'utf-8');
975
+ return JSON.parse(data).products;
976
+ }
937
977
 
938
- Expected results:
939
- Request timed out
940
- High delay
941
- Packet loss
978
+ function saveProducts(products) {
979
+ fs.writeFileSync('./product.json', JSON.stringify({ products }, null, 2));
980
+ }
942
981
 
943
- Indicates server overload and network congestion
982
+ // PUT: Replace product completely
983
+ app.put('/product/:id', (req, res) => {
944
984
 
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
985
+ const products = getProducts();
986
+ const id = parseInt(req.params.id);
950
987
 
951
- Step 9: Apply Switch Port Security
952
- enable
953
- configure terminal
988
+ const index = products.findIndex(el => el.id === id);
954
989
 
955
- interface fa0/2
956
- switchport port-security
957
- switchport port-security maximum 1
958
- switchport port-security violation shutdown
959
- exit
990
+
991
+ if (index === -1) {
992
+ return res.status(404).json({
993
+ status: 'fail',
994
+ message: 'Product not found'
995
+ });
996
+ }
960
997
 
961
- interface fa0/3
962
- switchport port-security
963
- switchport port-security maximum 1
964
- switchport port-security violation shutdown
965
- exit
998
+ const newData = req.body;
966
999
 
967
- Limits attacker behavior
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
+ }
968
1007
 
969
- Step 10: Improved Topology for Router Control
970
- Change Server network:
971
- Server IP 10.0.0.2 Gateway 10.0.0.1
1008
+
1009
+ newData.id = id;
972
1010
 
973
- Add router interface:
974
- interface g0/1
975
- ip address 10.0.0.1 255.255.255.0
976
- no shutdown
1011
+
1012
+ products[index] = newData;
977
1013
 
978
- Traffic now passes through router
1014
+ saveProducts(products);
979
1015
 
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
1016
+ res.status(200).json({
1017
+ status: 'success',
1018
+ message: 'Product replaced successfully',
1019
+ data: newData
1020
+ });
1021
+ });
984
1022
 
985
- interface g0/0
986
- ip access-group BLOCK_ICMP in
1023
+ app.listen(3000, () => {
1024
+ console.log('Server running on port 3000');
1025
+ });
987
1026
 
988
- Step 12: Final Testing
989
- From PC1:
990
- ping 10.0.0.2 (should work)
991
1027
 
992
- From PC2 and PC3:
993
- ping 10.0.0.2 (should fail)
994
1028
 
995
- Output Observation:
996
- Command Line:
997
- Compare ping before and during attack
998
1029
 
999
- Simulation Mode:
1000
- Filter ICMP
1001
- Observe multiple packets and congestion
1002
1030
 
1003
- Conclusion:
1004
- DoS attack floods server with requests causing delay and packet loss
1005
- Switch port security and ACL help control traffic
1006
1031
 
1007
- Result:
1008
- Attack simulated
1009
- Impact observed
1010
- Protection applied successfully
1011
1032
 
1012
1033
 
1013
1034
 
@@ -1024,3 +1045,27 @@ Protection applied successfully
1024
1045
 
1025
1046
 
1026
1047
 
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
+ );