import socket

# Change the following host and see what IP it prints!
host = "youtube.com"
ip = socket.gethostbyname(host)

print(ip)
142.250.188.238
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((ip, 80))
    print("Successfully connected!")
Successfully connected!

Check-In

  1. What is an IP address?
  • An IP address is a unique set of numbers that helps to identify a device on a computer network. It is useful in allowing computers to communicate with each other and send information. The IP address is used to make sure data gets to the right place on a network.
  1. What is a TCP port?
  • Transmission Control Protocol port is used for communication that allowed networked devices to establish a connection and exchange data. TCP and IP are used together to enable communication between devices. TCP generates a specific port number and destination port number, allowing for data to be transferred.
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())
HTTP/1.1 200 OK
Date: Fri, 28 Apr 2023 00:04:00 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-9BqxLCDVMTxKrwoM0hxbLw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2023-04-28-00; expires=Sun, 28-May-2023 00:04:00 GMT; path=/; domain=.google.com; Secure
Set-Cookie: AEC=AUEFqZdUPOlyrlIrdWUAuE7oWWGEWtJ_zxcOwBbjsROFAVUYpdI-FpiRFQ; expires=Wed, 25-Oct-2023 00:04:00 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=511=acq-JwHyEnI0aUp9UGbVmAImrOXpgonQ4PRjPBMn-4qbHaNzNFdaumD0I2-EOLDi8oHNl8egdjo6W47NN7AN8n158kgsqFuDRgK6GKqep3eFN-GcedMGIL1DKd9kteYflKV1l9AZ2mgSe1cx4tQL55gfK2kV-6ND2L6C1jB7y20; expires=Sat, 28-Oct-2023 00:04:00 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

