""" This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """ import socket import re import sys import base64 class pythonsploit: __proxyhost = '' __proxyuser = '' __proxypass = '' __proxyport = 0 __packet = '' __host = '' __port = 0 __method = '' __path = '' __headers = {} __cookies = {} __data = '' def __init__(self): self.__port = 80 def agent(self, agent): self.addheader('User-Agent',agent) def proxy(self, proxy, proxyp = ''): if(proxyp == ''): proxarr = proxy.split(':') self.__proxyhost = proxarr[0] self.__proxyport = proxarr[1] else: self.__proxyhost = proxy self.__proxyport = proxyp if(proxyp < 1 or proxyp > 65535): print("Error: invalid port number") sys.exit() def proxyauth(self, user, password): self.__proxyuser = user self.__proxypass = password def setport(self, newport): self.__port = newport def addheader(self, var, val): self.__headers[var] = val def addcookie(self, var, val): self.__cookies[var] = val def sock(self): mySock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if self.__proxyhost != '' and self.__proxyport != '': mySock.connect( (self.__proxyhost, self.__proxyport) ) else: mySock.connect( (self.__host, self.__port) ) if(not mySock): print("Error: Host seems down.") sys.exit() if(self.__method == "get"): self.__packet = "GET /"+self.__path+" HTTP/1.1\r\n" elif(self.__method == "post" or self.__method == "formdata"): self.__packet = "POST /"+self.__path+" HTTP/1.1\r\n" else: print("Unknown method.") sys.exit() if(self.__proxyuser != ''): self.__packet = "Proxy-Authorization: Basic "+base64.encode(self.__proxyuser+':'+self.__proxypass)+"\r\n" self.__packet += "Host: "+self.__host+"\r\n" l = len(self.__cookies) if(l): self.__packet += "Cookie: " for i in self.__cookies: self.__packet += str(i)+"="+self.__cookies[i]+"; " self.__packet += "\r\n" l = len(self.__headers) if(l): for i in self.__headers: self.__packet += str(i)+": "+self.__headers[i]+"\r\n" self.__packet += "Connection: close\r\n" if(self.__method == "post"): self.__packet += "Content-Type: application/x-www-form-urlencoded\r\n" self.__packet += "Content-Length: "+str(len(self.__data))+"\r\n\r\n" self.__packet += self.__data self.__packet += "\r\n" mySock.send(self.__packet) self.__recv = "" while 1: res = mySock.recv(1024) if not res: break else: self.__recv += res mySock.close() def getcontent(self): tab = self.__recv.split('\r\n\r\n') return tab[1] def getheaders(self): tab = self.__recv.split('\r\n\r\n') return tab[0] def get(self, url): motif = re.compile('http://([^/]+)/?(.+)?') catch = motif.findall(url)[0] self.__host = catch[0] self.__path = catch[1] self.__method = 'get' self.sock() return str(self.__recv) def post(self, url, content): motif = re.compile('http://([^/]+)/?(.+)?') catch = motif.findall(url)[0] self.__host = catch[0] self.__path = catch[1] self.__method = 'post' self.__data = content self.sock() return self.__recv def showlastrequest(self): if(__self.packet != ''): return __self.packet else: return 0