mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 03:06:10 +00:00
Integrated GUI
This commit is contained in:
parent
750e4c71f1
commit
b77e688b55
1 changed files with 42 additions and 41 deletions
83
aha/aha.py
83
aha/aha.py
|
@ -6,41 +6,49 @@ import os,sys,random,getopt,ConfigParser
|
||||||
from pyinotify import *
|
from pyinotify import *
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
from ahalib import *
|
from ahalib import *
|
||||||
|
import sqlite3,os.path
|
||||||
|
database = '../gui.db'
|
||||||
class KernelEvents(ProcessEvent):
|
class KernelEvents(ProcessEvent):
|
||||||
|
|
||||||
def __init__(self,inqueue,outqueue,insultmaxidx,cases,block):
|
def __init__(self,inqueue,outqueue,insultmaxidx,cases,block):
|
||||||
self.ahaa = AHAActions(inqueue,outqueue)
|
self.ahaa = AHAActions(inqueue,outqueue)
|
||||||
self.cases = cases
|
|
||||||
self.block = block
|
|
||||||
self.processtrees = ProcessTrees()
|
self.processtrees = ProcessTrees()
|
||||||
|
if os.path.exists(database):
|
||||||
#Blocks the sys_execve calls according the game
|
self.con = sqlite3.connect(database)
|
||||||
def play(self):
|
|
||||||
#By default allow the system call
|
|
||||||
print "PLAY: mixed cases ",cases
|
|
||||||
print "PLAY: blockpr", blockpr
|
|
||||||
b = 0
|
|
||||||
x = random.random()
|
|
||||||
|
|
||||||
if x < self.cases:
|
|
||||||
print "PLAY: Cases choice: ",x
|
|
||||||
#i.e. in 0.54 blocking probability of 0.1 should be used
|
|
||||||
y = random.random()
|
|
||||||
print "PLAY: Blocking choice",y
|
|
||||||
if y < self.block:
|
|
||||||
b = 1
|
|
||||||
else:
|
else:
|
||||||
# in the other cases another blocking probability should be used
|
self.con = None
|
||||||
y = random.random()
|
print "[ERROR] Database file not found ",database
|
||||||
q = 1-self.block
|
|
||||||
print "PLAY: Other blocking probability should be used ",q
|
|
||||||
print "PLAY: Other blocking choice: ",y
|
|
||||||
if y < q:
|
|
||||||
b = 1
|
|
||||||
|
|
||||||
return b
|
|
||||||
|
|
||||||
|
def askgui(self, filekey,msg):
|
||||||
|
if self.con == None:
|
||||||
|
return False
|
||||||
|
cur = self.con.cursor()
|
||||||
|
program = os.path.basename(msg['file'][0])
|
||||||
|
args = ','.join(msg['argument'][1:])
|
||||||
|
#Update the gui shell
|
||||||
|
outstr = program + "(" + args + ")"
|
||||||
|
print "######### User wants to execute ",outstr
|
||||||
|
cur.execute('INSERT INTO shell (cmd) VALUES (?)',[outstr])
|
||||||
|
self.con.commit()
|
||||||
|
#Lets see what the user has defined
|
||||||
|
action = 0
|
||||||
|
for row in cur.execute('SELECT action FROM perms WHERE cmd=?',[program]):
|
||||||
|
action = int(row[0])
|
||||||
|
if action == 0:
|
||||||
|
self.ahaa.create_message(filekey,block=0,exitcode=0, insult=0,substitue=0)
|
||||||
|
print "##### Allowed action"
|
||||||
|
return True
|
||||||
|
if action == 1:
|
||||||
|
self.ahaa.create_message(filekey, block=1,exitcode=1, insult=0, substitue=0)
|
||||||
|
print "##### Blocked action"
|
||||||
|
return True
|
||||||
|
if action == 2:
|
||||||
|
self.ahaa.create_message(filekey, block=0, exitcode=0, insult=2, substitue=0)
|
||||||
|
print "##### Insulted user"
|
||||||
|
return True
|
||||||
|
#Exception handling is done in decision method
|
||||||
|
#By default no decision was taken
|
||||||
|
return False
|
||||||
def decision(self,filekey,msg):
|
def decision(self,filekey,msg):
|
||||||
try:
|
try:
|
||||||
pid = int(msg['pid'][0])
|
pid = int(msg['pid'][0])
|
||||||
|
@ -71,19 +79,12 @@ class KernelEvents(ProcessEvent):
|
||||||
insult=0, substitue=0)
|
insult=0, substitue=0)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print "Process belongs to a user, play"
|
if msg.has_key('file'):
|
||||||
shouldBlock = self.play()
|
r = self.askgui(filekey,msg)
|
||||||
if shouldBlock:
|
if r:
|
||||||
print "User process is artifically blocked ..."
|
print "#A message was sent return"
|
||||||
self.ahaa.create_message(filekey,block=1,
|
return
|
||||||
exitcode=KERNEL_ERRORS.EACESS,insult=0,
|
|
||||||
substitue=0)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
print "User process is allowed ..."
|
|
||||||
self.ahaa.create_message(filekey,block=0,exitcode=0,insult=0,
|
|
||||||
substitue=0)
|
|
||||||
return
|
|
||||||
except KeyError,e:
|
except KeyError,e:
|
||||||
print "EXCEPTION: KeyError"
|
print "EXCEPTION: KeyError"
|
||||||
except IndexError,w:
|
except IndexError,w:
|
||||||
|
|
Loading…
Reference in a new issue