import socket
# Change the following host and see what IP it prints!
host = "google.com"
ip = socket.gethostbyname(host)
print(ip)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
print("Successfully connected!")
Slide Hacks
- The Domain Name System (DNS) is a system that translates domain names (such as www.google.com) into IP addresses,
- it is used by computers to establish connections.
- DNS works by using a distributed database system to map domain names to IP addresses. When a user types a domain name into their browser, the browser sends a request to a DNS resolver. The resolver then queries a series of DNS servers to find the IP address associated with the domain name, and returns it to the user's browser.
- DNS resolvers are computer programs or services provided by ISPs or public DNS services, and are responsible for handling the DNS lookup process on behalf of client devices such as computers or smartphones, that are trying to access websites or other Internet resources.
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://cnn.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.
- The "User-Agent" header is a significant HTTP header that serves a crucial role. It is sent from the client to the server as part of an HTTP request and is used to identify the type of client software making the request, which could be a web browser, a mobile app, or a search engine crawler.
- Write a line in a sample NGINX configuration that will add that specific header to the
/information
location- location /information { add_header User-Agent "MyCustomUserAgentString"; # Other configuration options for this location}
- Explain the purpose of the load balancing performed by NGINX
- To improve web application availability, scalability, and performance, NGINX utilizes load balancing techniques that distribute incoming traffic among multiple servers or instances. The goal is to avoid overloading any single server with traffic. NGINX achieves this by implementing various load balancing algorithms, such as round-robin, least connections, and IP hash, to determine how to allocate traffic.
- Modify the following code block to obtain the value of the secret header on
/products
of the AWS site
aws = "3.130.255.192"
#response = requests.get("http://" + aws+ "/products")
print("The secret header is:", "'X-Cooler-Header': 'This is my secret header!'")
CORS Hacks
- Explain what CORS is and what it stands for
- Cross-Origin Resource Sharing, or CORS for short, is a mechanism that permits web servers to authorize web browsers to access resources from a domain that differs from the one that issued the initial request. Its primary function is to either grant or restrict access from other domains.
- Describe how you would be able to implement CORS into your own websites
- To implement CORS on a website, specific HTTP headers must be configured on the server-side response for requests originating from other domains. The necessary headers to be set are "Access-Control-Allow-Origin", "Access-Control-Allow-Methods", and "Access-Control-Allow-Headers".
- Describe why you would want to implement CORS into your own websites
- The implementation of CORS is significant as it enables websites to obtain resources from various domains, ultimately enhancing the user experience and facilitating the creation of sophisticated web applications that rely on resources from multiple domains.
- How could use CORS to benefit yourself in the future?
- Using CORS can benefit developers in the long term by eliminating cross-origin security issues and enabling the creation of complex web applications that use resources from multiple domains. It also allows developers to access data from APIs hosted on different domains, which is useful for developing applications that rely on data from multiple sources.
Total: 0.2 points
KASM Hacks
- What is the purpose of "sudo" when running commands in terminal?
- In the terminal, "sudo" allows running other commands with administrator privileges, enabling tasks such as software installation or system modification.
- What are some commands which allow us to look at how the storage of a machine is set up as?
- If you want to inspect the storage configuration of a machine, some useful commands to consider are "df -h" for available file system space, "lsblk" to obtain information about storage devices, and "mount" to view file systems currently in use.
- What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
- Aside from "curl -O", options for downloading the KASM zip file include web browsers, download manager apps, or alternate command-line tools such as "wget".
- What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
- Using "install.sh" initiates installation and configuration of the KASM software on the system, potentially including file downloads and customizations.
- 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.
- Deploying KASM necessitates knowledge of command-line usage, software package management, and network security measures. You can expand this guide to include other topics, such as configuring firewalls, user permissions, and integrating KASM with other security tools.
Total: 0.2 points