Skip to content

Commit

Permalink
Merge pull request #44 from Srinivas11789/develop
Browse files Browse the repository at this point in the history
PcapXray 2.6
  • Loading branch information
Srinivas11789 authored Jul 2, 2019
2 parents f8f8191 + 4ed45cd commit 7c95d7b
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 24 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Tool Highlights:
* Device Details

### Tool Image:
![Alt text](https://srinivas11789.github.io/PcapXray/Samples/screen2_5_1.png?raw=true)
![Alt text](https://srinivas11789.github.io/PcapXray/Samples/screen2_6_1.png?raw=true)

![Alt text](https://srinivas11789.github.io/PcapXray/Samples/screen2_5_2.png?raw=true)
![Alt text](https://srinivas11789.github.io/PcapXray/Samples/screen2_6_2.png?raw=true)

### Components:
* Network Diagram
Expand Down Expand Up @@ -77,7 +77,7 @@ python Source/main.py
* Matplotlib – plot graph (not used as of now)

### Demo
![Alt text](https://srinivas11789.github.io/PcapXray/Samples/demo2_5.gif?raw=true)
![Alt text](https://srinivas11789.github.io/PcapXray/Samples/demo2_6.gif?raw=true)

### Getting started:
* Clone the repository
Expand Down Expand Up @@ -118,12 +118,6 @@ python Source/main.py
* Performing the steps in `run.sh` file manually would work to launch the tool via docker (I can help with errors)
* Running `run.sh` scripts is an attempt to automate (would not work 100 percent)
- tested on mac and linux - will be better soon!...

### PcapXray 2.0
* Includes zoom feature
* Improves usability with a Browse files feature
* Report directory fixes for graph images
* Includes some bug fixes

### Immediate Future Tasks: (Target: 3.0)

Expand All @@ -134,6 +128,7 @@ python Source/main.py
- Traffic support: ICMP, DNS
- Known file type detection and Extract
- Python2 and Python3
- Interactive map

### Future:
* Structured and clean code flow
Expand All @@ -143,6 +138,13 @@ python Source/main.py
* More protocol support
* Clean up code

### Credits:
* Thanks for making it better,
- Professor Marc Budofsky
- Kevin Gallagher
* Thanks for all the dependent libraries used
* Logo created with logomakr.com and www.inkscape.org

[![Analytics](https://ga-beacon.appspot.com/UA-114681129-1/PcapXray/readme)](https://github.com/igrigorik/ga-beacon)

## ***Just for Security Fun!***
Binary file added Samples/demo2_6.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Samples/screen2_6_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Samples/screen2_6_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
223 changes: 223 additions & 0 deletions Source/Module/interactive_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
import sys

# Tkinter Mac Setting
if sys.platform == 'darwin':
import matplotlib
matplotlib.use('TkAgg')

import memory

# This implementation is a modified version of the example of
# embedding CEF Python browser using Tkinter toolkit.
# Reference https://github.com/cztomczak/cefpython/blob/master/examples/tkinter_.py
#
# NOTE: This example often crashes on Mac (Python 2.7, Tk 8.5/8.6)
# during initial app loading with such message:
# "Segmentation fault: 11". Reported as Issue #309.
#
# Tested configurations:
# - Tk 8.5 on Windows/Mac
# - Tk 8.6 on Linux
# - CEF Python v55.3+
#
# Known issue on Linux: When typing url, mouse must be over url
# entry widget otherwise keyboard focus is lost (Issue #255
# and Issue #284).

from cefpython3 import cefpython as cef
import ctypes
try:
# for Python2
from Tkinter import *
#from Tkinter import Tkversion
import Tkinter as tk
import ttk
import Tkconstants
except ImportError:
# for Python3
from tkinter import *
import tkinter as tk
from tkinter import ttk
import sys
import os
import platform
import logging as _logging

# Platforms
WINDOWS = (platform.system() == "Windows")
LINUX = (platform.system() == "Linux")
MAC = (platform.system() == "Darwin")

# Globals
logger = _logging.getLogger("tkinter_.py")

# Constants
# Tk 8.5 doesn't support png images
#IMAGE_EXT = ".png" if TkVersion > 8.5 else ".gif"

interactive_map = ""
browser_frame = ""
FourthFrame = ""
def gimmick_initialize(window, map):
global browser_frame, FourthFrame
if not browser_frame and not FourthFrame:
global interactive_map
interactive_map = map
logger.setLevel(_logging.INFO)
stream_handler = _logging.StreamHandler()
formatter = _logging.Formatter("[%(filename)s] %(message)s")
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
logger.info("CEF Python {ver}".format(ver=cef.__version__))
logger.info("Python {ver} {arch}".format(
ver=platform.python_version(), arch=platform.architecture()[0]))
logger.info("Tk {ver}".format(ver=tk.Tcl().eval('info patchlevel')))
assert cef.__version__ >= "55.3", "CEF Python v55.3+ required to run this"
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error

FourthFrame = ttk.Frame(window, width=500, height=500, padding="10 10 10 10",relief= GROOVE)
FourthFrame.grid(column=50, row=10, sticky=(N, W, E, S), columnspan=200, rowspan=200, padx=5, pady=5)

browser_frame = BrowserFrame(FourthFrame)
browser_frame.grid(row=0, column=0,sticky=(N, W, E, S),columnspan=100, rowspan=100, padx=5, pady=5)

FourthFrame.columnconfigure(50, weight=1)
FourthFrame.rowconfigure(10, weight=1)
browser_frame.columnconfigure(0, weight=1)
browser_frame.rowconfigure(0, weight=1)

window.update()
else:
if FourthFrame:
FourthFrame.grid_forget()
FourthFrame, browser_frame = "", ""
window.update()

def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()

class BrowserFrame(tk.Frame):

def __init__(self, master):
self.closing = False
self.browser = None
# Python2 has a ttk frame error of using self as argument so use tk
#ttk.Frame.__init__(self, master, width=500, height=400, padding="10 10 10 10", relief=GROOVE)
tk.Frame.__init__(self, master, width=500, height=400)
self.bind("<FocusIn>", self.on_focus_in)
self.bind("<FocusOut>", self.on_focus_out)
self.bind("<Configure>", self.on_configure)
self.focus_set()

def embed_browser(self):
window_info = cef.WindowInfo()
rect = [0, 0, self.winfo_width(), self.winfo_height()]
window_info.SetAsChild(self.get_window_handle(), rect)
self.browser = cef.CreateBrowserSync(window_info, url=interactive_map)
assert self.browser
self.browser.SetClientHandler(LoadHandler(self))
self.browser.SetClientHandler(FocusHandler(self))
self.message_loop_work()

def get_window_handle(self):
if self.winfo_id() > 0 and not MAC:
return self.winfo_id()
elif MAC:
raise Exception("Couldn't obtain window handle")
# CEF crashes in mac so temp disable
# * CreateBrowserSync calling window handle crashes with segmentation fault 11
# * https://github.com/cztomczak/cefpython/issues/309
# On Mac window id is an invalid negative value (Issue #308).
# This is kind of a dirty hack to get window handle using
# PyObjC package. If you change structure of windows then you
# need to do modifications here as well.
# noinspection PyUnresolvedReferences
"""
try:
from AppKit import NSApp
# noinspection PyUnresolvedReferences
import objc
# Sometimes there is more than one window, when application
# didn't close cleanly last time Python displays an NSAlert
# window asking whether to Reopen that window.
# noinspection PyUnresolvedReferences
return objc.pyobjc_id(NSApp.windows()[-1].contentView())
except:
raise Exception("Couldn't obtain window handle")
"""
else:
raise Exception("Couldn't obtain window handle")

def message_loop_work(self):
cef.MessageLoopWork()
self.after(10, self.message_loop_work)

def on_configure(self, _):
if not self.browser:
self.embed_browser()

def on_root_configure(self):
# Root <Configure> event will be called when top window is moved
if self.browser:
self.browser.NotifyMoveOrResizeStarted()

def on_mainframe_configure(self, width, height):
if self.browser:
if WINDOWS:
ctypes.windll.user32.SetWindowPos(
self.browser.GetWindowHandle(), 0,
0, 0, width, height, 0x0002)
elif LINUX:
self.browser.SetBounds(0, 0, width, height)
self.browser.NotifyMoveOrResizeStarted()

def on_focus_in(self, _):
logger.debug("BrowserFrame.on_focus_in")
if self.browser:
self.browser.SetFocus(True)

def on_focus_out(self, _):
logger.debug("BrowserFrame.on_focus_out")
if self.browser:
self.browser.SetFocus(False)

def on_root_close(self):
if self.browser:
self.browser.CloseBrowser(True)
self.clear_browser_references()
self.destroy()

def clear_browser_references(self):
# Clear browser references that you keep anywhere in your
# code. All references must be cleared for CEF to shutdown cleanly.
self.browser = None


class LoadHandler(object):

def __init__(self, browser_frame):
self.browser_frame = browser_frame

class FocusHandler(object):

def __init__(self, browser_frame):
self.browser_frame = browser_frame

def OnTakeFocus(self, next_component, **_):
logger.debug("FocusHandler.OnTakeFocus, next={next}"
.format(next=next_component))

def OnSetFocus(self, source, **_):
logger.debug("FocusHandler.OnSetFocus, source={source}"
.format(source=source))
return False

def OnGotFocus(self, **_):
"""Fix CEF focus issues (#255). Call browser frame's focus_set
to get rid of type cursor in url entry widget."""
logger.debug("FocusHandler.OnGotFocus")
self.browser_frame.focus_set()



Loading

0 comments on commit 7c95d7b

Please sign in to comment.