Compare commits

..

32 Commits

Author SHA1 Message Date
4fb575ba62 Remove extraneous files 2022-10-11 01:39:26 -05:00
44166a2507 Add login functionality (no hashing) 2022-10-11 01:36:50 -05:00
09836efcc4 Ignore all generated csvs for development 2022-10-10 23:51:54 -05:00
1254b543e9 Add both links to ntfy 2022-10-10 23:38:42 -05:00
3838c37b1b Add icon to built exe, default run as admin with manifest, add bash runner script 2022-10-10 23:25:26 -05:00
02175cc67e Install into subfolder 2022-10-10 23:15:54 -05:00
c9de444432 Add exe installer builder 2022-10-10 23:13:30 -05:00
a83e4016ab Fix program quit, enable debug mode 2022-10-10 22:35:52 -05:00
d069196887 actually figure out tags now 2022-10-10 22:25:10 -05:00
ffefad5db5 Actually build before release 2022-10-10 22:13:31 -05:00
f0121274a6 Add notifications 2022-10-10 22:10:58 -05:00
302dcd5529 figure out how tags work 2022-10-10 22:08:54 -05:00
0a55b3ae8c Fix branch tag for release 2022-10-10 22:05:45 -05:00
494afed4ae Actually push commits 2022-10-10 22:03:07 -05:00
b12902183d Unique release tag 2022-10-10 22:01:36 -05:00
f3822c32f2 Publish release 2022-10-10 21:56:38 -05:00
8c5004c24d reformat curl 2022-10-10 21:51:34 -05:00
fb7544fe98 fix release script 2022-10-10 21:50:47 -05:00
0cf55aef93 split up files, add release script 2022-10-10 21:49:28 -05:00
45e1204397 Switch to paramiko; log output 2022-10-10 19:19:00 -05:00
d38e1384a6 add sftp 2022-09-27 21:04:49 -05:00
faafcf8505 update gitignore 2022-09-27 20:26:10 -05:00
0483147207 latest changes 2022-09-27 20:14:23 -05:00
3afe7faf7c add changes from last week 2022-09-27 18:30:27 -05:00
166aa5d93a simplify OS detection 2022-09-19 23:30:59 -05:00
e043a03890 add additional comments 2022-09-19 23:26:29 -05:00
8b005d0ece make more stuff win32 specific 2022-09-19 23:17:28 -05:00
ca3e489adb Add advanced windows netstat parser 2022-09-19 23:14:02 -05:00
159bbf2130 test data collection 2022-09-19 21:00:48 -05:00
b4aecb1974 test modules 2022-09-13 20:59:07 -05:00
f415fe7a6d add icon 2022-09-06 20:21:07 -05:00
c25f517aab add tray icon test 2022-09-06 20:21:02 -05:00
20 changed files with 57815 additions and 242 deletions

8
.gitignore vendored
View File

@ -1,2 +1,8 @@
build/
__pycache__/
build/
config.yaml
*.csv
admin-key.ppk
token.txt
*.zip
output.log

Binary file not shown.

26
auth.py Normal file
View File

@ -0,0 +1,26 @@
import ssh
import csv
from util import fprint
from util import find_data_file
from time import sleep
def login(config, user, password, sysid):
fprint("Attempting to login as " + user)
filename = sysid + "login.csv"
with open(find_data_file(filename), "w", newline="") as f:
writer = csv.writer(f)
writer.writerows([[user,password,sysid],])
fprint("done creating csv")
ssh.sftp_send_data(config, filename, 'sendlogin')
command = "python3 login_service.py " + sysid
ssh.run_ssh(config, command, 'scripts')
sleep(1)
filename = sysid + "success.txt"
if ssh.check_for_file(config, filename, 'receivelogin') == False:
filename = sysid + "fail.txt"
if ssh.check_for_file(config, filename, 'receivelogin') == False:
raise ValueError("Unable to determine login status")
else:
return False
else:
return True

19
config.yml Normal file
View File

@ -0,0 +1,19 @@
sftp:
host: ec2-34-232-29-46.compute-1.amazonaws.com
user: ec2-user
port: 22
keyfile: keyfile-admin.pem
filepath:
send: /home/ec2-user/Incoming/Incoming_Data
sendlogin: /home/ec2-user/Incoming/Login
receive: /home/ec2-user/Outgoing/Outgoing_Data
receivelogin: /home/ec2-user/Outgoing/Login
scripts: /home/ec2-user/scripts
ui:
darkmode: true
core:
autokill: false
localadmin: true
interval: 10

View File

