Author Topic: [Python] Assymetric Irc Key pass  (Read 552 times)

0 Members and 1 Guest are viewing this topic.

Offline cr4zi8

  • Serf
  • *
  • Posts: 29
  • Cookies: 26
    • View Profile
[Python] Assymetric Irc Key pass
« on: June 19, 2015, 09:38:00 pm »
Plugin made for hexchat or xchat.

Installation for Hexcha(for xchat replace every hexchat with xchat :P )t:
1. put the python file in the addons directory for hexchat (usually ~/.config/hexchat/addons/
2. Install pycrypto: https://www.dlitz.net/software/pycrypto/
3. If you are on Mac OSX you may need to compile pycrypto then drop the compiled library into the addons folder

Usage:
1. Type /invch to invite a user to a chat the syntax is /invch [nick] [key phrase for Fish] [channel to chat on]
2. User will receive a pm an should type /a [name of person you are accepting]
3. The keys will now be set talk freely
4. do /delkey [channel name] to end the chat

Code: (Python) [Select]
import sys
import hexchat
import re
from os.path import expanduser
home = expanduser("~")
sys.path.insert(0,home+"/.config/hexchat/addons/")
from Crypto.Cipher import AES
from Crypto.PublicKey import RSA
from Crypto import Random
__module_name__="rsa2fish"
__module_description__="rsa2fish"
__module_version__="1.0"
def rawblock(r):
    check=r.find(':')
    print(check)
    t=""
    i=0
    for i, x in enumerate (r):
        if x ==':':
            t+=chr(int(r[i+1:i+3],16))
    return t;

def setkey():
    pkey=RSA.generate(2048)
    return pkey

# encr=AES.new('abcdefghijklmnopqrstuvwxyzaaaaaa', AES.MODE_ECB)
# encr.block_size=16
# encr.key_size=32
# s=encr.encrypt("hi"+"XXXXXXXXXXXXXX")
#
# c=""
# for x in s:
#     c+=(str(':')+str(x.encode('hex')))
# print(c)
#
#
#
#
#  #   print(chr(int(c[check+1:check+3],16)))
# f=rawblock(c)
#
#
#
# print(f)
# print(encr.decrypt(f))
# pkey=setkey()
# print pkey.exportKey()
invlist=[]
inving=[]
password=[]
global privkey;
global key;
global m;
global chan;
m="";
chan="";
def finacc(arg1,arg2,arg3):
    list=arg2[0].split();

    for ind,x in enumerate(invlist):
        global m;
        global privkey;
        global chan
        if list[0]==x:
            if list[1].find("endofstr")==-1:
                m=m+list[1][3:]
            else:
                m=m+list[1][3:list[1].find("endofstr")-1]
                invlist.remove(invlist[ind])
                rstr=rawblock(m)
                hexchat.prnt("The command is:setkey "+chan+" "+privkey.decrypt(rstr))
                hexchat.command("setkey "+chan+" "+privkey.decrypt(rstr));
                hexchat.prnt("Your key is now "+privkey.decrypt(rstr))
                m="";
                return hexchat.EAT_ALL;

def fininv(arg1,arg2,arg3):
    global chan;
    list=arg2[0].split();
    for ind,x in enumerate(inving):
        if list[0]==x and list[1]=="ssh-rsa":
            hexchat.prnt("Public key received");
            key=RSA.importKey(list[1]+" "+list[2])
            pas=password[ind]
            stv=key.encrypt(pas,2);
            c=[""]
            c[0]="avx"
            i=0
            size=3
            for d in stv[0]:
                if size>200:
                    i=i+1
                    size=3
                    c.append("avx")
                c[i]+=(str(':')+str(d.encode('hex')))
                size=size+3
            c[i]+=":endofstr"



            for sbv in c:
                if len(sbv) > 0:
                    hexchat.command("msg "+list[0]+" "+sbv)
            password.remove(password[ind])
            inving.remove(inving[ind])
            hexchat.prnt("The command is:setkey "+chan+" "+pas)
            hexchat.command("setkey "+chan+" "+pas);
            return hexchat.EAT_ALL;
def acceptcheck(arg1,arg2,arg3):
    list=arg2[0].split();
    if list[1].find("sendkey")!=-1:
        hexchat.prnt(list[0]+" wants to chat via rsa2fish on "+ list[2] +" /a to accept!");
        global chan;
        chan=list[2];
        invlist.append(list[0])
        return hexchat.EAT_ALL;
    return
def accept(arg1,arg2,arg3):
    list=arg2[1].split();
    global privkey;
    for x in invlist:
        if x == list[0]:
            hexchat.prnt("accepting "+ x)
            pkey=setkey();
            privkey=pkey;
            p=[]
            #p.append(pkey.exportKey('OpenSSH'));
            p.append((pkey.publickey().exportKey('OpenSSH')))
            hexchat.prnt(str(len(p[0])))
            for y in p:
                hexchat.command("msg "+x+" "+y)
            hexchat.hook_print("Private Message to Dialog", finacc)

        return hexchat.EAT_ALL;
    hexchat.prnt("No user invs from "+x)
    return hexchat.EAT_ALL;




def inv(fun,args,true):
        list=args[1].split();
        global chan;
        if len(list)==3:
            hexchat.prnt("Inviting "+list[0]+" with the password "+list[1]);
            hexchat.command("msg "+list[0]+" sendkey "+ list[2]);
            inving.append(list[0]);
            password.append(list[1])
            hexchat.hook_print("Private Message to Dialog", fininv)
            chan=list[2];

        else:
            hexchat.prnt("1:Usage: /invch [user] [key phrase] [channel]")
        return hexchat.EAT_ALL;
hexchat.prnt("\002\00304rsa2fish loaded...")
hexchat.hook_print("Private Message to Dialog", acceptcheck)
hexchat.hook_command("invch",inv, help="no")
hexchat.hook_command("a",accept, help="no")



Bugs:
Currently hooks are left open stupidly :P
There is a DOS vuln cookies to those who find it ;)
Something has been going on one of my computers where it encrypts fine but for some reason it will not decrpt the other user's message, I think that might be a bug with hexchat's fish implementation (please report this if you see it so I can start to try to narrow down causes)
« Last Edit: June 19, 2015, 09:38:35 pm by cr4zi8 »