forked from michealkeines/Vulnerable-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
46 lines (34 loc) · 1.31 KB
/
script.py
File metadata and controls
46 lines (34 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import requests
import os
API_URL = "https://api.tomshein.com/v1/data"
API_PASSWORD = "admin123"
USERNAME = "erlis"
def make_api_call_basic_auth():
print("--- Attempting Basic Auth API Call ---")
try:
response = requests.get(API_URL, auth=(USERNAME, API_PASSWORD))
if response.status_code == 200:
print("Success! Data received:")
print(response.json())
else:
print(f"Failed. Server responded with status code: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"A network error occurred: {e}")
def make_api_call_bearer_token():
print("\n--- Attempting Bearer Token API Call ---")
headers = {
"Authorization": f"Bearer {API_PASSWORD}",
"Accept": "application/json"
}
try:
response = requests.get(API_URL, headers=headers)
if response.status_code == 200:
print("Success! Data received:")
print(response.json())
else:
print(f"Failed. Server responded with status code: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"A network error occurred: {e}")
if __name__ == "__main__":
make_api_call_basic_auth()
make_api_call_bearer_token()