import requests
# Define the URL and headers
url = 'http://localhost'
data = {
"a": "8c5402a42040dda391e23b48c0a650b2",
"b": {
"c": "ebf001fe",
"d": ["023b07b0", "b6003939 e92a012a&9a2a763c#02944590"]
}
}
# Send the POST request
response = requests.post(url, json=data)
# Print the response
print(response.text)
Challenge 31
Challenge 32
Challenge 33
Challenge 34
Challenge 35
Challenge 36
Challenge 37
The -b and -c parameters in curl are used to handle cookies:
-b or --cookie: This option specifies the file containing the cookies to be sent with the HTTP request. It can also be used to pass cookies directly in the request.
-c or --cookie-jar: This option specifies the file where cookies received from the server should be saved after the request is completed.
Challenge 38
#!/bin/bash
# Initialize the state and cookie
state=0
cookie=""
# Function to make an HTTP request and capture the response
make_request() {
request="GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n"
if [ -n "$cookie" ]; then
request+="Cookie: $cookie\r\n"
fi
request+="\r\n"
response=$(echo -e "$request" | nc localhost 80)
echo "$response"
}
# Function to extract the state and cookie from the response
extract_state_and_cookie() {
response="$1"
state=$(echo "$response" | grep -oP '(?<=state: )\d+')
cookie=$(echo "$response" | grep -oP '(?<=Set-Cookie: )[^;]+')
}
# Infinite loop to handle stateful interactions
while true; do
echo "Making request with state: $state..."
# Make the request and capture the response
response=$(make_request)
# Extract the state and cookie from the response
extract_state_and_cookie "$response"
# Print the response, current state, and cookie
echo "Response: $response"
echo "Current State: $state"
echo "Cookie: $cookie"
# Increment the state
state=$((state + 1))
# Sleep for a short time before the next request to avoid rapid polling (optional)
sleep 1
done
Challenge 39
import requests as r
host = "http://127.0.0.1/"
# First request
response1 = r.get(host)
cookie1 = response1.cookies
# Second request using cookies from the first response
response2 = r.get(host, cookies=cookie1)
cookie2 = response2.cookies
# Third request using cookies from the second response
response3 = r.get(host, cookies=cookie2)
cookie3 = response3.cookies
# Fourth request using cookies from the third response
response4 = r.get(host, cookies=cookie3)
cookie4 = response4.cookies
# Print the response of the fourth request
print(response4.text)