From cb9703864e09f622dc3e2d8d8409155c31a41811 Mon Sep 17 00:00:00 2001 From: r4sas Date: Tue, 22 May 2018 19:26:49 +0300 Subject: [PATCH] start adding server and proxy parameters --- cli | 5 ++- pbincli/settings.py | 4 +- pbincli/sjcl_simple.py | 88 ------------------------------------------ pbincli/transports.py | 11 +++++- 4 files changed, 15 insertions(+), 93 deletions(-) delete mode 100644 pbincli/sjcl_simple.py diff --git a/cli b/cli index 09a95e0..e89977f 100755 --- a/cli +++ b/cli @@ -18,12 +18,15 @@ def main(): 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)") + choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of text (default: plaintext)") + send_parser.add_argument("-S", "--server", help="Set server to work with") + send_parser.add_argument("-P", "--proxy", help="Proxy address (example: socks5://127.0.0.1:9050)") send_parser.add_argument("-t", "--text", help="comment in quotes. Ignored if used stdin") 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("--dry", default=False, action="store_true", help="invoke dry run") send_parser.add_argument("-f", "--file", help="example: image.jpg or full path to file") + send_parser.add_argument("stdin", help="input paste text from stdin", nargs="?", type=argparse.FileType("r"), default=sys.stdin) send_parser.set_defaults(func=pbincli.actions.send) diff --git a/pbincli/settings.py b/pbincli/settings.py index a39d266..b539dd5 100644 --- a/pbincli/settings.py +++ b/pbincli/settings.py @@ -2,8 +2,8 @@ def init(): global server, proxies, useproxy # Edit that variables - server = "http://paste.i2pd.xyz/" - proxies = {'http': 'http://127.0.0.1:4444'} + server = "https://paste.i2pd.xyz/" + proxies = {'socks5': 'socks5://127.0.0.1:9050'} # True/False useproxy = False diff --git a/pbincli/sjcl_simple.py b/pbincli/sjcl_simple.py deleted file mode 100644 index 74bd6eb..0000000 --- a/pbincli/sjcl_simple.py +++ /dev/null @@ -1,88 +0,0 @@ -import os -from base64 import b64decode, b64encode - -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes -from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC -from cryptography.hazmat.backends import default_backend - - -_BACKEND = default_backend() - - -def decrypt(pwd, json): - iv = b64decode(json['iv']) - ct = b64decode(json['ct']) - salt = b64decode(json['salt']) - ts = json['ts'] / 8 - - tag_start = len(ct) - ts - tag = ct[tag_start:] - ciphertext = ct[:tag_start] - - mode_class = getattr(modes, json['mode'].upper()) - algo_class = getattr(algorithms, json['cipher'].upper()) - - kdf = _kdf(json['ks'], iters=json['iter'], salt=salt)[0] - key = kdf.derive(pwd) - cipher = Cipher(algo_class(key), - mode_class(iv, tag, min_tag_length=ts), - backend=_BACKEND) - - dec = cipher.decryptor() - result = dec.update(ciphertext) + dec.finalize() - return result - - -def encrypt(pwd, plaintext, salt_in=None, mode='gcm', algorithm='aes', - keysize=256, tagsize=128, iters=10000): - ts = tagsize / 8 - - mode_class = getattr(modes, mode.upper()) - algo_class = getattr(algorithms, algorithm.upper()) - - iv = os.urandom(16) - kdf, salt = _kdf(keysize, iters, salt_in) - key = kdf.derive(pwd) - cipher = Cipher(algo_class(key), - mode_class(iv, min_tag_length=ts), - backend=_BACKEND) - - enc = cipher.encryptor() - ciphertext = enc.update(plaintext) + enc.finalize() - - json = { - "v": 1, - "iv": b64encode(iv), - "salt": b64encode(salt), - "ct": b64encode(ciphertext + enc.tag[:ts]), - "iter": iters, - "ks": keysize, - "ts": tagsize, - "mode": mode, - "cipher": algorithm, - "adata": "" - } - return json - - -def _kdf(keysize=256, iters=10000, salt=None, **kwargs): - kdf_salt = salt or os.urandom(8) - kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), - length=keysize / 8, - salt=kdf_salt, - iterations=iters, - backend=_BACKEND) - - return kdf, kdf_salt - - -if __name__ == "__main__": - import json - - blob = '{"iv":"/6dKRRAOZ60oyumLMQsBtg==","v":1,"iter":256000,"ks":128,"ts":64,"mode":"gcm","adata":"","cipher":"aes","salt":"s8+LFcBmbcc=","ct":"wTapp5CWmD6SFA=="}' - data = json.loads(blob) - result = decrypt('pwd', data) - assert result == "hi" - - print(decrypt('pwd', encrypt('pwd', result, tagsize=64))) diff --git a/pbincli/transports.py b/pbincli/transports.py index eb09e80..ce61dc9 100644 --- a/pbincli/transports.py +++ b/pbincli/transports.py @@ -3,14 +3,21 @@ import pbincli.settings class privatebin(object): def __init__(self): - self.server = pbincli.settings.server + if args.server: + self.server = args.server + else: + self.server = pbincli.settings.server + self.headers = {'X-Requested-With': 'JSONHttpRequest'} - if pbincli.settings.useproxy: + if args.proxy: + self.proxies = {args.proxy.split('://')[0]: args.proxy} + elif pbincli.settings.useproxy: self.proxies = pbincli.settings.proxies else: self.proxies = {} + def post(self, request): r = requests.post(url = self.server, headers = self.headers, proxies = self.proxies, data = request) return r.text