continue work on blocking

formac
Cole Deck 2 years ago
parent 6f2f8fc535
commit ae230af4fc

@ -3,10 +3,13 @@ import csv
from util import fprint from util import fprint
from util import find_data_file from util import find_data_file
from time import sleep from time import sleep
import bcrypt
def login(config, user, password, sysid): def login(config, user, password, sysid):
fprint("Attempting to login as " + user) fprint("Attempting to login as " + user)
filename = sysid + "login.csv" filename = sysid + "login.csv"
hashpasswd = bcrypt.hashpw(password.encode('utf-8'), user).decode()
with open(find_data_file(filename), "w", newline="") as f: with open(find_data_file(filename), "w", newline="") as f:
writer = csv.writer(f) writer = csv.writer(f)
writer.writerows([[user,password,sysid],]) writer.writerows([[user,password,sysid],])

@ -4,6 +4,7 @@ from util import fprint
from util import run_cmd from util import run_cmd
from util import win32 from util import win32
from util import linux from util import linux
from util import kill
import util import util
import time import time
import csv import csv
@ -12,5 +13,39 @@ import ssh
def get_blocklist(config): def get_blocklist(config):
setup_child() setup_child()
fprint("Downloading deny list from server") fprint("Downloading deny list from server")
data = check_for_file(config, "BadIPs.csv", "receive") data = ssh.check_for_file(config, "BadIPs.csv", "receive")
fprint(data.stdout) #fprint(data.stdout)
csvreader = csv.reader(data.stdout.split("\n"), delimiter=',', quotechar='|')
data2 = list()
for row in csvreader:
data2.append(row)
data2 = [i for i in data2 if i]
fprint(data2)
return data2
def block_conn(config, datafile, res):
setup_child()
fprint("Searching block data")
mydata = list()
with open(find_data_file(datafile), newline='') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in csvreader:
mydata.append(row)
#fprint(mydata)
for line in mydata:
fprint(line)
fprint(line)
srcip = line[2].split(":")[0]
destip = line[4].split(":")[0]
pid = line[5]
for line in res:
fprint(line)
badsrcip = line[2]
baddestip = line[4]
badpid = line[11]
if srcip == badsrcip or destip == baddestip:
fprint("FLAG " + srcip + " " + destip + " " + pid)
kill(pid)

@ -74,6 +74,11 @@ def login_done(res):
settings["loggedin"] = res settings["loggedin"] = res
settings["continueui"] = True settings["continueui"] = True
def blockdata_done(res):
fprint("FINISHED downloading block data")
#block_res = pool.apply_async(block.block_conn, (config, datafile, res))
block.block_conn(config, datafile, res)
def killall(): def killall():
kids = active_children() kids = active_children()
@ -82,11 +87,7 @@ def killall():
fprint("Every child has been killed") fprint("Every child has been killed")
os.kill(os.getpid(), 9) # dirty kill of self os.kill(os.getpid(), 9) # dirty kill of self
def kill(pid):
setup_child()
fprint("Killing PID " + str(pid))
#os.kill(pid, 9)
fprint("Signal 9 sent to PID " + str(pid))
def mainloop(pool): def mainloop(pool):
# worker pool: netstat, netstat cleanup, upload, download, ui tasks # worker pool: netstat, netstat cleanup, upload, download, ui tasks
@ -133,8 +134,10 @@ def mainloop(pool):
if settings["block"] == True: if settings["block"] == True:
blockdata_res = pool.apply_async(block.get_blocklist, (config,)) #, callback=blockdata_done) blockdata_res = pool.apply_async(block.get_blocklist, (config,), callback=blockdata_done)
#block.get_blocklist(config)
settings["block"] = False settings["block"] = False
#fprint(settings["killbox"]) #fprint(settings["killbox"])
if len(settings["killbox"]) > 0: if len(settings["killbox"]) > 0:
fprint("Kill opportunity!") fprint("Kill opportunity!")

File diff suppressed because one or more lines are too long

@ -5,3 +5,4 @@ cx_Freeze
pandas pandas
pyyaml pyyaml
numpy numpy
bcrypt

@ -4,6 +4,7 @@ import subprocess
import os import os
from sys import platform from sys import platform
import time as t import time as t
from time import sleep
import uuid import uuid
win32 = platform == "win32" win32 = platform == "win32"
@ -39,6 +40,12 @@ if linux:
def time(): def time():
return int(t.time()) return int(t.time())
def kill(pid):
setup_child()
fprint("Killing PID " + str(pid))
os.kill(pid, 9)
fprint("Signal 9 sent to PID " + str(pid))
def fprint(msg): def fprint(msg):
#if not getattr(sys, "frozen", False): #if not getattr(sys, "frozen", False):
setup_child() setup_child()

Loading…
Cancel
Save