AIL-framework/bin/SourceCode.py

56 lines
1.5 KiB
Python
Raw Normal View History

2018-05-04 13:53:29 +02:00
#!/usr/bin/env python3
2016-03-12 11:21:29 +01:00
# -*-coding:UTF-8 -*
import time
from packages import Paste
from pubsublogger import publisher
from Helper import Process
import re
if __name__ == "__main__":
publisher.port = 6380
publisher.channel = "Script"
config_section = "SourceCode"
p = Process(config_section)
publisher.info("Finding Source Code")
critical = 0 # AS TO BE IMPORTANT, MIGHT BE REMOVED
2016-03-12 11:21:29 +01:00
#RELEVANTS LANGUAGES
2016-03-12 11:21:29 +01:00
shell = "[a-zA-Z0-9]+@[a-zA-Z0-9\-]+\:\~\$"
c = "\#include\ \<[a-z\/]+.h\>"
php = "\<\?php"
python = "import\ [\w]+"
bash = "#!\/[\w]*\/bash"
javascript = "function\(\)"
ruby = "require \ [\w]+"
adr = "0x[a-f0-9]{2}"
2016-03-12 11:21:29 +01:00
#asm = "\"((?s).{1}x[0-9a-f]{2}){3,}" ISSUES WITH FINDALL, pattern like \x54\xaf\x23\..
2018-04-16 14:50:04 +02:00
2016-03-12 11:21:29 +01:00
languages = [shell, c, php, bash, python, javascript, bash, ruby, adr]
regex = '|'.join(languages)
2018-04-16 14:50:04 +02:00
print(regex)
2016-03-12 11:21:29 +01:00
while True:
message = p.get_from_set()
if message is None:
publisher.debug("Script Source Code is Idling 10s")
2016-03-12 11:21:29 +01:00
print('Sleeping')
time.sleep(10)
continue
filepath, count = message.split()
paste = Paste.Paste(filepath)
content = paste.get_p_content()
match_set = set(re.findall(regex, content))
if len(match_set) == 0:
continue
to_print = 'SourceCode;{};{};{};{}'.format(paste.p_source, paste.p_date, paste.p_name, message)
if len(match_set) > critical:
publisher.warning(to_print)
else:
publisher.info(to_print)