import socket

# Change the following host and see what IP it prints!
# Host changed to GitHub
host = "github.com"
ip = socket.gethostbyname(host)

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

[x] Check-In

  1. What is an IP address?
  • Internet Protocol (IP)

Unique address that identifies a device on the internet or a local network

  1. What is a TCP port?

Represents an application or service-specific endpoint identifier

Port: Logistical construct that identifies a specific process or a type of network service

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: Wed, 26 Apr 2023 20:52:04 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-I6rYAT4cKhWK3B8_hzVosw' '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-26-20; expires=Fri, 26-May-2023 20:52:04 GMT; path=/; domain=.google.com; Secure
Set-Cookie: AEC=AUEFqZcmXwwABrucuvamKJLByf3t_TkV_zy5XmS5mSCtumJ5KtiEVmzXVA; expires=Mon, 23-Oct-2023 20:52:04 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=511=HB-jM__FEcPwAv4Z_u4Uo6Uc2gLd2d53FnkbDzuKjxGmvHRgCCKFCMIRZ1IRRK2cXdXfAXgSBHyMr10Gm-sueqaNcpV2FoH0xF9-KmlMPrWqsgVuest6pJ899eai9hnjuQWvnf0uYLqs0H5GEnfjV2GBJN1Dde0ut--Y65Pyz9o; expires=Thu, 26-Oct-2023 20:52:04 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

5998
<!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="I6rYAT4cKhWK3B8_hzVosw">(function(){window.google={kEI:'9I5JZKyCOIXRkPIP09ig8Ac',kEXPI:'0,1359409,6059,206,4804,2316,383,246,5,1129120,1197694,707,380089,16115,19397,9287,22430,1362,12316,4748,12835,4998,13228,3847,38444,2872,2891,3926,213,7615,606,30668,19390,10632,15324,432,3,346,1244,1,16916,2652,4,1528,2302,29064,9871,3194,11443,2215,2980,1457,16786,5797,2560,4094,7596
import requests

# Change the URL to whatever you'd like
# Changed the URL into a github URL
response = requests.get("https://github.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: {'Server': 'GitHub.com', 'Date': 'Fri, 28 Apr 2023 07:23:44 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Vary': 'X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, Accept-Language, Accept-Encoding, Accept, X-Requested-With', 'content-language': 'en-US', 'ETag': 'W/"3a322c7ba8fdbcbd77f768b5f9f3f454"', 'Cache-Control': 'max-age=0, private, must-revalidate', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload', 'X-Frame-Options': 'deny', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '0', 'Referrer-Policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', 'Content-Security-Policy': "default-src 'none'; base-uri 'self'; block-all-mixed-content; child-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com objects-origin.githubusercontent.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com cdn.optimizely.com logx.optimizely.com/v1/events *.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ wss://*.actions.githubusercontent.com github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com github.githubassets.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com objects-origin.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github.githubassets.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; worker-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/", 'Content-Encoding': 'gzip', 'Set-Cookie': '_gh_sess=o5D7fuPPpw0RTfJ%2F01DYHfVHhCsLpKRxDYLzi7CQOinzRb1daoAi65GxhxDx9NXjtXCiFhUSSXnT1IpGTbNUf%2F0GT9QJfzpsY%2BRKa46mksgLkpVwIlVW%2BRWJ3ue0TqeJXN566zg4LWyNAsj76p7BWwWQSaFmDk2Am3Y7JqMIVbU6ldPcoo4fL1Dl0RXk7fpOXfc%2FI6D6T5HrmtKG4UPW7l1P%2Fw25cZlVfc83qT37eWZul2FPdvOq4HL%2FJ9q3dOa7UDARozh%2B67oS1OKB5IBpnw%3D%3D--jTkIqDI3aM0MYC%2F3--oKG68modmUYrQNIwF02fYQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax, _octo=GH1.1.29733226.1682666634; Path=/; Domain=github.com; Expires=Sun, 28 Apr 2024 07:23:54 GMT; Secure; SameSite=Lax, logged_in=no; Path=/; Domain=github.com; Expires=Sun, 28 Apr 2024 07:23:54 GMT; HttpOnly; Secure; SameSite=Lax', 'Accept-Ranges': 'bytes', 'Transfer-Encoding': 'chunked', 'X-GitHub-Request-Id': 'E49C:63EF:30D98E4:330187E:644B748A'}
Response text: 





<!DOCTYPE html>
<html lang="en"  data-a11y-animated-images="system">
  <head>
    <meta charse

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!";
    }
}

[x] Check In

  1. Research 1 HTTP header and describe, in detail, its purpose.

HTTP Header: Allow

Allow: lists the set of methods supported by a resource

  • header must be sent if server responds wit 405
  • an empty allow header indicates that the resource allows no request methods

allow: allow: GET, POST, HEAD</p>

  1. Write a line in a sample NGINX configuration that will add that specific header to the /information location

location /information { add_header X-Header "XHEADER"; }

//Will add 'X-Header' with value of 'XHEADER' to any responses sent from '/information' location

  1. Explain the purpose of the load balancing performed by NGINX

It maximizes the speed and capacity utilization and ensures that no server is overworked. Overwork = degredation in performance.

  1. Modify the following code block to obtain the value of the secret header on /products of the AWS site
</div> </div> </div>
aws = "3.130.255.192"

response = requests.get("http://" + aws+ "/products")

print("Secret Header:", response.headers['X-Cooler-Header'])
Secret Header: This is my secret header!

Hacks

  • [x] Complete the above check-in questions and change the hosts (0.1)
  • [x] 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.)

[x] CORS Hacks

  1. Explain what CORS is and what it stands for
  • Cross-Origin Resource Sharing (CORS)

Enables the control to access resources outside of a domain.

  1. Describe how you would be able to implement CORS into your own websites

Include CORS into header to create custom headers, can use Postman to request and check response headers.

  1. Describe why you would want to implement CORS into your own websites

Implementing CORS would mean users will be protected from malicious data.

  1. How could use CORS to benefit yourself in the future?

Adding CORS would mean adding more protection to the users and protecting the user data.

[x] KASM Hacks

  1. What is the purpose of "sudo" when running commands in terminal?

'Sudo' allows the terminal to have admin access.

  1. What are some commands which allow us to look at how the storage of a machine is set up as?
  • 'df': shows disk space on file system
  • 'du': shows disk usage of files
  • 'mount': shows currently mounted file systems and their mount points
  1. What do you think are some alternatives to running "curl -O" to get the zip file for KASM?

Using 'wget' is the fastest and easiest way that we use in class.

  1. What kind of commands do you think the "install.sh" command has and why is it necessary to call it?

KASM and some other apps require the install.sh to work.

  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 is related to other topics talked about in the lesson because it involves managing and configuring virtual machines, which requires knowledge of networking and system admin. To set up KASM, you need to create a virtual machine, install the necessary software, and configure the networking settings. You may need to set up security measures such as encryption. To add to this guide, you could explain the basics of networking, as well as how to configure security measures like encryption.

NOT DOING ANYMORE

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

</div>