Security and Privacy in Cloud LAB MANUAL
Security and Privacy in Cloud LAB MANUAL
Student Name :
Register No :
Subject Code :
Subject Name :
Year/Semester :
CERTIFICATE
Name :
Register No. :
……......
10
EX NO:1 Simulate a cloud scenario using cloud Sim and run a scheduling
algorithm not
present in cloud Sim
Date:
AIM: To simulate a cloud scenario using CloudSim and run a scheduling algorithm
that is not
present in CloudSim
ALGORITHM:
2
utilization, etc.
3
Program:
import org.cloudbus.cloudsim.*;
import org.cloudbus.cloudsim.core.CloudSim;
import java.util.*;
public class CustomSchedulingSimulation (
public static void main(String[] args) {
// Initialize the CloudSim simulation environment
int numUsers 1:
Calendar calendar Calendar.getInstance();
CloudSim.init(numUsers, calendar, false);
// Create a datacenter
Datacenter datacenter createDatacenter("Datacenter_0");
}
// Create a broker
Datacenter Broker broker createBroker();
// Set the custom VM allocation policy VmAllocationPolicy policy = new
CustomSchedulingPolicy(datacenter.getHostList()); broker.setDatacenter(datacenter);
broker.setVmAllocationPolicy (policy);
// Create and submit cloudlets to the broker int numVMs = 5: int numCloudlets = 10;
create
VMsAndCloudlets (broker, numVMs, numCloudlets);
// Start the simulation
CloudSim startSimulation();
// Process the results and generate output List<Cloudlet> finishedCloudlets
broker.getCloudletReceivedList();
// Perform necessary calculations and analysis
// Stop the simulation
CloudSim stopSimulation();
// Display the results printResults(finishedCloudlets);
private static Datacenter createDatacenter(String name) {
5
}
private static Datacenter Broker create Broker() {
Datacenter Broker broker = null;
try {
broker = new Datacenter Broker("Broker");
} catch (Exception e) {
e.printStackTrace();
}
broker,
private static void createVMsAndCloudlets (DatacenterBroker broker, int numVMs, int
numCloudlets) {
List<Vm> vmList = new ArrayList<>();
List<Cloudlet> cloudletList = new ArrayList<>();
// Create VMs with required characteristics // Define VM properties like MIPS, RAM,
storage,
bandwidth, etc.
// Use Vm and othe related classes in CloudSim
for (int i = 0; i < numVMs; i++) {
int mips = 1000; // Example MIPS value int ram 512; // Example RAM value
long size = 10000; // Example storage value
int bw 1000, // Example bandwidth value
int pesNumber-1.
Vm vm now Vmi, broker getld(), mips, pesNumber, ram, bw, size, Xen", new Cloudlet
SchedulerTimeShared()).
vmList.add(vm),
// Create cloudlets with required characteristics
6
long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();
Cloudlet cloudlet new Cloudlet(i, length, pesNumber, fileSize, outputSize,
utilizationModel,
utilization Model, utilizationModel);
cloudlet.setUserid(broker.getId());
cloudlet List add(cloudlet);
broker.bindCloudlet ToVm(cloudlet.getId(), vmList.get(i % numVMs).getId()); // Assign
VMs
to
cloudlets
broker.submit VimList(vmList);
broker.submitCloudletList(cloudletList);
private static void printResults(List<Cloudlet> cloudlets) {
// Process and print the simulation results
// Display performance metrics like makespan, resource utilization, response time, etc.
for (Cloudlet cloudlet: cloudlets) {
System.out.println("Cloudlet ID: + cloudlet.getCloudletId()+", VM ID:
+cloudlet.getVmld()
+", Status:" + cloudlet.getStatus()+", Start Time:" + cloudlet.getExecStartTime()
+*, Finish Time:" + cloudlet.getFinishTime());
8
Ex.No : 2 Simulate resource management using cloud sim
Date:
AIM:
The aim is to simulate resource management using CloudSim, which involves
managing the allocation and utilization of resources in a cloud environment. The
objective is to optimize resource allocation, maximize resource utilization and
improve overall system performance.
ALGORITHM:
1. Set up the development environment:
• Download the CloudSim library (version 3.0.3 or later) and include it in the
project.
• Install Java Development Kit (JDK).
2. Import the required CloudSim packages:
import org cloudbus.cloudsim.*;
import org.cloudbus.cloudsim.core.CloudSim;
import java.util.*;
3. Create a new Java class for the simulation, e.g., "Resource
ManagementSimulation".
4. Initialize CloudSim:
• Initialize the CloudSim simulation environment with the number of users
and the simulation
calendar.
• Set the simulation parameters, such as the simulation duration and
whether to trace the
simulation progress.
int numUsers = 1;
Calendar calendar Calendar.getInstance(); CloudSim.init(numUsers,
calendar, false);
5. Create a datacenter :
• Define the characteristics of the datacenter, such as the number of hosts,
host properties
(MIPS, RAM, storage, bandwidth), and VM provisioning policies.
9
• Use classes like Datacenter Characteristics, Host, Vm, and
VmAllocationPolicy in CloudSim
to create the datacenter.
Datacenter datacenter = createDatacenter("Datacenter");
6. Create a broker:
• Define the broker that will manage the allocation and utilization of
resources.
• Use the Datacenter Broker class in CloudSim to create the broker.
Datacenter Broker broker = createBroker();
• Define the virtual machines (VMs) with their characteristics, such as MIPS,
RAM,
storage, and bandwidth.
Security and Privacy in Cloud
7. Create VMs and cloudlets:
• Define the cloudlets with their characteristics, such as length, utilization
model and data
transfer size.
List<Vm> vmList = createVMs(numVMs), List<Cloudlet cloudletList =
createCloudlets(numCloudlets);
• Use the submitVmList() method to submit the list of VMs to the broker.
8. Submit VMs and cloudlets to the broker:
• Use the submit CloudletList() method to submit the list of cloudlets to the
broker.
broker.submitVmList(vmList):
broker.submitCloudletList(cloudletList);
9. Run the simulation:
• Start the simulation using CloudSim.startSimulation().
• CloudSim will simulate the resource management based on the defined
datacenter, broker,
VMs, and cloudlets. CloudSim.startSunulation().
10. Stop the simulation:
• Stop the simulation using CloudSim.stopSimulation().
10
• This will halt the simulation and collect the results.
CloudSim stopSimulation();
11. Process the results and generate output:
• Retrieve the results from the broker, such as the list of finished cloudlets
and their execution
details.
• Analyze and process the results to evaluate the resource management
performance.
• Generate the desired output, such as performance metrics, resource
utilization, execution
times, etc.
List<Cloudlet> finishedCloudlets broker.getCloudlet ReceivedList():
printResults(finishedCloudlets);
11
Program:
12
// Create and configure the virtual machines (VMs)
// Set VM properties like MIPS, RAM, storage, and bandwidth
// Return the list of created VMs
}
private static List<Cloudlet > createCloudlets(int numCloudlets) {
// Create and configure the cloudlets
// Return the list of created cloudlets
// Set cloudlet properties like length, utilization model, and data transfer size
private static void printResults(List<Cloudlet> cloudlets) { // Process and print the
results
// Analyze the finished cloudlets and generate desired output
Output
13
Result:
The result and output of the simulation will depend on the specific resource
management strategies implemented and the characteristics of the simulated
cloud scenario. It can analyse various performance metrics such as makespan,
resource utilization, response time, throughput,etc. The specific output and
result analysis will vary based on the implementation and the evaluation criteria,
chosen for resource management. It can print the output within the code using
System.out.println() statements or save the results to a file for furthe analysis.
14
Ex.No : 3 Simulate log forensics using cloud sim
Date:
AIM:
The aim is to simulate resource management using CloudSim, which involves
managing the allocation and utilization of resources in a cloud environment.
The objective is to optimize resource allocation, maximize resource utilization,
and improve overall system performance.
• Download the CloudSim library (version 3.0.3 or later) and include it in the project
PROCEDURE:
1. Set up the development environment:
• Install Java Development UDK)
2. Import the required CloudSim package:
unport org cloudous cloudsim", import org cloudbus cloudsim.core CloudSc import
java.util."
3. Create a new Java class for the simulation, e.g. "Resource Management Simulsion"
• Initialize the CloudSim simulation environment with the number of users and the
simulation calendar.
4. Initialize CloudSun
• Set the simulation parameters, such as the simulation duration and whether to
trace the
simulation progress
int numUsers 1: Calendar calendar Calendar.getInstance()
CloudSim.init(numUsers, calendar,
false);
5. Create a datacenter:
• Define the characteristics of the datacenter, such as the number of hosts, host
properties (MIPS, RAM, storage, bandwidth), and VM provisioning policies • Use
classes like
Datacenter Characteristics, Host, Vm, and VmAllocationPolicy m CloudSim to
create the
datacenter.
Datacenter datacenter createDatacenter("Datacenter");
15
6. Create a broker:
• Define the broker that will manage the allocation and utilization of resources
• Use the DatacenterBroker class in CloudSim to create the broker.
Datacenter Broker broker createBecker()
Create VMs and cloudlets
•Define the Virtual Machines (VMs) with their characteristics, such as MIPS, RAM.
storage
and bandwidth.
• Define the cloudlets with their characteristics, such as length, utilization model,
and data
transfer size.
List<Vm> vmLast createVMs(numVMs); List<Cloudlet loudletList
createCloudlets(numCloudlets):
8. Submit VMs and cloudlets to the broker
• Use the submitVml.ist() method to submit the list of VMs to the broker.
• Use the submitCloudletList() method to submit the list of cloudlets to the
broker,
broker.submitVmlist(vmList); broker submitCloudletList(cloudletList);
• Start the simulation using CloudSim startSimulation(). • CloudSim
9. Run the sinulation:
will simulate the resource management based on the defined datacenter,
broker, VMs, and
cloudlets. CloudSim startSimulation().
10. Stop the simulation:
• Stop the simulation using CloudSim.stopSimulation().
• This will halt the simulation and collect the results.
CloudSim.stopSimulation();
11. Process the results and generate output:
• Retrieve the results from the broker, such as the list of finished cloudlets
and their execution
details.
Analyze and process the results to evaluate the resource management
performance.
• • Generate the desired output, such as performance metrics, resource
utilization, execution
times, etc.
List<Cloudlet> finishedCloudlets = broker.getCloudlet ReceivedList();
printResults(finishedCloudlets);
Source code:
16
import org.cloudbus.cloudsim.*;
import org.cloudbus.cloudsim.core.CloudSim,
import java.util.*;
public class LogForensicsSimulation { public static void main(String[] args) {
int numUsers = 1;
Calendar calendar Calendar.getInstance();
CloudSim.init(numUsers, calendar, false);
List<LogEntry> logData = generateLogData();
List<LogEntry> suspiciousActivities detectSuspiciousActivities(logData);
List<LogEntry>
anomalies detect Anomalies(logData):
printSuspicious Activities(suspicious Activities);
printAnomalies(anomalies);
private static List<LogEntry> generatel.ogData() ( Generate or retrieve log data for
the
simulation.
// Sumotate tog entries with various attributes like timestamp, source IP, destination
IP, log
message, etc // Return the generated log dats as a list of LogEntry objects
private static List<LogEntry detect Suspicious Activities(List<LogEntry> logData) {
// Implement log analysis algorithms to detect suspicious activities // Use pattern
matching,
machine learning, statistical analysis, etc.
// Return the list of detected suspicious activities as LogEntry objects
private static List<LogEntry> detect Anomalies(List<LogEntry> logData) {
// Implement log analysis algorithms to detect anomalies // Use pattern matching,
machine
learning, statistical analysis, etc.
// Return the list of detected anomalies as LogEntry objects
private static void printSuspiciousActivities(List<LogEntry> suspiciousActivities) (
// Print or process the list of detected suspicious activities // Generate alerts, reports,
or
17
visualizations based on the detected activities
private static void printAnomalies (List<LogEntry> anomalies) { // Print or process
the list of
detected anomalies
// Generate alerts, reports, or visualizations based on the detected anomalies
Output
18
Result and Output:
The result and output of the simulation will depend on the log data generated
and the log analysis algorithms implemented. The can analyze the log data to
detect suspicious activities and anomalies, and generate output such as alerts,
reports, or visualizations based on the findings. The specific output and result
analysis will vary based on the implementation and the log analysis techniques
used. The can print the output within the code using System.out.println()
statements or save the results to a file or database for furthe analysis and
reporting.
19
EXP NO:4 Simulate a secure file sharing using a cloud
DATE:
AIM:
The aim is to simulate a secure file sharing system using CloudSim. The
objective is to evaluate the performance and security aspects of the file
sharing process in a cloud-based environment. The simulation will help
identify potential vulnerabilities, test security measures, and optimize the
system's overall performance.
ALGORITHM:
Simulation Results:
Secure File Sharing Simulation
Datacenter Information:
-Number of hosts: 5
- Number of virtual machines: 10
- Number of users: 1
14
File Sharing Activities:
- Total file uploads: 20
-Total file downloads: 20
Security Metrics:
-Authentication success rate: 95%
-Encryption level: AES-256
Performance Metrics:
- Average response time: 5.0 seconds
-Throughput: 0.04 files/second
14
Result and Output:
The specific result and output of the simulation will depend on the implementation of
the file
sharing mechanisms, security measures and performance metrics. The output may
include
information such as:
• Simulation progress and duration
• File upload and download activities
• Performance metrics (e.g., response time, throughput)
Security-related metrics (eg, authentication success rate, data encryption level)
• Simulation reports, charts, or visualizations
It can customize the output based on the specific requirements and the metrics
choosen to
measure. The output will provide insights into the performance and security aspects
of the
simulated secure file sharing system and help evaluate its effectiveness and potential
improvements.
Output
23
EXP NO:5 Implement data anonymization techniques over the simple dataset
(masking,
kanonymization, etc)
DATE:
AIM:
The aim of masking is to replace sensitive data with a non-sensitive placeholder
value while preserving the structure and format of the original data.
ALGORITHM:
1. Identify the sensitive attribute(s) in the dataset, such as names or email addresses.
2. Replace the sensitive values with a masking value (e.g., "X" or "").
3. Ensure that the masking maintains the same length or format as the original data to
preserve
data integrity.
4. Generate a new anonymized dataset with masked values.
Source code:
import pandas as pd
Original dataset
data pd.DataFrame(
Name': ['John Doe', 'Jane Smith', 'Michael Johnson'],
Email: [[email protected]', [email protected]',
'[email protected]'].
Age 125, 30, 351
})
#Masking sensitive attributes
data[Name'] = XXXXXXXXXX
data[Email] xxxxxxxxxx
#Output anonymized dataset
print(data)
Output
Name
24
Email Age
• XXXXXXXXXXxxxxxxxxxxxxxx
25
1 XXXXXXXXXXXxxxxxxXxxx
30
2 XXXXXXXXXXxxxxxxxxxxxxxxxx
35
Result:
The sensitive attributes, Name and Email, have been replaced with masking values,
ensuring
the original structure and format of the dataset are maintained.
K-Anonymization:
Procedure:
Source code:
import pandas as pd
Original dataset
data = pd.DataFrame({
Name': ['John Doe', 'Jane Smith', 'Michael Johnson'].
Zip Code': ('12345', '67890', '54321'].
Age: 125, 30, 351
25
#Kanonymization with generalization
data['Name'] = 'Anonymous'
data "Zip Code'] = 'XXXXX
Output anonymized dataset print(data)
Output:
Result:
The quasi identifiers, Name and Zip Code, have been generalized to
"Anonymous" and "XXXXX," respectively, ensuring each record is
indistinguishable from at least k-1 other records (in this case, 2-1-1). The
original structure and format of the dataset are preserved.
26
EXP NO:6 Implement any encryption algorithm to protect the images.
DATE:
AIM: The aim is to encrypt an image file using the AES encryption algorithm
to protect its contents from unauthorized access.
ALGORITHM:
Source Code:
27
Set encryption key (must be 16, 24, or 32 bytes long) cryption key =
b'ThisIsASecretKey!
of encrypt image(input file): Read the image file
with open(input_file, rb') as file:
image_data = file.read()
Generate a random initialization vector (IV)
jy = os.urandom(16)
Create an AES cipher object
cipher = AES.new(encryption_key, AES MODE_CBC. iv)
Pad the image data
padded_data = pad(image_data, AES block_size)
#Encrypt the padded data
encrypted_data = cipher.encrypt(padded_data)
#Return encrypted data and IV return encrypted_data, iv
def upload encrypted_image(encrypted_data, iv, filename):
#Create an S3 client
#3 boto3.client('s3.
d
aws_access_key_id=AWS_ACCESS_KEY_ID, aws
secret_access_key=AWS_SECRET_ACCESS_KEY)
d
e
# Upload encrypted data as an S3 object s3.put_object(Body=encrypted_data. Bucket-
BUCKET_NAME. Key=filename)
#Upload IV as a separate S3 object
iv_filename = f(filename).iv
83.put_object(Body=iv.
Bucket-BUCKET_NAME.
Key=iv_filename)
#Set the path to the image file Input_file = "original_image.jpg
#Encrypt the image encrypted_data, iv encrypt_image(input_file)
#Set the filename for the encrypted image
Alename encrypted_image.jpg
28
Upload the encrypted image to 83 upload_encrypted image(encrypted data,
iv, filename)
Output
Result:
The script will encrypt the image using AES encryption and produce an encrypted
image file
encrypted_image.jpg in the same directory.
29
Ex. No :7 Implement any image obfuscation
mechanism
Date:
Procedure:
Source code:
import to from google. Cloud import vision
def obfuscate image (image path):
Authenticate with Google Cloud Vision API client vision Image Annotator
Client ()
Read the image file
with lo. open (image path, 'rb') as image file: content image_file. read ()
30
Create a Vision API image object image = vision. Image(content=content)
Apply blurring to obfuscate the image response = client.
safe_search_detection(image=image)
blurred_image = response full_text_annotation
Save the obfuscated image
output_path = 'obfuscated_image.jpg
blurred_image.save(output_path, 'JPEG)
return output path
#Set the path to the image file
image_path = 'original_image.jpg'
#Obfuscate the image
obfuscated_image_path = obfuscate_image(image_path)
# Print the path to the obfuscated image print("Obfuscated image path:",
obfuscated_image_path)
Make sure the have the necessary credentials and have installed the google-
cloud-vision library
(pip install google-cloud-vision) to interact with the Google Cloud Vision API.
Output:
Upon successful execution, the script will obfuscate the image using the
blurring filter from
the Google Cloud Vision API. The resulting obfuscated image will be saved as
obfuscated_image.jpg in the same directory. The script will print the path to
the obfuscated
image.
Result:
31
The image will be visually obfuscated by applying a blurring filter. The level of
obfuscation
depends on the specific blurring technique used by the Vision API. The
resulting obfuscated
image can help protect sensitive visual information while preserving the
overall structure and
context of the original image.
32