import socket

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

print(ip)
192.30.255.113
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 similar to how phone numbers works, an IP Address is a unique address, just like how each person has their own phone number
    • Each device has their own unique IP Address
  2. What is a TCP port?
    • Hardware ports are ports you can plug a wire into
    • Ports are numbers such as 80 or even 65000
    • This stands for Transmission Control Protocol
    • It can decide how the data is sent
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:59:53 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-QnQnILiOUh8EUm73F5QZTg' '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:59:53 GMT; path=/; domain=.google.com; Secure
Set-Cookie: AEC=AUEFqZfYRTGzWj6yZgmHemvpry4bHYvbe-1RnK5fng7XXjQH1pKRGDt09w; expires=Mon, 23-Oct-2023 20:59:53 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=511=R__JXhNp1ArhpdPcCYqj0oLI3dQ147ZcDpLh87nvDPmsmmQJHlvMZVFT6mTNECz8jrlp2kgfTz1dRjttpzu-lue893DCUE_YATIUbP8iEC3rU_xbzUB_zUPonXWRaClbIXZV7EOUOzPav6hc5859uN87-QFhlPYnVADk7SLDWCY; expires=Thu, 26-Oct-2023 20:59:53 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

58f8
<!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="QnQnILiOUh8EUm73F5QZTg">(function(){window.google={kEI:'yZBJZMixOuTKkPIPts-C4A0',kEXPI:'0,18168,1341241,1710,4348,207,4804,2316,383,246,5,1129120,1197762,632,380097,16114,28684,22431,1361,283,12033,2818,14765,4998,13228,3847,35733,2711,2872,2891,3926,8434,60689,15325,432,3,346,1244,1,16916,2652,4,1528,2304,29062,13064,13659,2980,18243,5830,2527,4094,7596,1,42160,2,14016,23
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': 'Wed, 26 Apr 2023 21:11:44 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-cIf-arP_cgbur-4lPzHEkw' '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-26-21; expires=Fri, 26-May-2023 21:11:44 GMT; path=/; domain=.google.com; Secure, AEC=AUEFqZfUYb-nIV5ltQPakr9yzsSWnFcKPJHyDEMQIpp7nHmTi2S2ZENLcQ; expires=Mon, 23-Oct-2023 21:11:44 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax, NID=511=qykZLfATGLEkgqyZulvF9fqlOrv0WlbBTBik9iTYjetswQH33q1MzFB1QdfbNClb68sIBaJhFUb9eQ7VrjbbwVCGRlaj12oZN3QvAoUHJ8zc-tSL9L4k7Myqju-i1ahzMdoWBmm2YeBXfQM-KDSLXBnGIduAlhw4TqBFDVC0OLc; expires=Thu, 26-Oct-2023 21:11:44 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)
<html><body onload="document.forms[0].submit()">
<form action="https://ckf03.powayusd.com/cgi-bin/blockpage/poway.cgi" method="GET">
<input type="Hidden" name="URL" value="3.130.255.192">
<input type="Hidden" name="CAT" value="Non-Managed">
<input type="Hidden" name="CATNO" value="-1">
<input type="Hidden" name="ACC" value="1900747/pusd">
<input type="Hidden" name="WHY" value="Policy=student_hs; AD Group=idm-all_students_hs">
<input type="Hidden" name="MOD" value="2">
<input type="Hidden" name="APP" value="http_proxy">
<input type="Hidden" name="ISO" value="App Permanently Blocked">
<input type="Hidden" name="IPA" value="172.16.1.7">
<input type="Hidden" name="RAW" value="http://3.130.255.192">
<input type="Hidden" name="AUTH0" value=",Non-Managed">
<input type="Hidden" name="PGE" value="https://ckf03.powayusd.com/cgi-bin/blockpage/poway.cgi">
<input type="Hidden" name="STR" value="null,null,null,null,null">
<input type="Hidden" name="SRV" value="null">
<input type="Hidden" name="AUTH1" value=",3.130.255.192,Non-Managed">
</form></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 dataformat.com {
    server server1.dataformat.com;
    server server1.dataformat.com;
}

HTTP Headers

server {
    add_header X-Cool-Header "DATA TYPE";

    location /pages {
        add_header X-Cooler-Header "This is my secret header with Data Types!";
    }
}

Check In

  1. Research 1 HTTP header and describe, in detail, its purpose.
    • I tried researching it, and I am not really sure what it is, but I think that Content-Type is a HTTP header
    • I think this is important because it is used to identify the type of data format or media is being used to send the HTTP message body such as text
  2. Write a line in a sample NGINX configuration that will add that specific header to the /information location
  • Not sure if I did this right

    // Inform server about original client
          proxy_set_header Content-Type "application/json";
          add_header X-Frame-Options "SAMEORIGIN";
          proxy_set_header        X-Forwarded-Proto $scheme;
    
          // Forward all requests transparently to the server running on our computer
          proxy_pass              http://localhost:9099;
    
  1. Explain the purpose of the load balancing performed by NGINX
    • The purpose of load balancing by NGINX is to distribute everything across multiple backend servers
    • It sits between the clients and the backend servers, receiving requests from clients and forwarding it to a backend server
    • It helps with NGINX so that it can ensure that web applications are highly available, scalable, and performant even during lots of traffic
  2. Modify the following code block to obtain the value of the secret header on /products of the AWS site
  • Not sure how exactly to do this, but I will try
  • I tried it 3 different ways
import requests
aws = "3.130.255.192"

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

print("The secret header is:", response.headers)
The secret header is: {'Server': 'nginx/1.18.0 (Ubuntu)', 'Date': 'Fri, 28 Apr 2023 15:04:38 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'}
import socket
aws = "3.130.255.192"

response = socket.gethostbyname("http://" + aws+ "/products")

print("The secret header is:", response)
import requests

aws = "3.130.255.192"

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

# Get the value of the secret header, if it exists
secret_header = response.headers.get('secret')

if secret_header:
    print("The secret header is:", secret_header)
else:
    print("The secret header is not present in the response.")
The secret header is not present in the response.

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)

LAYERS OF ABSTRACTION by Edwin Abraham Create a diagram showing the layers of abstraction that allow us to use HTTP (IP, TCP, etc.)

CORS Hacks

  1. Explain what CORS is and what it stands for
    • CORS stands for Cross-Origin Resource Sharing
    • CORS allows us to protect websites and online services
    • Today, there are many cyber attacks that are happening to websites, but CORS, an advanced security tool and technique like Certbot and Cross-Origin Security, the website owners and developers are better able to protect their websites
    • CORS allows and blocks access from other domains
    • CORS is a set of techniques used to prevent web pages from accessing resources on other domains without permission
  2. Describe how you would be able to implement CORS into your own websites
    • I would be able to implement CORS into my own website maybe through my backend. I am aware that we did something with CORS in our flasks to help us with our backend
  3. Describe why you would want to implement CORS into your own websites
    • We should implement CORS into our websites because this can help protect our sites, and we should do it for our group website
    • Implementing CORS in our group website would be helpful to do as a security measure for our website, especially if we will have a lot of data in the backend
  4. How could use CORS to benefit yourself in the future?
    • We could use CORS in our group project websites
    • I want to try and make my own website, so by implementing CORS, I can make sure that no one else tries to do something to my website Total: 0.2 points

KASM Hacks

  1. What is the purpose of "sudo" when running commands in terminal?
    • The purpose of running "sudo" for commands in terminal is to make sure that you are running the terminal as an admin
    • This means that you are able to run some commands that not everyone is able to if they are not in "sudo" mode
    • "Sudo" elevates your access to commands
  2. What are some commands which allow us to look at how the storage of a machine is set up as?
    • There are some commands we can use to look at the storage of the machine
    • We can use "df" which displays information about disk storage space usage, including the available space, used space, and the file system types
    • The "du" command is used to estimate the file and directory space usage, providing a summary of the sizes of individual files or directories
    • "lsblk" is used to list information about block devices, including disks and their partitions in the storage
  3. What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
    • Using a web browser to download a zip file manually from the KASM website
    • It can also be used as a download manager app
    • It can also be used for different lines such as wget
  4. What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
    • This is a command that installs and configures the KASM software
    • It could include downloading necessary files and setting up configuration options
  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. Deploying KASM requires knowledge of using the command line, managing software packages, and security networks. KASM is related to firewalls and other things like setting up firewalls, user permissions, and integrating KASM with other security tools. Using KASM with other tools allows us to increase the functionality of those tools and make them more efficient, and perform better

Total: 0.2 points

AWS/RDS Hacks (Cancelled)

PARTIALLY DONE 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