You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import hashlib,binascii
import tkinter as tk
import tkinter.messagebox
import tkinter.ttk
import sys
import keyboard
import time
from multiprocessing import Pool
g = ['!','@','#','$','%','^','&','*','0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
Z=10**8
l1=20
checkPointHeavy=[0.0416,0.0855,0.1316,0.2318,0.2870,0.4117,0.5684,0.7381]
checkpoint=[]
for i in checkPointHeavy:
if int(i*l1) not in checkpoint:
checkpoint.append(int(i*l1))
rainbowTableSum=20
rainbowTable= {}
rainbowTables=[]
coefficient=[]
coefficientCheckPoint=''
win=tk.Tk()
win.title('彩虹表破解程序')
win.geometry('400x400')
entry=tk.Entry(win,width=50)
entry.place(x=20,y=100)
cobox=tkinter.ttk.Combobox(win)
cobox.place()
cobox['value']=('NTLM','sha256')
cobox.place(x=20,y=20)
def NTLMOrSha256(str,mode):
if mode==0:
return binascii.hexlify(hashlib.new('md4', str.encode('utf-16le')).digest())
elif mode==1:
return binascii.hexlify(hashlib.new('sha256',str.encode('utf-8')).digest())
def R(x,i,r,l2):
x=int(x.decode(),16)
x+=i
x=str(hex(x))[2:]
str1=''
for j in range(l2):
x1=(int(x[j%len(x)],16)+int(x[(j+l2)%len(x)],16)+Z//(i+1)+r)%len(g)
str1+=g[x1]
return str1
def select(lenth):
f=open('rockyou1.txt','r')
list1=list(f.read().split('\n'))
f.close()
coefficient=[]
for i in list1:
if len(i)==lenth:
coefficient.append(i)
return coefficient
def createRainbowTableProcess(*cRTP):
dic=cRTP[0][0]
st=cRTP[0][1]
r=cRTP[0][2]
rs=cRTP[0][3]
mode=cRTP[0][4]
for t in st:
dic[t] = ''
x = t
j = 0
coefficientCheckPoint = ''
for i in range(l1):
x = NTLMOrSha256(x,mode)
if i == int(checkpoint[j]):
coefficientCheckPoint += str(int(x.decode(), 16) & 1)
j = (j + 1) % len(checkpoint)
x = R(x, i + 1, r, rs)
c = int(coefficientCheckPoint, 2)
if c <= 15:
x = x[:-2] + '0' + hex(c)[2:]
else:
x = x[:-2] + hex(int(coefficientCheckPoint, 2))[2:]
dic[t] = x
dic_key=list(dic.keys())
dic_value=list(dic.values())
return dic_key,dic_value
def createRainbowTable():
if cobox.get()!='NTLM':
mode=1
else:
mode=0
pool = Pool()
global coefficientCheckPoint
rs=5
#表头输入
st=select(rs)
while st!=[]:
rainbowTable={}
for r in range(rainbowTableSum):
dic = {}
if r!=0:
st=list(rainbowTable[r-1].values())
args=([dic,st,r,rs,mode],)
returnDic=pool.map(createRainbowTableProcess,args)
returnDic=dict(zip(returnDic[0][0],returnDic[0][1]))
rainbowTable[r]=returnDic
rainbowTables.append(rainbowTable)
rs+=1
st = select(rs)
pool.close()
pool.join()
returnDict[0]=rainbowTables
returnDict[1]=mode
def useRainbowTableProcess(*uRTP):
key=uRTP[0][0]
value=uRTP[0][1]
inputValue=uRTP[0][2]
mode=uRTP[0][3]
returntutle=[]
for k_value, v_value in value.items():
for i in range(l1, 0, -1):
coefficientCheckPoint = ''
for execR in range(l1 + 1 - i):
if execR == 0:
inputValue1 = R(inputValue, i + execR, key, len(k_value))
if i + execR - 1 in checkpoint:
coefficientCheckPoint += str(int(inputValue.decode(), 16) & 1)
else:
inputValue1 = NTLMOrSha256(inputValue1,mode)
if i + execR - 1 in checkpoint:
coefficientCheckPoint += str(int(inputValue1.decode(), 16) & 1)
inputValue1 = R(inputValue1, i + execR, key, len(k_value))
if i==1 and len(k_value)==6:
pass
if inputValue1[:-2] == v_value[:-2]:
if len(coefficientCheckPoint) and int(bin(int(v_value[-2:], 16))[2:].zfill(8)[0-len(coefficientCheckPoint):],2) != int(coefficientCheckPoint, 2):
continue
returntutle.append((k_value, i - 1, key))
return returntutle
def useRainbowTable(rainbowTables,mode):
inputValue = entry.get().rstrip()
inputValue = inputValue.encode()
returnValues=[]
returnValue=[]
pool=Pool()
global coefficientCheckPoint
for table in rainbowTables:
for key,value in table.items():
args = ([key, value, inputValue,mode],)
returnValues.append(pool.map(useRainbowTableProcess,args))
for i in returnValues:
if i[0]!=[]:
for j in i:
returnValue.append(j)
pool.close()
pool.join()
if returnValue != []:
t = 1
for i in returnValue:
rainbowtop,location,judgetable = i[0][0], i[0][1], i[0][2]
length = len(rainbowtop)
for i in range(location):
rainbowtop = NTLMOrSha256(rainbowtop, mode)
rainbowtop = R(rainbowtop, i + 1, judgetable, length)
decyptstr=rainbowtop
decyptstr_NTLM=str(NTLMOrSha256(rainbowtop, mode))[2:-1]
if decyptstr_NTLM == inputValue:
tkinter.messagebox.showinfo(title='提示信息', message=decyptstr)
t = 0
if t:
print("破解失败这可能是由于输入的hash值不一致导致的")
else:
print("破解失败!")
returnDict = {}
def main():
btn1 = tk.Button(win, text='创建彩虹表', command=lambda: createRainbowTable())
btn1.place(x=260, y=98)
# rainbowTableFile=open('rainbowtable.txt','w')
# count=0
# for i in returnDict[0]:
# for j in i:
# for k in i[j]:
# rainbowTableFile.write(str(k)+':'+str(i[j][k])+'\t')
# count = (count+1)%5
# if count==4:
# rainbowTableFile.write('\n')
btn=tk.Button(win,text='破解',command=lambda :useRainbowTable(returnDict[0],returnDict[1]))
btn.place(x=360,y=98)
win.mainloop()
if __name__=='__main__':
main()