zoukankan      html  css  js  c++  java
  • 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
    Server: nginx/1.10.0 (CentOS)
    Date: ' + time_str +' GMT
    Content-Type: text/html
    Last-Modified: ' + time_str + ' GMT
    Connection: close
    ETag: W/"583bbb00-264"
    Content-Length: 612
    '+"""
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
        body {
             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分析一下,蜜罐就露出马脚~

  • 相关阅读:
    Jmeter-跨线程组传参
    HTTP请求方法:GET和POST
    Java之数组的遍历、最大值、最小值、、总和、平均值、数组的复制,反转,查找(线性查找、二分法查找)
    Java数组
    Java代码题2
    Java程序流程控制
    Java代码题
    JAVA基本语法
    Java语言特性与基础
    jmeter接口测试带有token的请求
  • 原文地址:https://www.cnblogs.com/xiaoxiaoleo/p/6358126.html
Copyright © 2011-2022 走看看