Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
basic prototype employing mitmproxy
- Loading branch information
Showing
8 changed files
with
577 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from twisted.internet.protocol import Factory, Protocol | ||
|
||
#WebSocket GUI Session | ||
class GuiSession(Protocol): | ||
def connectionMade(self): | ||
self.factory.write("HoneyProxySession: connectionMade") | ||
self.factory.sessions.add(self) | ||
def connectionLost(self,reason): | ||
self.factory.sessions.remove(self) | ||
self.factory.write("HoneyProxySession: connectionLost: "+str(reason)) | ||
def dataReceived(self, data): | ||
self.factory.write("HoneyProxySession: dataReceived: "+data+" ("+str(len(self.factory.sessions))+")") | ||
|
||
#WebSocket GUI Session Management | ||
class GuiSessionFactory(Factory): | ||
def __init__(self): | ||
self.sessions = set() | ||
def write(self,msg): | ||
print "Sending \""+msg+"\"" | ||
import base64 | ||
msg = base64.b64encode(msg) # somewhat crazy unicode bugs. | ||
for session in self.sessions: | ||
session.transport.write(msg) | ||
protocol = GuiSession |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,92 @@ | ||
''' | ||
@author: mhils | ||
''' | ||
# Copyright (C) 2010 Aldo Cortesi | ||
# | ||
# 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 3 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, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
|
||
import gui.session | ||
import os | ||
|
||
from libmproxy import controller, proxy | ||
|
||
from twisted.web.server import Site | ||
from twisted.web.static import File | ||
from twisted.internet import reactor, task | ||
from lib.websockets import WebSocketsResource | ||
|
||
class HoneyProxyMaster(controller.Master): | ||
def __init__(self, server, sessionFactory): | ||
controller.Master.__init__(self, server) | ||
self.sessionFactory = sessionFactory | ||
|
||
def start(self): | ||
#see controller.Master.run() | ||
global should_exit | ||
should_exit = False | ||
self.server.start_slave(controller.Slave, self.masterq) | ||
|
||
def tick(self): | ||
if not should_exit: | ||
controller.Master.tick(self, self.masterq) | ||
else: | ||
self.shutdown() | ||
|
||
def handle_request(self, msg): | ||
#hid = (msg.host, msg.port) | ||
#if msg.headers["cookie"]: | ||
# self.stickyhosts[hid] = msg.headers["cookie"] | ||
#elif hid in self.stickyhosts: | ||
# msg.headers["cookie"] = self.stickyhosts[hid] | ||
print "request to "+msg.host | ||
self.sessionFactory.write(msg.host) | ||
msg._ack() | ||
|
||
def handle_response(self, msg): | ||
#hid = (msg.request.host, msg.request.port) | ||
#if msg.headers["set-cookie"]: | ||
# self.stickyhosts[hid] = msg.headers["set-cookie"] | ||
print "response from "+msg.request.host | ||
gui.session.GuiSession() | ||
msg._ack() | ||
|
||
def main(): | ||
#TODO add libmproxy options - evaluate OptionsParser (see mitmdump / mitmproxy) | ||
config = proxy.ProxyConfig( | ||
cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem") | ||
) | ||
|
||
guiSessionFactory = gui.session.GuiSessionFactory() | ||
websocketRes = WebSocketsResource(guiSessionFactory) | ||
|
||
server = proxy.ProxyServer(config, 8080) | ||
m = HoneyProxyMaster(server, guiSessionFactory) | ||
|
||
|
||
|
||
|
||
reactor.listenTCP(8082, Site(websocketRes)) | ||
reactor.listenTCP(8081, Site(File("./gui/static"))) | ||
m.start() | ||
|
||
import urllib, webbrowser | ||
webbrowser.open("http://localhost:8081/#"+urllib.quote("ws://localhost:8082")) | ||
|
||
|
||
l = task.LoopingCall(m.tick) | ||
l.start(0.01) # call every 10ms | ||
reactor.run() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
Oops, something went wrong.