Skip to content

Networking ex/pratham #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added SS/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SS/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SS/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SS/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SS/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SS/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions projects/bash_networking_security/New key1.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAjDl9yWMpX5LCKBipxAs/Yxy7xv13tuySXmmUe183Cz/PSGrj
h3HGEKrZGTMswc0YquC/SJ0cNdJgWjX2KKWCGJRN7E92Ucj2qtulUBAzmuPG0/vo
KL9751ZaycwpaR8SgNoC9s/NKP7YyO6LuyjwmKcD7Yj3bg1SjDGQpUzLkQg2wiJT
cmutBBuiOfdVr1XU/W9UP4d/J9SHqKBID1BnkroMx5L7GjmWB9BngSAfxngPcNmf
v54wVZ52OilbZZ2EpPETp0wlTbfVEk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G11qC
xQ2qFkEcmMVUiuBiHuQ2KbWjZhojgaGWS9EafcKSnlAcgPRebLuPPWbPmuYwdwWw
mjdPw+ahAoGAYIik2DL0bMXYx/mKOUCIxT5gZu7vwpDlU2EMNnV7eyrYQTn2wbAv
U8xw4OoDjrF6TkAs5xzD5uXPsHI4heqd7iJ0rMA3OqiKowmihfbjFarOJTEjiFIU
/YVvUZMXXz+cfhE++TxdS6azNl4sHPCn2ta2N1mVCnaHQ8qOw2V4IiY=
-----END RSA PRIVATE KEY-----
14 changes: 9 additions & 5 deletions projects/bash_networking_security/SOLUTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
Local DNS Server IP
-------------------
<ip-here>
127.0.0.53



Default gateway IP
-------------------
<ip-here>

10.0.0.1
0.0.0.0
0.0.0.0
0.0.0.0


DHCP IP allocation sys-logs
-------------------
<logs-here>

255.255.255.255
10.0.0.183
10.0.0.183
10.0.0.183
25 changes: 25 additions & 0 deletions projects/bash_networking_security/bastion_connect.sh
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
#!/bin/bash
# Check if KEY_PATH environment variable exists
if [[ -z "$KEY_PATH" ]]; then
echo "KEY_PATH env var is expected"
exit 5
fi

# Check if the public instance IP address is provided
if [[ $# -lt 1 ]]; then
echo "Please provide bastion IP address"
exit 1
fi

# Connect to the private instance using the public instance as a bastion host
if [[ $# -eq 2 ]]; then
public_instance_ip=$1
private_instance_ip=$2

# Connect to the private instance via the bastion host
ssh -i "$KEY_PATH" ubuntu@"$public_instance_ip" ssh -t -t -i "/home/ubuntu/flask/key.pem" ubuntu@"$private_instance_ip"
else
public_instance_ip=$1

# Connect to the public instance
ssh -i "$KEY_PATH" ubuntu@"$public_instance_ip"
fi
54 changes: 53 additions & 1 deletion projects/bash_networking_security/tlsHandshake.sh
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
#!/bin/bash
#!/bin/bash -x

# Step 1 - Client Hello (Client -> Server)
RESPONSE=$(curl -X POST -H "Content-Type: application/json" -d '{
"version": "1.3",
"ciphersSuites": ["TLS_AES_128_GCM_SHA256", "TLS_CHACHA20_POLY1305_SHA256"],
"message": "Client Hello"
}' http://54.225.54.226:8080/clienthello)


# Step 2 - Server Hello (Server -> Client)
SESSION_ID=$(jq -r '.sessionID' <<< "$RESPONSE")

echo "$RESPONSE" | jq -r '.serverCert' > cert.pem


# Step 3 - Server Certificate Verification
wget https://devops-feb23.s3.eu-north-1.amazonaws.com/cert-ca-aws.pem -O cert-ca-aws.pem

VERIFICATION=$(openssl verify -CAfile cert-ca-aws.pem cert.pem)

if [ "$VERIFICATION" != "cert.pem: OK" ]; then
echo "Server Certificate is invalid"
exit 5
fi


# Step 4 - Client-Server master-key exchange
openssl rand -out masterKey.txt -base64 32

MASTER_KEY=$(openssl smime -encrypt -aes-256-cbc -in masterKey.txt -outform DER cert.pem | base64 -w 0)


# Step 5 - Server verification message
RESPONSE=$(curl -X POST -H "Content-Type: application/json" -d '{
"sessionID": "'"$SESSION_ID"'",
"masterKey": "'"$MASTER_KEY"'",
"sampleMessage": "Hi server, please encrypt me and send to client!"
}' http://54.225.54.226/keyexchange)


# Step 6 - Client verification message
echo "$RESPONSE" | jq -r '.encryptedSampleMessage' > encSampleMsg.txt
cat encSampleMsg.txt | base64 -d > encSampleMsgReady.txt

decrypted_sample_msg=$(openssl enc -d -aes-256-cbc -pbkdf2 -kfile masterKey.txt -in encSampleMsgReady.txt)

if [ "$decrypted_sample_msg" != "Hi server, please encrypt me and send to client!" ]; then
echo "Server symmetric encryption using the exchanged master-key has failed."
exit 6
else
echo "Client-Server TLS handshake has been completed successfully"
fi
8 changes: 4 additions & 4 deletions projects/bash_networking_security/vpc.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REGION=""
VPC_ID=""
PUBLIC_INSTANCE_ID=""
PRIVATE_INSTANCE_ID=""
REGION="us-east-1"
VPC_ID="vpc-04f1bfa3b26f70757"
PUBLIC_INSTANCE_ID="i-09172549d32f9a390"
PRIVATE_INSTANCE_ID="i-03086e4bdb2131454"