I am following a tutorial to retrieve the HTML from a webpage using Python Sockets found here.
I have an Apache server running on an Ubuntu guest that is hosting a single HTML file for my website. I have made a DNS entry on my host OS's /etc/hosts file to make the webpage accessible with the url vulnerable.
I have verified that my webpage can be accessed from a web browser on my host machine.
I have made a few modifications to the code to fit my case.
import socket
import sys # needed for sys.exit()
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print ("Failed to initialize socket")
sys.exit()
print ("Socket initialized")
host = "vulnerable"
port = 80
try:
remote_ip = socket.gethostbyname(host)
except socket.gaierror as e:
print ("Hostname could not be resolved. Exiting")
sys.exit()
s.connect((remote_ip, port))
print ("Socket Connected to " +host+ " on IP " + remote_ip)
message = "GET /HTTP/1.1\r\n\r\n".encode('utf-8') # convert string to byte message, otherwise won't send
try:
s.sendall(message)
except socket.error:
print ("Send Failed")
sys.exit()
print ("Message sent successfully")
reply = s.recv(4096)
print (reply)
When I try to retrieve the HTML from my website, I get an unexpected Error 404.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /HTTP/1.1 was not found on this server.</p>
<hr>
<address>Apache/2.4.10 (Ubuntu) Server at 127.0.1.1 Port 80</address>
</body></html>
I do not understand why I am getting this 404 error when I can reach my webpage from a web browser without issue.