HoneyPy 模拟Nginx服务器脚本

HoneyPy是一个Python写的低交互式蜜罐,可以通过自定义Plugins的方式来配置不同的场景。这里是一个模拟Nginx空白页面的代码:

# Auth xiaoxiaoleo
# http://www.cnblogs.com/xiaoxiaoleo/
#  

from twisted.internet import protocol, reactor, endpoints
from twisted.python import log
import uuid
import datetime 
### START CUSTOM IMPORTS ###

############################

class Web(protocol.Protocol): ### Set custom protocol class name
	localhost   = None
	remote_host = None
	session     = None

	### START CUSTOM VARIABLES ###############################################################
	
	##########################################################################################
	
	# handle events
	def connectionMade(self):
		self.connect()

		### START CUSTOM CODE ####################################################################
		
		##########################################################################################

	def dataReceived(self, data):
		self.rx(data)

		### START CUSTOM CODE ####################################################################
                time_str = datetime.datetime.now().strftime('%d %b %Y %H:%M:%S')
		response = 'HTTP/1.1 200 OK\r\nServer: nginx/1.10.0 (CentOS)\r\nDate: ' + time_str +' GMT\r\nContent-Type: text/html\r\nLast-Modified: ' + time_str + ' GMT\r\nConnection: close\r\nETag: W/"583bbb00-264"\r\nContent-Length: 612\r\n'+"""
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
"""
		self.tx(response)

		##########################################################################################

	### START CUSTOM FUNCTIONS ###################################################################

	##############################################################################################

	def connect(self):
		self.local_host  = self.transport.getHost()
		self.remote_host = self.transport.getPeer()
		self.session     = uuid.uuid1()
		log.msg('%s %s CONNECT %s %s %s %s %s' % (self.session, self.remote_host.type, self.local_host.host, self.local_host.port, self.factory.name, self.remote_host.host, self.remote_host.port))

	def tx(self, data):
		log.msg('%s %s TX %s %s %s %s %s %s' % (self.session, self.remote_host.type, self.local_host.host, self.local_host.port, self.factory.name, self.remote_host.host, self.remote_host.port, data.encode("hex")))
		self.transport.write(data)

	def rx(self, data):
		log.msg('%s %s RX %s %s %s %s %s %s' % (self.session, self.remote_host.type, self.local_host.host, self.local_host.port, self.factory.name, self.remote_host.host, self.remote_host.port, data.encode("hex")))

class pluginFactory(protocol.Factory):
	protocol = Web ### Set protocol to custom protocol class name
	
	def __init__(self, name=None):
		self.name = name or 'HoneyPy'

  

 

效果:

HTTP header:

HTML:

 

 脚本写得不够完美,对Etag和Last-Modified分析一下,蜜罐就露出马脚~

posted @ 2017-01-30 15:41  小小leo  阅读(424)  评论(0编辑  收藏  举报