diff --git a/pbincli.py b/pbincli.py index ebeab05..ac4dfa5 100755 --- a/pbincli.py +++ b/pbincli.py @@ -16,10 +16,12 @@ def main(): --comment "My file" --password mypass image.txt""" ) send_parser.add_argument("-B", "--burn", default=False, action="store_true", help="burn sent paste after reading") - send_parser.add_argument("-c", "--comment", help="comment in quotes") send_parser.add_argument("-D", "--discus", default=False, action="store_true", help="open discussion of sent paste") - send_parser.add_argument("-E", "--expire", default="1day", action="store", help="expiration of paste (default: 1day)") - send_parser.add_argument("-F", "--format", default="plaintext", action="store", choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of paste (default: plaintext)") + send_parser.add_argument("-E", "--expire", default="1day", action="store", + choices=["5min", "10min", "1hour", "1day", "1week", "1month", "1year", "never"], help="expiration of paste (default: 1day)") + send_parser.add_argument("-F", "--format", default="plaintext", action="store", + choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of comment (default: plaintext)") + send_parser.add_argument("-c", "--comment", help="comment in quotes") send_parser.add_argument("-p", "--password", help="password for encrypting paste") send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="enable debug") send_parser.add_argument("-f", "--file", help="example: image.jpg or full path to file") diff --git a/pbincli/actions.py b/pbincli/actions.py index 7686da5..cec9ac1 100644 --- a/pbincli/actions.py +++ b/pbincli/actions.py @@ -5,7 +5,6 @@ from base64 import b64encode, b64decode from mimetypes import guess_type from pbincli.transports import privatebin from pbincli.utils import PBinCLIException, check_readable, check_writable, json_load_byteified -from zlib import compress, decompress def path_leaf(path): @@ -17,13 +16,16 @@ def send(args): if args.comment: text = args.comment elif args.file: - text = "Sending file to you!" + text = "Sending a file to you!" else: print("Nothing to send!") sys.exit(1) + salt = os.urandom(8) passphrase = b64encode(os.urandom(32)) if args.debug: print("Passphrase:\t{}".format(passphrase)) + + """If we set PASSWORD variable""" if args.password: digest = hashlib.sha256(args.password.encode("UTF-8")).hexdigest() password = passphrase + digest.encode("UTF-8") @@ -32,6 +34,10 @@ def send(args): if args.debug: print("Password:\t{}".format(password)) + cipher = pbincli.sjcl_simple.encrypt(password, text, salt) + request = {'data':json.dumps(cipher, ensure_ascii=False).replace(' ',''),'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)} + + """If we set FILE variable""" if args.file: check_readable(args.file) with open(args.file, "rb") as f: @@ -43,13 +49,9 @@ def send(args): file = "data:" + mime[0] + ";base64," + b64encode(contents) filename = path_leaf(args.file) - cipherfile = pbincli.sjcl_simple.encrypt(password, file) - cipherfilename = pbincli.sjcl_simple.encrypt(password, filename) - - cipher = pbincli.sjcl_simple.encrypt(password, text) - request = {'data':json.dumps(cipher, ensure_ascii=False).replace(' ',''),'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)} + cipherfile = pbincli.sjcl_simple.encrypt(password, file, salt) + cipherfilename = pbincli.sjcl_simple.encrypt(password, filename, salt) - if cipherfile and cipherfilename: request['attachment'] = json.dumps(cipherfile, ensure_ascii=False).replace(' ','') request['attachmentname'] = json.dumps(cipherfilename, ensure_ascii=False).replace(' ','') @@ -66,7 +68,7 @@ def send(args): sys.exit(1) if 'status' in result and not result['status']: - print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t{}?{}#{}".format(result['id'], passphrase, result['deletetoken'], server, result['id'], passphrase)) + print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t\t{}?{}#{}".format(result['id'], passphrase, result['deletetoken'], server, result['id'], passphrase)) elif 'status' in result and result['status']: print("Something went wrong...\nError:\t\t{}".format(result['message'])) sys.exit(1) @@ -106,10 +108,10 @@ def get(args): print("Paste received! Text inside:") data = pbincli.utils.json_loads_byteified(result['data']) - if args.debug: print("Text:\t{}".format(data)) + if args.debug: print("Text:\t{}\n".format(data)) text = pbincli.sjcl_simple.decrypt(password, data) - print(text) + print("{}\n".format(text)) check_writable("paste.txt") with open("paste.txt", "wb") as f: diff --git a/pbincli/sjcl_simple.py b/pbincli/sjcl_simple.py index c3f4842..74bd6eb 100644 --- a/pbincli/sjcl_simple.py +++ b/pbincli/sjcl_simple.py @@ -34,7 +34,7 @@ def decrypt(pwd, json): return result -def encrypt(pwd, plaintext, mode='gcm', algorithm='aes', +def encrypt(pwd, plaintext, salt_in=None, mode='gcm', algorithm='aes', keysize=256, tagsize=128, iters=10000): ts = tagsize / 8 @@ -42,7 +42,7 @@ def encrypt(pwd, plaintext, mode='gcm', algorithm='aes', algo_class = getattr(algorithms, algorithm.upper()) iv = os.urandom(16) - kdf, salt = _kdf(keysize, iters) + kdf, salt = _kdf(keysize, iters, salt_in) key = kdf.derive(pwd) cipher = Cipher(algo_class(key), mode_class(iv, min_tag_length=ts), diff --git a/pbincli/transports.py b/pbincli/transports.py index 873cae4..5901797 100644 --- a/pbincli/transports.py +++ b/pbincli/transports.py @@ -1,5 +1,6 @@ import requests + class privatebin(object): def __init__(self): self.proxies = {'http': 'http://127.0.0.1:4444'} diff --git a/requirements.txt b/requirements.txt index e15df7a..4cf0e1d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,8 @@ +# cryptography dependecies appdirs -packaging cffi -cryptography +packaging pycparser +# required packeges +cryptography requests