@ -1,187 +1,138 @@
import glob
import wx
import wx.lib.buttons as buttons
import numpy as np
import pandas as pd
BG_IMG = 'icon.png'
COLUMN_NAMES = np.flip(['Server name', 'Port number', 'Status', 'Source IP', 'Destination IP', 'Source port number', 'Destination port number', 'Number of requests made since flag', 'Date', 'Process Name', 'Address hostname', 'Refresh rate'])
TEST_FILE = pd.read_csv('out.csv', )
TEST_FILE = TEST_FILE.iloc[1:, :]
TEST_FILE.columns = ['Server name', 'Port number', 'Status', 'Source IP', 'Destination IP', 'Source port']
print(TEST_FILE)
print(len(TEST_FILE))
print(TEST_FILE.iloc[1, 1])
class OtherFrame(wx.Frame):
"""
Class used for creating frames other than the main one
"""
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Server Panel', size=(600, 250))
panel = ServerPanel(self)
self.Show()
def on_edit(self, event):
print('in on_edit')
import wx.adv
import os
from time import sleep
from multiprocessing import Process, Pipe
from sys import platform
def update_mp3_listing(self, folder_path):
print(folder_path)
def on_window(self, event):
return
class HelpFrame(wx.Frame):
"""
Class used for creating frames other than the main one
"""
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Help', size=(600, 250))
panel = HelpPanel(self)
self.Show()
# Panel with all the login widgets
class LoginPanel(wx.Panel):
def __init__(self, parent):
super(LoginPanel, self).__init__(parent)
self.SetBackgroundColour((44, 51, 51))
basicLabel = wx.StaticText(self, -1, "Username")
basicLabel.SetForegroundColour((255,255,255))
basicText = wx.TextCtrl(self, -1, "", size=(175, -1))
# basicText.SetInsertionPoint(0)
pwdLabel = wx.StaticText(self, -1, "Password")
pwdText = wx.TextCtrl(self, -1, "", size=(175, -1), style=wx.TE_PASSWORD)
pwdLabel.SetForegroundColour((255, 255, 255))
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox.Add(basicLabel, 0, wx.ALIGN_CENTER | 100, 5)
vbox.Add(basicText, 0, wx.ALIGN_CENTER | 100, 5)
vbox.Add(pwdLabel, 0, wx.ALIGN_CENTER | 100, 5)
vbox.Add(pwdText, 0, wx.ALIGN_CENTER | 100, 5)
login_button = wx.Button(self, label='Login')
login_button.Bind(wx.EVT_BUTTON, self.on_login)
help_button = wx.Button(self, label='Help')
help_button.Bind(wx.EVT_BUTTON, self.on_help)
# signup_button = wx.Button(self, label='Sign Up')
hbox.Add(login_button, 0, wx.ALL | 200, 20)
# hbox.Add(signup_button, 0, wx.ALL | 200, 20)
hbox.Add(help_button, 0, wx.ALL | 200, 20)
vbox.Add(hbox, 0, wx.ALIGN_CENTER | 100, 5)
self.SetSizer(vbox)
def on_login(self, event):
OtherFrame()
def on_help(self, event):
HelpFrame()
# Panel with all the login widgets
class HelpPanel(wx.Panel):
def __init__(self, parent):
super(HelpPanel, self).__init__(parent)
self.SetBackgroundColour((44, 51, 51))
# basicLabel = wx.StaticText(self, -1, "Username")
# basicLabel.SetForegroundColour((255,255,255))
# basicText = wx.TextCtrl(self, -1, "", size=(175, -1))
#
# # basicText.SetInsertionPoint(0)
# pwdLabel = wx.StaticText(self, -1, "Password")
# pwdText = wx.TextCtrl(self, -1, "", size=(175, -1), style=wx.TE_PASSWORD)
# pwdLabel.SetForegroundColour((255, 255, 255))
# vbox = wx.BoxSizer(wx.VERTICAL)
# hbox = wx.BoxSizer(wx.HORIZONTAL)
# vbox.Add(basicLabel, 0, wx.ALIGN_CENTER | 100, 5)
# vbox.Add(basicText, 0, wx.ALIGN_CENTER | 100, 5)
# vbox.Add(pwdLabel, 0, wx.ALIGN_CENTER | 100, 5)
# vbox.Add(pwdText, 0, wx.ALIGN_CENTER | 100, 5)
# login_button = wx.Button(self, label='Login')
# login_button.Bind(wx.EVT_BUTTON, self.on_login)
# help_button = wx.Button(self, label='Help')
# # signup_button = wx.Button(self, label='Sign Up')
# hbox.Add(login_button, 0, wx.ALL | 200, 20)
# # hbox.Add(signup_button, 0, wx.ALL | 200, 20)
# hbox.Add(help_button, 0, wx.ALL | 200, 20)
# vbox.Add(hbox, 0, wx.ALIGN_CENTER | 100, 5)
# self.SetSizer(vbox)
TRAY_TOOLTIP = 'IP Pigeon'
TRAY_ICON = 'icon.png'
"""if platform == "linux" or platform == "linux2":
# linux
elif platform == "darwin":
# OS X
elif platform == "win32":
# Windows...
"""
displaydata = None
settings = None
class ServerPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent, size=(500, 500))
self.SetBackgroundColour((44, 51, 51))
# self.toolbar = self.CreateToolBar()
# tb = wx.ToolBar(self, -1)
super().__init__(parent)
main_sizer = wx.BoxSizer(wx.VERTICAL)
secondary_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.row_obj_dict = {}
self.list_ctrl = wx.ListCtrl(
self, size=(-1, 75),
self, size=(-1, 100),
style=wx.LC_REPORT | wx.BORDER_SUNKEN
)
# self.pnl1.SetBackgroundColour(wx.BLACK)
self.handle_columns()
for i in range(len(TEST_FILE)):
self.list_ctrl.InsertItem(i, TEST_FILE.iloc[i, 0])
for j in range(1, 5):
self.list_ctrl.SetItem(i, j, TEST_FILE.iloc[i, j])
main_sizer.Add(self.list_ctrl, 0, wx.ALL | wx.EXPAND, 20)
self.list_ctrl.InsertColumn(0, 'Server name', width=140)
self.list_ctrl.InsertColumn(1, 'Port number', width=140)
self.list_ctrl.InsertColumn(2, 'Status', width=200)
main_sizer.Add(self.list_ctrl, 0, wx.ALL | wx.EXPAND, 5)
start_button = wx.Button(self, label='Start')
start_button.SetBackgroundColour((205, 215, 206))
start_button.Bind(wx.EVT_BUTTON, self.on_edit)
start_button.Bind(wx.EVT_ENTER_WINDOW, self.on_edit)
stop_button = wx.Button(self, label='Stop')
stop_button.SetBackgroundColour('#F08080')
secondary_frame_button = wx.Button(self, label='Window')
secondary_frame_button.Bind(wx.EVT_BUTTON, self.on_window)
# wx.BORDER(stop_button, wx.BORDER_NONE)
stop_button.Bind(wx.EVT_BUTTON, self.on_edit)
main_sizer.Add(start_button, 0, wx.CENTER | wx.ALL | 100, 5)
main_sizer.Add(stop_button, 0, wx.CENTER | 100, 5)
main_sizer.Add(secondary_frame_button, 0, wx.CENTER | 100, 5)
main_sizer.Add(start_button, 0, wx.ALL | 100, 5)
main_sizer.Add(stop_button, 0, wx.ALL | 100, 5)
self.SetSizer(main_sizer)
def handle_columns(self):
for col in COLUMN_NAMES:
self.list_ctrl.InsertColumn(0, col, width=200)
def on_edit(self, event):
print('in on_edit')
def update_mp3_listing(self, folder_path):
print(folder_path)
def on_window(self, event):
OtherFrame()
def ShowImage(self, imageFile):
if imageFile == "":
self.bitmap = wx.StaticBitmap(self, -1, size=(0, 0))
else:
bmp = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap = wx.StaticBitmap(self, -1, bmp, (0, 0))
class ServerFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None,
title='Server Dashboard')
self.panel = LoginPanel(self)
# image = wx.StaticBitmap(self, wx.ID_ANY)
# image.SetBitmap(wx.Bitmap('WXPython.png'))
self.panel = ServerPanel(self)
self.Show()
### Taskbar Icon
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.Append(item)
return item
class TaskBarIcon(wx.adv.TaskBarIcon):
def __init__(self, frame):
self.frame = frame
super(TaskBarIcon, self).__init__()
self.set_icon(TRAY_ICON)
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Control Panel', self.on_open)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def set_icon(self, path):
icon = wx.Icon(path)
self.SetIcon(icon, TRAY_TOOLTIP)
def on_left_down(self, event):
print ('Tray icon was left-clicked.')
def on_open(self, event):
foreground()
#self.close_popup()
def on_exit(self, event):
wx.CallAfter(self.Destroy)
self.close_popup()
def close_popup(self):
self.frame.Close()
class TaskbarApp(wx.App):
def OnInit(self):
frame=wx.Frame(None)
self.SetTopWindow(frame)
TaskBarIcon(frame)
return True
class FullApp(wx.App):
def OnInit(self):
fullframe=ServerFrame()
return True
def background():
app = TaskbarApp(False)
#with Manager() as manager:
app.MainLoop()
#displaydata = manager.list()
#settings = manager.list()
#rawdata = manager.list()
#logdata = manager.list()
#uploaddata = manager.list()
#downloaddata = manager.list()
def open_fg(outputdata, uisettings):
app = FullApp(False)
app.MainLoop()
def foreground():
# Open the foreground in a separate process so that UI acts independently of the taskbar icon
p = Process(target=open_fg, args=(displaydata, settings))
p.start()
#p.join()
print("Launched foreground")
if __name__ == '__main__':
app = wx.App(False)
frame = ServerFrame()
app.MainLoop()
background()

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