586e
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="9BqxLCDVMTxKrwoM0hxbLw">(function(){window.google={kEI:'cA1LZLOeE4GlgQaMjr-wAQ',kEXPI:'0,1359409,6058,207,4804,2316,383,246,5,1129120,1197759,380732,16114,28684,22431,1361,12311,2824,14764,4998,13227,3848,6884,31560,2872,2891,3926,7828,606,30668,30021,2615,12710,432,3,346,1244,1,16916,2652,4,1528,2304,29062,13065,11443,2215,2980,1457,16786,5824,2533,4094,7596,1,11943,30211
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!
Status code: 200
Headers: {'Date': 'Fri, 28 Apr 2023 00:04:08 GMT', 'Expires': '-1', 'Cache-Control': 'private, max-age=0', 'Content-Type': 'text/html; charset=ISO-8859-1', 'Content-Security-Policy-Report-Only': "object-src 'none';base-uri 'self';script-src 'nonce-cW2zI1LSvqKqsZD6VIghig' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp", 'P3P': 'CP="This is not a P3P policy! See g.co/p3phelp for more info."', 'Content-Encoding': 'gzip', 'Server': 'gws', 'X-XSS-Protection': '0', 'X-Frame-Options': 'SAMEORIGIN', 'Set-Cookie': '1P_JAR=2023-04-28-00; expires=Sun, 28-May-2023 00:04:08 GMT; path=/; domain=.google.com; Secure, AEC=AUEFqZcsrmkj0IR_ojsHYKoZMDlkwYZ7arzcqWSF4Bi8zv33Y8XMbdFFTw; expires=Wed, 25-Oct-2023 00:04:08 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax, NID=511=HlN0sq4DnEPGeGXTqumleYuUSobUHKsVVxgsqjY0JiypELzIt8TCeIzRL64-9Ro8ctu7vWKCfrHDqxZMiGycAHULN3-VgplMilByWOCqwD91Wk-FzlIXYDECI4T-EqrUhQfEkWKZwV6C4ZGtXmVWbnR8mTXSEkkxCIX5yIv3fBA; expires=Sat, 28-Oct-2023 00:04:08 GMT; path=/; domain=.google.com; HttpOnly', 'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000', 'Transfer-Encoding': 'chunked'}
Response text: <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content

NGINX

aws = "3.130.255.192"

response = requests.get("http://" + aws)
print(response.text)
<!doctype html>
<html>
<head>
<title>Cool site</title>
<meta name="description" content="cool site for apcsp">
</head>
<body>
Hello, this is my cool site. Check out my products:
<a href="/products">Products!!</a>
</body>
</html>

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

  1. Research 1 HTTP header and describe, in detail, its purpose.
  • HTTP header is used to identify the client application that is making the HTTP request. The purpose is to provide information to the server about the client application so that the server can provide a response.
  1. Write a line in a sample NGINX configuration that will add that specific header to the /information location
server {
    add_header X-Cool-Header "Grace Wang";

    location /information {
        add_header X-Cooler-Header "A super specific header";
    }
}
  1. Explain the purpose of the load balancing performed by NGINX
  • The load balancing feature in NGINX distributes incoming requests evenly across multiple servers in order to not overwhelm a single server. This helps improve the performance and reliability of the website.
  1. 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:", "...")
print(response.headers)
The secret header is: ...
{'Server': 'nginx/1.18.0 (Ubuntu)', 'Date': 'Fri, 28 Apr 2023 04:10:47 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Last-Modified': 'Thu, 20 Apr 2023 20:42:12 GMT', 'X-Cooler-Header': 'This is my secret header!', 'Content-Encoding': 'gzip'}

Hacks

  • Complete the above check-in questions and change the hosts (0.1)
  • Complete the above code-segment to retrieve the secret header (0.1)

Bonus (0.05)

Create a diagram showing the layers of abstraction that allow us to use HTTP (IP, TCP, etc.)

Slides Questions

  1. What does DNS stand for?
  • Domain Name System
  1. What is the purpose of DNS?
  • DNS serves as a phone book of the internet, mapping human-readable domain names to IP addresses. It enables users to access websites and services without needing to remember the numerical IP address of each website. Additionally, DNS helps to distribute web traffic across different servers and locations, improving website speed and reliability.
  1. How does DNS work?
  • When a user types a domain name into their web browser, the browser sends a request to a DNS server to look up the IP address associated with that domain name. The DNS server then responds with the corresponding IP address, allowing the browser to establish a connection and load the requested website.
  1. What is a DNS resolver?
  • A DNS resolver is a computer program or a server that translates domain names into IP addresses, allowing devices to communicate with each other on the internet. It receives requests from client devices and uses the DNS protocol to look up and retrieve the IP address associated with the requested domain name.

CORS Hacks

  1. Explain what CORS is and what it stands for
  • CORS stands for cross-origin security
  • It is a set of techniques that prevents web pages frm accessing resources on other domains without permissions and keeps your website safe
  1. Describe how you would be able to implement CORS into your own websites
  • when creating function read options for api on the CPT project, I used mode CORS. This was done in the javascript brackets when defining a functon for read options.
  1. Describe why you would want to implement CORS into your own websites
  • CORS protects users from bad websites that can steal your data. Building websites that makes requirests to a different domain will need CORS in order to allow the web browser to make the requests because without CORS the web browser may block the requests and your website would not be able to obtain the data.
  1. How could use CORS to benefit yourself in the future?
  • I will implement CORS in the future websites that I build in order to improve user experience and make sure user data is not stolen.

Total: 0.2 points

KASM Hacks

  1. What is the purpose of "sudo" when running commands in terminal?
  • the purpose of adding sudo is to be able to runt he command with administrative privileges. Sudo bypasses levels of access and permissions in order to be able to run any code on the system.
  1. What are some commands which allow us to look at how the storage of a machine is set up as?
  • Disk Utility: This is a built-in tool that allows you to view and manage disks, volumes, and partitions on your Mac. You can access it by searching for "Disk Utility" in Spotlight or navigating to "Applications" > "Utilities" > "Disk Utility".

  • Terminal: You can use the "diskutil" command-line utility to view information about disks and partitions. Open the Terminal and type "diskutil list" to see a list of all the disks and partitions on your system.

  1. What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
  • Use a web browser: You can also download the KASM zip file using a web browser. Simply navigate to the KASM website, locate the download link for the zip file, and download it using your browser's download feature.
  1. What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
  • Checking for dependencies
  • Creating directories
  • Setting permissions
  1. 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 requires knowledge of several related topics, such as security, application isolation, and remote access. KASM provides a secure and isolated environment for running applications, which requires understanding of security concepts and best practices. Additionally, KASM can be accessed remotely, which requires knowledge of remote access tools and protocols.

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