Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'Brad'
- #File must be named 'interp.py'
- #Must be in the same directory as 'kernel.py' and 'eret.py'
- #You must have pycrypto installed on your computer
- #Python version must be python 2.7
- #DO NOT RUN THIS FILE run the file 'kernel.py'
- #This script is made to run on a unix terminal. the clear screen commands may not match.
- import os
- import random
- import time
- import platform
- import subprocess
- import smtplib
- import base64
- import hashlib
- from Crypto.Cipher import AES
- from eret import errorcodes
- def escape():
- print
- def cls():
- print("\x1B[2J")
- def cpuname():
- if platform.system() == "Windows":
- return platform.processor()
- elif platform.system() == "Darwin":
- return subprocess.check_output(['/usr/sbin/sysctl', "-n", "machdep.cpu.brand_string"]).strip()
- elif platform.system() == "Linux":
- command = "cat /proc/cpuinfo"
- return subprocess.check_output(command, shell=True).strip()
- return ""
- def interpret(com):
- #the say command
- if com == "say":
- print("syntax: say phrase")
- elif com[:3] == "say":
- word = com[4:]
- print(word)
- #the resetpw command
- elif com[:7] == "resetpw":
- f1 = open("pass.enc", "r+")
- password = f1.read()
- PADDING = '{'
- DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
- key = 'hj%4jfd 7&gh17g*'
- cipher = AES.new(key)
- decoded = DecodeAES(cipher, password)
- if ("resetpw " + decoded + " ") in com:
- x = len(decoded) + 9
- npas = com[x:]
- BLOCK_SIZE = 16
- PADDING ='{'
- pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
- EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
- key = 'hj%4jfd 7&gh17g*'
- cipher = AES.new(key)
- encodedpass = EncodeAES(cipher, npas)
- open("pass.txt", 'w').close()
- f2 = open("pass.enc", "r+")
- f2.write(encodedpass)
- f2.flush()
- open("state.txt", "w").close()
- oss = open("state.txt", "r+")
- oss.write("osState: 0")
- print("Password Reset")
- else:
- print("syntax: resetpw oldpassword newpassword")
- #the count command
- elif com == "count":
- print("syntax: count startingnumber endingnumber interval")
- elif com[:5] == "count":
- coms = com[6:].split(" ")
- snum = float(coms[0])
- enum = float(coms[1])
- interval = float(coms[2])
- while snum <= enum:
- print str(snum)
- snum += interval
- #the sysinf command
- elif com == "sysinf":
- print("OS name: " + platform.release())
- print("OS type: " + platform.system())
- print("OS version: " + platform.version())
- print("CPU: " + cpuname())
- print("CPU type: " + platform.machine())
- print("Python version: " + platform.python_version())
- print("Network name: " + platform.node())
- #the coms command
- elif com == "coms":
- print("commands: coms, resetpw, count, calc, say, sysinf, rstusr, exit, new, view, cls, dir, encrypt, decrypt")
- #the rstusr command
- elif com == "rstusr":
- print"syntax: rstusr oldusername newusername"
- elif com[:6] == "rstusr":
- coms = com[7:].split(" ")
- newusr = coms[1]
- oldusr = coms[0]
- f1 = open("usr.txt", "r+")
- username = f1.read()
- if oldusr == username:
- open("usr.txt", 'w').close()
- f3 = open("usr.txt", "r+")
- f3.write(newusr)
- f3.flush()
- print("Username Reset")
- else:
- print("Username does not exist")
- #the exit command
- elif com == "exit":
- exit()
- #the new command
- elif com == "new":
- print("syntax: new filename")
- elif com[:3] == "new":
- coms = com[4:]
- fname = coms
- x = 1
- y = 1
- open(fname, "w").close()
- file = open(fname, "r+")
- cls()
- print("PCOS Editor v1.2 | write [end] to end file")
- print("------------------------------------------")
- while y == 1:
- line = raw_input(str(x) + ") ")
- if line == "[end]":
- escape()
- y = 0
- else:
- file.write(line + "\n")
- file.flush()
- x += 1
- #the view command
- elif com == "view":
- print("syntax: view filename")
- elif com[:4] == "view":
- coms = com[5:].split(" ")
- name = coms[0]
- if name == "pass.txt" or name == "state.txt":
- print(errorcodes(1))
- else:
- try:
- fdata = open(name, "r+").read()
- print("The file contains:")
- print(fdata)
- except IOError:
- print("Invalid file name/characters in file")
- #the cls command
- elif com == "cls":
- cls()
- #the mail command
- elif com == "mail":
- print("syntax: mail youremail password recipientemail subject message")
- elif com[:4] == "mail":
- coms = com[4:].split(" ")
- userEmail = coms[0]
- userPass = coms[1]
- TO = coms[2]
- SUBJECT = coms[3]
- TEXT = coms[4]
- FROM = userEmail
- # Prepare actual message
- message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
- """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
- try:
- #server = smtplib.SMTP(SERVER)
- server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
- server.ehlo()
- server.starttls()
- server.login(userEmail, userPass)
- server.sendmail(FROM, TO, message)
- #server.quit()
- server.close()
- print 'successfully sent the mail'
- except:
- print (errorcodes(2))
- elif com == "dir":
- os.system("dir")
- elif com == "encrypt":
- print("syntax: encrypt file password")
- elif com[:7] == "encrypt":
- try:
- coms = com[8:].split(" ")
- fileName = coms[0]
- passCode = coms[1]
- file = open(fileName, "r+")
- etext = file.read()
- BLOCK_SIZE = 32
- PADDING ='{'
- pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
- EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
- key = hashlib.sha256(passCode).digest()
- cipher = AES.new(key)
- encoded = EncodeAES(cipher, etext)
- open(fileName + ".enc", "w").close
- file = open(fileName + ".enc", "r+")
- file.write(encoded)
- file.flush()
- file.close()
- print("Encrypted " + fileName + " to " + fileName + ".enc")
- except:
- print("File does not exist")
- elif com == "decrypt":
- print("syntax: decrypt filename password")
- elif com[:7] == "decrypt":
- try:
- coms = com[8:].split(" ")
- fileName = coms[0]
- passWord = coms[1]
- file = open(fileName, "r+")
- encrypted = file.read()
- PADDING = '{'
- DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
- key = hashlib.sha256(passWord).digest()
- cipher = AES.new(key)
- decoded = DecodeAES(cipher, encrypted)
- newFileName = "decrypted-" + fileName[:(len(fileName) - 4)]
- open(newFileName, "w").close()
- newFile = open(newFileName, "r+")
- newFile.write(decoded)
- newFile.flush()
- newFile.close()
- print("Decrypted " + fileName + " to " + newFileName)
- print("If the password was incorrect, the file content will be incorrect as well")
- except:
- print("File does not exist. Check the file name and be sure to include the '.enc' extension")
- elif com == "calc":
- print("syntax: calc function first_integer second_integer")
- print("example: calc add 5 5")
- elif com[:4] == "calc":
- coms = com[5:].split(" ")
- x = float(coms[1])
- y = float(coms[2])
- function = coms[0]
- if function == "add":
- z = x + y
- print(str(x) + " + " + str(y) + " = " + str(z))
- elif function == "subtract":
- z = x - y
- print(str(x) + " - " + str(y) + " = " + str(z))
- elif function == "multiply":
- z = x * y
- print(str(x) + " x " + str(y) + " = " + str(z))
- elif function == "divide":
- z = x / y
- print(str(x) + " / " + str(y) + " = " + str(z))
- else:
- print("invalid function")
- elif com == "run":
- print("syntax: run file")
- print("file can have .py or .pyc extensions")
- elif com[:3] == "run":
- file = com[4:]
- os.system("python " + file)
- else:
- print("Unknown command")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement