Browse Source

start adding server and proxy parameters

pull/6/head
R4SAS 7 years ago
parent
commit
cb9703864e
  1. 5
      cli
  2. 4
      pbincli/settings.py
  3. 88
      pbincli/sjcl_simple.py
  4. 9
      pbincli/transports.py

5
cli

@ -18,12 +18,15 @@ def main():
send_parser.add_argument("-E", "--expire", default="1day", action="store", 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)") 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", 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("-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("-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("-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("--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("-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.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) send_parser.set_defaults(func=pbincli.actions.send)

4
pbincli/settings.py

@ -2,8 +2,8 @@ def init():
global server, proxies, useproxy global server, proxies, useproxy
# Edit that variables # Edit that variables
server = "http://paste.i2pd.xyz/" server = "https://paste.i2pd.xyz/"
proxies = {'http': 'http://127.0.0.1:4444'} proxies = {'socks5': 'socks5://127.0.0.1:9050'}
# True/False # True/False
useproxy = False useproxy = False

88
pbincli/sjcl_simple.py

@ -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)))

9
pbincli/transports.py

@ -3,14 +3,21 @@ import pbincli.settings
class privatebin(object): class privatebin(object):
def __init__(self): def __init__(self):
if args.server:
self.server = args.server
else:
self.server = pbincli.settings.server self.server = pbincli.settings.server
self.headers = {'X-Requested-With': 'JSONHttpRequest'} 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 self.proxies = pbincli.settings.proxies
else: else:
self.proxies = {} self.proxies = {}
def post(self, request): def post(self, request):
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