160
ippigeon.py Normal file
View File

@ -0,0 +1,160 @@
import os
import sys
import subprocess
from multiprocessing import Process, Manager, Pool, TimeoutError, freeze_support, active_children
from sys import platform
from time import sleep
import uuid
import yaml
from util import find_data_file
from util import fprint
import taskbartool
import util
import netstat
import ssh
import auth
displaydata = None
settings = None
netdata_res = None
procdata_res = None
killme = None
datafile = ""
#print(datafile)
config = None
interval = 10
win32 = platform == "win32"
linux = platform == "linux" or platform == "linux2"
macos = platform == "darwin"
# Get unique system values
if win32:
sysid = hex(uuid.getnode())
datafile += sysid
datafile += "gendata.csv"
# Python is running as Administrator (so netstat can get filename, to block, etc),
# so we use this to see who is actually logged in
# it's very hacky
startupinfo = subprocess.STARTUPINFO()
#if not getattr(sys, "frozen", False):
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # hide powershell window
res = subprocess.check_output(["WMIC", "ComputerSystem", "GET", "UserName"], universal_newlines=True, startupinfo=startupinfo)
_, username = res.strip().rsplit("\n", 1)
userid, sysdom = username.rsplit("\\", 1)
def netstat_done(res):
fprint("netstat done, processing")
procdata_res = pool.apply_async(netstat.process, (res,), callback=process_done)
#netstat.process(res)
def process_done(res):
fprint("uploading to sftp...")
#ssh.sftp_send_data(res, config, datafile)
procdata_res = pool.apply_async(ssh.sftp_send_data, (config, datafile, 'send'))
def login_done(res):
if not res:
fprint("Login failure")
settings["message"] = "Login failure"
else:
fprint("Login result in main: " + str(res))
def killall():
kids = active_children()
for kid in kids:
kid.kill()
fprint("Every child has been killed")
os.kill(os.getpid(), 9) # dirty kill of self
def mainloop(pool):
# worker pool: netstat, netstat cleanup, upload, download, ui tasks
global counter
global netdata_res
global procdata_res
global rawdata
global killme
#print(killme)
if killme.value > 0:
#print("killing")
killall()
#print(res.get(timeout=1))
if counter == 0: # runs every INTERVAL
fprint("start loop")
if netdata_res is None or netdata_res.ready():
#rawdata = netdata_res.get()
#procdata_res = pool.apply_async(process_netstat, (rawdata))
fprint("netstat starting")
netdata_res = pool.apply_async(netstat.start, callback=netstat_done)
#fprint(netdata_res.successful())
# runs every 50ms
if settings["login"] == True:
login_res = pool.apply_async(auth.login, (config, settings["username"], settings["password"], sysid), callback=login_done)
#fprint(auth.login(config, settings["username"], settings["password"], sysid))
settings["login"] = False
sleep(interval / (interval * 20.0))
counter += 1
if counter == interval * 20:
counter = 0
class Logger(object):
def __init__(self, filename="output.log"):
self.log = open(filename, "a")
self.terminal = sys.stdout
def write(self, message):
self.log.write(message)
#close(filename)
#self.log = open(filename, "a")
try:
self.terminal.write(message)
except:
sleep(0)
def flush(self):
print("")
if __name__ == '__main__':
freeze_support() # required if packaged into single EXE
# create manager to share data to me, background, foreground
# create worker pool
sys.stdout = Logger(filename=find_data_file("output.log"))
sys.stderr = Logger(filename=find_data_file("output.log"))
with Pool(processes=5) as pool:
with Manager() as manager:
with open(find_data_file('config.yml'), 'r') as file:
#global config
config = yaml.safe_load(file)
#print(config['sftp']['host'])
interval = config['core']['interval']
displaydata = manager.list(range(2)) # data to be printed
settings = manager.dict() # configuration
settings["login"] = False
settings["loggedin"] = False
killme = manager.Value('d', 0)
#killme = False
# launch background UI app as process
p = Process(target=taskbartool.background, args=(displaydata,settings,killme))
p.start()
#p.join() # not a foreground job, so let's not join it
keeprunning = True
# initial setup
#netdata_res = pool.apply_async(netstat, callback=netstat_done)
# launch loop - non-blocking!
counter = 0
while(keeprunning):
mainloop(pool)

27
keyfile-admin.pem Normal file
View File

