Egress-Assess/protocols/clients/http_client.py

57 lines
1.8 KiB
Python
Raw Normal View History

2014-12-24 13:37:31 +00:00
'''
This is the web client code
'''
import sys
import urllib2
class Client:
def __init__(self, cli_object):
self.data_to_transmit = ''
self.remote_server = cli_object.ip
self.protocol = "http"
if cli_object.client_port is None:
self.port = 80
else:
self.port = cli_object.client_port
2015-05-16 02:11:21 +00:00
if cli_object.file is None:
self.file_transfer = False
else:
if "/" in cli_object.file:
self.file_transfer = cli_object.file.split("/")[-1]
else:
self.file_transfer = cli_object.file
2014-12-24 13:37:31 +00:00
def transmit(self, data_to_transmit):
2015-05-16 02:11:21 +00:00
if not self.file_transfer:
url = "http://" + self.remote_server + ":" + str(self.port) + "/post_data.php"
2015-05-16 02:11:21 +00:00
# Post the data to the web server at the specified URL
try:
f = urllib2.urlopen(url, data_to_transmit)
f.close()
print "[*] File sent!!!"
except urllib2.URLError:
print "[*] Error: Web server may not be active on " + self.remote_server
print "[*] Error: Please check server to make sure it is active!"
sys.exit()
else:
url = "http://" + self.remote_server + ":" + str(self.port) + "/post_file.php"
2015-05-16 02:11:21 +00:00
try:
data_to_transmit = self.file_transfer + ".:::-989-:::." + data_to_transmit
f = urllib2.urlopen(url, data_to_transmit)
f.close()
print "[*] File sent!!!"
except urllib2.URLError:
print "[*] Error: Web server may not be active on " + self.remote_server
print "[*] Error: Please check server to make sure it is active!"
sys.exit()
2014-12-24 13:37:31 +00:00
return