Browse Source

update get command

pull/4/head
R4SAS 7 years ago
parent
commit
e986df6413
  1. 3
      pbincli.py
  2. 44
      pbincli/actions.py
  3. 13
      pbincli/sjcl_gcm.py
  4. 9
      pbincli/transports.py

3
pbincli.py

@ -13,9 +13,10 @@ def main():
# a send command # a send command
send_parser = subparsers.add_parser("send", description="Send data to PrivateBin instance", usage=""" send_parser = subparsers.add_parser("send", description="Send data to PrivateBin instance", usage="""
%(prog)s --burn --discus --expire 1day --format plaintext \\ %(prog)s --burn --discus --expire 1day --format plaintext \\
--password mypass image.txt""" --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("-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("-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("-e", "--expire", default="1day", action="store", help="expiration of paste (default: 1day)")
send_parser.add_argument("-f", "--format", default="plaintext", action="store", help="format of paste (default: plaintext)") send_parser.add_argument("-f", "--format", default="plaintext", action="store", help="format of paste (default: plaintext)")

44
pbincli/actions.py

@ -1,24 +1,28 @@
"""Action functions for argparser""" """Action functions for argparser"""
import json import json
#import mimetypes
import os import os
import pbincli.actions import pbincli.actions
'''from pbincli.sjcl_gcm import SJCL''' import sys
#import pbincli.sjcl_gcm
import pbincli.sjcl_simple import pbincli.sjcl_simple
import pbincli.utils import pbincli.utils
from base64 import b64encode from base64 import b64encode, b64decode
from Crypto.Hash import SHA256 from Crypto.Hash import SHA256
from pbincli.transports import privatebin from pbincli.transports import privatebin
from zlib import compress from zlib import compress, decompress
def send(args): def send(args):
""" Sub-command for sending paste """ if args.comment:
text = args.comment
else:
text = "Test!"
#check_readable(args.filename) #check_readable(args.filename)
#with open(args.filename, "rb") as f: #with open(args.filename, "rb") as f:
# contents = f.read() # contents = f.read()
#file = b64encode(compress(contents)) #file = b64encode(compress(contents))
data = b'Test!'
passphrase = os.urandom(32) passphrase = os.urandom(32)
if args.debug: print("Passphrase: {}".format(passphrase)) if args.debug: print("Passphrase: {}".format(passphrase))
@ -26,30 +30,24 @@ def send(args):
p = SHA256.new() p = SHA256.new()
p.update(args.password.encode("UTF-8")) p.update(args.password.encode("UTF-8"))
passphrase = b64encode(passphrase + p.hexdigest().encode("UTF-8")) passphrase = b64encode(passphrase + p.hexdigest().encode("UTF-8"))
else: else:
passphrase = b64encode(passphrase) passphrase = b64encode(passphrase)
if args.degub: print("Password:\t{}".format(passphrase)) if args.debug: print("Password:\t{}".format(passphrase))
#data = SJCL().encrypt(file, password.decode("UTF-8"))
#cipher = pbincli.sjcl_simple.encrypt(b64encode(passphrase), file)
"""Sending text from 'data' string""" """Sending text from 'data' string"""
cipher = pbincli.sjcl_simple.encrypt(passphrase, data) #cipher = SJCL().encrypt(b64encode(text), passphrase)
request = {'data':json.dumps(cipher, ensure_ascii=False).replace(' ',''),'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus) cipher = pbincli.sjcl_simple.encrypt(passphrase, text)
} request = {'data':json.dumps(cipher, ensure_ascii=False).replace(' ',''),'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)}
if args.debug: print("Request:\t{}".format(request)) if args.debug: print("Request:\t{}".format(request))
result, server = privatebin().post(request) result, server = privatebin().post(request)
if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8"))) if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8")))
result = json.loads(result) result = json.loads(result)
"""Standart response: {"status":0,"id":"aaabbb","url":"\/?aaabbb","deletetoken":"aaabbbccc"}""" """Standart response: {"status":0,"id":"aaabbb","url":"\/?aaabbb","deletetoken":"aaabbbccc"}"""
if result['status'] == 0: if result['status'] == 0:
print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t{}?{}#{}".format(result['id'], passphrase.decode("UTF-8"), result['deletetoken'], server, result['id'], passphrase.decode("UTF-8"))) print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t{}?{}#{}".format(result['id'], passphrase.decode("UTF-8"), result['deletetoken'], server, result['id'], passphrase.decode("UTF-8")))
else: else:
print("Something went wrong...\nError:\t{}".format(result['error'])) print("Something went wrong...\nError:\t{}".format(result['message']))
sys.exit(1) sys.exit(1)
@ -61,19 +59,19 @@ def get(args):
else: else:
print("PBinCLI error: Incorrect request") print("PBinCLI error: Incorrect request")
sys.exit(1) sys.exit(1)
if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8"))) if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8")))
result = json.loads(result) result = json.loads(result)
if result['status'] == 0: if result['status'] == 0:
print("Paste received!\n") print("Paste received!\n")
text = pbincli.utils.json_loads_byteified(result['data']) text = pbincli.utils.json_loads_byteified(result['data'])
out = pbincli.sjcl_simple.decrypt(paste[1], text) out = pbincli.sjcl_simple.decrypt(paste[1], text)
#out = pbincli.sjcl_gcm.SJCL().decrypt(text, paste[1])
print(out) print(out)
if 'burnafterreading' in result['meta'] and result['meta']['burnafterreading']: if 'burnafterreading' in result['meta'] and result['meta']['burnafterreading']:
print("Meow!") result = privatebin().delete(paste[0], 'burnafterreading')
if args.debug: print("Delete response:\t{}\n".format(result.decode("UTF-8")))
else: else:
print("Something went wrong...\nError:\t{}".format(result['error'])) print("Something went wrong...\nError:\t{}".format(result['message']))
sys.exit(1) sys.exit(1)

13
pbincli/sjcl_gcm.py

@ -72,9 +72,9 @@ class SJCL(object):
if len(salt) != self.salt_size: if len(salt) != self.salt_size:
raise Exception("salt should be %d bytes long" % self.salt_size) raise Exception("salt should be %d bytes long" % self.salt_size)
dkLen = data["ks"]//8 dkLen = data["ks"] / 8
if dkLen != 16: if dkLen != 32:
raise Exception("key length should be 16 bytes") raise Exception("key length should be 32 bytes")
key = PBKDF2( key = PBKDF2(
passphrase, passphrase,
@ -86,22 +86,23 @@ class SJCL(object):
# print "key", hex_string(key) # print "key", hex_string(key)
ciphertext = base64.b64decode(data["ct"]) ciphertext = base64.b64decode(data["ct"])
# ciphertext = data["ct"]
iv = base64.b64decode(data["iv"]) iv = base64.b64decode(data["iv"])
# print AES.block_size # print AES.block_size
nonce = truncate_iv(iv, len(ciphertext)*8, data["ts"]) nonce = truncate_iv(iv, len(ciphertext)*8, data["ts"])
# split tag from ciphertext (tag was simply appended to ciphertext) # split tag from ciphertext (tag was simply appended to ciphertext)
mac = ciphertext[-(data["ts"]//8):] mac = ciphertext[-(data["ts"] / 8):]
# print len(ciphertext) # print len(ciphertext)
ciphertext = ciphertext[:-(data["ts"]//8)] ciphertext = ciphertext[:-(data["ts"] / 8)]
# print len(ciphertext) # print len(ciphertext)
# print len(tag) # print len(tag)
# print "len", len(nonce) # print "len", len(nonce)
cipher = AES.new(key, AES.MODE_GCM, nonce) cipher = AES.new(key, AES.MODE_GCM, nonce)
plaintext = cipher.decrypt(ciphertext) plaintext = cipher.decrypt(ciphertext)
print(mac) # print(mac)
# cipher.verify(mac) # cipher.verify(mac)
return plaintext return plaintext

9
pbincli/transports.py

@ -1,8 +1,8 @@
import requests import requests
import json #import urllib
import urllib
class privatebin(object):
class privatebin(object):
def __init__(self): def __init__(self):
self.proxies = {'http': 'http://127.0.0.1:4444'} self.proxies = {'http': 'http://127.0.0.1:4444'}
@ -21,6 +21,7 @@ class privatebin(object):
return r.text return r.text
def delete(self, request): def delete(self, pasteid, token):
request = {'pasteid':pasteid,'deletetoken':token}
r = requests.post(url=self.server, headers=self.headers, proxies=self.proxies, data=request) r = requests.post(url=self.server, headers=self.headers, proxies=self.proxies, data=request)
return r.text return r.text

Loading…
Cancel
Save