@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAkKf5kPTTHIvL44Tfe7QO13K/JVfD+DbIwWQBURqa60ohVldN
mWg7dngpMeHcr27JXLHfAT1c2ztbZR13ZZzKTpu1IbUtecVhCsduNtMzLehB8seQ
0lPLAUeE76IK7KfYBUXNXnA5n9oFTS2DJwnYgSqAODbILOxbUpdRajTbacE3Mo0p
nMLwvqcCwXXfKEhlcccclckDKkZYpwLfmuw7veD007NlBfq/lOezdFBERezEUIgr
+A22JP5KCsVeuQBJuuRrXdz8p334n2xaR4RDjN3p0cmMi2Oohm7M7MbhAImC/J+P
HXOJMQpdEgD6Ea17Jr9ORPf08HrrjaZzA/SW7QIDAQABAoIBAEe07LKdmjTxW42a
JUpl9GF6gSRawEs/pP6wuzJgFOGD6sipGE9uauOMJyeSBdp0+Z5YkepEZ85JO0IB
fFlDgsm6x+xAqp1NaZB1Ub4draYZFu/pW3HXla85q706P14Wya+7bVVeHkKOSch7
QiNM7yUAU3UKOuqB87caSYJzVzyxhUd5S6/ro2VNbXT/7vHSsKCja2scy+JaRhKn
m4cc3P+ggI06JLfZsMZY1zJKDhbWiHGmB5ZdzqAJsu/bAtXWY25QsHowYAqPG7Uq
7rcJlbbdkCASE4MXqi427uJfeqBB0vfykttSriBpQVBKus5wpcCEOMkpEho0zU0Z
yx9bdeECgYEA9d0PDjAqIwrVSxjeOd6eXcSwmMzaK5fc5beptKRQA0U/O4swhn2+
NOio6v6fTWuDwNHAsMZiDvW3boO357GCm2N7YkqvdarydfOt7IccsUnEROaAxOqx
1wlnl0NkVIwaTo3XoRSWIcIqE3mCAaz8peqtRmIcXcQ/S9RGm3QeiAUCgYEAlp67
vmn6Z1U0XLILnf4i9D3ECJlwJXEP64pB4XnXiHU/StaXY7CSRaCX+SxfgUR8pATQ
ySYDRY1Ag6cHxSVIo1vkotT3P11x7/8yWnomvnEwRJqTMdN+/VuTi4tPzU1ScNXX
F7aRqkNoGEkmsmi2wdszbJcruI74k4TGLcbNj8kCgYEAgG37AVRTjn6IMHRLETui
yiSGgyrvBDqN30lzUrNKQIsZnsb0kCx7ATRPmIFtQYnaBw0KdM0MR/g+23HezR7C
tNzghNWyleq4QLkLrzRc3pdD+SHXPgXC5Cs7e55ueGO/Ei2x56jTS8sbI5UjPjDY
wOq3nL5/RtPOpJO8VlPv5ukCgYEAjytM/D9SdNyJzD61SjWiVhVL/HyVHBHvdw3R
d5jQZfZE9kcqWekh8KspKgGiuoY2D9Y/+6N1YqxUkY+4lA3PkPAtURYr+wBA6Ebk
PxpzL3z5y4w+tBL8V6mvguomLdj8ryKktPamWXh/Pu5xqQ5eAcDxjZvYRDMqV1bS
5fpdtPkCgYEAoRVdlDSaj9u3NPoFkschl1bOZlJpm9tJVU+LoWxRe8tuLIwVDvXP
JsZMcpfinEPWSrJN+hlGDuaq7k5LtSNeQoruaafhlE+CV54G7J2Khn8pRKWT+n/p
36PfgGbhuLsZl8KDy+PXjS+L5A1kuTxB4rOBdHXIHm60aNCqB0BRcTM=
-----END RSA PRIVATE KEY-----

1
known_hosts Normal file
View File

@ -0,0 +1 @@
ec2-34-232-29-46.compute-1.amazonaws.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBM8sLlu0mu1PqYXk+a9XYHXXFiOaxk/2tIS5O3q+3ah13bd5Iz+NSxS0bXT7TdMTA/lD1kWMUXROEauADgIfT98=

View File

80
netstat.py Normal file
View File

