import socket
# Change the following host and see what IP it prints!
host = "google.com"
# this allows us to translate a host name into an ip adress
ip = socket.gethostbyname(host)
print(ip)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
print("Successfully connected!")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
# Send a GET request to "/"
s.sendall(b"GET / HTTP/1.1\r\n\r\n")
# Recieve & print 2048 bytes of data
data = s.recv(2048)
print(data.decode())
import requests
# Change the URL to whatever you'd like
response = requests.get("https://google.com")
print("Status code:", response.status_code)
print("Headers:", response.headers)
print("Response text:", response.text[:100])
# Add a line to print the "Content-Type" header of the response
# Try an image URL!
aws = "3.130.255.192"
response = requests.get("http://" + aws)
print(response.text)
Configuration
server {
// Listen on virtual "port 80"
listen 80;
listen [::]:80;
server_name 3.130.255.192;
location / {
// Inform server about original client
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
// Forward all requests transparently to the server running on our computer
proxy_pass http://localhost:9099;
}
}
Load Balancing
upstream example.com {
server server1.example.com;
server server1.example.com;
}
HTTP Headers
server {
add_header X-Cool-Header "I love APCSP!";
location /pages {
add_header X-Cooler-Header "This is my secret header!";
}
}
Check In
- Research 1 HTTP header and describe, in detail, its purpose.
- Another HTTP header that is commonly used is the "Authorization" header. The purpose of the Authorization header is to provide credentials to access a protected resource. The header typically contains some type of authentication information that is used to authenticate the user making the request.
- Write a line in a sample NGINX configuration that will add that specific header to the
/information
location
- location /information { add_header Authorization "Bearer my_access_token"; ... }
- Explain the purpose of the load balancing performed by NGINX
- The purpose of load balancing performed by NGINX is to distribute incoming network traffic across multiple servers to improve performance, increase availability, and reduce the risk of downtime due to server failures.
- Modify the following code block to obtain the value of the secret header on
/products
of the AWS site
- Check below
aws = "3.130.255.192"
response = requests.get("http://" + aws + "/products")
print("The secret header is: " + response.headers['X-Cooler-Header'])
DNS Hacks
- What does DNS stand for?
- DNS stands for Domain Name System.
- What is the purpose of DNS?
- The purpose of DNS is turn domain names into IP addresses.
- How does DNS work?
- When a user types a domain name into their web browser, the browser sends a request to a DNS resolver, which is a server that is configured to look up the IP address associated with that domain name.
- What is a DNS resolver?
- A DNS resolver is a server that is responsible for finding domain names to IP addresses. When a user types a domain name into their browser, the browser sends a request to a DNS resolver, which then looks up the IP address associated with that domain name.
- Make a canva image on the process of DNS (you can base it off of the previous slide)
CORS Hacks
- Explain what CORS is and what it stands for
- CORS stands for Cross-Origin Resource Sharing. It is a mechanism that allows web servers to specify which domains are allowed to access the resources on the server. By default, web browsers restrict cross-origin HTTP requests initiated from scripts, so CORS is used to lessen these restrictions and allow web applications to access resources from different domains.
- Describe how you would be able to implement CORS into your own websites
- To implement CORS in a website, the server-side application needs to set the Access-Control-Allow-Origin header to indicate which origins are allowed to access the server's resources. Then the server can set other headers to control the types of HTTP methods and headers that are allowed to be used in cross-origin requests.
- Describe why you would want to implement CORS into your own websites
- To allow access to resources hosted on a different domain, such as third-party API.
- How could use CORS to benefit yourself in the future?
- It can demonstrate my skills in web security, which are highly valued skills in the industry.
Total: 0.2 points
KASM Hacks
- What is the purpose of "sudo" when running commands in terminal?
- The "sudo" command is used to run commands with extra privileges in a terminal. It allows a user to execute commands as the root user, which has unrestricted access to the system and can perform administrative tasks that regular users cannot. Using "sudo" is necessary when performing tasks that require administrative privileges, such as installing software.
- What are some commands which allow us to look at how the storage of a machine is set up as?
- "df" - displays the amount of disk space used and available on mounted file systems.
- What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
- Downloading the zip file manually from the website and saving it to a local directory.
- What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
- The "install.sh" command is likely to have commands that install the software that it is associated with. It is necessary to call "install.sh" because it helps the installation process and ensures that all necessary dependencies are installed correctly.
- Explain in at least 3-4 sentences how deploying KASM is related to/requires other topics talked about in the lesson and/or potential ways to add things mentioned in the lesson to this guide.
- Setting up microservices to manage and secure application services across many environments is part of the KASM deployment process. Understanding HTTP is necessary for this because it is the protocol used for microservice communication. In order for the process to function, CORS must be set up to allow cross-domain requests between microservices. Total: 0.2 points
AWS/RDS Hacks ()
See the setup post
- Create your own database in the EC2 I have created (ec2-database-connect)
- name it with your first and last name (example: aditya-nawandhar) (0.1)
- Create a table using the commands on the link provided. (0.1)
- using commands from the link provided make columns and rows with test data (can be anything) (example: “name” and “class” are the columns with rows being something like “Aditya” and “Junior”). At least 4 test rows (0.1)
- additional points if the data matches CPT (Bonus: 0.05)
Total: 0.3