import socket

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

print(ip)
142.250.217.174
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?
    IP address is an internet protocol, every device has a unique IP
  2. What is a TCP port?
    A TCP port is a safe way to send information ove the internet in packets
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 21:07:26 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-R1raQeptcsEmB4BSjgfD4Q' '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-21; expires=Fri, 26-May-2023 21:07:26 GMT; path=/; domain=.google.com; Secure
Set-Cookie: AEC=AUEFqZeFf_SVdLnoeTwrKbju0vOlMg8bPwLYK8vDZfDL1z_9GHd22qkHZw; expires=Mon, 23-Oct-2023 21:07:26 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=511=OpF5gimsGVCopMc3yBew4a9-EDkkPgm0zb68ppDg5DfI3VjwwciM0pBGye3bX8xh_zKXwFu-bMAw8XkNKAClEpAzI6AFD8os9HGbxspBHsIq_Y_Ar5-5hhe9DviWapZceVxcu6GW0atly2QkpdH1gSek3N8xhz7RO_ZrKDn_tD0; expires=Thu, 26-Oct-2023 21:07:26 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

5a4c
<!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="R1raQeptcsEmB4BSjgfD4Q">(function(){window.google={kEI:'jpJJZMeOGNfGkPIPtK6yiAc',kEXPI:'0,1303459,55950,6058,207,4804,2316,383,246,5,1129120,1197731,663,380097,16114,28684,22431,1361,283,12029,17587,4998,13228,3847,38444,887,1985,2891,3926,7828,606,58286,2404,15324,432,3,346,1244,1,16916,2652,4,1528,2304,24859,4203,9871,3193,11443,2216,2980,1457,16786,5797,2560,4094,7596,1
import requests

# Change the URL to whatever you'd like
response = requests.get("https://0x0800.github.io/2048-CUPCAKES/")

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: {'Connection': 'keep-alive', 'Content-Length': '1637', 'Server': 'GitHub.com', 'Content-Type': 'text/html; charset=utf-8', 'permissions-policy': 'interest-cohort=()', 'x-origin-cache': 'HIT', 'Last-Modified': 'Tue, 07 Mar 2017 14:38:21 GMT', 'Access-Control-Allow-Origin': '*', 'ETag': 'W/"58bec5dd-133f"', 'expires': 'Tue, 25 Apr 2023 12:17:08 GMT', 'Cache-Control': 'max-age=600', 'Content-Encoding': 'gzip', 'x-proxy-cache': 'MISS', 'X-GitHub-Request-Id': '6CA2:1395:72F0C2:866C54:6447C26C', 'Accept-Ranges': 'bytes', 'Date': 'Wed, 26 Apr 2023 21:14:30 GMT', 'Via': '1.1 varnish', 'Age': '506', 'X-Served-By': 'cache-bur-kbur8200147-BUR', 'X-Cache': 'HIT', 'X-Cache-Hits': '1', 'X-Timer': 'S1682543671.655344,VS0,VE1', 'Vary': 'Accept-Encoding', 'X-Fastly-Request-ID': 'c08b543c7960962268fc92aec0ae85bc4f6c59bd'}
Response text: <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>2048 CUPCAKES</title>

  <link href=

NGINX

aws = "3.130.255.192"

response = requests.get("http://" + aws)
print(response.text)
<html><head><title>ContentKeeper</title></heQad>
<body bgcolor="#A02E5F" text="White" link="Lime" vlink="Aqua">
<center><br><h1>ContentKeeper<br>Non-Managed Site</h1>
No access is available to NON-Managed Sites.<br><br>
<table border="1" cellspacing="0">
<tr><td>URL</td><td><b>3.130.255.192</b></td></tr>
<tr><td>Username</td><td><b>1905546/pusd</b></td></tr></table>
</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.
  2. Write a line in a sample NGINX configuration that will add that specific header to the /information location
  3. Explain the purpose of the load balancing performed by NGINX
  4. 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!'")
The secret header is: 'X-Cooler-Header': 'This is my secret header!'

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)

Questions From Slides

  1. What does DNS stand for?
    Domain name service
  2. What is the purpose of DNS?
    It's purpose is to assign an IP address to each domain name
  3. How does DNS work?
    a naming system that allows users to access websites using human-readable domain names rather than IP addresses.
  4. What is a DNS resolver?
    a component of the internet infrastructure that translates domain names into IP addresses that are used by computers to communicate with each other over the internet

CORS Hacks

  1. Explain what CORS is and what it stands for
    Cross origin resource sharing
  2. Describe how you would be able to implement CORS into your own websites
    To implement CORS in your website you need to add the Access-Control-Allow-Origin header, which specifies the domain(s) that are allowed to make requests to your server
  3. Describe why you would want to implement CORS into your own websites
    to protect users from getting information stolen and be able to make requests without permission to other domains
  4. How could use CORS to benefit yourself in the future?
    I can use CORS to benefit myself in the future to be bale to make websites that need to access multiple domains whilst still keeping the user protected. Total: 0.2 points

KASM Hacks

  1. What is the purpose of "sudo" when running commands in terminal?
    to get permission to run certain commands
  2. 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 available on each file system. du: Shows the disk usage of files and directories. lsblk: Lists information about all available or the specified block devices.
  3. What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
    Using wget to download the zip file directly to the server.
  4. What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
    The "install.sh" command likely contains a series of commands to install and configure KASM on the server. It may download and extract the KASM zip file, install any necessary dependencies, and configure the KASM service to run on startup. It is necessary to call the "install.sh" command to ensure that KASM is installed and configured correctly.
  5. 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.
    To deploy KASM, you may need to configure firewall rules to allow traffic to and from the KASM service, set up SSL/TLS certificates for secure communication, and manage user accounts and permissions. Additionally, integrating KASM with other security tools, such as IDS/IPS or SIEM systems, may enhance its capabilities and provide a more comprehensive security solution. To add these topics to the guide, you could include sections on firewall configuration, SSL/TLS certificates, user management, and integrating KASM with other security tools. Total: 0.2 points