@ -0,0 +1,80 @@
from util import find_data_file
from util import setup_child
from util import fprint
from util import run_ps
from util import win32
import util
import time
import csv
def process(data):
setup_child()
fprint("netstat processing")
if win32:
#output = data.stdout
#print(output)
output = data.stdout.decode().split('\r\n') # split stdout into lines
#print(output)
if output[0].find("The requested operation requires elevation.") >= 0:
#print("test3")
raise PermissionError("Unable to acquire netstat data without admin!")
#print("test2")
output2 = list()
output2.append([util.sysid, util.userid, util.sysdom, util.time()]) # add metadata
#print(output2)
procname = ""
"""for x in range(4, len(output)):
tmp = output[x].split(" ")
print(tmp)
tmp = [i for i in output[x] if i]
print(tmp)
print(len(tmp))
if len(len(tmp) == 1):
procname = tmp[0]
print(x)
else:
print(x)
output2[x] = list()
output2[x].append(procname)
output2[x].append(output[x].split(" "))
output2[x] = [i for i in output2[x] if i]
output2 = [i for i in output2 if i]
print(output2)"""
x = len(output) - 1 # start at the end because filename comes after connection
procname = "Unknown" # if the very last connection happens to have no file (yes, it's possible), we can say unknown
while x > 3:
string = output[x]
#print("LINE: ", string)
string_split = string.split(" ")
string_split = [i for i in string_split if i]
if string.find("Can not obtain ownership information") >= 0: # Higher privilige than us, must be system
procname = "Windows System"
elif string.find("]") >= 0 and string.find("[") == 1: # generic [file.exe]
procname = string[2:-1]
elif len(string_split) == 5: # actual netstat line
tmp = [procname,] # add executable name first
tmp.extend(string.split(" "))
tmp = [i for i in tmp if i]
#print(tmp)
output2.append(tmp)
#else: # In case of an extra line above file, or an empty line, ignore it
#print("Garbage data", string)
x = x - 1
#output2 = output2[2:]
#print(output2)
with open(find_data_file(util.datafile), "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(output2)
fprint("done creating csv")
def start():
fprint("netstat started")
setup_child()
if win32:
data = run_ps("netstat -n -o -b")
fprint("data acquired")
return data

84
out.csv
View File

@ -1,84 +0,0 @@
firefox.exe,TCP,[2620:f3:8000:5060:5939:a4c0:4f5b:113f]:53338,[2607:f518:5::4816:b9c7]:80,ESTABLISHED,8008
firefox.exe,TCP,[2620:f3:8000:5060:5939:a4c0:4f5b:113f]:53301,[2607:f8b0:4009:817::200e]:443,ESTABLISHED,8008
firefox.exe,TCP,[2620:f3:8000:5060:5939:a4c0:4f5b:113f]:53292,[2607:f8b0:4009:808::2003]:80,TIME_WAIT,0
firefox.exe,TCP,[2620:f3:8000:5060:5939:a4c0:4f5b:113f]:53285,[2606:4700:4400::6812:2962]:443,TIME_WAIT,0
python.exe,TCP,127.0.0.1:51987,127.0.0.1:51986,ESTABLISHED,17244
python.exe,TCP,127.0.0.1:51986,127.0.0.1:51987,ESTABLISHED,17244
VSCodium.exe,TCP,127.0.0.1:51978,127.0.0.1:51977,ESTABLISHED,17828
VSCodium.exe,TCP,127.0.0.1:51977,127.0.0.1:51978,ESTABLISHED,17828
firefox.exe,TCP,127.0.0.1:51761,127.0.0.1:51760,ESTABLISHED,10420
firefox.exe,TCP,127.0.0.1:51760,127.0.0.1:51761,ESTABLISHED,10420
firefox.exe,TCP,127.0.0.1:51759,127.0.0.1:51758,ESTABLISHED,8008
firefox.exe,TCP,127.0.0.1:51758,127.0.0.1:51759,ESTABLISHED,8008
nxserver.bin,TCP,127.0.0.1:50792,127.0.0.1:22890,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:50778,127.0.0.1:4742,ESTABLISHED,8116
tailscale-ipn.exe,TCP,127.0.0.1:50530,127.0.0.1:41112,ESTABLISHED,14552
nxclient.bin,TCP,127.0.0.1:50409,127.0.0.1:19231,ESTABLISHED,11836
nxclient.bin,TCP,127.0.0.1:50408,127.0.0.1:26068,ESTABLISHED,11836
nxclient.bin,TCP,127.0.0.1:50407,127.0.0.1:10632,ESTABLISHED,11836
nxnode.bin,TCP,127.0.0.1:50406,127.0.0.1:25001,ESTABLISHED,11608
nxnode.bin,TCP,127.0.0.1:50405,127.0.0.1:23938,ESTABLISHED,11608
nxnode.bin,TCP,127.0.0.1:50402,127.0.0.1:28488,ESTABLISHED,11608
nxnode.bin,TCP,127.0.0.1:50397,127.0.0.1:17311,ESTABLISHED,11608
nxnode.bin,TCP,127.0.0.1:50395,127.0.0.1:21968,ESTABLISHED,11608
nxnode.bin,TCP,127.0.0.1:50174,127.0.0.1:10055,ESTABLISHED,11608
nxservice64.exe,TCP,127.0.0.1:50160,127.0.0.1:19492,ESTABLISHED,5544
nxserver.bin,TCP,127.0.0.1:49772,127.0.0.1:16950,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:49767,127.0.0.1:16619,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:49766,127.0.0.1:31770,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:49765,127.0.0.1:7039,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:49762,127.0.0.1:22921,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:49761,127.0.0.1:6363,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:49698,127.0.0.1:15907,ESTABLISHED,8116
AppleMobileDeviceService.exe,TCP,127.0.0.1:49674,127.0.0.1:5354,ESTABLISHED,4280
AppleMobileDeviceService.exe,TCP,127.0.0.1:49670,127.0.0.1:5354,ESTABLISHED,4280
tailscaled.exe,TCP,127.0.0.1:41112,127.0.0.1:50530,ESTABLISHED,8076
nxserver.bin,TCP,127.0.0.1:31770,127.0.0.1:49766,ESTABLISHED,8116
nxnode.bin,TCP,127.0.0.1:28488,127.0.0.1:50402,ESTABLISHED,11608
nxclient.bin,TCP,127.0.0.1:26068,127.0.0.1:50408,ESTABLISHED,11836
nxclient.bin,TCP,127.0.0.1:25001,127.0.0.1:50406,ESTABLISHED,11836
nxnode.bin,TCP,127.0.0.1:23938,127.0.0.1:50405,ESTABLISHED,11608
nxserver.bin,TCP,127.0.0.1:22921,127.0.0.1:49762,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:22890,127.0.0.1:50792,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:21968,127.0.0.1:50395,ESTABLISHED,8116
nxservice64.exe,TCP,127.0.0.1:19492,127.0.0.1:50160,ESTABLISHED,5544
nxclient.bin,TCP,127.0.0.1:19231,127.0.0.1:50409,ESTABLISHED,11836
nxnode.bin,TCP,127.0.0.1:17311,127.0.0.1:50397,ESTABLISHED,11608
nxserver.bin,TCP,127.0.0.1:16950,127.0.0.1:49772,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:16619,127.0.0.1:49767,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:15907,127.0.0.1:49698,ESTABLISHED,8116
nxclient.bin,TCP,127.0.0.1:10632,127.0.0.1:50407,ESTABLISHED,11836
nxnode.bin,TCP,127.0.0.1:10055,127.0.0.1:50174,ESTABLISHED,11608
nxserver.bin,TCP,127.0.0.1:7039,127.0.0.1:49765,ESTABLISHED,8116
nxserver.bin,TCP,127.0.0.1:6363,127.0.0.1:49761,ESTABLISHED,8116
mDNSResponder.exe,TCP,127.0.0.1:5354,127.0.0.1:49674,ESTABLISHED,4076
mDNSResponder.exe,TCP,127.0.0.1:5354,127.0.0.1:49670,ESTABLISHED,4076
nxserver.bin,TCP,127.0.0.1:4742,127.0.0.1:50778,ESTABLISHED,8116
nxserver.bin,TCP,104.194.122.206:53343,208.59.79.12:443,TIME_WAIT,0
nxserver.bin,TCP,104.194.122.206:53340,54.212.237.219:443,TIME_WAIT,0
firefox.exe,TCP,104.194.122.206:53339,54.212.237.219:443,ESTABLISHED,8008
firefox.exe,TCP,104.194.122.206:53337,54.212.237.219:443,ESTABLISHED,8008
firefox.exe,TCP,104.194.122.206:53335,208.59.79.12:443,TIME_WAIT,0
firefox.exe,TCP,104.194.122.206:53334,208.59.79.12:443,ESTABLISHED,8008
VSCodium.exe,TCP,104.194.122.206:53314,76.76.21.61:443,ESTABLISHED,3816
VSCodium.exe,TCP,104.194.122.206:53313,76.76.21.164:443,ESTABLISHED,3816
VSCodium.exe,TCP,104.194.122.206:53312,76.76.21.164:443,CLOSE_WAIT,3816
firefox.exe,TCP,104.194.122.206:53307,104.192.142.9:443,ESTABLISHED,8008
firefox.exe,TCP,104.194.122.206:53300,54.201.164.58:443,TIME_WAIT,0
firefox.exe,TCP,104.194.122.206:53299,35.186.227.140:443,ESTABLISHED,8008
firefox.exe,TCP,104.194.122.206:53298,162.159.130.232:443,TIME_WAIT,0
firefox.exe,TCP,104.194.122.206:53297,162.159.128.232:443,TIME_WAIT,0
firefox.exe,TCP,104.194.122.206:53290,162.159.138.232:443,TIME_WAIT,0
firefox.exe,TCP,104.194.122.206:53289,162.159.135.234:443,ESTABLISHED,8008
firefox.exe,TCP,104.194.122.206:53284,72.21.91.29:80,TIME_WAIT,0
firefox.exe,TCP,104.194.122.206:53160,142.250.191.106:443,ESTABLISHED,8008
firefox.exe,TCP,104.194.122.206:53154,142.250.191.106:443,ESTABLISHED,8008
firefox.exe,TCP,104.194.122.206:52525,104.192.142.11:443,ESTABLISHED,8008
syncthing.exe,TCP,104.194.122.206:51451,172.245.94.35:22067,ESTABLISHED,8896
tailscaled.exe,TCP,104.194.122.206:51107,18.156.90.224:80,ESTABLISHED,8076
firefox.exe,TCP,104.194.122.206:50786,54.148.242.254:443,ESTABLISHED,8008
tailscaled.exe,TCP,104.194.122.206:50750,199.38.182.118:443,ESTABLISHED,8076
svchost.exe,TCP,104.194.122.206:49413,40.83.240.146:443,ESTABLISHED,6108
VcomSvc.exe,TCP,100.106.209.107:56843,192.168.1.173:5000,ESTABLISHED,5936
Windows System,TCP,100.106.209.107:52378,192.168.1.11:445,ESTABLISHED,4
Windows System,TCP,100.106.209.107:52377,192.168.1.216:445,ESTABLISHED,4
1 firefox.exe TCP [2620:f3:8000:5060:5939:a4c0:4f5b:113f]:53338 [2607:f518:5::4816:b9c7]:80 ESTABLISHED 8008
2 firefox.exe TCP [2620:f3:8000:5060:5939:a4c0:4f5b:113f]:53301 [2607:f8b0:4009:817::200e]:443 ESTABLISHED 8008
3 firefox.exe TCP [2620:f3:8000:5060:5939:a4c0:4f5b:113f]:53292 [2607:f8b0:4009:808::2003]:80 TIME_WAIT 0
4 firefox.exe TCP [2620:f3:8000:5060:5939:a4c0:4f5b:113f]:53285 [2606:4700:4400::6812:2962]:443 TIME_WAIT 0
5 python.exe TCP 127.0.0.1:51987 127.0.0.1:51986 ESTABLISHED 17244
6 python.exe TCP 127.0.0.1:51986 127.0.0.1:51987 ESTABLISHED 17244
7 VSCodium.exe TCP 127.0.0.1:51978 127.0.0.1:51977 ESTABLISHED 17828
8 VSCodium.exe TCP 127.0.0.1:51977 127.0.0.1:51978 ESTABLISHED 17828
9 firefox.exe TCP 127.0.0.1:51761 127.0.0.1:51760 ESTABLISHED 10420
10 firefox.exe TCP 127.0.0.1:51760 127.0.0.1:51761 ESTABLISHED 10420
11 firefox.exe TCP 127.0.0.1:51759 127.0.0.1:51758 ESTABLISHED 8008
12 firefox.exe TCP 127.0.0.1:51758 127.0.0.1:51759 ESTABLISHED 8008
13 nxserver.bin TCP 127.0.0.1:50792 127.0.0.1:22890 ESTABLISHED 8116
14 nxserver.bin TCP 127.0.0.1:50778 127.0.0.1:4742 ESTABLISHED 8116
15 tailscale-ipn.exe TCP 127.0.0.1:50530 127.0.0.1:41112 ESTABLISHED 14552
16 nxclient.bin TCP 127.0.0.1:50409 127.0.0.1:19231 ESTABLISHED 11836
17 nxclient.bin TCP 127.0.0.1:50408 127.0.0.1:26068 ESTABLISHED 11836
18 nxclient.bin TCP 127.0.0.1:50407 127.0.0.1:10632 ESTABLISHED 11836
19 nxnode.bin TCP 127.0.0.1:50406 127.0.0.1:25001 ESTABLISHED 11608
20 nxnode.bin TCP 127.0.0.1:50405 127.0.0.1:23938 ESTABLISHED 11608
21 nxnode.bin TCP 127.0.0.1:50402 127.0.0.1:28488 ESTABLISHED 11608
22 nxnode.bin TCP 127.0.0.1:50397 127.0.0.1:17311 ESTABLISHED 11608
23 nxnode.bin TCP 127.0.0.1:50395 127.0.0.1:21968 ESTABLISHED 11608
24 nxnode.bin TCP 127.0.0.1:50174 127.0.0.1:10055 ESTABLISHED 11608
25 nxservice64.exe TCP 127.0.0.1:50160 127.0.0.1:19492 ESTABLISHED 5544
26 nxserver.bin TCP 127.0.0.1:49772 127.0.0.1:16950 ESTABLISHED 8116
27 nxserver.bin TCP 127.0.0.1:49767 127.0.0.1:16619 ESTABLISHED 8116
28 nxserver.bin TCP 127.0.0.1:49766 127.0.0.1:31770 ESTABLISHED 8116
29 nxserver.bin TCP 127.0.0.1:49765 127.0.0.1:7039 ESTABLISHED 8116
30 nxserver.bin TCP 127.0.0.1:49762 127.0.0.1:22921 ESTABLISHED 8116
31 nxserver.bin TCP 127.0.0.1:49761 127.0.0.1:6363 ESTABLISHED 8116
32 nxserver.bin TCP 127.0.0.1:49698 127.0.0.1:15907 ESTABLISHED 8116
33 AppleMobileDeviceService.exe TCP 127.0.0.1:49674 127.0.0.1:5354 ESTABLISHED 4280
34 AppleMobileDeviceService.exe TCP 127.0.0.1:49670 127.0.0.1:5354 ESTABLISHED 4280
35 tailscaled.exe TCP 127.0.0.1:41112 127.0.0.1:50530 ESTABLISHED 8076
36 nxserver.bin TCP 127.0.0.1:31770 127.0.0.1:49766 ESTABLISHED 8116
37 nxnode.bin TCP 127.0.0.1:28488 127.0.0.1:50402 ESTABLISHED 11608
38 nxclient.bin TCP 127.0.0.1:26068 127.0.0.1:50408 ESTABLISHED 11836
39 nxclient.bin TCP 127.0.0.1:25001 127.0.0.1:50406 ESTABLISHED 11836
40 nxnode.bin TCP 127.0.0.1:23938 127.0.0.1:50405 ESTABLISHED 11608
41 nxserver.bin TCP 127.0.0.1:22921 127.0.0.1:49762 ESTABLISHED 8116
42 nxserver.bin TCP 127.0.0.1:22890 127.0.0.1:50792 ESTABLISHED 8116
43 nxserver.bin TCP 127.0.0.1:21968 127.0.0.1:50395 ESTABLISHED 8116
44 nxservice64.exe TCP 127.0.0.1:19492 127.0.0.1:50160 ESTABLISHED 5544
45 nxclient.bin TCP 127.0.0.1:19231 127.0.0.1:50409 ESTABLISHED 11836
46 nxnode.bin TCP 127.0.0.1:17311 127.0.0.1:50397 ESTABLISHED 11608
47 nxserver.bin TCP 127.0.0.1:16950 127.0.0.1:49772 ESTABLISHED 8116
48 nxserver.bin TCP 127.0.0.1:16619 127.0.0.1:49767 ESTABLISHED 8116
49 nxserver.bin TCP 127.0.0.1:15907 127.0.0.1:49698 ESTABLISHED 8116
50 nxclient.bin TCP 127.0.0.1:10632 127.0.0.1:50407 ESTABLISHED 11836
51 nxnode.bin TCP 127.0.0.1:10055 127.0.0.1:50174 ESTABLISHED 11608
52 nxserver.bin TCP 127.0.0.1:7039 127.0.0.1:49765 ESTABLISHED 8116
53 nxserver.bin TCP 127.0.0.1:6363 127.0.0.1:49761 ESTABLISHED 8116
54 mDNSResponder.exe TCP 127.0.0.1:5354 127.0.0.1:49674 ESTABLISHED 4076
55 mDNSResponder.exe TCP 127.0.0.1:5354 127.0.0.1:49670 ESTABLISHED 4076
56 nxserver.bin TCP 127.0.0.1:4742 127.0.0.1:50778 ESTABLISHED 8116
57 nxserver.bin TCP 104.194.122.206:53343 208.59.79.12:443 TIME_WAIT 0
58 nxserver.bin TCP 104.194.122.206:53340 54.212.237.219:443 TIME_WAIT 0
59 firefox.exe TCP 104.194.122.206:53339 54.212.237.219:443 ESTABLISHED 8008
60 firefox.exe TCP 104.194.122.206:53337 54.212.237.219:443 ESTABLISHED 8008
61 firefox.exe TCP 104.194.122.206:53335 208.59.79.12:443 TIME_WAIT 0
62 firefox.exe TCP 104.194.122.206:53334 208.59.79.12:443 ESTABLISHED 8008
63 VSCodium.exe TCP 104.194.122.206:53314 76.76.21.61:443 ESTABLISHED 3816
64 VSCodium.exe TCP 104.194.122.206:53313 76.76.21.164:443 ESTABLISHED 3816
65 VSCodium.exe TCP 104.194.122.206:53312 76.76.21.164:443 CLOSE_WAIT 3816
66 firefox.exe TCP 104.194.122.206:53307 104.192.142.9:443 ESTABLISHED 8008
67 firefox.exe TCP 104.194.122.206:53300 54.201.164.58:443 TIME_WAIT 0
68 firefox.exe TCP 104.194.122.206:53299 35.186.227.140:443 ESTABLISHED 8008
69 firefox.exe TCP 104.194.122.206:53298 162.159.130.232:443 TIME_WAIT 0
70 firefox.exe TCP 104.194.122.206:53297 162.159.128.232:443 TIME_WAIT 0
71 firefox.exe TCP 104.194.122.206:53290 162.159.138.232:443 TIME_WAIT 0
72 firefox.exe TCP 104.194.122.206:53289 162.159.135.234:443 ESTABLISHED 8008
73 firefox.exe TCP 104.194.122.206:53284 72.21.91.29:80 TIME_WAIT 0
74 firefox.exe TCP 104.194.122.206:53160 142.250.191.106:443 ESTABLISHED 8008
75 firefox.exe TCP 104.194.122.206:53154 142.250.191.106:443 ESTABLISHED 8008
76 firefox.exe TCP 104.194.122.206:52525 104.192.142.11:443 ESTABLISHED 8008
77 syncthing.exe TCP 104.194.122.206:51451 172.245.94.35:22067 ESTABLISHED 8896
78 tailscaled.exe TCP 104.194.122.206:51107 18.156.90.224:80 ESTABLISHED 8076
79 firefox.exe TCP 104.194.122.206:50786 54.148.242.254:443 ESTABLISHED 8008
80 tailscaled.exe TCP 104.194.122.206:50750 199.38.182.118:443 ESTABLISHED 8076
81 svchost.exe TCP 104.194.122.206:49413 40.83.240.146:443 ESTABLISHED 6108
82 VcomSvc.exe TCP 100.106.209.107:56843 192.168.1.173:5000 ESTABLISHED 5936
83 Windows System TCP 100.106.209.107:52378 192.168.1.11:445 ESTABLISHED 4
84 Windows System TCP 100.106.209.107:52377 192.168.1.216:445 ESTABLISHED 4

57089
output.log Normal file

File diff suppressed because it is too large Load Diff

57
release.sh Normal file
View File

@ -0,0 +1,57 @@
#!/bin/bash
#set -x
TOKEN=$(< token.txt)
EDITOR=nano git commit -a
git push
COMMIT=$(git log | head -n 1 | cut -d' ' -f2)
echo $COMMIT
export PATH=$PATH:"C:\Program Files\7-Zip"
TAG=$(date +%s)
"C:/Program Files/Python310/python.exe" setup.py build
sleep 2
mv ./build/exe.win-amd64-3.10/ ./build/ippigeon-win
7z a -r release-$COMMIT.zip ./build/ippigeon-win
7z a -sfx7z.sfx IPPigeon-install.exe ./build/ippigeon-win
mv ./build/ippigeon-win/ ./build/exe.win-amd64-3.10
#sleep 30
DATA='{
"body": "Autogenerated release",
"draft": false,
"name": "Development release",
"prerelease": true,
"tag_name": "'$TAG'",
"target_commitish": "'$COMMIT'"
}'
OUT=$(curl -X 'POST' \
'https://git.deck.sh/api/v1/repos/Interfaz/ff/releases?token='$TOKEN'' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "$DATA")
ID=$(echo $OUT | cut -d',' -f 1 | cut -d':' -f 2)
OUT=$(curl -X 'POST' \
'https://git.deck.sh/api/v1/repos/Interfaz/ff/releases/'$ID'/assets?token='$TOKEN'' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'attachment=@IPPigeon-install.exe;type=application/octet-stream')
URL=$(echo $OUT | cut -d',' -f 7 | cut -d\" -f4)
OUT=$(curl -X 'POST' \
'https://git.deck.sh/api/v1/repos/Interfaz/ff/releases/'$ID'/assets?token='$TOKEN'' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'attachment=@'release-$COMMIT.zip';type=application/x-zip-compressed')
URLZIP=$(echo $OUT | cut -d',' -f 7 | cut -d\" -f4)
curl -d "Self extracting installer: $URL
Portable Zip: $URLZIP" https://notify.deck.sh/ipro-release
rm release-$COMMIT.zip
rm IPPigeon-install.exe

2
run.sh Normal file
View File

@ -0,0 +1,2 @@
"C:/Program Files/Python310/python.exe" setup.py build

File diff suppressed because one or more lines are too long

21
setup.py Normal file
View File

@ -0,0 +1,21 @@
import sys
from cx_Freeze import setup, Executable
debug = True
#debug = not debug
# Dependencies are automatically detected, but it might need fine tuning.
# "packages": ["os"] is used as example only
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"], "include_msvcr": True, "include_files": ["icon.png", "config.yml", "keyfile-admin.pem"], "optimize": 2}
# base="Win32GUI" should be used only for Windows GUI app
base = None
if sys.platform == "win32" and not debug:
base = "Win32GUI"
setup(
name="IP Pigeon",
version="0.2.4",
description="IP Pigeon client application",
options={"build_exe": build_exe_options},
executables=[Executable("ippigeon.py", base=base, icon="icon.ico", uac_admin=True, target_name="IPPigeon.exe")],
)

39
ssh.py Normal file
View File

@ -0,0 +1,39 @@
#from __future__ import with_statement
from fabric import Connection
from util import find_data_file
from util import setup_child
from util import fprint
from invoke import exceptions
import sys
def sftp_send_data(config, filename, filetype):
setup_child()
fprint("Connecting over SSH to " + config['sftp']['host'])
c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),})
fprint("Sending data over SFTP: " + filename)
fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath'][filetype]))
fprint("Data sent over SFTP successfully")
#command = 'ls ' + config['sftp']['filepath'][filetype]
#fprint(c.run(command))
def check_for_file(config, filename, location):
setup_child()
fprint("Connecting over SSH to " + config['sftp']['host'])
c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),})
fprint("Checking for existence of file " + config['sftp']['filepath'][location] + "/" + filename)
try:
res = c.run("ls -l " + config['sftp']['filepath'][location] + "/" + filename, hide=True)
fprint("File " + filename + " exists!")
return c.run("cat " + config['sftp']['filepath'][location] + "/" + filename, hide=True)
except exceptions.UnexpectedExit:
return False
def run_ssh(config, command, location):
setup_child()
fprint("Connecting over SSH to " + config['sftp']['host'])
c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),})
fprint("cd to " + config['sftp']['filepath'][location])
with c.cd(config['sftp']['filepath'][location]):
fprint("Running ssh command: " + command)
res = c.run(command, hide=True, asynchronous=True)
return res

82
taskbartool.py Normal file
View File

@ -0,0 +1,82 @@
import glob
import wx
import wx.adv
import os
from time import sleep
from sys import platform
import sys
from util import find_data_file
from util import fprint
TRAY_TOOLTIP = 'IP Pigeon'
displaydata = None
settings = None
killme = False
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.Append(item)
return item
class TaskBarIcon(wx.adv.TaskBarIcon):
def __init__(self, frame):
self.frame = frame
super(TaskBarIcon, self).__init__()
self.set_icon(TRAY_ICON)
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Control Panel', self.on_open)
create_menu_item(menu, 'Login test', self.on_login)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def set_icon(self, path):
icon = wx.Icon(path)
self.SetIcon(icon, TRAY_TOOLTIP)
def on_left_down(self, event):
fprint ('Tray icon was left-clicked.')
def on_open(self, event):
foreground()
#self.close_popup()
def on_login(self, event):
settings["username"] = "Cole"
settings["password"] = "12345"
settings["login"] = True
def on_exit(self, event):
wx.CallAfter(self.Destroy)
self.close_popup()
#print("kill cmd")
global killme
killme.value += 1
def close_popup(self):
self.frame.Close()
class TaskbarApp(wx.App):
def OnInit(self):
frame=wx.Frame(None)
self.SetTopWindow(frame)
TaskBarIcon(frame)
return True
def background(data, sets, kill):
global killme
global settings
global displaydata
killme = kill
app = TaskbarApp(False)
displaydata = data
settings = sets
app.MainLoop()
TRAY_ICON = find_data_file('icon.png')

98
util.py Normal file
View File

@ -0,0 +1,98 @@
import inspect
import sys
import subprocess
import os
from sys import platform
import time as t
import uuid
win32 = platform == "win32"
linux = platform == "linux" or platform == "linux2"
macos = platform == "darwin"
datafile = ""
if win32:
sysid = hex(uuid.getnode())
datafile += sysid
datafile += "gendata.csv"
# Python is running as Administrator (so netstat can get filename, to block, etc),
# so we use this to see who is actually logged in
# it's very hacky
startupinfo = subprocess.STARTUPINFO()
#if not getattr(sys, "frozen", False):
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # hide powershell window
res = subprocess.check_output(["WMIC", "ComputerSystem", "GET", "UserName"], universal_newlines=True, startupinfo=startupinfo)
_, username = res.strip().rsplit("\n", 1)
userid, sysdom = username.rsplit("\\", 1)
def time():
return int(t.time())
def fprint(msg):
#if not getattr(sys, "frozen", False):
setup_child()
try:
frm = inspect.stack()[1]
mod = inspect.getmodule(frm[0])
print('[' + mod.__name__ + ":" + frm.function + ']:', msg)
except Exception as e:
try:
print('[????:' + frm.function + ']:', msg)
except:
print('[????]:', msg)
# else:
#print(msg)
def find_data_file(filename):
if getattr(sys, "frozen", False):
# The application is frozen
datadir = os.path.dirname(sys.executable)
else:
# The application is not frozen
# Change this bit to match where you store your data files:
datadir = os.path.dirname(__file__)
return os.path.join(datadir, filename)
def run_ps(cmd):
fprint("init PS")
if win32:
startupinfo = subprocess.STARTUPINFO()
#print("DICKS")
#if not getattr(sys, "frozen", False):
# print("test")
#
#completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
#else:
# print("alt")
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # , "-WindowStyle", "hidden"
fprint("running PS command: " + cmd)
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
fprint("ran PS command successfully")
#completed = subprocess.run(["powershell", "-WindowStyle", "hidden", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
return completed
def setup_child():
if not getattr(sys, "frozen", False):
sys.stdout = Logger(filename=find_data_file("output.log"))
sys.stderr = Logger(filename=find_data_file("output.log"))
class Logger(object):
def __init__(self, filename="output.log"):
self.log = open(filename, "a")
self.terminal = sys.stdout
def write(self, message):
self.log.write(message)
#close(filename)
#self.log = open(filename, "a")
try:
self.terminal.write(message)
except:
sleep(0)
def flush(self):
print("")